Skip to main content

BackTesting Engine - A feature-rich Python framework for backtesting and trading

Project description

nijigen-backtrader

PyPI Version License Python versions

A feature-rich Python framework for backtesting and trading.

Note: This is a maintained fork of the original backtrader project.

Quick Start

Here's 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 as sigsmacross/sigsmacross2.py. Along it is sigsmacross.py which can be parametrized from the command line.

Features

Live Trading and backtesting platform written in Python.

  • Live Data Feed and Trading with

    • Interactive Brokers (needs IbPy and benefits greatly from an installed pytz)
    • Visual Chart (needs a fork of comtypes until a pull request is integrated in the release and benefits from pytz)
    • Oanda (needs oandapy) (REST API Only - v20 did not support streaming when implemented)
  • Data feeds from csv/files, online sources or from pandas and blaze

  • Filters for datas, like breaking a daily bar into chunks to simulate intraday or working with Renko bricks

  • Multiple data feeds and multiple strategies supported

  • Multiple timeframes at once

  • Integrated Resampling and Replaying

  • Step by Step backtesting or at once (except in the evaluation of the Strategy)

  • Integrated battery of indicators

  • TA-Lib indicator support (needs python ta-lib / check the docs)

  • Easy development of custom indicators

  • Analyzers (for example: TimeReturn, Sharpe Ratio, SQN) and pyfolio integration (deprecated)

  • Flexible definition of commission schemes

  • Integrated broker simulation with Market, Close, Limit, Stop, StopLimit, StopTrail, StopTrailLimit and OCO orders, bracket order, slippage, volume filling strategies and continuous cash adjustment for future-like instruments

  • Sizers for automated staking

  • Cheat-on-Close and Cheat-on-Open modes

  • Schedulers

  • Trading Calendars

  • Plotting (requires matplotlib)

Documentation

Python Support

  • Python >= 3.9
  • It also works with pypy and pypy3 (no plotting - matplotlib is not supported under pypy)

Installation

nijigen-backtrader is self-contained with no external dependencies (except if you want to plot)

From pypi:

pip install nijigen-backtrader

With plotting support:

pip install nijigen-backtrader[plotting]

Note: The minimum matplotlib version is 1.4.1

Optional Dependencies

An example for IB Data Feeds/Trading:

  • IbPy doesn't seem to be in PyPi. Do either:

    pip install git+https://github.com/blampe/IbPy.git
    

    or (if git is not available in your system):

    pip install https://github.com/blampe/IbPy/archive/master.zip
    

For other functionalities like: Visual Chart, Oanda, TA-Lib, check the dependencies in the documentation.

From source:

  • Place the backtrader directory found in the sources inside your project

Version Numbering

X.Y.Z

  • X: Major version number. Should stay stable unless something big is changed like an overhaul to use numpy
  • Y: 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 fixes

License

GNU General Public License v3.0 or later (GPLv3+)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nijigen_backtrader-1.10.1.tar.gz (290.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nijigen_backtrader-1.10.1-py3-none-any.whl (418.6 kB view details)

Uploaded Python 3

File details

Details for the file nijigen_backtrader-1.10.1.tar.gz.

File metadata

  • Download URL: nijigen_backtrader-1.10.1.tar.gz
  • Upload date:
  • Size: 290.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for nijigen_backtrader-1.10.1.tar.gz
Algorithm Hash digest
SHA256 7d1efa3e257f094765f0f50194f43c6c7cf3873d35eb0ccdf2d39e34e4afcd74
MD5 8df8169489b5ed88a3941291a9beb9bf
BLAKE2b-256 b75c6bd12d48a24c6bbd150c2a46d8e51a4099a41b30fb54ff6e66b86716c6bb

See more details on using hashes here.

File details

Details for the file nijigen_backtrader-1.10.1-py3-none-any.whl.

File metadata

File hashes

Hashes for nijigen_backtrader-1.10.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6dfa5a14670472297de922f251680c44feba4bd4cbc7d426a49bc40c2bb78f06
MD5 532e6820bf8a24fb99f36f716ac49f22
BLAKE2b-256 6c87002c9b03ca2db9804b6a25d697ccb28e08622855bb67612a84390ff1d104

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page