https://github.com/kernc/backtesting.py
π π π π° Backtest trading strategies in Python.
Science Score: 36.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
βCITATION.cff file
-
βcodemeta.json file
Found codemeta.json file -
β.zenodo.json file
Found .zenodo.json file -
βDOI references
-
βAcademic publication links
-
βCommitters with academic emails
1 of 35 committers (2.9%) from academic institutions -
βInstitutional organization owner
-
βJOSS paper metadata
-
βScientific vocabulary similarity
Low similarity (9.4%) to scientific vocabulary
Keywords
Repository
π π π π° Backtest trading strategies in Python.
Basic Info
- Host: GitHub
- Owner: kernc
- License: agpl-3.0
- Language: Python
- Default Branch: master
- Homepage: https://kernc.github.io/backtesting.py/
- Size: 13.2 MB
Statistics
- Stars: 7,084
- Watchers: 126
- Forks: 1,276
- Open Issues: 52
- Releases: 0
Topics
Metadata Files
README.md
Backtesting.py
Backtest trading strategies with Python.
Project website + Documentation | YouTube
Installation
$ pip install backtesting
Usage
```python from backtesting import Backtest, Strategy from backtesting.lib import crossover
from backtesting.test import SMA, GOOG
class SmaCross(Strategy): def init(self): price = self.data.Close self.ma1 = self.I(SMA, price, 10) self.ma2 = self.I(SMA, price, 20)
def next(self):
if crossover(self.ma1, self.ma2):
self.buy()
elif crossover(self.ma2, self.ma1):
self.sell()
bt = Backtest(GOOG, SmaCross, commission=.002, exclusive_orders=True) stats = bt.run() bt.plot() ```
Results in:
```text Start 2004-08-19 00:00:00 End 2013-03-01 00:00:00 Duration 3116 days 00:00:00 Exposure Time [%] 94.27 Equity Final [$] 68935.12 Equity Peak [$] 68991.22 Return [%] 589.35 Buy & Hold Return [%] 703.46 Return (Ann.) [%] 25.42 Volatility (Ann.) [%] 38.43 CAGR [%] 16.80 Sharpe Ratio 0.66 Sortino Ratio 1.30 Calmar Ratio 0.77 Alpha [%] 450.62 Beta 0.02 Max. Drawdown [%] -33.08 Avg. Drawdown [%] -5.58 Max. Drawdown Duration 688 days 00:00:00 Avg. Drawdown Duration 41 days 00:00:00
Trades 93
Win Rate [%] 53.76
Best Trade [%] 57.12
Worst Trade [%] -16.63
Avg. Trade [%] 1.96
Max. Trade Duration 121 days 00:00:00
Avg. Trade Duration 32 days 00:00:00
Profit Factor 2.13
Expectancy [%] 6.91
SQN 1.78
Kelly Criterion 0.6134
strategy SmaCross(n1=10, n2=20)
_equitycurve Equ...
_trades Size EntryB...
dtype: object
```

Find more usage examples in the documentation.
Features
- Simple, well-documented API
- Blazing fast execution
- Built-in optimizer
- Library of composable base strategies and utilities
- Indicator-library-agnostic
- Supports any financial instrument with candlestick data
- Detailed results
- Interactive visualizations

