Spaces:
Running
Running
File size: 659 Bytes
bb4e28f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
import bt
def run_simple_backtest(
strategy_name="SMA Cross", tickers=["AAPL"], sma_short=20, sma_long=50
):
def strategy_logic():
prices = bt.get(tickers, start="2020-01-01")
sma_s = prices.rolling(sma_short).mean()
sma_l = prices.rolling(sma_long).mean()
# Note: Signal is not used in bt directly
return bt.Strategy(
strategy_name,
[
bt.algos.SelectAll(),
bt.algos.WeighEqually(),
bt.algos.Rebalance(),
]
)
s = strategy_logic()
data = bt.get(tickers)
test = bt.Backtest(s, data)
return bt.run(test)
|