mirror of
https://github.com/freqtrade/freqtrade.git
synced 2025-12-15 04:11:14 +00:00
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.
This commit is contained in:
@@ -173,9 +173,9 @@ def test_lookahead_helper_export_to_csv(lookahead_conf):
|
|||||||
lookahead_conf['lookahead_analysis_exportfilename'] = "temp_csv_lookahead_analysis.csv"
|
lookahead_conf['lookahead_analysis_exportfilename'] = "temp_csv_lookahead_analysis.csv"
|
||||||
|
|
||||||
strategy_obj1 = {
|
strategy_obj1 = {
|
||||||
'name': "strat1",
|
'name': "strat1",
|
||||||
'location': PurePosixPath("file1.py"),
|
'location': PurePosixPath("file1.py"),
|
||||||
}
|
}
|
||||||
|
|
||||||
instance1 = LookaheadAnalysis(lookahead_conf, strategy_obj1)
|
instance1 = LookaheadAnalysis(lookahead_conf, strategy_obj1)
|
||||||
instance1.current_analysis = analysis1
|
instance1.current_analysis = analysis1
|
||||||
@@ -270,9 +270,24 @@ def test_lookahead_helper_export_to_csv(lookahead_conf):
|
|||||||
Path(lookahead_conf['lookahead_analysis_exportfilename']).unlink()
|
Path(lookahead_conf['lookahead_analysis_exportfilename']).unlink()
|
||||||
|
|
||||||
|
|
||||||
def test_initialize_single_lookahead_analysis():
|
def test_initialize_single_lookahead_analysis(lookahead_conf, mocker):
|
||||||
# TODO
|
mocker.patch('freqtrade.data.history.get_timerange', get_timerange)
|
||||||
pytest.skip("TODO")
|
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', [
|
@pytest.mark.parametrize('scenario', [
|
||||||
@@ -307,10 +322,10 @@ def test_biased_strategy(lookahead_conf, mocker, caplog, scenario) -> None:
|
|||||||
instance.start()
|
instance.start()
|
||||||
# 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)
|
||||||
# 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
|
# check non-biased strategy
|
||||||
# assert False
|
if scenario == "no_bias":
|
||||||
# Run with `pytest tests/optimize/test_lookahead_analysis.py -k test_biased_strategy`
|
assert not instance.current_analysis.has_bias
|
||||||
|
# check biased strategy
|
||||||
|
elif scenario == "bias1":
|
||||||
|
assert instance.current_analysis.has_bias
|
||||||
|
|||||||
@@ -29,12 +29,13 @@ class strategy_test_v3_with_lookahead_bias(IStrategy):
|
|||||||
|
|
||||||
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
||||||
# bias is introduced here
|
# bias is introduced here
|
||||||
ichi = ichimoku(dataframe,
|
if self.scenario.value != 'no_bias':
|
||||||
conversion_line_period=20,
|
ichi = ichimoku(dataframe,
|
||||||
base_line_periods=60,
|
conversion_line_period=20,
|
||||||
laggin_span=120,
|
base_line_periods=60,
|
||||||
displacement=30)
|
laggin_span=120,
|
||||||
dataframe['chikou_span'] = ichi['chikou_span']
|
displacement=30)
|
||||||
|
dataframe['chikou_span'] = ichi['chikou_span']
|
||||||
|
|
||||||
return dataframe
|
return dataframe
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user