added daily sharpe ratio test and modified hyperopt_loss_sharpe_daily

This commit is contained in:
Yazeed Al Oyoun 2020-01-31 22:16:44 +01:00
parent 323192faaf
commit 3eda434fcf
2 changed files with 27 additions and 3 deletions

View File

@ -1,5 +1,5 @@
"""
SharpeHyperOptLoss
SharpeHyperOptLossDaily
This module defines the alternative HyperOptLoss class which can be used for
Hyperoptimization.
@ -43,7 +43,7 @@ class SharpeHyperOptLossDaily(IHyperOptLoss):
* 100.0
)
if np.std(results.profit_percent) != 0.0:
if (np.std(sum_daily.profit_percent) != 0.):
sharp_ratio = (
sum_daily["profit_percent"].mean()
/ sum_daily["profit_percent"].std()

View File

@ -42,7 +42,13 @@ def hyperopt_results():
'profit_percent': [-0.1, 0.2, 0.3],
'profit_abs': [-0.2, 0.4, 0.6],
'trade_duration': [10, 30, 10],
'sell_reason': [SellType.STOP_LOSS, SellType.ROI, SellType.ROI]
'sell_reason': [SellType.STOP_LOSS, SellType.ROI, SellType.ROI],
'close_time':
[
datetime(2019, 1, 1, 9, 26, 3, 478039),
datetime(2019, 2, 1, 9, 26, 3, 478039),
datetime(2019, 3, 1, 9, 26, 3, 478039)
]
}
)
@ -336,6 +342,24 @@ def test_sharpe_loss_prefers_higher_profits(default_conf, hyperopt_results) -> N
assert under > correct
def test_sharpe_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_under = hyperopt_results.copy()
results_under['profit_percent'] = hyperopt_results['profit_percent'] / 2
default_conf.update({'hyperopt_loss': 'SharpeHyperOptLossDaily'})
hl = HyperOptLossResolver.load_hyperoptloss(default_conf)
correct = hl.hyperopt_loss_function(hyperopt_results, len(hyperopt_results),
datetime(2019, 1, 1), datetime(2019, 5, 1))
over = hl.hyperopt_loss_function(results_over, len(hyperopt_results),
datetime(2019, 1, 1), datetime(2019, 5, 1))
under = hl.hyperopt_loss_function(results_under, len(hyperopt_results),
datetime(2019, 1, 1), datetime(2019, 5, 1))
assert over < correct
assert under > correct
def test_onlyprofit_loss_prefers_higher_profits(default_conf, hyperopt_results) -> None:
results_over = hyperopt_results.copy()
results_over['profit_percent'] = hyperopt_results['profit_percent'] * 2