mirror of
https://github.com/freqtrade/freqtrade.git
synced 2025-11-29 08:33:07 +00:00
Add parameters for analysis tests ...
This commit is contained in:
@@ -113,7 +113,10 @@ def test_initialize_single_lookahead_analysis():
|
|||||||
pytest.skip("TODO")
|
pytest.skip("TODO")
|
||||||
|
|
||||||
|
|
||||||
def test_biased_strategy(lookahead_conf, mocker, caplog) -> None:
|
@pytest.mark.parametrize('scenario', [
|
||||||
|
'no_bias', 'bias1'
|
||||||
|
])
|
||||||
|
def test_biased_strategy(lookahead_conf, mocker, caplog, scenario) -> None:
|
||||||
|
|
||||||
mocker.patch('freqtrade.data.history.get_timerange', get_timerange)
|
mocker.patch('freqtrade.data.history.get_timerange', get_timerange)
|
||||||
mocker.patch(f'{EXMS}.get_fee', return_value=0.0)
|
mocker.patch(f'{EXMS}.get_fee', return_value=0.0)
|
||||||
@@ -128,10 +131,26 @@ def test_biased_strategy(lookahead_conf, mocker, caplog) -> None:
|
|||||||
lookahead_conf['timerange'] = '20180119-20180122'
|
lookahead_conf['timerange'] = '20180119-20180122'
|
||||||
lookahead_conf['strategy'] = 'strategy_test_v3_with_lookahead_bias'
|
lookahead_conf['strategy'] = 'strategy_test_v3_with_lookahead_bias'
|
||||||
|
|
||||||
|
# Patch scenario Parameter to allow for easy selection
|
||||||
|
mocker.patch('freqtrade.strategy.hyper.HyperStrategyMixin.load_params_from_file',
|
||||||
|
return_value={
|
||||||
|
'params': {
|
||||||
|
"buy": {
|
||||||
|
"scenario": scenario
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
strategy_obj = {}
|
strategy_obj = {}
|
||||||
strategy_obj['name'] = "strategy_test_v3_with_lookahead_bias"
|
strategy_obj['name'] = "strategy_test_v3_with_lookahead_bias"
|
||||||
instance = LookaheadAnalysis(lookahead_conf, strategy_obj)
|
instance = LookaheadAnalysis(lookahead_conf, strategy_obj)
|
||||||
instance.start()
|
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)
|
assert log_has_re(r".*bias detected.*", caplog)
|
||||||
|
|
||||||
# TODO: assert something ... most likely output (?) or instance state?
|
# 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`
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ from pandas import DataFrame
|
|||||||
from technical.indicators import ichimoku
|
from technical.indicators import ichimoku
|
||||||
|
|
||||||
from freqtrade.strategy import IStrategy
|
from freqtrade.strategy import IStrategy
|
||||||
|
from freqtrade.strategy.parameters import CategoricalParameter
|
||||||
|
|
||||||
|
|
||||||
class strategy_test_v3_with_lookahead_bias(IStrategy):
|
class strategy_test_v3_with_lookahead_bias(IStrategy):
|
||||||
@@ -21,6 +22,7 @@ class strategy_test_v3_with_lookahead_bias(IStrategy):
|
|||||||
|
|
||||||
# Optimal timeframe for the strategy
|
# Optimal timeframe for the strategy
|
||||||
timeframe = '5m'
|
timeframe = '5m'
|
||||||
|
scenario = CategoricalParameter(['no_bias', 'bias1'], 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 = 20
|
startup_candle_count: int = 20
|
||||||
@@ -37,14 +39,19 @@ class strategy_test_v3_with_lookahead_bias(IStrategy):
|
|||||||
return dataframe
|
return dataframe
|
||||||
|
|
||||||
def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
||||||
dataframe.loc[
|
if self.scenario.value == 'no_bias':
|
||||||
dataframe['close'].shift(-10) > dataframe['close'],
|
dataframe.loc[dataframe['close'].shift(10) < dataframe['close'], 'enter_long'] = 1
|
||||||
'enter_long'] = 1
|
else:
|
||||||
|
dataframe.loc[dataframe['close'].shift(-10) > dataframe['close'], 'enter_long'] = 1
|
||||||
|
|
||||||
return dataframe
|
return dataframe
|
||||||
|
|
||||||
def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
||||||
dataframe.loc[
|
if self.scenario.value == 'no_bias':
|
||||||
dataframe['close'].shift(-10) > dataframe['close'], 'exit'] = 1
|
dataframe.loc[
|
||||||
|
dataframe['close'].shift(10) < dataframe['close'], 'exit'] = 1
|
||||||
|
else:
|
||||||
|
dataframe.loc[
|
||||||
|
dataframe['close'].shift(-10) > dataframe['close'], 'exit'] = 1
|
||||||
|
|
||||||
return dataframe
|
return dataframe
|
||||||
|
|||||||
Reference in New Issue
Block a user