What can be done with freqAI
- After configuration, freqAI can be used to obtain a
What do you need to prepare to use freqtrade
- strategy
- configuration file
- model
Their paths are here
freqtrade/templates/FreqaiExampleStrategy.py, freqtrade/freqai/prediction_models/LightGBMRegressor.py, and config_examples/config_freqai.example.json, respectively.
Set up the configuration file
"freqai": {
"enabled": true,
"purge_old_models": 2,
"train_period_days": 30, // Number of days for training data
"backtest_period_days": 7,
"identifier" : "unique-id",
"feature_parameters" : {
"include_timeframes": ["5m","15m","4h"],
"include_corr_pairlist": [
"ETH/USD",
"LINK/USD",
"BNB/USD"
],
"label_period_candles": 24,
"include_shifted_candles": 2,
"indicator_periods_candles": [10, 20]
},
"data_split_parameters" : {
"test_size": 0.25
}
}
Set up the strategy
startup_candle_count: int = 20
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
dataframe = self.freqai.start(dataframe, metadata, self)
return dataframe
def feature_engineering_expand_all(self, dataframe: DataFrame, period, **kwargs) -> DataFrame:
dataframe["%-rsi-period"] = ta.RSI(dataframe, timeperiod=period)
dataframe["%-mfi-period"] = ta.MFI(dataframe, timeperiod=period)
dataframe["%-adx-period"] = ta.ADX(dataframe, timeperiod=period)
dataframe["%-sma-period"] = ta.SMA(dataframe, timeperiod=period)
dataframe["%-ema-period"] = ta.EMA(dataframe, timeperiod=period)
return dataframe
def feature_engineering_expand_basic(self, dataframe: DataFrame, **kwargs) -> DataFrame:
dataframe["%-pct-change"] = dataframe["close"].pct_change()
dataframe["%-raw_volume"] = dataframe["volume"]
dataframe["%-raw_price"] = dataframe["close"]
return dataframe
def feature_engineering_standard(self, dataframe: DataFrame, **kwargs) -> DataFrame:
dataframe["%-day_of_week"] = (dataframe["date"].dt.dayofweek + 1) / 7
dataframe["%-hour_of_day"] = (dataframe["date"].dt.hour + 1) / 25
return dataframe
def set_freqai_targets(self, dataframe: DataFrame, **kwargs) -> DataFrame:
dataframe["&-s_close"] = (
dataframe["close"]
.shift(-self.freqai_info["feature_parameters"]["label_period_candles"])
.rolling(self.freqai_info["feature_parameters"]["label_period_candles"])
.mean()
/ dataframe["close"]
- 1
)
return dataframe
startup_candle_count, the startup period of the strategy, is the period during which there may be errors in the calculation of indicators. To solve this problem, allocate the startup_candle_count attribute to the strategy. This value is the maximum period required for calculating indicators. For example,
startup_candle_count = 100
dataframe['ema100'] = ta.EMA(dataframe, timeperiod=100)
Dynamic valve
Variable table
Time keyframe
Features
Dictionary
Installation prerequisites
Notes
Cannot be used with VolumePairlists
But can be used with ShufflePairlist VolumePairlist
Start freqAI
freqtrade trade --config config_examples/config_freqai.example.json --strategy FreqaiExampleStrategy --freqaimodel LightGBMRegressor --strategy-path freqtrade/templates
When you start freqAI, it will immediately generate a new model. If you want to start training a new model after half an hour of startup
"freqai": {
"live_retrain_hours": 0.5
}
Or tell freqAI to avoid training before half an hour
"freqai": {
"expired_hours": 0.5
}
If you want to clear old models and save disk space
"freqai": {
"purge_old_models": true
}
If you want to use a pre-trained model, specify the identifier
"freqai": {
"identifier": "example",
}
Then freqAI will automatically download the required data based on all the configurations
Backtesting
Backtesting mode is different from before, you need to download the data in advance, and the time range should be larger
Command to start backtesting mode
freqtrade backtesting --strategy FreqaiExampleStrategy --strategy-path freqtrade/templates --config config_examples/config_freqai.example.json --freqaimodel LightGBMRegressor --timerange 20210501-20210701