skka3134

skka3134

email
telegram

加密貨幣和量化:7.AI配置

使用 freqAI 可以做什麼

  • 完成配置後可以使用 freqAI 去獲得一個

使用 freqtrade 需要準備什麼

  1. strategy
  2. configuration file
  3. model
    他們的路徑在這裡
freqtrade/templates/FreqaiExampleStrategy.py, freqtrade/freqai/prediction_models/LightGBMRegressor.py, and config_examples/config_freqai.example.json, respectively.

設置配置文件

    "freqai": {
        "enabled": true,
        "purge_old_models": 2,
        "train_period_days": 30, //用於訓練數據的天數
        "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
        }
    }

設置策略


    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,策略的啟動時期,策略的啟動時期,是指在這個時間內,指標的計算會有誤差,但具體的啟動時間是多長時間,為了解決這個問題,給策略分配 startup_candle_count 這個屬性,該值是計算指標所需要的最大周期,例如

startup_candle_count = 100
dataframe['ema100'] = ta.EMA(dataframe, timeperiod=100)

動態閥門
變量表
時間關鍵幀
特點
字典
安裝前提

注意事項
不能與 VolumePairlists
但是可以和 ShufflePairlist VolumePairlist

啟動 freqAI

freqtrade trade --config config_examples/config_freqai.example.json --strategy FreqaiExampleStrategy --freqaimodel LightGBMRegressor --strategy-path freqtrade/templates

當你啟動 freqAI 後,他會立即生成新的模型,如果你希望在啟動半小時後才開始訓練新的模型

    "freqai": {
        "live_retrain_hours": 0.5
    }

或者告訴 freqAI 避免早於半小時開始訓練

    "freqai": {
        "expired_hours": 0.5
    }

如果想要清空舊的模型,節省磁盤空間

    "freqai": {
        "purge_old_models": true
    }

如果想使用已經訓練的模型,指定 identifier

    "freqai": {
        "identifier": "example",
    }

然後 freqAI 會根據所有的配置自動下載需要的數據(如果沒有的話)
回測
回測模式不同於之前,需要提前下載數據,並且時間範圍要更大一些
啟動回測模式的命令

freqtrade backtesting --strategy FreqaiExampleStrategy --strategy-path freqtrade/templates --config config_examples/config_freqai.example.json --freqaimodel LightGBMRegressor --timerange 20210501-20210701

載入中......
此文章數據所有權由區塊鏈加密技術和智能合約保障僅歸創作者所有。