Add "bias2" test with full lookahead bias

This commit is contained in:
Matthias
2023-09-29 07:06:11 +02:00
parent 39ede449a0
commit 20ea679b2b
2 changed files with 15 additions and 10 deletions

View File

@@ -148,7 +148,7 @@ def test_initialize_single_recursive_analysis(recursive_conf, mocker, caplog):
@pytest.mark.parametrize('scenario', [
'no_bias', 'bias1'
'no_bias', 'bias1', 'bias2'
])
def test_recursive_biased_strategy(recursive_conf, mocker, caplog, scenario) -> None:
mocker.patch('freqtrade.data.history.get_timerange', get_timerange)
@@ -177,10 +177,13 @@ def test_recursive_biased_strategy(recursive_conf, mocker, caplog, scenario) ->
# Assert init correct
assert log_has_re(f"Strategy Parameter: scenario = {scenario}", caplog)
diff_pct = abs(float(instance.dict_recursive['rsi'][100].replace("%", "")))
# check non-biased strategy
if scenario == "no_bias":
assert diff_pct < 0.01
# check biased strategy
elif scenario == "bias1":
assert diff_pct >= 0.01
if scenario == "bias2":
assert log_has_re("=> found lookahead in indicator rsi", caplog)
else:
diff_pct = abs(float(instance.dict_recursive['rsi'][100].replace("%", "")))
# check non-biased strategy
if scenario == "no_bias":
assert diff_pct < 0.01
# check biased strategy
elif scenario == "bias1":
assert diff_pct >= 0.01

View File

@@ -19,7 +19,7 @@ class strategy_test_v3_recursive_issue(IStrategy):
# Optimal timeframe for the strategy
timeframe = '5m'
scenario = CategoricalParameter(['no_bias', 'bias1'], default='bias1', space="buy")
scenario = CategoricalParameter(['no_bias', 'bias1', 'bias2'], default='bias1', space="buy")
# Number of candles the strategy requires before producing valid signals
startup_candle_count: int = 100
@@ -28,8 +28,10 @@ class strategy_test_v3_recursive_issue(IStrategy):
# bias is introduced here
if self.scenario.value == 'no_bias':
dataframe['rsi'] = ta.RSI(dataframe, timeperiod=14)
else:
elif self.scenario.value == 'bias1':
dataframe['rsi'] = ta.RSI(dataframe, timeperiod=50)
else:
dataframe['rsi'] = ta.RSI(dataframe, timeperiod=50).shift(-1)
return dataframe