feat: add SQN to backtest result

closes #11397
This commit is contained in:
Matthias
2025-03-02 15:47:30 +01:00
parent e1f6702932
commit ccfc690281
3 changed files with 5 additions and 0 deletions

View File

@@ -315,6 +315,7 @@ It contains some useful key metrics about performance of your strategy on backte
| Sortino | 1.88 | | Sortino | 1.88 |
| Sharpe | 2.97 | | Sharpe | 2.97 |
| Calmar | 6.29 | | Calmar | 6.29 |
| SQN | 2.45 |
| Profit factor | 1.11 | | Profit factor | 1.11 |
| Expectancy (Ratio) | -0.15 (-0.05) | | Expectancy (Ratio) | -0.15 (-0.05) |
| Avg. stake amount | 0.001 BTC | | Avg. stake amount | 0.001 BTC |
@@ -368,6 +369,7 @@ It contains some useful key metrics about performance of your strategy on backte
- `Sortino`: Annualized Sortino ratio. - `Sortino`: Annualized Sortino ratio.
- `Sharpe`: Annualized Sharpe ratio. - `Sharpe`: Annualized Sharpe ratio.
- `Calmar`: Annualized Calmar ratio. - `Calmar`: Annualized Calmar ratio.
- `SQN`: System Quality Number (SQN) - by Van Tharp.
- `Profit factor`: profit / loss. - `Profit factor`: profit / loss.
- `Avg. stake amount`: Average stake amount, either `stake_amount` or the average when using dynamic stake amount. - `Avg. stake amount`: Average stake amount, either `stake_amount` or the average when using dynamic stake amount.
- `Total trade volume`: Volume generated on the exchange to reach the above profit. - `Total trade volume`: Volume generated on the exchange to reach the above profit.

View File

@@ -312,6 +312,7 @@ def text_table_add_metrics(strat_results: dict) -> None:
("Sortino", f"{strat_results['sortino']:.2f}" if "sortino" in strat_results else "N/A"), ("Sortino", f"{strat_results['sortino']:.2f}" if "sortino" in strat_results else "N/A"),
("Sharpe", f"{strat_results['sharpe']:.2f}" if "sharpe" in strat_results else "N/A"), ("Sharpe", f"{strat_results['sharpe']:.2f}" if "sharpe" in strat_results else "N/A"),
("Calmar", f"{strat_results['calmar']:.2f}" if "calmar" in strat_results else "N/A"), ("Calmar", f"{strat_results['calmar']:.2f}" if "calmar" in strat_results else "N/A"),
("SQN", f"{strat_results['sqn']:.2f}" if "sqn" in strat_results else "N/A"),
( (
"Profit factor", "Profit factor",
( (

View File

@@ -16,6 +16,7 @@ from freqtrade.data.metrics import (
calculate_max_drawdown, calculate_max_drawdown,
calculate_sharpe, calculate_sharpe,
calculate_sortino, calculate_sortino,
calculate_sqn,
) )
from freqtrade.ft_types import BacktestResultType from freqtrade.ft_types import BacktestResultType
from freqtrade.util import decimals_per_coin, fmt_coin, get_dry_run_wallet from freqtrade.util import decimals_per_coin, fmt_coin, get_dry_run_wallet
@@ -468,6 +469,7 @@ def generate_strategy_stats(
"sortino": calculate_sortino(results, min_date, max_date, start_balance), "sortino": calculate_sortino(results, min_date, max_date, start_balance),
"sharpe": calculate_sharpe(results, min_date, max_date, start_balance), "sharpe": calculate_sharpe(results, min_date, max_date, start_balance),
"calmar": calculate_calmar(results, min_date, max_date, start_balance), "calmar": calculate_calmar(results, min_date, max_date, start_balance),
"sqn": calculate_sqn(results, start_balance),
"profit_factor": profit_factor, "profit_factor": profit_factor,
"backtest_start": min_date.strftime(DATETIME_PRINT_FORMAT), "backtest_start": min_date.strftime(DATETIME_PRINT_FORMAT),
"backtest_start_ts": int(min_date.timestamp() * 1000), "backtest_start_ts": int(min_date.timestamp() * 1000),