Package: backtrader
backtraderYahoo API Note:[2018-11-16] After some testing it would seem that data downloads can be
again relied upon over the web interface (or APIv7)TicketsThe ticket system is (was, actually) more often than not abused to ask for
advice about samples.Forfeedback/questions/…use theCommunityHere a snippet of a Simple Moving Average CrossOver. It can be done in several
different ways. Use the docs (and examples) Luke!from datetime import datetime
import backtrader as bt

class SmaCross(bt.SignalStrategy):
    def __init__(self):
        sma1, sma2 = bt.ind.SMA(period=10), bt.ind.SMA(period=30)
        crossover = bt.ind.CrossOver(sma1, sma2)
        self.signal_add(bt.SIGNAL_LONG, crossover)

cerebro = bt.Cerebro()
cerebro.addstrategy(SmaCross)

data0 = bt.feeds.YahooFinanceData(dataname='MSFT', fromdate=datetime(2011, 1, 1),
                                  todate=datetime(2012, 12, 31))
cerebro.adddata(data0)

cerebro.run()
cerebro.plot()Including a full featured chart. Give it a try! This is included in the samples
assigsmacross/sigsmacross2.py. Along it issigsmacross.pywhich can be
parametrized from the command line.Features:Live Trading and backtesting platform written in Python.Live Data Feed and Trading withInteractive Brokers (needsIbPyand benefits greatly from an
installedpytz)Visual Chart(needs a fork ofcomtypesuntil a pull request is
integrated in the release and benefits frompytz)Oanda(needsoandapy) (REST API Only - v20 did not support
streaming when implemented)Data feeds from csv/files, online sources or frompandasandblazeFilters for datas, like breaking a daily bar into chunks to simulate
intraday or working with Renko bricksMultiple data feeds and multiple strategies supportedMultiple timeframes at onceIntegrated Resampling and ReplayingStep by Step backtesting or at once (except in the evaluation of the Strategy)Integrated battery of indicatorsTA-Libindicator support (needs pythonta-lib/ check the docs)Easy development of custom indicatorsAnalyzers (for example: TimeReturn, Sharpe Ratio, SQN) andpyfoliointegration (deprecated)Flexible definition of commission schemesIntegrated broker simulation withMarket,Close,Limit,Stop,StopLimit,StopTrail,StopTrailLimit*and *OCOorders, bracket order,
slippage, volume filling strategies and continuous cash adjustmet for
future-like instrumentsSizers for automated stakingCheat-on-Close and Cheat-on-Open modesSchedulersTrading CalendarsPlotting (requires matplotlib)DocumentationThe blog:BlogRead the full documentation at:DocumentationList of built-in Indicators (122)Indicators ReferencePython 2/3 SupportPython >=3.2It also works withpypyandpypy3(no plotting -matplotlibis
not supported underpypy)Installationbacktraderis self-contained with no external dependencies (except if you
want to plot)Frompypi:pip install backtraderpip install backtrader[plotting]Ifmatplotlibis not installed and you wish to do some plottingNoteThe minimum matplotlib version is1.4.1An example forIBData Feeds/Trading:IbPydoesn’t seem to be in PyPi. Do either:pip install git+https://github.com/blampe/IbPy.gitor (ifgitis not available in your system):pip install https://github.com/blampe/IbPy/archive/master.zipFor other functionalities like:Visual Chart,Oanda,TA-Lib, check
the dependencies in the documentation.From source:Place thebacktraderdirectory found in the sources inside your projectVersion numberingX.Y.Z.IX: Major version number. Should stay stable unless something big is changed
like an overhaul to usenumpyY: Minor version number. To be changed upon adding a complete new feature or
(god forbids) an incompatible API change.Z: Revision version number. To be changed for documentation updates, small
changes, small bug fixesI: Number of Indicators already built into the platform