ExPostFacto.TradeStats.SystemQuality (ex_post_facto v0.2.1)

View Source

Calculates the System Quality Number (SQN) for trading performance analysis.

The SQN measures the quality of a trading system by analyzing the distribution of trade results. It was developed by Van Tharp and is used to evaluate whether a trading system's performance is due to skill or luck.

SQN = (Average Trade Result / Standard Deviation of Trade Results) * sqrt(Number of Trades)

SQN Interpretation:

  • Below 1.6: Poor system
  • 1.6 to 1.9: Below average but tradeable
  • 2.0 to 2.4: Average system
  • 2.5 to 2.9: Good system
  • 3.0 to 5.0: Excellent system
  • 5.0 to 6.9: Superb system
  • Above 7.0: Too good to be true (likely curve-fitted)

Summary

Functions

Calculates the confidence level for the SQN.

Returns a textual interpretation of the SQN value.

Calculates the System Quality Number (SQN).

Functions

confidence_level(result)

@spec confidence_level(
  result :: %ExPostFacto.Result{
    alpha: term(),
    annual_volatility: term(),
    average_draw_down_duration: term(),
    average_draw_down_percentage: term(),
    average_losing_trade: term(),
    average_trade_by_percentage: term(),
    average_trade_duration: term(),
    average_winning_trade: term(),
    best_trade_by_percentage: term(),
    beta: term(),
    cagr_pct: term(),
    calmar_ratio: term(),
    data_points: term(),
    duration: term(),
    end_date: term(),
    expectancy: term(),
    expectancy_pct: term(),
    gross_loss: term(),
    gross_profit: term(),
    information_ratio: term(),
    is_position_open: term(),
    kelly_criterion: term(),
    kelly_interpretation: term(),
    largest_losing_trade: term(),
    largest_winning_trade: term(),
    market_correlation: term(),
    max_draw_down: term(),
    max_draw_down_duration: term(),
    max_draw_down_percentage: term(),
    max_trade_duration: term(),
    profit_factor: term(),
    sharpe_ratio: term(),
    sortino_ratio: term(),
    sqn: term(),
    sqn_interpretation: term(),
    start_date: term(),
    starting_balance: term(),
    total_profit_and_loss: term(),
    total_return_pct: term(),
    tracking_error: term(),
    trade_pairs: term(),
    trades_count: term(),
    win_count: term(),
    win_rate: term(),
    worst_trade_by_percentage: term()
  }
) :: float()

Calculates the confidence level for the SQN.

Higher confidence levels indicate more reliable results.

sqn_interpretation(sqn)

@spec sqn_interpretation(sqn :: float()) :: String.t()

Returns a textual interpretation of the SQN value.

system_quality_number(result)

@spec system_quality_number(
  result :: %ExPostFacto.Result{
    alpha: term(),
    annual_volatility: term(),
    average_draw_down_duration: term(),
    average_draw_down_percentage: term(),
    average_losing_trade: term(),
    average_trade_by_percentage: term(),
    average_trade_duration: term(),
    average_winning_trade: term(),
    best_trade_by_percentage: term(),
    beta: term(),
    cagr_pct: term(),
    calmar_ratio: term(),
    data_points: term(),
    duration: term(),
    end_date: term(),
    expectancy: term(),
    expectancy_pct: term(),
    gross_loss: term(),
    gross_profit: term(),
    information_ratio: term(),
    is_position_open: term(),
    kelly_criterion: term(),
    kelly_interpretation: term(),
    largest_losing_trade: term(),
    largest_winning_trade: term(),
    market_correlation: term(),
    max_draw_down: term(),
    max_draw_down_duration: term(),
    max_draw_down_percentage: term(),
    max_trade_duration: term(),
    profit_factor: term(),
    sharpe_ratio: term(),
    sortino_ratio: term(),
    sqn: term(),
    sqn_interpretation: term(),
    start_date: term(),
    starting_balance: term(),
    total_profit_and_loss: term(),
    total_return_pct: term(),
    tracking_error: term(),
    trade_pairs: term(),
    trades_count: term(),
    win_count: term(),
    win_rate: term(),
    worst_trade_by_percentage: term()
  }
) :: float()

Calculates the System Quality Number (SQN).

Parameters

  • result: The backtest result containing trade pairs

Returns

Float representing the SQN value