mirror of
https://github.com/freqtrade/freqtrade.git
synced 2025-11-29 08:33:07 +00:00
Add "bias2" test with full lookahead bias
This commit is contained in:
@@ -148,7 +148,7 @@ def test_initialize_single_recursive_analysis(recursive_conf, mocker, caplog):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('scenario', [
|
@pytest.mark.parametrize('scenario', [
|
||||||
'no_bias', 'bias1'
|
'no_bias', 'bias1', 'bias2'
|
||||||
])
|
])
|
||||||
def test_recursive_biased_strategy(recursive_conf, mocker, caplog, scenario) -> None:
|
def test_recursive_biased_strategy(recursive_conf, mocker, caplog, scenario) -> None:
|
||||||
mocker.patch('freqtrade.data.history.get_timerange', get_timerange)
|
mocker.patch('freqtrade.data.history.get_timerange', get_timerange)
|
||||||
@@ -177,6 +177,9 @@ def test_recursive_biased_strategy(recursive_conf, mocker, caplog, scenario) ->
|
|||||||
# Assert init correct
|
# Assert init correct
|
||||||
assert log_has_re(f"Strategy Parameter: scenario = {scenario}", caplog)
|
assert log_has_re(f"Strategy Parameter: scenario = {scenario}", caplog)
|
||||||
|
|
||||||
|
if scenario == "bias2":
|
||||||
|
assert log_has_re("=> found lookahead in indicator rsi", caplog)
|
||||||
|
else:
|
||||||
diff_pct = abs(float(instance.dict_recursive['rsi'][100].replace("%", "")))
|
diff_pct = abs(float(instance.dict_recursive['rsi'][100].replace("%", "")))
|
||||||
# check non-biased strategy
|
# check non-biased strategy
|
||||||
if scenario == "no_bias":
|
if scenario == "no_bias":
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ class strategy_test_v3_recursive_issue(IStrategy):
|
|||||||
|
|
||||||
# Optimal timeframe for the strategy
|
# Optimal timeframe for the strategy
|
||||||
timeframe = '5m'
|
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
|
# Number of candles the strategy requires before producing valid signals
|
||||||
startup_candle_count: int = 100
|
startup_candle_count: int = 100
|
||||||
@@ -28,8 +28,10 @@ class strategy_test_v3_recursive_issue(IStrategy):
|
|||||||
# bias is introduced here
|
# bias is introduced here
|
||||||
if self.scenario.value == 'no_bias':
|
if self.scenario.value == 'no_bias':
|
||||||
dataframe['rsi'] = ta.RSI(dataframe, timeperiod=14)
|
dataframe['rsi'] = ta.RSI(dataframe, timeperiod=14)
|
||||||
else:
|
elif self.scenario.value == 'bias1':
|
||||||
dataframe['rsi'] = ta.RSI(dataframe, timeperiod=50)
|
dataframe['rsi'] = ta.RSI(dataframe, timeperiod=50)
|
||||||
|
else:
|
||||||
|
dataframe['rsi'] = ta.RSI(dataframe, timeperiod=50).shift(-1)
|
||||||
|
|
||||||
return dataframe
|
return dataframe
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user