散户生存之道;鼓励入场,惩罚长时间持有+2
This commit is contained in:
parent
2839ea9ad1
commit
34ea6a04eb
@ -71,8 +71,8 @@ class FreqaiPrimer(IStrategy):
|
||||
|
||||
# 添加用于检测大户操纵的特征
|
||||
# 1. 价格波动率特征
|
||||
dataframe["%-volatility_5"] = dataframe["close"].rolling(5).std()
|
||||
dataframe["%-volatility_10"] = dataframe["close"].rolling(10).std()
|
||||
dataframe["%-volatility_5"] = dataframe["close"].rolling(5).std().fillna(0)
|
||||
dataframe["%-volatility_10"] = dataframe["close"].rolling(10).std().fillna(0)
|
||||
|
||||
# 2. 量价关系特征
|
||||
dataframe["%-volume_change"] = dataframe["volume"].pct_change().fillna(0)
|
||||
@ -80,24 +80,36 @@ class FreqaiPrimer(IStrategy):
|
||||
|
||||
# 3. 价格偏离特征 - 直接计算布林带而不依赖外部列
|
||||
bbands = ta.bbands(dataframe['close'], length=20, std=2)
|
||||
dataframe["%-bb_upper"] = bbands['BBU_20_2.0']
|
||||
dataframe["%-bb_lower"] = bbands['BBL_20_2.0']
|
||||
dataframe["%-bb_position"] = (dataframe["close"] - dataframe["%-bb_lower"]) / (dataframe["%-bb_upper"] - dataframe["%-bb_lower"])
|
||||
dataframe["%-hl_ratio"] = (dataframe["high"] - dataframe["low"]) / dataframe["close"]
|
||||
dataframe["%-bb_upper"] = bbands['BBU_20_2.0'].fillna(dataframe['close'])
|
||||
dataframe["%-bb_lower"] = bbands['BBL_20_2.0'].fillna(dataframe['close'])
|
||||
bb_width = dataframe["%-bb_upper"] - dataframe["%-bb_lower"]
|
||||
bb_width = bb_width.replace(0, 1e-10)
|
||||
dataframe["%-bb_position"] = (dataframe["close"] - dataframe["%-bb_lower"]) / bb_width
|
||||
dataframe["%-bb_position"] = dataframe["%-bb_position"].fillna(0.5)
|
||||
dataframe["%-hl_ratio"] = (dataframe["high"] - dataframe["low"]) / dataframe["close"].replace(0, 1e-10)
|
||||
dataframe["%-hl_ratio"] = dataframe["%-hl_ratio"].fillna(0)
|
||||
|
||||
# 4. VWAP 特征 (简化版)
|
||||
dataframe["%-vwap"] = (dataframe['volume'] * (dataframe['high'] + dataframe['low'] + dataframe['close']) / 3).rolling(window=20).sum() / dataframe['volume'].rolling(window=20).sum()
|
||||
dataframe["%-price_vwap_diff"] = (dataframe["close"] - dataframe["%-vwap"]) / dataframe["%-vwap"]
|
||||
volume_sum = dataframe['volume'].rolling(window=20).sum().replace(0, 1e-10)
|
||||
typical_price = (dataframe['high'] + dataframe['low'] + dataframe['close']) / 3
|
||||
vwap_numerator = (dataframe['volume'] * typical_price).rolling(window=20).sum()
|
||||
dataframe["%-vwap"] = vwap_numerator / volume_sum
|
||||
dataframe["%-vwap"] = dataframe["%-vwap"].fillna(dataframe['close'])
|
||||
vwap_safe = dataframe["%-vwap"].replace(0, 1e-10)
|
||||
dataframe["%-price_vwap_diff"] = (dataframe["close"] - dataframe["%-vwap"]) / vwap_safe
|
||||
dataframe["%-price_vwap_diff"] = dataframe["%-price_vwap_diff"].fillna(0)
|
||||
|
||||
# 5. MFI (资金流量指标) - 简化版
|
||||
typical_price = (dataframe['high'] + dataframe['low'] + dataframe['close']) / 3
|
||||
money_flow = typical_price * dataframe['volume']
|
||||
dataframe["%-mfi"] = ta.rsi(money_flow.fillna(0), length=14)
|
||||
dataframe["%-mfi"] = dataframe["%-mfi"].fillna(50)
|
||||
|
||||
# 6. Z-Score (标准分) - 检测异常波动
|
||||
rolling_mean = dataframe['close'].rolling(window=20).mean()
|
||||
rolling_std = dataframe['close'].rolling(window=20).std()
|
||||
rolling_mean = dataframe['close'].rolling(window=20).mean().fillna(dataframe['close'])
|
||||
rolling_std = dataframe['close'].rolling(window=20).std().fillna(0)
|
||||
rolling_std = rolling_std.replace(0, 1e-10)
|
||||
dataframe["%-z_score"] = (dataframe['close'] - rolling_mean) / rolling_std
|
||||
dataframe["%-z_score"] = dataframe["%-z_score"].fillna(0)
|
||||
|
||||
return dataframe
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user