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

Appearance settings

Commit b4a4353

Browse filesBrowse files
committed
DOC: Update README.md
1 parent 74ff445 commit b4a4353
Copy full SHA for b4a4353

1 file changed

+84-3Lines changed: 84 additions & 3 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎README.md‎

Copy file name to clipboardExpand all lines: README.md
+84-3Lines changed: 84 additions & 3 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,93 @@
22

33
Backtesting.py
44
==============
5-
Backtest trading strategies with Python.
6-
75
[![Build Status](https://img.shields.io/travis/kernc/backtesting.py.svg?style=for-the-badge)](https://travis-ci.org/kernc/backtesting.py)
86
[![Code Coverage](https://img.shields.io/codecov/c/gh/kernc/backtesting.py.svg?style=for-the-badge)](https://codecov.io/gh/kernc/backtesting.py)
97
[![Backtesting on PyPI](https://img.shields.io/pypi/v/backtesting.svg?style=for-the-badge)](https://pypi.org/project/backtesting)
108

9+
Backtest trading strategies with Python.
10+
1111
[**Project website**](https://kernc.github.io/backtesting.py/)
1212

13-
[Documentation](https://kernc.github.io/backtesting.py/doc/backtesting/)
13+
[Documentation]
14+
15+
[Documentation]: https://kernc.github.io/backtesting.py/doc/backtesting/
16+
17+
18+
Installation
19+
------------
20+
21+
$ pip install backtesting
22+
23+
24+
Usage
25+
-----
26+
```python
27+
from backtesting import Backtest, Strategy
28+
from backtesting.lib import crossover
29+
30+
from backtesting.test import SMA, GOOG
31+
32+
33+
class SmaCross(Strategy):
34+
def init(self):
35+
Close = self.data.Close
36+
self.ma1 = self.I(SMA, Close, 10)
37+
self.ma2 = self.I(SMA, Close, 20)
38+
39+
def next(self):
40+
if crossover(self.ma1, self.ma2):
41+
self.buy()
42+
elif crossover(self.ma2, self.ma1):
43+
self.sell()
44+
45+
46+
bt = Backtest(GOOG, SmaCross,
47+
cash=10000, commission=.002)
48+
bt.run()
49+
bt.plot()
50+
```
51+
52+
Results in:
53+
54+
```text
55+
Start 2004-08-19 00:00:00
56+
End 2013-03-01 00:00:00
57+
Duration 3116 days 00:00:00
58+
Exposure [%] 94.29
59+
Equity Final [$] 69665.12
60+
Equity Peak [$] 69722.15
61+
Return [%] 596.65
62+
Buy & Hold Return [%] 703.46
63+
Max. Drawdown [%] -33.61
64+
Avg. Drawdown [%] -5.68
65+
Max. Drawdown Duration 689 days 00:00:00
66+
Avg. Drawdown Duration 41 days 00:00:00
67+
# Trades 93
68+
Win Rate [%] 53.76
69+
Best Trade [%] 56.98
70+
Worst Trade [%] -17.03
71+
Avg. Trade [%] 2.44
72+
Max. Trade Duration 121 days 00:00:00
73+
Avg. Trade Duration 32 days 00:00:00
74+
Expectancy [%] 6.92
75+
SQN 1.77
76+
Sharpe Ratio 0.22
77+
Sortino Ratio 0.54
78+
Calmar Ratio 0.07
79+
_strategy SmaCross
80+
```
81+
[![plot of trading simulation](https://i.imgur.com/q6OSQD8.png)](https://kernc.github.io/backtesting.py/#example)
82+
83+
Find more usage examples in the [documentation].
84+
85+
Features
86+
--------
87+
* Simple, well-documented API
88+
* Blazing fast execution
89+
* Built-in optimizer
90+
* Library of composable base strategies and utilities
91+
* Indicator-library-agnostic
92+
* Supports _any_ financial instrument with candlestick data
93+
* Detailed results
94+
* Interactive visualizations

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.