From d830105605863c2c88839d7df864c35b6db7de4f Mon Sep 17 00:00:00 2001 From: robcaulk Date: Sun, 31 Jul 2022 17:05:29 +0200 Subject: [PATCH] *BREAKING CHANGE* remove unnecessary arguments from populate_any_indicators(), accommodate tests --- freqtrade/freqai/data_kitchen.py | 13 +++----- freqtrade/strategy/interface.py | 5 ++- freqtrade/templates/FreqaiExampleStrategy.py | 31 +++++++++++++------ .../strats/freqai_test_multimodel_strat.py | 4 ++- tests/strategy/strats/freqai_test_strat.py | 4 ++- 5 files changed, 35 insertions(+), 22 deletions(-) diff --git a/freqtrade/freqai/data_kitchen.py b/freqtrade/freqai/data_kitchen.py index 4a936475a..aedf01d11 100644 --- a/freqtrade/freqai/data_kitchen.py +++ b/freqtrade/freqai/data_kitchen.py @@ -892,29 +892,26 @@ class FreqaiDataKitchen: else: dataframe = base_dataframes[self.config["timeframe"]].copy() - sgi = True + sgi = False for tf in tfs: + if tf == tfs[-1]: + sgi = True # doing this last allows user to use all tf raw prices in labels dataframe = strategy.populate_any_indicators( - pair, pair, dataframe.copy(), tf, informative=base_dataframes[tf], - coin=pair.split("/")[0] + "-", - set_generalized_indicators=sgi, + set_generalized_indicators=sgi ) - sgi = False if pairs: for i in pairs: if pair in i: continue # dont repeat anything from whitelist dataframe = strategy.populate_any_indicators( - pair, i, dataframe.copy(), tf, - informative=corr_dataframes[i][tf], - coin=i.split("/")[0] + "-", + informative=corr_dataframes[i][tf] ) return dataframe diff --git a/freqtrade/strategy/interface.py b/freqtrade/strategy/interface.py index 431e67a98..be6447811 100644 --- a/freqtrade/strategy/interface.py +++ b/freqtrade/strategy/interface.py @@ -557,8 +557,8 @@ class IStrategy(ABC, HyperStrategyMixin): """ return None - def populate_any_indicators(self, basepair: str, pair: str, df: DataFrame, tf: str, - informative: DataFrame = None, coin: str = "", + def populate_any_indicators(self, pair: str, df: DataFrame, tf: str, + informative: DataFrame = None, set_generalized_indicators: bool = False) -> DataFrame: """ Function designed to automatically generate, name and merge features @@ -570,7 +570,6 @@ class IStrategy(ABC, HyperStrategyMixin): :param df: strategy dataframe which will receive merges from informatives :param tf: timeframe of the dataframe which will modify the feature names :param informative: the dataframe associated with the informative pair - :param coin: the name of the coin which will modify the feature names. """ return df diff --git a/freqtrade/templates/FreqaiExampleStrategy.py b/freqtrade/templates/FreqaiExampleStrategy.py index 1196405ab..90343cc80 100644 --- a/freqtrade/templates/FreqaiExampleStrategy.py +++ b/freqtrade/templates/FreqaiExampleStrategy.py @@ -65,7 +65,7 @@ class FreqaiExampleStrategy(IStrategy): return informative_pairs def populate_any_indicators( - self, metadata, pair, df, tf, informative=None, coin="", set_generalized_indicators=False + self, pair, df, tf, informative=None, set_generalized_indicators=False ): """ Function designed to automatically generate, name and merge features @@ -78,9 +78,10 @@ class FreqaiExampleStrategy(IStrategy): :param df: strategy dataframe which will receive merges from informatives :param tf: timeframe of the dataframe which will modify the feature names :param informative: the dataframe associated with the informative pair - :param coin: the name of the coin which will modify the feature names. """ + coin = pair.split('/')[0] + with self.freqai.lock: if informative is None: informative = self.dp.get_pair_dataframe(pair, tf) @@ -92,11 +93,8 @@ class FreqaiExampleStrategy(IStrategy): informative[f"%-{coin}rsi-period_{t}"] = ta.RSI(informative, timeperiod=t) informative[f"%-{coin}mfi-period_{t}"] = ta.MFI(informative, timeperiod=t) informative[f"%-{coin}adx-period_{t}"] = ta.ADX(informative, window=t) - informative[f"{coin}20sma-period_{t}"] = ta.SMA(informative, timeperiod=t) - informative[f"{coin}21ema-period_{t}"] = ta.EMA(informative, timeperiod=t) - informative[f"%-{coin}close_over_20sma-period_{t}"] = ( - informative["close"] / informative[f"{coin}20sma-period_{t}"] - ) + informative[f"{coin}sma-period_{t}"] = ta.SMA(informative, timeperiod=t) + informative[f"{coin}ema-period_{t}"] = ta.EMA(informative, timeperiod=t) informative[f"%-{coin}mfi-period_{t}"] = ta.MFI(informative, timeperiod=t) @@ -148,8 +146,6 @@ class FreqaiExampleStrategy(IStrategy): df["%-hour_of_day"] = (df["date"].dt.hour + 1) / 25 # user adds targets here by prepending them with &- (see convention below) - # If user wishes to use multiple targets, a multioutput prediction model - # needs to be used such as templates/CatboostPredictionMultiModel.py df["&-s_close"] = ( df["close"] .shift(-self.freqai_info["feature_parameters"]["label_period_candles"]) @@ -159,6 +155,23 @@ class FreqaiExampleStrategy(IStrategy): - 1 ) + # If user wishes to use multiple targets, they can add more by + # appending more columns with '&'. User should keep in mind that multi targets + # requires a multioutput prediction model such as + # templates/CatboostPredictionMultiModel.py, + + # df["&-s_range"] = ( + # df["close"] + # .shift(-self.freqai_info["feature_parameters"]["label_period_candles"]) + # .rolling(self.freqai_info["feature_parameters"]["label_period_candles"]) + # .max() + # - + # df["close"] + # .shift(-self.freqai_info["feature_parameters"]["label_period_candles"]) + # .rolling(self.freqai_info["feature_parameters"]["label_period_candles"]) + # .min() + # ) + return df def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame: diff --git a/tests/strategy/strats/freqai_test_multimodel_strat.py b/tests/strategy/strats/freqai_test_multimodel_strat.py index 9652e816b..e58086757 100644 --- a/tests/strategy/strats/freqai_test_multimodel_strat.py +++ b/tests/strategy/strats/freqai_test_multimodel_strat.py @@ -62,7 +62,7 @@ class freqai_test_multimodel_strat(IStrategy): return informative_pairs def populate_any_indicators( - self, metadata, pair, df, tf, informative=None, coin="", set_generalized_indicators=False + self, pair, df, tf, informative=None, set_generalized_indicators=False ): """ Function designed to automatically generate, name and merge features @@ -79,6 +79,8 @@ class freqai_test_multimodel_strat(IStrategy): :coin: the name of the coin which will modify the feature names. """ + coin = pair.split('/')[0] + with self.freqai.lock: if informative is None: informative = self.dp.get_pair_dataframe(pair, tf) diff --git a/tests/strategy/strats/freqai_test_strat.py b/tests/strategy/strats/freqai_test_strat.py index 8679d4d74..8288228d1 100644 --- a/tests/strategy/strats/freqai_test_strat.py +++ b/tests/strategy/strats/freqai_test_strat.py @@ -62,7 +62,7 @@ class freqai_test_strat(IStrategy): return informative_pairs def populate_any_indicators( - self, metadata, pair, df, tf, informative=None, coin="", set_generalized_indicators=False + self, pair, df, tf, informative=None, set_generalized_indicators=False ): """ Function designed to automatically generate, name and merge features @@ -79,6 +79,8 @@ class freqai_test_strat(IStrategy): :coin: the name of the coin which will modify the feature names. """ + coin = pair.split('/')[0] + with self.freqai.lock: if informative is None: informative = self.dp.get_pair_dataframe(pair, tf)