Files
GitHubandClaude Opus 4.8 b5b5d0dc5b release: v1.8.0 - backtest engine with batch strategy comparison
- Add backtest section to README with CLI usage and run_all_strategies.py demo
- Update all version numbers to 1.8.0 (pyproject.toml, __init__.py, cli/__init__.py, docs/conf.py)
- Fix turtle_breakout strategy: TAQ returns 3 values (UP, MID, DOWN)
- Add run_all_strategies.py batch comparison script
- Update README intro to highlight backtest feature
- Add backtest to CLI command table and architecture tree

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-09 20:35:38 +08:00

30 lines
851 B
Python

"""海龟交易法(唐安奇通道)策略。
价格突破 N 日最高价买入,跌破 N 日最低价卖出。
经典的趋势跟踪策略。
用法::
easy-tdx backtest SZ 000001 --strategy-file strategies/turtle_breakout.py --table
"""
from easy_tdx.backtest import Strategy
from easy_tdx import MyTT
class TurtleStrategy(Strategy):
"""海龟交易法(唐安奇通道突破)策略。"""
def init(self) -> None:
self.upper, _, self.lower = self.I(MyTT.TAQ, self.data.high, self.data.low, 20)
def next(self) -> None:
cur = self.data.close[0]
upper = self.upper[self._bar_index]
lower = self.lower[self._bar_index]
if cur >= upper and self.position["size"] == 0:
self.buy(size=0)
elif cur <= lower and self.position["size"] > 0:
self.sell(size=0)