feat: phase 1 — data downloader, backtrader runner, SMA strategy

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Yuxuan Yan
2026-06-07 09:21:16 +08:00
parent 338c912029
commit fd86190e9a
19 changed files with 456 additions and 0 deletions
View File
+23
View File
@@ -0,0 +1,23 @@
"""Base strategy and example SMA crossover for Chinese equities."""
import backtrader as bt
class SmaCross(bt.Strategy):
"""Simple SMA crossover strategy: buy when fast crosses above slow, sell when below."""
params = (
("fast", 10),
("slow", 30),
)
def __init__(self):
self.fast_ma = bt.indicators.SMA(self.data.close, period=self.params.fast)
self.slow_ma = bt.indicators.SMA(self.data.close, period=self.params.slow)
self.crossover = bt.indicators.CrossOver(self.fast_ma, self.slow_ma)
def next(self):
if not self.position:
if self.crossover > 0: # fast crosses above slow
self.buy()
elif self.crossover < 0: # fast crosses below slow
self.close()