feat: 修复报错

This commit is contained in:
Daniel
2026-03-26 14:13:44 +08:00
commit b2223ec058
31 changed files with 17401 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
from .sma_cross import SmaCrossStrategy
__all__ = ["SmaCrossStrategy"]

View File

@@ -0,0 +1,22 @@
from __future__ import annotations
import backtrader as bt
class SmaCrossStrategy(bt.Strategy):
params = (
("fast", 3),
("slow", 8),
("stake", 1),
)
def __init__(self) -> None:
self.fast_sma = bt.indicators.SMA(self.data.close, period=self.params.fast)
self.slow_sma = bt.indicators.SMA(self.data.close, period=self.params.slow)
self.cross_signal = bt.indicators.CrossOver(self.fast_sma, self.slow_sma)
def next(self) -> None:
if not self.position and self.cross_signal > 0:
self.buy(size=self.params.stake)
elif self.position and self.cross_signal < 0:
self.close()