Bugs
Before reporting bugs or posting to the
discussion board,
please read contributing guidelines, particularly the section
about crafting useful bug reports and ```-fencing your code. We thank you!
Alternatives
See alternatives.md for a list of alternative Python backtesting frameworks and related packages.
Owner
- Login: kernc
- Kind: user
- Repositories: 145
- Profile: https://github.com/kernc
Committers
Last synced: 9 months ago
Top Committers
| Name | Commits | |
|---|---|---|
| Kernc | k****e@g****m | 369 |
| Billy Cao | a****o@g****m | 2 |
| Eric Ervin | e****n@r****m | 2 |
| Ivan Vaigult | i****t@g****m | 2 |
| NEMi | t****k@g****m | 2 |
| TankorSmash | t****b@g****m | 2 |
| crazy25000 | c****0 | 2 |
| jensnesten | 4****n | 2 |
| Diego Lovison | d****n@g****m | 1 |
| CtrlX | 7****x | 1 |
| Chuan | c****i@g****m | 1 |
| BΓ©nouare | 2****e | 1 |
| Andrew Schwartz | a****w@m****m | 1 |
| Andrew | q****e | 1 |
| Andre Miras | A****s | 1 |
| Ali Gheshlaghi | a****7@g****m | 1 |
| tani3010 | t****0@g****m | 1 |
| Jack McPherson | j****b@g****m | 1 |
| t | t****s@t****m | 1 |
| paklong | p****6@g****m | 1 |
| lachyn21 | 7****1 | 1 |
| arkershaw | a****w | 1 |
| Zeel Patel | z****l | 1 |
| Valentin Mikhaylenko | v****o@g****m | 1 |
| Tony | 3****n | 1 |
| Tomasz Εakota | 4****a | 1 |
| Syed Kawish Qayyum | 8****m | 1 |
| Sean Kernitsman | s****l@g****m | 1 |
| S. Alexander Zaman | a****n@c****m | 1 |
| Murat Saglam | 4****m | 1 |
| and 5 more... | ||
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: 6 months ago
All Time
- Total issues: 275
- Total pull requests: 114
- Average time to close issues: about 1 year
- Average time to close pull requests: 11 months
- Total issue authors: 213
- Total pull request authors: 54
- Average comments per issue: 2.57
- Average comments per pull request: 1.17
- Merged pull requests: 45
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 56
- Pull requests: 38
- Average time to close issues: 13 days
- Average time to close pull requests: 20 days
- Issue authors: 42
- Pull request authors: 15
- Average comments per issue: 0.75
- Average comments per pull request: 0.74
- Merged pull requests: 18
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- ironhak (8)
- bravegag (6)
- kernc (6)
- rusty-peilin (4)
- zeshansari (4)
- ck0099 (4)
- trueToastedCode (4)
- vladiscripts (3)
- kbs-code (3)
- gypsyzz (3)
- jsulopzs (3)
- zha0yangchen (3)
- Ish2K (2)
- efeint01 (2)
- eromoe (2)
Pull Request Authors
- kernc (10)
- jensnesten (6)
- zlpatel (6)
- abhirathmahipal (5)
- ivaigult (4)
- tani3010 (4)
- gitctrlx (2)
- lachyn21 (2)
- themantalope (2)
- abd1rahmane (2)
- arkershaw (2)
- jmcph4 (2)
- Benouare (2)
- diegolovison (2)
- IperGiove (2)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 6
-
Total downloads:
- pypi 78,830 last-month
-
Total dependent packages: 2
(may contain duplicates) -
Total dependent repositories: 22
(may contain duplicates) - Total versions: 59
- Total maintainers: 4
pypi.org: backtesting
Backtest trading strategies in Python
- Homepage: https://kernc.github.io/backtesting.py/
- Documentation: https://kernc.github.io/backtesting.py/doc/backtesting/
- License: AGPL-3.0
-
Latest release: 0.6.5
published 7 months ago
Rankings
Maintainers (1)
pypi.org: foxbt
Backtest trading strategies in Python
- Homepage: https://kernc.github.io/backtesting.py/
- Documentation: https://kernc.github.io/backtesting.py/doc/backtesting/
- License: AGPL-3.0
-
Latest release: 0.2.9
published over 4 years ago
Rankings
Maintainers (1)
pypi.org: multibacktesting2
Backtest trading strategies in Python
- Homepage: https://kernc.github.io/backtesting.py/
- Documentation: https://kernc.github.io/backtesting.py/doc/backtesting/
- License: AGPL-3.0
-
Latest release: 0.1.4
published over 1 year ago
Rankings
Maintainers (1)
pypi.org: multiplebacktesting2
Backtest trading strategies in Python
- Homepage: https://kernc.github.io/backtesting.py/
- Documentation: https://kernc.github.io/backtesting.py/doc/backtesting/
- License: AGPL-3.0
Rankings
Maintainers (1)
pypi.org: multiple-backtesting
Backtest trading strategies in Python
- Homepage: https://kernc.github.io/backtesting.py/
- Documentation: https://kernc.github.io/backtesting.py/doc/backtesting/
- License: AGPL-3.0
-
Latest release: 0.0.3
published over 1 year ago
Rankings
Maintainers (1)
pypi.org: multibacktesting
Backtest trading strategies in Python
- Homepage: https://kernc.github.io/backtesting.py/
- Documentation: https://kernc.github.io/backtesting.py/doc/backtesting/
- License: AGPL-3.0
-
Latest release: 0.0.7
published over 1 year ago
Rankings
Maintainers (1)
Dependencies
- bokeh *
- numpy *
- pandas *
- actions/cache v3 composite
- actions/checkout v3 composite
- actions/setup-python v4 composite
- actions/cache v2 composite
- actions/checkout v2 composite
- actions/setup-python v2 composite
