fix flake 8 compliancy

This commit is contained in:
Pialat 2019-09-16 15:52:56 +02:00
parent a246b2ec3f
commit ba430a3a27

View File

@ -44,6 +44,7 @@ def hyperopt_results():
} }
) )
@pytest.fixture(scope='function') @pytest.fixture(scope='function')
def hyperopt_results_min_median_drawdown(): def hyperopt_results_min_median_drawdown():
return pd.DataFrame( return pd.DataFrame(
@ -52,10 +53,12 @@ def hyperopt_results_min_median_drawdown():
'profit_percent': [0.1, 0.1, -0.1, 0.1, 0.1], 'profit_percent': [0.1, 0.1, -0.1, 0.1, 0.1],
'profit_abs': [0.2, 0.2, -0.2, 0.2, 0.2], 'profit_abs': [0.2, 0.2, -0.2, 0.2, 0.2],
'trade_duration': [10, 30, 10, 30, 10], 'trade_duration': [10, 30, 10, 30, 10],
'sell_reason': [SellType.ROI, SellType.ROI, SellType.STOP_LOSS,SellType.ROI, SellType.ROI] 'sell_reason':
[SellType.ROI, SellType.ROI, SellType.STOP_LOSS, SellType.ROI, SellType.ROI]
} }
) )
@pytest.fixture(scope='function') @pytest.fixture(scope='function')
def hyperopt_results_max_median_drawdown(): def hyperopt_results_max_median_drawdown():
return pd.DataFrame( return pd.DataFrame(
@ -64,10 +67,12 @@ def hyperopt_results_max_median_drawdown():
'profit_percent': [0.3, -0.1, -0.1, -0.1, 0.3], 'profit_percent': [0.3, -0.1, -0.1, -0.1, 0.3],
'profit_abs': [0.6, -0.2, -0.2, -0.2, 0.6], 'profit_abs': [0.6, -0.2, -0.2, -0.2, 0.6],
'trade_duration': [10, 30, 10, 30, 10], 'trade_duration': [10, 30, 10, 30, 10],
'sell_reason': [SellType.ROI, SellType.STOP_LOSS, SellType.STOP_LOSS,SellType.STOP_LOSS, SellType.ROI] 'sell_reason':
[SellType.ROI, SellType.STOP_LOSS, SellType.STOP_LOSS, SellType.STOP_LOSS, SellType.ROI]
} }
) )
# Functions for recurrent object patching # Functions for recurrent object patching
def create_trials(mocker, hyperopt, testdatadir) -> None: def create_trials(mocker, hyperopt, testdatadir) -> None:
""" """
@ -328,7 +333,13 @@ def test_sharpe_loss_prefers_higher_profits(default_conf, hyperopt_results) -> N
assert over < correct assert over < correct
assert under > correct assert under > correct
# When the profit a two backtests are the same i prefer to take the one that minimise the median drawdown
"""
When the profit a two backtests are the same i prefer to take
the one that minimise the median drawdown
"""
def test_calmar_loss_prefers_higher_profits(default_conf, def test_calmar_loss_prefers_higher_profits(default_conf,
hyperopt_results_min_median_drawdown, hyperopt_results_min_median_drawdown,
hyperopt_results_max_median_drawdown) -> None: hyperopt_results_max_median_drawdown) -> None:
@ -336,11 +347,11 @@ def test_calmar_loss_prefers_higher_profits(default_conf,
default_conf.update({'hyperopt_loss': 'CalmarHyperOptLoss'}) default_conf.update({'hyperopt_loss': 'CalmarHyperOptLoss'})
hl = HyperOptLossResolver(default_conf).hyperoptloss hl = HyperOptLossResolver(default_conf).hyperoptloss
min_median_drawdown_loss = hl.hyperopt_loss_function(hyperopt_results_min_median_drawdown, min_median_drawdown_loss = hl.hyperopt_loss_function(hyperopt_results_min_median_drawdown,
len(hyperopt_results_min_median_drawdown), len(hyperopt_results_min_median_drawdown),
datetime(2019, 1, 1), datetime(2019, 5, 1)) datetime(2019, 1, 1), datetime(2019, 5, 1))
max_median_drawdown_loss = hl.hyperopt_loss_function(hyperopt_results_max_median_drawdown, max_median_drawdown_loss = hl.hyperopt_loss_function(hyperopt_results_max_median_drawdown,
len(hyperopt_results_max_median_drawdown), len(hyperopt_results_max_median_drawdown),
datetime(2019, 1, 1), datetime(2019, 5, 1)) datetime(2019, 1, 1), datetime(2019, 5, 1))
assert min_median_drawdown_loss < max_median_drawdown_loss assert min_median_drawdown_loss < max_median_drawdown_loss