Adjust handling of zero stdev in loss functions
This commit is contained in:
parent
c49fefc94d
commit
73c19da4b9
@ -36,7 +36,7 @@ class SharpeHyperOptLoss(IHyperOptLoss):
|
|||||||
expected_returns_mean = total_profit.sum() / days_period
|
expected_returns_mean = total_profit.sum() / days_period
|
||||||
up_stdev = np.std(total_profit)
|
up_stdev = np.std(total_profit)
|
||||||
|
|
||||||
if (np.std(total_profit) != 0.):
|
if up_stdev != 0:
|
||||||
sharp_ratio = expected_returns_mean / up_stdev * np.sqrt(365)
|
sharp_ratio = expected_returns_mean / up_stdev * np.sqrt(365)
|
||||||
else:
|
else:
|
||||||
# Define high (negative) sharpe ratio to be clear that this is NOT optimal.
|
# Define high (negative) sharpe ratio to be clear that this is NOT optimal.
|
||||||
|
@ -51,7 +51,7 @@ class SharpeHyperOptLossDaily(IHyperOptLoss):
|
|||||||
expected_returns_mean = total_profit.mean()
|
expected_returns_mean = total_profit.mean()
|
||||||
up_stdev = total_profit.std()
|
up_stdev = total_profit.std()
|
||||||
|
|
||||||
if (up_stdev != 0.):
|
if up_stdev != 0:
|
||||||
sharp_ratio = expected_returns_mean / up_stdev * math.sqrt(days_in_year)
|
sharp_ratio = expected_returns_mean / up_stdev * math.sqrt(days_in_year)
|
||||||
else:
|
else:
|
||||||
# Define high (negative) sharpe ratio to be clear that this is NOT optimal.
|
# Define high (negative) sharpe ratio to be clear that this is NOT optimal.
|
||||||
|
@ -39,7 +39,7 @@ class SortinoHyperOptLoss(IHyperOptLoss):
|
|||||||
results.loc[total_profit < 0, 'downside_returns'] = results['profit_percent']
|
results.loc[total_profit < 0, 'downside_returns'] = results['profit_percent']
|
||||||
down_stdev = np.std(results['downside_returns'])
|
down_stdev = np.std(results['downside_returns'])
|
||||||
|
|
||||||
if np.std(total_profit) != 0.0:
|
if down_stdev != 0:
|
||||||
sortino_ratio = expected_returns_mean / down_stdev * np.sqrt(365)
|
sortino_ratio = expected_returns_mean / down_stdev * np.sqrt(365)
|
||||||
else:
|
else:
|
||||||
# Define high (negative) sortino ratio to be clear that this is NOT optimal.
|
# Define high (negative) sortino ratio to be clear that this is NOT optimal.
|
||||||
|
@ -59,7 +59,7 @@ class SortinoHyperOptLossDaily(IHyperOptLoss):
|
|||||||
# where P = sum_daily["profit_percent_after_slippage"]
|
# where P = sum_daily["profit_percent_after_slippage"]
|
||||||
down_stdev = math.sqrt((total_downside**2).sum() / len(total_downside))
|
down_stdev = math.sqrt((total_downside**2).sum() / len(total_downside))
|
||||||
|
|
||||||
if (down_stdev != 0.):
|
if down_stdev != 0:
|
||||||
sortino_ratio = expected_returns_mean / down_stdev * math.sqrt(days_in_year)
|
sortino_ratio = expected_returns_mean / down_stdev * math.sqrt(days_in_year)
|
||||||
else:
|
else:
|
||||||
# Define high (negative) sortino ratio to be clear that this is NOT optimal.
|
# Define high (negative) sortino ratio to be clear that this is NOT optimal.
|
||||||
|
Loading…
Reference in New Issue
Block a user