mirror of
https://github.com/freqtrade/freqtrade.git
synced 2024-11-10 10:21:59 +00:00
Add parameters for analysis tests ...
This commit is contained in:
parent
104fa9e32d
commit
3e6a2bf9b0
|
@ -113,7 +113,10 @@ def test_initialize_single_lookahead_analysis():
|
|||
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(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['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['name'] = "strategy_test_v3_with_lookahead_bias"
|
||||
instance = LookaheadAnalysis(lookahead_conf, strategy_obj)
|
||||
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`
|
||||
|
|
|
@ -3,6 +3,7 @@ from pandas import DataFrame
|
|||
from technical.indicators import ichimoku
|
||||
|
||||
from freqtrade.strategy import IStrategy
|
||||
from freqtrade.strategy.parameters import CategoricalParameter
|
||||
|
||||
|
||||
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
|
||||
timeframe = '5m'
|
||||
scenario = CategoricalParameter(['no_bias', 'bias1'], default='bias1', space="buy")
|
||||
|
||||
# Number of candles the strategy requires before producing valid signals
|
||||
startup_candle_count: int = 20
|
||||
|
@ -37,13 +39,18 @@ class strategy_test_v3_with_lookahead_bias(IStrategy):
|
|||
return dataframe
|
||||
|
||||
def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
||||
dataframe.loc[
|
||||
dataframe['close'].shift(-10) > dataframe['close'],
|
||||
'enter_long'] = 1
|
||||
if self.scenario.value == 'no_bias':
|
||||
dataframe.loc[dataframe['close'].shift(10) < dataframe['close'], 'enter_long'] = 1
|
||||
else:
|
||||
dataframe.loc[dataframe['close'].shift(-10) > dataframe['close'], 'enter_long'] = 1
|
||||
|
||||
return dataframe
|
||||
|
||||
def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
||||
if self.scenario.value == 'no_bias':
|
||||
dataframe.loc[
|
||||
dataframe['close'].shift(10) < dataframe['close'], 'exit'] = 1
|
||||
else:
|
||||
dataframe.loc[
|
||||
dataframe['close'].shift(-10) > dataframe['close'], 'exit'] = 1
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user