From 86ba7dae92467118e225f4e23c9c00c6600f28ac Mon Sep 17 00:00:00 2001 From: Stefano Ariestasia Date: Sat, 7 Jan 2023 08:56:40 +0900 Subject: [PATCH] change sharpe hyperopt loss --- .../hyperopt_loss/hyperopt_loss_sharpe.py | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/freqtrade/optimize/hyperopt_loss/hyperopt_loss_sharpe.py b/freqtrade/optimize/hyperopt_loss/hyperopt_loss_sharpe.py index 2c8ae552d..0db14adab 100644 --- a/freqtrade/optimize/hyperopt_loss/hyperopt_loss_sharpe.py +++ b/freqtrade/optimize/hyperopt_loss/hyperopt_loss_sharpe.py @@ -22,25 +22,13 @@ class SharpeHyperOptLoss(IHyperOptLoss): @staticmethod def hyperopt_loss_function(results: DataFrame, trade_count: int, min_date: datetime, max_date: datetime, - *args, **kwargs) -> float: + config: Config, *args, **kwargs) -> float: """ Objective function, returns smaller number for more optimal results. Uses Sharpe Ratio calculation. """ - total_profit = results["profit_ratio"] - days_period = (max_date - min_date).days - - # adding slippage of 0.1% per trade - total_profit = total_profit - 0.0005 - expected_returns_mean = total_profit.sum() / days_period - up_stdev = np.std(total_profit) - - if up_stdev != 0: - sharp_ratio = expected_returns_mean / up_stdev * np.sqrt(365) - else: - # Define high (negative) sharpe ratio to be clear that this is NOT optimal. - sharp_ratio = -20. - + starting_balance = config['dry_run_wallet'] + sharp_ratio = calculate_sharpe(results, min_date, max_date, starting_balance) # print(expected_returns_mean, up_stdev, sharp_ratio) return -sharp_ratio