diff --git a/freqtrade/optimize/hyperopt_loss_sortino_daily.py b/freqtrade/optimize/hyperopt_loss_sortino_daily.py index 0739379f6..31482b981 100644 --- a/freqtrade/optimize/hyperopt_loss_sortino_daily.py +++ b/freqtrade/optimize/hyperopt_loss_sortino_daily.py @@ -47,11 +47,13 @@ class SortinoHyperOptLossDaily(IHyperOptLoss): ) total_profit = sum_daily["profit_percent_after_slippage"] - risk_free_rate + total_downside = sum_daily['downside_returns'] - risk_free_rate expected_returns_mean = total_profit.mean() - results['downside_returns'] = 0 - results.loc[total_profit < 0, 'downside_returns'] = results['profit_percent_after_slippage'] - down_stdev = results['downside_returns'].std() + sum_daily['downside_returns'] = 0 + sum_daily.loc[total_profit < 0, + 'downside_returns'] = sum_daily['profit_percent_after_slippage'] + down_stdev = total_downside.std() if (down_stdev != 0.): sortino_ratio = expected_returns_mean / down_stdev * math.sqrt(days_in_year) diff --git a/tests/optimize/test_hyperopt.py b/tests/optimize/test_hyperopt.py index 5cdbe7b5a..a2a98b0fb 100644 --- a/tests/optimize/test_hyperopt.py +++ b/tests/optimize/test_hyperopt.py @@ -380,9 +380,9 @@ def test_sortino_loss_prefers_higher_profits(default_conf, hyperopt_results) -> def test_sortino_loss_daily_prefers_higher_profits(default_conf, hyperopt_results) -> None: results_over = hyperopt_results.copy() - results_over['profit_percent'] = hyperopt_results['profit_percent'] * 2 + results_over['profit_percent_after_slippage'] = hyperopt_results['profit_percent_after_slippage'] * 2 results_under = hyperopt_results.copy() - results_under['profit_percent'] = hyperopt_results['profit_percent'] / 2 + results_under['profit_percent_after_slippage'] = hyperopt_results['profit_percent_after_slippage'] / 2 default_conf.update({'hyperopt_loss': 'SortinoHyperOptLossDaily'}) hl = HyperOptLossResolver.load_hyperoptloss(default_conf)