diff --git a/freqtrade/freqai/freqai_interface.py b/freqtrade/freqai/freqai_interface.py index fc352ea8b..c393420b5 100644 --- a/freqtrade/freqai/freqai_interface.py +++ b/freqtrade/freqai/freqai_interface.py @@ -65,7 +65,6 @@ class IFreqaiModel(ABC): self.data_split_parameters = config.get("freqai", {}).get("data_split_parameters") self.model_training_parameters = config.get("freqai", {}).get("model_training_parameters") self.feature_parameters = config.get("freqai", {}).get("feature_parameters") - self.model = None self.retrain = False self.first = True self.set_full_path() @@ -372,8 +371,8 @@ class IFreqaiModel(ABC): """ Base data cleaning method for train Any function inside this method should drop training data points from the filtered_dataframe - based on user decided logic. See FreqaiDataKitchen::remove_outliers() for an example - of how outlier data points are dropped from the dataframe used for training. + based on user decided logic. See FreqaiDataKitchen::use_SVM_to_remove_outliers() for an + example of how outlier data points are dropped from the dataframe used for training. """ if self.freqai_info.get("feature_parameters", {}).get( diff --git a/freqtrade/freqai/prediction_models/BaseRegressionModel.py b/freqtrade/freqai/prediction_models/BaseRegressionModel.py index c2fd53d0f..2db025fd6 100644 --- a/freqtrade/freqai/prediction_models/BaseRegressionModel.py +++ b/freqtrade/freqai/prediction_models/BaseRegressionModel.py @@ -1,6 +1,7 @@ import logging -from typing import Tuple +from typing import Any, Tuple +import numpy.typing as npt from pandas import DataFrame from freqtrade.freqai.data_kitchen import FreqaiDataKitchen @@ -28,7 +29,7 @@ class BaseRegressionModel(IFreqaiModel): def train( self, unfiltered_dataframe: DataFrame, pair: str, dk: FreqaiDataKitchen - ) -> Tuple[DataFrame, DataFrame]: + ) -> Any: """ Filter the training data and train a model to it. Train makes heavy use of the datakitchen for storing, saving, loading, and analyzing the data. @@ -83,7 +84,7 @@ class BaseRegressionModel(IFreqaiModel): def predict( self, unfiltered_dataframe: DataFrame, dk: FreqaiDataKitchen, first: bool = False - ) -> Tuple[DataFrame, DataFrame]: + ) -> Tuple[DataFrame, npt.ArrayLike]: """ Filter the prediction features data and predict with it. :param: unfiltered_dataframe: Full dataframe for the current backtest period. diff --git a/tests/freqai/test_freqai_interface.py b/tests/freqai/test_freqai_interface.py index ce1a52bbf..6699ef563 100644 --- a/tests/freqai/test_freqai_interface.py +++ b/tests/freqai/test_freqai_interface.py @@ -194,3 +194,30 @@ def test_follow_mode(mocker, freqai_conf): assert len(freqai.dk.return_dataframe.index) == 5702 shutil.rmtree(Path(freqai.dk.full_path)) + + +def test_principal_component_analysis(mocker, freqai_conf): + freqai_conf.update({"timerange": "20180110-20180130"}) + freqai_conf.get("freqai", {}).get("feature_parameters", {}).update( + {"princpial_component_analysis": "true"}) + + strategy = get_patched_freqai_strategy(mocker, freqai_conf) + exchange = get_patched_exchange(mocker, freqai_conf) + strategy.dp = DataProvider(freqai_conf, exchange) + strategy.freqai_info = freqai_conf.get("freqai", {}) + freqai = strategy.freqai + freqai.live = True + freqai.dk = FreqaiDataKitchen(freqai_conf, freqai.dd) + timerange = TimeRange.parse_timerange("20180110-20180130") + freqai.dk.load_all_pair_histories(timerange) + + freqai.dd.pair_dict = MagicMock() + + data_load_timerange = TimeRange.parse_timerange("20180110-20180130") + new_timerange = TimeRange.parse_timerange("20180120-20180130") + + freqai.train_model_in_series(new_timerange, "ADA/BTC", strategy, freqai.dk, data_load_timerange) + + assert Path(freqai.dk.data_path / f"{freqai.dk.model_filename}_pca_object.pkl") + + shutil.rmtree(Path(freqai.dk.full_path))