feat: 枢轴S/R注入回测引擎+v11系列——枢轴波段(v11.0)4仓+86.3%/回撤1.3%碾压MA10波段,证明复合强弱支撑优于简单均线;固定15%/ATR仍优于裸枢轴强压止盈
This commit is contained in:
+25
-1
@@ -170,9 +170,32 @@ def prepare_bars(code, start_date, end_date):
|
||||
trend_strength = calc_trend_strength(highs, lows, closes)
|
||||
obv = calc_obv(closes, volumes)
|
||||
roc = calc_roc(closes)
|
||||
|
||||
|
||||
bars = []
|
||||
for i in range(len(dates)):
|
||||
# ── 枢轴S/R(与实盘 technical_analysis.calc_support_resistance 同算法)──
|
||||
piv = {}
|
||||
if i >= 1:
|
||||
h, l, c = highs[i], lows[i], closes[i]
|
||||
yc = closes[i-1]
|
||||
# 多日波幅(近20日)
|
||||
win = bars[max(0, i-19):i] if i > 0 else []
|
||||
multi_high = max([h] + [x.get('high', 0) or 0 for x in win])
|
||||
multi_low = min([l] + [x.get('low', 1e9) or 1e9 for x in win])
|
||||
eff_range = max(h - l, multi_high - multi_low, c * 0.05)
|
||||
tp = (c - multi_low) / (multi_high - multi_low) if multi_high > multi_low else 0.5
|
||||
if tp > 0.8 or tp < 0.2:
|
||||
eff_range = max(eff_range, c * 0.08)
|
||||
pp = (h + l + c) / 3
|
||||
s1 = 2 * pp - h
|
||||
s2 = pp - eff_range
|
||||
r1 = 2 * pp - l
|
||||
r2 = pp + eff_range
|
||||
if yc < s1: s1 = yc
|
||||
if yc > r1: r1 = yc
|
||||
piv = {'pivot': pp, 'weak_support': s1, 'strong_support': s2,
|
||||
'weak_resist': r1, 'strong_resist': r2}
|
||||
|
||||
bars.append({
|
||||
'date': dates[i],
|
||||
'open': opens[i],
|
||||
@@ -192,6 +215,7 @@ def prepare_bars(code, start_date, end_date):
|
||||
'adx': trend_strength[i] if i < len(trend_strength) else None,
|
||||
'obv': obv[i] if i < len(obv) else None,
|
||||
'roc': roc[i] if i < len(roc) else None,
|
||||
**piv,
|
||||
})
|
||||
return bars
|
||||
|
||||
|
||||
Reference in New Issue
Block a user