Fix : exit if no losing trades before applyting slippage

This commit is contained in:
Pialat 2019-09-12 16:07:58 +02:00
parent 6958160ae6
commit 78ae177a5b

View File

@ -32,6 +32,10 @@ class CalmarHyperOptLoss(IHyperOptLoss):
Objective function, returns smaller number for better results Objective function, returns smaller number for better results
""" """
# exclude the case when no trade was lost
if(results.profit_percent.min() >= 0):
return MAX_LOSS
simulated_drawdowns = [] simulated_drawdowns = []
backtest_duration_years = ((max_date-min_date).days/365.2425) backtest_duration_years = ((max_date-min_date).days/365.2425)
@ -44,10 +48,6 @@ class CalmarHyperOptLoss(IHyperOptLoss):
sample_size = round(trade_count_average_per_year * SIMULATION_YEAR_DURATION) sample_size = round(trade_count_average_per_year * SIMULATION_YEAR_DURATION)
# exclude the case when no trade was lost
if(results.profit_percent.min() >= 0):
return MAX_LOSS
# simulate n years of run to define a median max drawdown # simulate n years of run to define a median max drawdown
for i in range(0, NB_SIMULATIONS): for i in range(0, NB_SIMULATIONS):
randomized_result = results.profit_percent.sample(n=sample_size, randomized_result = results.profit_percent.sample(n=sample_size,