添加了全面的量价关系指标,包括成交量趋势指标和量价关系指标
This commit is contained in:
parent
45c3c0f1fc
commit
c8616c3175
@ -89,6 +89,25 @@
|
||||
- 使用高级市场状态信息进行决策
|
||||
- 实现了动态止损调整
|
||||
|
||||
#### 4.6 量价关系指标添加
|
||||
- **成交量趋势指标**:
|
||||
- `volume_change`: 成交量变化率
|
||||
- `volume_ma_ratio`: 成交量移动平均比值
|
||||
- `volume_std`: 成交量标准差(衡量成交量波动性)
|
||||
- `volume_cv`: 成交量变异系数
|
||||
- `volume_zscore`: 成交量Z分数(检测异常成交量)
|
||||
- `volume_trend`: 成交量趋势(成交量是否在上升通道)
|
||||
- `volume_ema_fast/slow`: 成交量EMA趋势
|
||||
|
||||
- **量价关系指标**:
|
||||
- `price_change`: 价格变化率
|
||||
- `volume_price_confirmation`: 量价确认度(价格和成交量同向变动)
|
||||
- `volume_price_ratio`: 量价比率(成交量/价格)
|
||||
- `bearish_divergence`: 熊市背离(价格创新高但成交量未创新高)
|
||||
- `bullish_divergence`: 牛市背离(价格创新低但成交量未创新低)
|
||||
- `obv`: OBV平衡成交量
|
||||
- `volume_price_corr_short/medium`: 量价相关系数(短期/中期窗口)
|
||||
|
||||
### 5. 移除的逻辑
|
||||
- 移除了冷启动保护逻辑,确保回测和实盘的一致性
|
||||
|
||||
|
||||
@ -706,6 +706,59 @@ class FreqaiPrimer(IStrategy):
|
||||
# 为第一行设置默认值
|
||||
dataframe['prev_market_state'] = dataframe['prev_market_state'].fillna('neutral')
|
||||
|
||||
# ========== 新增:成交量趋势指标 ==========
|
||||
# 成交量变化率
|
||||
dataframe['volume_change'] = dataframe['volume'].pct_change()
|
||||
|
||||
# 成交量移动平均比值
|
||||
dataframe['volume_ma_ratio'] = dataframe['volume'] / dataframe['volume_ma']
|
||||
|
||||
# 成交量标准差(衡量成交量波动性)
|
||||
dataframe['volume_std'] = dataframe['volume'].rolling(window=20).std()
|
||||
dataframe['volume_cv'] = dataframe['volume_std'] / dataframe['volume_ma'] # 变异系数
|
||||
|
||||
# 成交量Z分数(检测异常成交量)
|
||||
dataframe['volume_zscore'] = (dataframe['volume'] - dataframe['volume_ma']) / dataframe['volume_std']
|
||||
|
||||
# 成交量趋势(成交量是否在上升通道)
|
||||
dataframe['volume_trend'] = np.where(dataframe['volume'] > dataframe['volume_ma'], 1, 0)
|
||||
|
||||
# 成交量EMA趋势
|
||||
dataframe['volume_ema_fast'] = dataframe['volume'].ewm(span=5, adjust=False).mean()
|
||||
dataframe['volume_ema_slow'] = dataframe['volume'].ewm(span=20, adjust=False).mean()
|
||||
dataframe['volume_ema_trend'] = np.where(dataframe['volume_ema_fast'] > dataframe['volume_ema_slow'], 1, 0)
|
||||
|
||||
# ========== 新增:量价关系指标 ==========
|
||||
# 价格变化率
|
||||
dataframe['price_change'] = dataframe['close'].pct_change()
|
||||
|
||||
# 量价确认度(价格和成交量同向变动)
|
||||
dataframe['volume_price_confirmation'] = np.sign(dataframe['price_change']) * np.sign(dataframe['volume_change'])
|
||||
|
||||
# 量价比率(成交量/价格)
|
||||
dataframe['volume_price_ratio'] = dataframe['volume'] / dataframe['close']
|
||||
|
||||
# 量价背离检测
|
||||
# 价格创新高但成交量未创新高(顶背离)
|
||||
dataframe['price_new_high'] = (dataframe['close'] == dataframe['close'].rolling(20).max()).astype(int)
|
||||
dataframe['volume_new_high'] = (dataframe['volume'] == dataframe['volume'].rolling(20).max()).astype(int)
|
||||
dataframe['bearish_divergence'] = (dataframe['price_new_high'] == 1) & (dataframe['volume_new_high'] == 0)
|
||||
|
||||
# 价格创新低但成交量未创新低(底背离)
|
||||
dataframe['price_new_low'] = (dataframe['close'] == dataframe['close'].rolling(20).min()).astype(int)
|
||||
dataframe['volume_new_low'] = (dataframe['volume'] == dataframe['volume'].rolling(20).min()).astype(int)
|
||||
dataframe['bullish_divergence'] = (dataframe['price_new_low'] == 1) & (dataframe['volume_new_low'] == 0)
|
||||
|
||||
# OBV (On Balance Volume) - 平衡成交量
|
||||
dataframe['obv'] = dataframe['volume'] * np.sign(dataframe['close'].diff())
|
||||
dataframe['obv'] = dataframe['obv'].cumsum()
|
||||
|
||||
# 量价相关系数(短期窗口)
|
||||
dataframe['volume_price_corr_short'] = dataframe['close'].pct_change().rolling(window=10).corr(dataframe['volume'].pct_change())
|
||||
|
||||
# 量价相关系数(中期窗口)
|
||||
dataframe['volume_price_corr_medium'] = dataframe['close'].pct_change().rolling(window=20).corr(dataframe['volume'].pct_change())
|
||||
|
||||
# 记录当前的市场状态
|
||||
if len(dataframe) > 0:
|
||||
current_score = dataframe['market_score'].iloc[-1]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user