edc50e8809
- 数据层: build_aggregates_sql 新增 2h/6h 聚合视图,默认起始时间调整为 2017-05 - 模型层: KlineInterval 类型扩展 2h/6h,DataService 新增对应表名和毫秒映射 - 指标层: 新增 incremental.py 增量指标模块 (EmaInc/AtrInc/RsiInc/BbInc),O(1) per bar - 策略重构: long_short.py 和 regime_all.py 从批量 ema/atr 迁移至增量指标,避免每 bar 重复全量计算 - regime 探测器: RegimeDetector3 改为增量 EMA200,detect() 接口简化 - 回测扩展: regime_timeframe_comparison 从 4h/1d 扩展至 2h/4h/6h/1d - 新增示例: multi_strategy_report, vol_break_compare/periods, intraday_explore, top3_trades 等分析脚本
34 lines
1.0 KiB
Python
34 lines
1.0 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
|
|
|
|
__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",
|
|
]
|