Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Backtests Python trading strategies with data feeds, brokers, commission and slippage models, analyzers, and live trading support.
86% 91%+5 ptsof test cases passed
Passed 20 of 22 test cases with the skill, and 19 of 22 without it.
How do you feed historical pricing data into the main simulation engine instance?
Calls adddata on the cerebro instance
3 of 3 safety checks passed
Backtrader is a Python backtesting framework for trading strategies. Supports multiple data feeds, live trading, commission/slippage models, custom analyzers, and visualization. Well-suited for equity, futures, and crypto strategy development.
uv pip install backtrader
import backtrader as bt
class SmaCross(bt.Strategy):
params = dict(short=10, long=30)
def __init__(self):
sma_short = bt.ind.SMA(self.data.close, period=self.params.short)
sma_long = bt.ind.SMA(self.data.close, period=self.params.long)
self.crossover = bt.ind.CrossOver(sma_short, sma_long)
def next(self):
if self.crossover > 0:
self.buy()
elif self.crossover < 0:
self.sell()
cerebro = bt.Cerebro()
data = bt.feeds.YahooFinanceData(dataname="AAPL", fromdate="2022-01-01", todate="2023-01-01")
cerebro.adddata(data)
cerebro.addstrategy(SmaCross)
cerebro.broker.setcash(10000.0)
print(f"Final value: ${cerebro.run()[0]:.2f}")
cerebro.plot()
Skills that do similar work, with their benchmark result.
Next to this one in the catalogue, plus more from the same author.