先shift再rolling,逻辑混乱

This commit is contained in:
zhangkun9038@dingtalk.com 2026-01-16 00:50:06 +08:00
parent 7b8e9250a2
commit 2ed9286e90

View File

@ -348,8 +348,8 @@ class FreqaiPrimer(IStrategy):
current_volatility = dataframe["close"].pct_change().rolling(window=10, min_periods=5).std()
# 计算未来10根K线的波动率向未来移动
future_pct_change = dataframe["close"].pct_change().shift(-1) # 未来的收盘价变化
future_volatility = future_pct_change.rolling(window=10, min_periods=5).std().shift(-9) # 未来10根K线的波动率
# 正确做法:先计算 rolling再整体 shift
future_volatility = dataframe["close"].pct_change().rolling(window=10, min_periods=5).std().shift(-10)
# 标签:未来波动率 > 当前波动率 * 1.5 则标记为高波动(趋势启动)
volatility_ratio = future_volatility / (current_volatility + 1e-8) # 避免除以0