From a7426755bc5892c0d9a4dc98a7f536612a6ec296 Mon Sep 17 00:00:00 2001 From: hippocritical Date: Sat, 27 May 2023 20:35:45 +0200 Subject: [PATCH] added a check for bias1. Looking at has_bias should be enough to statisfy the test. The tests could be extended with thecking the buy/sell signals and the dataframe itself - but this should be sufficient for now. --- tests/optimize/test_lookahead_analysis.py | 39 +++++++++++++------ .../strategy_test_v3_with_lookahead_bias.py | 13 ++++--- 2 files changed, 34 insertions(+), 18 deletions(-) diff --git a/tests/optimize/test_lookahead_analysis.py b/tests/optimize/test_lookahead_analysis.py index 85cd8fd66..1bd864906 100644 --- a/tests/optimize/test_lookahead_analysis.py +++ b/tests/optimize/test_lookahead_analysis.py @@ -173,9 +173,9 @@ def test_lookahead_helper_export_to_csv(lookahead_conf): lookahead_conf['lookahead_analysis_exportfilename'] = "temp_csv_lookahead_analysis.csv" strategy_obj1 = { - 'name': "strat1", - 'location': PurePosixPath("file1.py"), - } + 'name': "strat1", + 'location': PurePosixPath("file1.py"), + } instance1 = LookaheadAnalysis(lookahead_conf, strategy_obj1) instance1.current_analysis = analysis1 @@ -270,9 +270,24 @@ def test_lookahead_helper_export_to_csv(lookahead_conf): Path(lookahead_conf['lookahead_analysis_exportfilename']).unlink() -def test_initialize_single_lookahead_analysis(): - # TODO - pytest.skip("TODO") +def test_initialize_single_lookahead_analysis(lookahead_conf, mocker): + mocker.patch('freqtrade.data.history.get_timerange', get_timerange) + mocker.patch(f'{EXMS}.get_fee', return_value=0.0) + mocker.patch(f'{EXMS}.get_min_pair_stake_amount', return_value=0.00001) + mocker.patch(f'{EXMS}.get_max_pair_stake_amount', return_value=float('inf')) + patch_exchange(mocker) + mocker.patch('freqtrade.plugins.pairlistmanager.PairListManager.whitelist', + PropertyMock(return_value=['UNITTEST/BTC'])) + lookahead_conf['pairs'] = ['UNITTEST/USDT'] + + lookahead_conf['timeframe'] = '5m' + lookahead_conf['timerange'] = '20180119-20180122' + strategy_obj = { + 'name': "strat1", + 'location': PurePosixPath("file1.py"), + } + LookaheadAnalysisSubFunctions.initialize_single_lookahead_analysis( + strategy_obj, lookahead_conf) @pytest.mark.parametrize('scenario', [ @@ -307,10 +322,10 @@ def test_biased_strategy(lookahead_conf, mocker, caplog, scenario) -> None: instance.start() # Assert init correct assert log_has_re(f"Strategy Parameter: scenario = {scenario}", caplog) - # Assert bias detected - assert log_has_re(r".*bias detected.*", caplog) - # TODO: assert something ... most likely output (?) or instance state? - # Assert False to see full logs in output - # assert False - # Run with `pytest tests/optimize/test_lookahead_analysis.py -k test_biased_strategy` + # check non-biased strategy + if scenario == "no_bias": + assert not instance.current_analysis.has_bias + # check biased strategy + elif scenario == "bias1": + assert instance.current_analysis.has_bias diff --git a/tests/strategy/strats/lookahead_bias/strategy_test_v3_with_lookahead_bias.py b/tests/strategy/strats/lookahead_bias/strategy_test_v3_with_lookahead_bias.py index d35b85b2d..e50d5d17b 100644 --- a/tests/strategy/strats/lookahead_bias/strategy_test_v3_with_lookahead_bias.py +++ b/tests/strategy/strats/lookahead_bias/strategy_test_v3_with_lookahead_bias.py @@ -29,12 +29,13 @@ class strategy_test_v3_with_lookahead_bias(IStrategy): def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame: # bias is introduced here - ichi = ichimoku(dataframe, - conversion_line_period=20, - base_line_periods=60, - laggin_span=120, - displacement=30) - dataframe['chikou_span'] = ichi['chikou_span'] + if self.scenario.value != 'no_bias': + ichi = ichimoku(dataframe, + conversion_line_period=20, + base_line_periods=60, + laggin_span=120, + displacement=30) + dataframe['chikou_span'] = ichi['chikou_span'] return dataframe