Files
big-qmt/labs/analysis/etf/entries.py
2026-09-19 19:45:43 +08:00

41 lines
1.5 KiB
Python

"""入场机会频率:日线上"进入门槛 + 当日收回门槛以上"到底出现多少次,以及 MA60 上限的影响。
用法: py -3.14 -B analysis/etf/entries.py
"""
import sys
from datetime import date
from pathlib import Path
HERE = Path(__file__).resolve().parent
sys.path.insert(0, str(HERE))
from backtest import SYMBOLS, SYMBOL_PARAMS, EtfDefaults, EtfSymbolConfig, fetch_daily, precondition
BASE = EtfDefaults()
data = {c: fetch_daily(c) for c in SYMBOLS}
print(f"{'标的':11} {'可回放日':>7} {'跌破门槛':>8} {'收在门槛上':>10} {'入场信号':>8} "
f"{'低于门槛的天数占比':>18} {'现价<MA60 天数占比':>18}")
for code in SYMBOLS:
series = precondition(data[code], EtfSymbolConfig(**SYMBOL_PARAMS[code]), BASE)
below = above = signal = 0
below_ma = 0
for bar, ind in series:
entry, ma60 = ind["etf_entry"], ind["etf_ma60"]
if bar["low"] <= entry:
below += 1
if bar["close"] > entry and bar["low"] <= entry:
above += 1
if bar["low"] <= entry and bar["close"] > entry:
signal += 1
if bar["close"] < ma60:
below_ma += 1
n = len(series)
print(f"{code:11} {n:7} {below:8} {above:10} {signal:8} "
f"{below / n * 100:17.1f}% {below_ma / n * 100:17.1f}%")
print()
print("说明:'入场信号' = 当日最低价跌破入场门槛、且收盘价收回门槛之上(回测里建网的日线近似)。")
print(" 它是机会频率的上界:实盘还要再满足盘中反弹 0.5% 的确认。")