{ "info": { "author": "Zach L\u00fbster", "author_email": "", "bugtrack_url": null, "classifiers": [ "Intended Audience :: Financial and Insurance Industry", "Intended Audience :: Science/Research", "License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)", "Operating System :: OS Independent", "Programming Language :: Python :: 3 :: Only", "Topic :: Office/Business :: Financial :: Investment", "Topic :: Scientific/Engineering :: Visualization" ], "description": "[![](https://i.imgur.com/E8Kj69Y.png)](https://kernc.github.io/backtesting.py/)\n\nBacktesting.py\n==============\n[![Build Status](https://img.shields.io/travis/kernc/backtesting.py.svg?style=for-the-badge)](https://travis-ci.org/kernc/backtesting.py)\n[![Code Coverage](https://img.shields.io/codecov/c/gh/kernc/backtesting.py.svg?style=for-the-badge)](https://codecov.io/gh/kernc/backtesting.py)\n[![Backtesting on PyPI](https://img.shields.io/pypi/v/backtesting.svg?color=blue&style=for-the-badge)](https://pypi.org/project/backtesting)\n\nBacktest trading strategies with Python.\n\n[**Project website**](https://kernc.github.io/backtesting.py/)\n\n[Documentation]\n\n[Documentation]: https://kernc.github.io/backtesting.py/doc/backtesting/\n\n\nInstallation\n------------\n\n $ pip install backtesting\n\n\nUsage\n-----\n```python\nfrom backtesting import Backtest, Strategy\nfrom backtesting.lib import crossover\n\nfrom backtesting.test import SMA, GOOG\n\n\nclass SmaCross(Strategy):\n def init(self):\n Close = self.data.Close\n self.ma1 = self.I(SMA, Close, 10)\n self.ma2 = self.I(SMA, Close, 20)\n\n def next(self):\n if crossover(self.ma1, self.ma2):\n self.buy()\n elif crossover(self.ma2, self.ma1):\n self.sell()\n\n\nbt = Backtest(GOOG, SmaCross,\n cash=10000, commission=.002)\nbt.run()\nbt.plot()\n```\n\nResults in:\n\n```text\nStart 2004-08-19 00:00:00\nEnd 2013-03-01 00:00:00\nDuration 3116 days 00:00:00\nExposure [%] 94.29\nEquity Final [$] 69665.12\nEquity Peak [$] 69722.15\nReturn [%] 596.65\nBuy & Hold Return [%] 703.46\nMax. Drawdown [%] -33.61\nAvg. Drawdown [%] -5.68\nMax. Drawdown Duration 689 days 00:00:00\nAvg. Drawdown Duration 41 days 00:00:00\n# Trades 93\nWin Rate [%] 53.76\nBest Trade [%] 56.98\nWorst Trade [%] -17.03\nAvg. Trade [%] 2.44\nMax. Trade Duration 121 days 00:00:00\nAvg. Trade Duration 32 days 00:00:00\nExpectancy [%] 6.92\nSQN 1.77\nSharpe Ratio 0.22\nSortino Ratio 0.54\nCalmar Ratio 0.07\n_strategy SmaCross\n```\n[![plot of trading simulation](https://i.imgur.com/q6OSQD8.png)](https://kernc.github.io/backtesting.py/#example)\n\nFind more usage examples in the [documentation].\n\nFeatures\n--------\n* Simple, well-documented API\n* Blazing fast execution\n* Built-in optimizer\n* Library of composable base strategies and utilities\n* Indicator-library-agnostic\n* Supports _any_ financial instrument with candlestick data\n* Detailed results\n* Interactive visualizations", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://kernc.github.io/backtesting.py/", "keywords": "algo,algorithmic,ashi,backtest,backtesting,bitcoin,bokeh,bonds,candles,candlestick,cboe,chart,cme,commodities,crash,crypto,currency,drawdown,equity,ethereum,exchange,finance,financial,forex,fund,futures,fx,fxpro,gold,heiken,historical,indicator,invest,investing,investment,macd,market,mechanical,money,oanda,ohlc,ohlcv,order,profit,quant,quantitative,silver,stocks,strategy,ticker,trader,trading,tradingview,usd", "license": "AGPL-3.0", "maintainer": "", "maintainer_email": "", "name": "Backtesting", "package_url": "https://pypi.org/project/Backtesting/", "platform": "", "project_url": "https://pypi.org/project/Backtesting/", "project_urls": { "Documentation": "https://kernc.github.io/backtesting.py/doc/backtesting/", "Homepage": "https://kernc.github.io/backtesting.py/", "Source": "https://github.com/kernc/backtesting.py/", "Tracker": "https://github.com/kernc/backtesting.py/issues" }, "release_url": "https://pypi.org/project/Backtesting/0.1.2/", "requires_dist": null, "requires_python": ">=3.4", "summary": "Backtest trading strategies in Python", "version": "0.1.2" }, "last_serial": 5871093, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "6dd292cf958f1087bab400d8d8468141", "sha256": "050ec126f6d183ace83243f46b46b041ef33ab0e694bdc7764dea921378d2550" }, "downloads": -1, "filename": "Backtesting-0.1.0.tar.gz", "has_sig": false, "md5_digest": "6dd292cf958f1087bab400d8d8468141", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.4", "size": 154235, "upload_time": "2019-01-17T11:25:10", "url": "https://files.pythonhosted.org/packages/44/4d/13cd1da447c23a2a723c715b8b95033343c9d2e7ba70d833e5ade3bad419/Backtesting-0.1.0.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "3e3ab87e1a30787830f65dd271c9463b", "sha256": "ca03fd5713e922b54e79ac17963cc62c17a437caa00c2020732f6da18e35ecba" }, "downloads": -1, "filename": "Backtesting-0.1.1.tar.gz", "has_sig": false, "md5_digest": "3e3ab87e1a30787830f65dd271c9463b", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.4", "size": 158372, "upload_time": "2019-09-23T01:22:39", "url": "https://files.pythonhosted.org/packages/50/5f/1d0d21f3f12a90763587acdcf8ecd682ffbc035a00eee50062d5d0bf5d89/Backtesting-0.1.1.tar.gz" } ], "0.1.2": [ { "comment_text": "", "digests": { "md5": "8838e24e9ccf89c891f5aada04e84c0b", "sha256": "a49b89fbc4acc861424d9dba5af62583a9ac2cd18bd7ba78894393fd7766c7d2" }, "downloads": -1, "filename": "Backtesting-0.1.2.tar.gz", "has_sig": false, "md5_digest": "8838e24e9ccf89c891f5aada04e84c0b", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.4", "size": 158402, "upload_time": "2019-09-23T01:58:02", "url": "https://files.pythonhosted.org/packages/cb/08/78f3cddd05554662737a05a085adaa2aec492272d5cc30cec519b6acde3b/Backtesting-0.1.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "8838e24e9ccf89c891f5aada04e84c0b", "sha256": "a49b89fbc4acc861424d9dba5af62583a9ac2cd18bd7ba78894393fd7766c7d2" }, "downloads": -1, "filename": "Backtesting-0.1.2.tar.gz", "has_sig": false, "md5_digest": "8838e24e9ccf89c891f5aada04e84c0b", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.4", "size": 158402, "upload_time": "2019-09-23T01:58:02", "url": "https://files.pythonhosted.org/packages/cb/08/78f3cddd05554662737a05a085adaa2aec492272d5cc30cec519b6acde3b/Backtesting-0.1.2.tar.gz" } ] }