4294ec401d
- engine/indicators/regime.py: RegimeDetector(四法投票) + MultiTimeframeRegime(多周期并行) 四法: EMA200斜率 / 价格vsEMA200 / ATH回撤 / 窄幅盘整(<3%振幅) 全部 O(1)/bar 增量计算,适用于回测和实时 - engine/example/regime_display.py: 多周期牛熊矩阵展示脚本 独立加载各周期数据 → 运行判定 → 日线对齐矩阵 + 详细拆解 + 统计 输出 engine/backtest/REGIME_MATRIX_BTCUSDT.md - engine/example/regime_mtf_strategy.py: 多周期共识策略 + 四策略对比回测 MTF Consensus: 1w定方向 + 1d确认 + 4h EMA入场 vs Old Regime(单TF基线) vs Long/Short(无过滤) - engine/indicators/__init__.py: 导出 RegimeDetector, MultiTimeframeRegime
37 lines
1.1 KiB
Python
37 lines
1.1 KiB
Python
"""
|
|
技术指标库
|
|
|
|
提供常用的趋势、动量、波动率和成交量指标计算。
|
|
所有函数均为纯 Python 实现,无外部依赖。
|
|
|
|
用法:
|
|
from engine.indicators import sma, ema, macd, rsi, bollinger, atr
|
|
|
|
closes = [100.0, 101.0, 102.0, ...]
|
|
ma = sma(closes, period=20)
|
|
rsi_vals = rsi(closes, period=14)
|
|
upper, mid, lower = bollinger(closes, period=20, std=2)
|
|
"""
|
|
|
|
from .trend import sma, ema, macd, macd_signal, macd_histogram, adx
|
|
from .momentum import rsi, stoch, stoch_k, stoch_d
|
|
from .volatility import bollinger, bollinger_upper, bollinger_mid, bollinger_lower, atr
|
|
from .volume import obv, vwap
|
|
from .incremental import EmaInc, AtrInc, RsiInc, BbInc
|
|
from .regime import RegimeDetector, MultiTimeframeRegime
|
|
|
|
__all__ = [
|
|
# 趋势
|
|
"sma", "ema", "macd", "macd_signal", "macd_histogram", "adx",
|
|
# 动量
|
|
"rsi", "stoch", "stoch_k", "stoch_d",
|
|
# 波动率
|
|
"bollinger", "bollinger_upper", "bollinger_mid", "bollinger_lower", "atr",
|
|
# 成交量
|
|
"obv", "vwap",
|
|
# 增量
|
|
"EmaInc", "AtrInc", "RsiInc", "BbInc",
|
|
# 牛熊判定
|
|
"RegimeDetector", "MultiTimeframeRegime",
|
|
]
|