A feature-rich Python framework for backtesting and trading

backtrader allows you to focus on writing reusable trading strategies, indicators and analyzers instead of having to spend time building infrastructure.


Open Source

Use, modify, audit and share it. The secret is in the sauce and you are the cook. This is just the tool.

GitHub Repo

Feature Complete

Multiple Data Feeds, timeframes, strategies, indicators, optimization and more.

See More

Fully Documented

Check the QuickStart, In-Depth topics, Indicators and also ideas and others in the blog.

See Docs See Blog

Community Enabled

See what others have already asked, answered & shared. You are the community! Join and be it!

Community


It can be as easy as this snippet!

	
    from datetime import datetime
    import backtrader as bt
    
    class SmaCross(bt.SignalStrategy):
        params = (('pfast', 10), ('pslow', 30),)
        def __init__(self):
            sma1, sma2 = bt.ind.SMA(period=self.p.pfast), bt.ind.SMA(period=self.p.pslow)
            self.signal_add(bt.SIGNAL_LONG, bt.ind.CrossOver(sma1, sma2))
    
    cerebro = bt.Cerebro()
    
    data = bt.feeds.YahooFinanceData(dataname='YHOO', fromdate=datetime(2011, 1, 1),
                                     todate=datetime(2012, 12, 31))
    cerebro.adddata(data)

    cerebro.addstrategy(SmaCross)
    cerebro.run()
    cerebro.plot()
	
      

x


In these few lines you'll find a complete SMA CrossOver strategy with customizable parameters, automatic order management and plotting. There are many other possibilities. Check it out!


...

Click the Chart!


Used in
Drop a note in the community f you also use it
   2 EuroStoxx 50 Banks
   6 Quantitative Trading Firms