diff --git a/freqtrade/strategy/interface.py b/freqtrade/strategy/interface.py index 8ec46c91b..70d656199 100644 --- a/freqtrade/strategy/interface.py +++ b/freqtrade/strategy/interface.py @@ -614,8 +614,8 @@ class IStrategy(ABC, HyperStrategyMixin): """ return df - def feature_engineering_expand_all(self, dataframe: DataFrame, - period: int, **kwargs): + def feature_engineering_expand_all(self, dataframe: DataFrame, period: int, + metadata: Dict, **kwargs): """ *Only functional with FreqAI enabled strategies* This function will automatically expand the defined features on the config defined @@ -634,14 +634,14 @@ class IStrategy(ABC, HyperStrategyMixin): https://www.freqtrade.io/en/latest/freqai-feature-engineering/#defining-the-features - :param df: strategy dataframe which will receive the features + :param dataframe: strategy dataframe which will receive the features :param period: period of the indicator - usage example: :param metadata: metadata of current pair dataframe["%-ema-period"] = ta.EMA(dataframe, timeperiod=period) """ return dataframe - def feature_engineering_expand_basic(self, dataframe: DataFrame, **kwargs): + def feature_engineering_expand_basic(self, dataframe: DataFrame, metadata: Dict, **kwargs): """ *Only functional with FreqAI enabled strategies* This function will automatically expand the defined features on the config defined @@ -663,14 +663,14 @@ class IStrategy(ABC, HyperStrategyMixin): https://www.freqtrade.io/en/latest/freqai-feature-engineering/#defining-the-features - :param df: strategy dataframe which will receive the features + :param dataframe: strategy dataframe which will receive the features :param metadata: metadata of current pair dataframe["%-pct-change"] = dataframe["close"].pct_change() dataframe["%-ema-200"] = ta.EMA(dataframe, timeperiod=200) """ return dataframe - def feature_engineering_standard(self, dataframe: DataFrame, **kwargs): + def feature_engineering_standard(self, dataframe: DataFrame, metadata: Dict, **kwargs): """ *Only functional with FreqAI enabled strategies* This optional function will be called once with the dataframe of the base timeframe. @@ -688,13 +688,13 @@ class IStrategy(ABC, HyperStrategyMixin): https://www.freqtrade.io/en/latest/freqai-feature-engineering - :param df: strategy dataframe which will receive the features + :param dataframe: strategy dataframe which will receive the features :param metadata: metadata of current pair usage example: dataframe["%-day_of_week"] = (dataframe["date"].dt.dayofweek + 1) / 7 """ return dataframe - def set_freqai_targets(self, dataframe, **kwargs): + def set_freqai_targets(self, dataframe: DataFrame, metadata: Dict, **kwargs): """ *Only functional with FreqAI enabled strategies* Required function to set the targets for the model. @@ -704,7 +704,7 @@ class IStrategy(ABC, HyperStrategyMixin): https://www.freqtrade.io/en/latest/freqai-feature-engineering - :param df: strategy dataframe which will receive the targets + :param dataframe: strategy dataframe which will receive the targets :param metadata: metadata of current pair usage example: dataframe["&-target"] = dataframe["close"].shift(-1) / dataframe["close"] """ diff --git a/freqtrade/templates/FreqaiExampleHybridStrategy.py b/freqtrade/templates/FreqaiExampleHybridStrategy.py index c5dbe8dbd..ee574fda3 100644 --- a/freqtrade/templates/FreqaiExampleHybridStrategy.py +++ b/freqtrade/templates/FreqaiExampleHybridStrategy.py @@ -1,4 +1,5 @@ import logging +from typing import Dict import numpy as np import pandas as pd @@ -95,7 +96,8 @@ class FreqaiExampleHybridStrategy(IStrategy): short_rsi = IntParameter(low=51, high=100, default=70, space='sell', optimize=True, load=True) exit_short_rsi = IntParameter(low=1, high=50, default=30, space='buy', optimize=True, load=True) - def feature_engineering_expand_all(self, dataframe, period, **kwargs): + def feature_engineering_expand_all(self, dataframe: DataFrame, period: int, + metadata: Dict, **kwargs): """ *Only functional with FreqAI enabled strategies* This function will automatically expand the defined features on the config defined @@ -114,8 +116,9 @@ class FreqaiExampleHybridStrategy(IStrategy): https://www.freqtrade.io/en/latest/freqai-feature-engineering/#defining-the-features - :param df: strategy dataframe which will receive the features + :param dataframe: strategy dataframe which will receive the features :param period: period of the indicator - usage example: + :param metadata: metadata of current pair dataframe["%-ema-period"] = ta.EMA(dataframe, timeperiod=period) """ @@ -148,7 +151,7 @@ class FreqaiExampleHybridStrategy(IStrategy): return dataframe - def feature_engineering_expand_basic(self, dataframe, **kwargs): + def feature_engineering_expand_basic(self, dataframe: DataFrame, metadata: Dict, **kwargs): """ *Only functional with FreqAI enabled strategies* This function will automatically expand the defined features on the config defined @@ -170,7 +173,8 @@ class FreqaiExampleHybridStrategy(IStrategy): https://www.freqtrade.io/en/latest/freqai-feature-engineering/#defining-the-features - :param df: strategy dataframe which will receive the features + :param dataframe: strategy dataframe which will receive the features + :param metadata: metadata of current pair dataframe["%-pct-change"] = dataframe["close"].pct_change() dataframe["%-ema-200"] = ta.EMA(dataframe, timeperiod=200) """ @@ -179,7 +183,7 @@ class FreqaiExampleHybridStrategy(IStrategy): dataframe["%-raw_price"] = dataframe["close"] return dataframe - def feature_engineering_standard(self, dataframe, **kwargs): + def feature_engineering_standard(self, dataframe: DataFrame, metadata: Dict, **kwargs): """ *Only functional with FreqAI enabled strategies* This optional function will be called once with the dataframe of the base timeframe. @@ -197,14 +201,15 @@ class FreqaiExampleHybridStrategy(IStrategy): https://www.freqtrade.io/en/latest/freqai-feature-engineering - :param df: strategy dataframe which will receive the features + :param dataframe: strategy dataframe which will receive the features + :param metadata: metadata of current pair usage example: dataframe["%-day_of_week"] = (dataframe["date"].dt.dayofweek + 1) / 7 """ dataframe["%-day_of_week"] = dataframe["date"].dt.dayofweek dataframe["%-hour_of_day"] = dataframe["date"].dt.hour return dataframe - def set_freqai_targets(self, dataframe, **kwargs): + def set_freqai_targets(self, dataframe: DataFrame, metadata: Dict, **kwargs): """ *Only functional with FreqAI enabled strategies* Required function to set the targets for the model. @@ -214,7 +219,8 @@ class FreqaiExampleHybridStrategy(IStrategy): https://www.freqtrade.io/en/latest/freqai-feature-engineering - :param df: strategy dataframe which will receive the targets + :param dataframe: strategy dataframe which will receive the targets + :param metadata: metadata of current pair usage example: dataframe["&-target"] = dataframe["close"].shift(-1) / dataframe["close"] """ dataframe['&s-up_or_down'] = np.where(dataframe["close"].shift(-50) > diff --git a/freqtrade/templates/FreqaiExampleStrategy.py b/freqtrade/templates/FreqaiExampleStrategy.py index acf6cfde6..0093c7f7a 100644 --- a/freqtrade/templates/FreqaiExampleStrategy.py +++ b/freqtrade/templates/FreqaiExampleStrategy.py @@ -1,5 +1,6 @@ import logging from functools import reduce +from typing import Dict import talib.abstract as ta from pandas import DataFrame @@ -46,7 +47,8 @@ class FreqaiExampleStrategy(IStrategy): std_dev_multiplier_sell = CategoricalParameter( [0.75, 1, 1.25, 1.5, 1.75], space="sell", default=1.25, optimize=True) - def feature_engineering_expand_all(self, dataframe, period, metadata, **kwargs): + def feature_engineering_expand_all(self, dataframe: DataFrame, period: int, + metadata: Dict, **kwargs): """ *Only functional with FreqAI enabled strategies* This function will automatically expand the defined features on the config defined @@ -69,8 +71,9 @@ class FreqaiExampleStrategy(IStrategy): https://www.freqtrade.io/en/latest/freqai-feature-engineering/#defining-the-features - :param df: strategy dataframe which will receive the features + :param dataframe: strategy dataframe which will receive the features :param period: period of the indicator - usage example: + :param metadata: metadata of current pair dataframe["%-ema-period"] = ta.EMA(dataframe, timeperiod=period) """ @@ -103,7 +106,7 @@ class FreqaiExampleStrategy(IStrategy): return dataframe - def feature_engineering_expand_basic(self, dataframe, metadata, **kwargs): + def feature_engineering_expand_basic(self, dataframe: DataFrame, metadata: Dict, **kwargs): """ *Only functional with FreqAI enabled strategies* This function will automatically expand the defined features on the config defined @@ -129,7 +132,8 @@ class FreqaiExampleStrategy(IStrategy): https://www.freqtrade.io/en/latest/freqai-feature-engineering/#defining-the-features - :param df: strategy dataframe which will receive the features + :param dataframe: strategy dataframe which will receive the features + :param metadata: metadata of current pair dataframe["%-pct-change"] = dataframe["close"].pct_change() dataframe["%-ema-200"] = ta.EMA(dataframe, timeperiod=200) """ @@ -138,7 +142,7 @@ class FreqaiExampleStrategy(IStrategy): dataframe["%-raw_price"] = dataframe["close"] return dataframe - def feature_engineering_standard(self, dataframe, metadata, **kwargs): + def feature_engineering_standard(self, dataframe: DataFrame, metadata: Dict, **kwargs): """ *Only functional with FreqAI enabled strategies* This optional function will be called once with the dataframe of the base timeframe. @@ -160,14 +164,15 @@ class FreqaiExampleStrategy(IStrategy): https://www.freqtrade.io/en/latest/freqai-feature-engineering - :param df: strategy dataframe which will receive the features + :param dataframe: strategy dataframe which will receive the features + :param metadata: metadata of current pair usage example: dataframe["%-day_of_week"] = (dataframe["date"].dt.dayofweek + 1) / 7 """ dataframe["%-day_of_week"] = dataframe["date"].dt.dayofweek dataframe["%-hour_of_day"] = dataframe["date"].dt.hour return dataframe - def set_freqai_targets(self, dataframe, metadata, **kwargs): + def set_freqai_targets(self, dataframe: DataFrame, metadata: Dict, **kwargs): """ *Only functional with FreqAI enabled strategies* Required function to set the targets for the model. @@ -181,7 +186,8 @@ class FreqaiExampleStrategy(IStrategy): https://www.freqtrade.io/en/latest/freqai-feature-engineering - :param df: strategy dataframe which will receive the targets + :param dataframe: strategy dataframe which will receive the targets + :param metadata: metadata of current pair usage example: dataframe["&-target"] = dataframe["close"].shift(-1) / dataframe["close"] """ dataframe["&-s_close"] = ( diff --git a/tests/strategy/strats/freqai_rl_test_strat.py b/tests/strategy/strats/freqai_rl_test_strat.py index 6fa926fc9..2bf4aaa30 100644 --- a/tests/strategy/strats/freqai_rl_test_strat.py +++ b/tests/strategy/strats/freqai_rl_test_strat.py @@ -1,5 +1,6 @@ import logging from functools import reduce +from typing import Dict import talib.abstract as ta from pandas import DataFrame @@ -24,20 +25,21 @@ class freqai_rl_test_strat(IStrategy): startup_candle_count: int = 300 can_short = False - def feature_engineering_expand_all(self, dataframe, period, **kwargs): + def feature_engineering_expand_all(self, dataframe: DataFrame, period: int, + metadata: Dict, **kwargs): dataframe["%-rsi-period"] = ta.RSI(dataframe, timeperiod=period) return dataframe - def feature_engineering_expand_basic(self, dataframe: DataFrame, **kwargs): + def feature_engineering_expand_basic(self, dataframe: DataFrame, metadata: Dict, **kwargs): dataframe["%-pct-change"] = dataframe["close"].pct_change() dataframe["%-raw_volume"] = dataframe["volume"] return dataframe - def feature_engineering_standard(self, dataframe, **kwargs): + def feature_engineering_standard(self, dataframe: DataFrame, metadata: Dict, **kwargs): dataframe["%-day_of_week"] = dataframe["date"].dt.dayofweek dataframe["%-hour_of_day"] = dataframe["date"].dt.hour @@ -49,7 +51,7 @@ class freqai_rl_test_strat(IStrategy): return dataframe - def set_freqai_targets(self, dataframe, **kwargs): + def set_freqai_targets(self, dataframe: DataFrame, metadata: Dict, **kwargs): dataframe["&-action"] = 0 diff --git a/tests/strategy/strats/freqai_test_classifier.py b/tests/strategy/strats/freqai_test_classifier.py index 02427ab59..61b9f0c37 100644 --- a/tests/strategy/strats/freqai_test_classifier.py +++ b/tests/strategy/strats/freqai_test_classifier.py @@ -1,5 +1,6 @@ import logging from functools import reduce +from typing import Dict import numpy as np import talib.abstract as ta @@ -56,7 +57,8 @@ class freqai_test_classifier(IStrategy): informative_pairs.append((pair, tf)) return informative_pairs - def feature_engineering_expand_all(self, dataframe, period, **kwargs): + def feature_engineering_expand_all(self, dataframe: DataFrame, period: int, + metadata: Dict, **kwargs): dataframe["%-rsi-period"] = ta.RSI(dataframe, timeperiod=period) dataframe["%-mfi-period"] = ta.MFI(dataframe, timeperiod=period) @@ -64,7 +66,7 @@ class freqai_test_classifier(IStrategy): return dataframe - def feature_engineering_expand_basic(self, dataframe: DataFrame, **kwargs): + def feature_engineering_expand_basic(self, dataframe: DataFrame, metadata: Dict, **kwargs): dataframe["%-pct-change"] = dataframe["close"].pct_change() dataframe["%-raw_volume"] = dataframe["volume"] @@ -72,14 +74,14 @@ class freqai_test_classifier(IStrategy): return dataframe - def feature_engineering_standard(self, dataframe, **kwargs): + def feature_engineering_standard(self, dataframe: DataFrame, metadata: Dict, **kwargs): dataframe["%-day_of_week"] = dataframe["date"].dt.dayofweek dataframe["%-hour_of_day"] = dataframe["date"].dt.hour return dataframe - def set_freqai_targets(self, dataframe, **kwargs): + def set_freqai_targets(self, dataframe: DataFrame, metadata: Dict, **kwargs): dataframe['&s-up_or_down'] = np.where(dataframe["close"].shift(-100) > dataframe["close"], 'up', 'down') diff --git a/tests/strategy/strats/freqai_test_multimodel_classifier_strat.py b/tests/strategy/strats/freqai_test_multimodel_classifier_strat.py index 65f2e4540..b2ddc21e3 100644 --- a/tests/strategy/strats/freqai_test_multimodel_classifier_strat.py +++ b/tests/strategy/strats/freqai_test_multimodel_classifier_strat.py @@ -1,5 +1,6 @@ import logging from functools import reduce +from typing import Dict import numpy as np import talib.abstract as ta @@ -43,7 +44,8 @@ class freqai_test_multimodel_classifier_strat(IStrategy): ) max_roi_time_long = IntParameter(0, 800, default=400, space="sell", optimize=False, load=True) - def feature_engineering_expand_all(self, dataframe, period, **kwargs): + def feature_engineering_expand_all(self, dataframe: DataFrame, period: int, + metadata: Dict, **kwargs): dataframe["%-rsi-period"] = ta.RSI(dataframe, timeperiod=period) dataframe["%-mfi-period"] = ta.MFI(dataframe, timeperiod=period) @@ -51,7 +53,7 @@ class freqai_test_multimodel_classifier_strat(IStrategy): return dataframe - def feature_engineering_expand_basic(self, dataframe: DataFrame, **kwargs): + def feature_engineering_expand_basic(self, dataframe: DataFrame, metadata: Dict, **kwargs): dataframe["%-pct-change"] = dataframe["close"].pct_change() dataframe["%-raw_volume"] = dataframe["volume"] @@ -59,14 +61,14 @@ class freqai_test_multimodel_classifier_strat(IStrategy): return dataframe - def feature_engineering_standard(self, dataframe, **kwargs): + def feature_engineering_standard(self, dataframe: DataFrame, metadata: Dict, **kwargs): dataframe["%-day_of_week"] = dataframe["date"].dt.dayofweek dataframe["%-hour_of_day"] = dataframe["date"].dt.hour return dataframe - def set_freqai_targets(self, dataframe, **kwargs): + def set_freqai_targets(self, dataframe: DataFrame, metadata: Dict, **kwargs): dataframe['&s-up_or_down'] = np.where(dataframe["close"].shift(-50) > dataframe["close"], 'up', 'down') diff --git a/tests/strategy/strats/freqai_test_multimodel_strat.py b/tests/strategy/strats/freqai_test_multimodel_strat.py index 5c9712629..5b09598a5 100644 --- a/tests/strategy/strats/freqai_test_multimodel_strat.py +++ b/tests/strategy/strats/freqai_test_multimodel_strat.py @@ -1,5 +1,6 @@ import logging from functools import reduce +from typing import Dict import talib.abstract as ta from pandas import DataFrame @@ -42,7 +43,8 @@ class freqai_test_multimodel_strat(IStrategy): ) max_roi_time_long = IntParameter(0, 800, default=400, space="sell", optimize=False, load=True) - def feature_engineering_expand_all(self, dataframe, period, **kwargs): + def feature_engineering_expand_all(self, dataframe: DataFrame, period: int, + metadata: Dict, **kwargs): dataframe["%-rsi-period"] = ta.RSI(dataframe, timeperiod=period) dataframe["%-mfi-period"] = ta.MFI(dataframe, timeperiod=period) @@ -50,7 +52,7 @@ class freqai_test_multimodel_strat(IStrategy): return dataframe - def feature_engineering_expand_basic(self, dataframe: DataFrame, **kwargs): + def feature_engineering_expand_basic(self, dataframe: DataFrame, metadata: Dict, **kwargs): dataframe["%-pct-change"] = dataframe["close"].pct_change() dataframe["%-raw_volume"] = dataframe["volume"] @@ -58,14 +60,14 @@ class freqai_test_multimodel_strat(IStrategy): return dataframe - def feature_engineering_standard(self, dataframe, **kwargs): + def feature_engineering_standard(self, dataframe: DataFrame, metadata: Dict, **kwargs): dataframe["%-day_of_week"] = dataframe["date"].dt.dayofweek dataframe["%-hour_of_day"] = dataframe["date"].dt.hour return dataframe - def set_freqai_targets(self, dataframe, **kwargs): + def set_freqai_targets(self, dataframe: DataFrame, metadata: Dict, **kwargs): dataframe["&-s_close"] = ( dataframe["close"] diff --git a/tests/strategy/strats/freqai_test_strat.py b/tests/strategy/strats/freqai_test_strat.py index b52c95908..6db308406 100644 --- a/tests/strategy/strats/freqai_test_strat.py +++ b/tests/strategy/strats/freqai_test_strat.py @@ -1,5 +1,6 @@ import logging from functools import reduce +from typing import Dict import talib.abstract as ta from pandas import DataFrame @@ -42,7 +43,8 @@ class freqai_test_strat(IStrategy): ) max_roi_time_long = IntParameter(0, 800, default=400, space="sell", optimize=False, load=True) - def feature_engineering_expand_all(self, dataframe, period, **kwargs): + def feature_engineering_expand_all(self, dataframe: DataFrame, period: int, + metadata: Dict, **kwargs): dataframe["%-rsi-period"] = ta.RSI(dataframe, timeperiod=period) dataframe["%-mfi-period"] = ta.MFI(dataframe, timeperiod=period) @@ -50,7 +52,7 @@ class freqai_test_strat(IStrategy): return dataframe - def feature_engineering_expand_basic(self, dataframe: DataFrame, **kwargs): + def feature_engineering_expand_basic(self, dataframe: DataFrame, metadata: Dict, **kwargs): dataframe["%-pct-change"] = dataframe["close"].pct_change() dataframe["%-raw_volume"] = dataframe["volume"] @@ -58,14 +60,14 @@ class freqai_test_strat(IStrategy): return dataframe - def feature_engineering_standard(self, dataframe, **kwargs): + def feature_engineering_standard(self, dataframe: DataFrame, metadata: Dict, **kwargs): dataframe["%-day_of_week"] = dataframe["date"].dt.dayofweek dataframe["%-hour_of_day"] = dataframe["date"].dt.hour return dataframe - def set_freqai_targets(self, dataframe, **kwargs): + def set_freqai_targets(self, dataframe: DataFrame, metadata: Dict, **kwargs): dataframe["&-s_close"] = ( dataframe["close"]