Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Python Backtesting library for trading strategies

License

NotificationsYou must be signed in to change notification settings

paperswithbacktest/pwb-backtrader

 
 

Repository files navigation

.. image::https://img.shields.io/pypi/v/backtrader.svg:alt: PyPi Version:scale: 100%:target:https://pypi.python.org/pypi/backtrader/

.. .. image::https://img.shields.io/pypi/dm/backtrader.svg:alt: PyPi Monthly Donwloads:scale: 100%:target:https://pypi.python.org/pypi/backtrader/

.. image::https://img.shields.io/pypi/l/backtrader.svg:alt: License:scale: 100%:target:https://github.com/backtrader/backtrader/blob/master/LICENSE.. image::https://travis-ci.org/backtrader/backtrader.png?branch=master:alt: Travis-ci Build Status:scale: 100%:target:https://travis-ci.org/backtrader/backtrader.. image::https://img.shields.io/pypi/pyversions/backtrader.svg:alt: Python versions:scale: 100%:target:https://pypi.python.org/pypi/backtrader/

Yahoo API Note:

[2018-11-16] After some testing it would seem that data downloads can beagain relied upon over the web interface (or APIv7)

Tickets

The ticket system is (was, actually) more often than not abused to ask foradvice about samples.

Forfeedback/questions/... use theCommunity <https://community.backtrader.com>_

Here a snippet of a Simple Moving Average CrossOver. It can be done in severaldifferent ways. Use the docs (and examples) Luke!::

from datetime import datetimeimport backtrader as bt

class SmaCross(bt.SignalStrategy):definit(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 samplesassigsmacross/sigsmacross2.py. Along it issigsmacross.py which can beparametrized from the command line.

Features:

Live Trading and backtesting platform written in Python.

  • Live Data Feed and Trading with

    • Interactive Brokers (needsIbPy and benefits greatly from aninstalledpytz)
    • Visual Chart (needs a fork ofcomtypes until a pull request isintegrated in the release and benefits frompytz)
    • Oanda (needsoandapy) (REST API Only - v20 did not supportstreaming when implemented)
  • Data feeds from csv/files, online sources or frompandas andblaze

  • Filters for datas, like breaking a daily bar into chunks to simulateintraday 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 pythonta-lib / check the docs)

  • Easy development of custom indicators

  • Analyzers (for example: TimeReturn, Sharpe Ratio, SQN) andpyfoliointegration (deprecated)

  • Flexible definition of commission schemes

  • Integrated broker simulation withMarket,Close,Limit,Stop,StopLimit,StopTrail,StopTrailLimitandOCO orders, bracket order,slippage, volume filling strategies and continuous cash adjustmet forfuture-like instruments

  • Sizers for automated staking

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

  • Schedulers

  • Trading Calendars

  • Plotting (requires matplotlib)

Documentation

The blog:

  • Blog <http://www.backtrader.com/blog>_

Read the full documentation at:

  • Documentation <http://www.backtrader.com/docu>_

List of built-in Indicators (122)

  • Indicators Reference <http://www.backtrader.com/docu/indautoref.html>_

Python 2/3 Support

  • Python >=3.2

  • It also works withpypy andpypy3 (no plotting -matplotlib isnot supported underpypy)

Installation

backtrader is self-contained with no external dependencies (except if youwant to plot)

Frompypi:

  • pip install backtrader

  • pip install backtrader[plotting]

    Ifmatplotlib is not installed and you wish to do some plotting

.. note:: The minimum matplotlib version is1.4.1

An example forIB Data Feeds/Trading:

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

From source:

  • Place thebacktrader directory found in the sources inside your project

Version numbering

X.Y.Z.I

  • X: Major version number. Should stay stable unless something big is changedlike an overhaul to usenumpy
  • 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, smallchanges, small bug fixes
  • I: Number of Indicators already built into the platform

Build the Package

To build the package, run:

python -m pip install --upgrade buildrm -r distpython -m build

To upload the package to PyPI, run:

twine upload dist/*

About

Python Backtesting library for trading strategies

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python100.0%

[8]ページ先頭

©2009-2025 Movatter.jp