From d62cef01beba253f4410f3ecf1b8e3a5fb22ea3f Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 17 Sep 2022 10:18:08 +0200 Subject: [PATCH] Add test for __informative_pairs_freqai --- tests/freqai/test_freqai_interface.py | 25 ++++++++++++++++++++++ tests/strategy/strats/freqai_test_strat.py | 13 ----------- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/tests/freqai/test_freqai_interface.py b/tests/freqai/test_freqai_interface.py index a66594d7f..6aa4f40c3 100644 --- a/tests/freqai/test_freqai_interface.py +++ b/tests/freqai/test_freqai_interface.py @@ -8,6 +8,7 @@ import pytest from freqtrade.configuration import TimeRange from freqtrade.data.dataprovider import DataProvider from freqtrade.freqai.data_kitchen import FreqaiDataKitchen +from freqtrade.plugins.pairlistmanager import PairListManager from tests.conftest import get_patched_exchange, log_has_re from tests.freqai.conftest import get_patched_freqai_strategy @@ -315,3 +316,27 @@ def test_principal_component_analysis(mocker, freqai_conf): assert Path(freqai.dk.data_path / f"{freqai.dk.model_filename}_pca_object.pkl") shutil.rmtree(Path(freqai.dk.full_path)) + + +@pytest.mark.parametrize('timeframes,corr_pairs', [ + (['5m'], ['ADA/BTC', 'DASH/BTC']), + (['5m'], ['ADA/BTC', 'DASH/BTC']), + (['5m', '15m'], ['ADA/BTC', 'DASH/BTC', 'ETH/USDT']), +]) +def test_freqai_informative_pairs(mocker, freqai_conf, timeframes, corr_pairs): + freqai_conf['freqai']['feature_parameters'].update({ + 'include_timeframes': timeframes, + 'include_corr_pairlist': corr_pairs, + + }) + strategy = get_patched_freqai_strategy(mocker, freqai_conf) + exchange = get_patched_exchange(mocker, freqai_conf) + pairlists = PairListManager(exchange, freqai_conf) + strategy.dp = DataProvider(freqai_conf, exchange, pairlists) + pairlist = strategy.dp.current_whitelist() + + pairs_a = strategy.informative_pairs() + assert len(pairs_a) == 0 + pairs_b = strategy.gather_informative_pairs() + # we expect unique pairs * timeframes + assert len(pairs_b) == len(set(pairlist + corr_pairs)) * len(timeframes) diff --git a/tests/strategy/strats/freqai_test_strat.py b/tests/strategy/strats/freqai_test_strat.py index 792a3952f..cdfb7f4d0 100644 --- a/tests/strategy/strats/freqai_test_strat.py +++ b/tests/strategy/strats/freqai_test_strat.py @@ -43,19 +43,6 @@ class freqai_test_strat(IStrategy): ) max_roi_time_long = IntParameter(0, 800, default=400, space="sell", optimize=False, load=True) - def informative_pairs(self): - whitelist_pairs = self.dp.current_whitelist() - corr_pairs = self.config["freqai"]["feature_parameters"]["include_corr_pairlist"] - informative_pairs = [] - for tf in self.config["freqai"]["feature_parameters"]["include_timeframes"]: - for pair in whitelist_pairs: - informative_pairs.append((pair, tf)) - for pair in corr_pairs: - if pair in whitelist_pairs: - continue # avoid duplication - informative_pairs.append((pair, tf)) - return informative_pairs - def populate_any_indicators( self, pair, df, tf, informative=None, set_generalized_indicators=False ):