加入了在a117548d02中拥有的ai辅助指标
This commit is contained in:
parent
406a412f8c
commit
cb032be176
@ -51,6 +51,7 @@ class FreqaiPrimer(IStrategy):
|
|||||||
}
|
}
|
||||||
|
|
||||||
def feature_engineering_expand_all(self, dataframe: DataFrame, period: int, metadata: dict, **kwargs) -> DataFrame:
|
def feature_engineering_expand_all(self, dataframe: DataFrame, period: int, metadata: dict, **kwargs) -> DataFrame:
|
||||||
|
# 保留原有指标
|
||||||
dataframe["%-rsi-period"] = ta.RSI(dataframe, timeperiod=period)
|
dataframe["%-rsi-period"] = ta.RSI(dataframe, timeperiod=period)
|
||||||
dataframe["%-sma-period"] = ta.SMA(dataframe, timeperiod=period)
|
dataframe["%-sma-period"] = ta.SMA(dataframe, timeperiod=period)
|
||||||
dataframe["%-ema-period"] = ta.EMA(dataframe, timeperiod=period)
|
dataframe["%-ema-period"] = ta.EMA(dataframe, timeperiod=period)
|
||||||
@ -61,8 +62,24 @@ class FreqaiPrimer(IStrategy):
|
|||||||
dataframe["bb_upperband-period"] = upperband
|
dataframe["bb_upperband-period"] = upperband
|
||||||
dataframe["bb_middleband-period"] = middleband
|
dataframe["bb_middleband-period"] = middleband
|
||||||
dataframe["%-bb_width-period"] = (dataframe["bb_upperband-period"] - dataframe["bb_lowerband-period"]) / dataframe["bb_middleband-period"]
|
dataframe["%-bb_width-period"] = (dataframe["bb_upperband-period"] - dataframe["bb_lowerband-period"]) / dataframe["bb_middleband-period"]
|
||||||
|
|
||||||
dataframe["%-roc-period"] = ta.ROC(dataframe, timeperiod=period)
|
dataframe["%-roc-period"] = ta.ROC(dataframe, timeperiod=period)
|
||||||
|
|
||||||
|
# 添加策略 B 的指标
|
||||||
|
dataframe["%-mfi-period"] = ta.MFI(dataframe, timeperiod=period) # 资金流指标
|
||||||
|
dataframe["%-adx-period"] = ta.ADX(dataframe, timeperiod=period) # 趋势强度
|
||||||
|
dataframe["%-tema-period"] = ta.TEMA(dataframe, timeperiod=period) # TEMA 指标
|
||||||
|
dataframe["%-relative_volume-period"] = dataframe["volume"] / dataframe["volume"].rolling(period).mean() # 相对成交量
|
||||||
|
dataframe["%-close-bb_lower-period"] = dataframe["close"] / dataframe["bb_lowerband-period"] # 收盘价/布林带下轨
|
||||||
|
|
||||||
|
# 数据清理
|
||||||
|
columns_to_clean = [
|
||||||
|
"%-rsi-period", "%-mfi-period", "%-sma-period", "%-ema-period", "%-adx-period",
|
||||||
|
"bb_lowerband-period", "bb_middleband-period", "bb_upperband-period",
|
||||||
|
"%-bb_width-period", "%-roc-period", "%-relative_volume-period", "%-close-bb_lower-period", "%-tema-period"
|
||||||
|
]
|
||||||
|
for col in columns_to_clean:
|
||||||
|
dataframe[col] = dataframe[col].replace([np.inf, -np.inf], 0).ffill().fillna(0)
|
||||||
|
|
||||||
return dataframe
|
return dataframe
|
||||||
|
|
||||||
def set_freqai_targets(self, dataframe: DataFrame, metadata: dict, **kwargs) -> DataFrame:
|
def set_freqai_targets(self, dataframe: DataFrame, metadata: dict, **kwargs) -> DataFrame:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user