完成模型更新
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
"""
|
||||
扩展特征 v3.4 (16维)
|
||||
扩展特征 v3.4 + v6.7新增 (20维: 16维 v3.4 + 4维 v6.7新增)
|
||||
"""
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
from core.scoring.features.v3_2_features import _ols_slope
|
||||
from core.scoring.features.v3_3_features import _grid_touch_count
|
||||
from core.scoring.config import GRID_LOW, GRID_HIGH
|
||||
|
||||
|
||||
@@ -104,6 +105,29 @@ def calculate_features_v3_4(ctx) -> pd.DataFrame:
|
||||
feat['wick_ratio_20d'] = np.mean(
|
||||
wick_len / np.where(total_len > 0, total_len, 1)) * 100
|
||||
|
||||
# ── v6.7 新增 4 维特征 ──────────────────────────────
|
||||
# 53. vol_decay_5d: 近5日波动率 / 近20日波动率 (波动率用对数收益std)
|
||||
log_ret = np.diff(np.log(np.maximum(closes, 1e-10)))
|
||||
vol_5d = np.std(log_ret[-5:], ddof=1) if len(log_ret) >= 5 else 0
|
||||
vol_20d = np.std(log_ret[-20:], ddof=1) if len(log_ret) >= 20 else vol_5d
|
||||
feat['vol_decay_5d'] = float(vol_5d / vol_20d) if vol_20d > 0 else 0.0
|
||||
|
||||
# 54. grid_touch_relative_10d: 10日振幅比 / 60日振幅比
|
||||
range_10d = float(np.max(highs[-10:]) - np.min(lows[-10:]))
|
||||
range_60d = float(np.max(highs[-60:]) - np.min(lows[-60:])) if len(highs) >= 60 else range_10d
|
||||
close_now = float(closes[-1])
|
||||
close_60d_mean = float(np.mean(closes[-60:])) if len(closes) >= 60 else close_now
|
||||
if close_now > 0 and close_60d_mean > 0 and range_60d > 0:
|
||||
feat['grid_touch_relative_10d'] = (range_10d / close_now) / (range_60d / close_60d_mean)
|
||||
else:
|
||||
feat['grid_touch_relative_10d'] = 0.0
|
||||
|
||||
# 55. vol_decay_x_grid_balance: vol_decay × 网格均衡度
|
||||
feat['vol_decay_x_grid_balance'] = feat['vol_decay_5d'] * feat.get('grid_room_balance', 0.0)
|
||||
|
||||
# 56. vol_decay_x_dist_lower: vol_decay × 下轨距离
|
||||
feat['vol_decay_x_dist_lower'] = feat['vol_decay_5d'] * feat.get('dist_to_grid_lower', 0.0)
|
||||
|
||||
features[code] = feat
|
||||
|
||||
return pd.DataFrame.from_dict(features, orient='index')
|
||||
|
||||
Reference in New Issue
Block a user