Skip to content

Commit 7d5ba05

Browse files
authored
Merge PR #47 (Order/Trade/Position API)
2 parents fde1054 + a95b259 commit 7d5ba05

16 files changed

+2629
-1388
lines changed

README.md

+25-22
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ from backtesting.test import SMA, GOOG
3333

3434
class SmaCross(Strategy):
3535
def init(self):
36-
Close = self.data.Close
37-
self.ma1 = self.I(SMA, Close, 10)
38-
self.ma2 = self.I(SMA, Close, 20)
36+
price = self.data.Close
37+
self.ma1 = self.I(SMA, price, 10)
38+
self.ma2 = self.I(SMA, price, 20)
3939

4040
def next(self):
4141
if crossover(self.ma1, self.ma2):
@@ -44,8 +44,8 @@ class SmaCross(Strategy):
4444
self.sell()
4545

4646

47-
bt = Backtest(GOOG, SmaCross,
48-
cash=10000, commission=.002)
47+
bt = Backtest(GOOG, SmaCross, commission=.002,
48+
exclusive_orders=True)
4949
bt.run()
5050
bt.plot()
5151
```
@@ -56,30 +56,33 @@ Results in:
5656
Start 2004-08-19 00:00:00
5757
End 2013-03-01 00:00:00
5858
Duration 3116 days 00:00:00
59-
Exposure [%] 94.29
60-
Equity Final [$] 69665.12
61-
Equity Peak [$] 69722.15
62-
Return [%] 596.65
59+
Exposure Time [%] 94.27
60+
Equity Final [$] 68935.12
61+
Equity Peak [$] 68991.22
62+
Return [%] 589.35
6363
Buy & Hold Return [%] 703.46
64-
Max. Drawdown [%] -33.61
65-
Avg. Drawdown [%] -5.68
66-
Max. Drawdown Duration 689 days 00:00:00
64+
Max. Drawdown [%] -33.08
65+
Avg. Drawdown [%] -5.58
66+
Max. Drawdown Duration 688 days 00:00:00
6767
Avg. Drawdown Duration 41 days 00:00:00
6868
# Trades 93
6969
Win Rate [%] 53.76
70-
Best Trade [%] 56.98
71-
Worst Trade [%] -17.03
72-
Avg. Trade [%] 2.44
70+
Best Trade [%] 57.12
71+
Worst Trade [%] -16.63
72+
Avg. Trade [%] 1.96
7373
Max. Trade Duration 121 days 00:00:00
7474
Avg. Trade Duration 32 days 00:00:00
75-
Expectancy [%] 6.92
76-
SQN 1.77
77-
Sharpe Ratio 0.22
78-
Sortino Ratio 0.54
79-
Calmar Ratio 0.07
80-
_strategy SmaCross
75+
Profit Factor 2.13
76+
Expectancy [%] 6.91
77+
SQN 1.78
78+
Sharpe Ratio 0.18
79+
Sortino Ratio 0.44
80+
Calmar Ratio 0.06
81+
_strategy SmaCross(n1=10, n2=20)
82+
_equity_curve Equ...
83+
_trades Size EntryB...
8184
```
82-
[![plot of trading simulation](https://i.imgur.com/q6OSQD8.png)](https://kernc.github.io/backtesting.py/#example)
85+
[![plot of trading simulation](https://i.imgur.com/xRFNHfg.png)](https://kernc.github.io/backtesting.py/#example)
8386

8487
Find more usage examples in the [documentation].
8588

backtesting/__init__.py

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
"""
22
# Backtesting.py Documentation
33
4+
.. warning:: v0.2.0 breaking changes
5+
Version 0.2.0 introduced some **breaking API changes**. For quick ways to
6+
migrate existing 0.1.x code, see the implementing
7+
[pull request](https://github.com/kernc/backtesting.py/pull/47/).
8+
49
## Manuals
510
611
* [**Quick Start User Guide**](../examples/Quick Start User Guide.html)
@@ -11,7 +16,7 @@
1116
* [Multiple Time Frames](../examples/Multiple Time Frames.html)
1217
* [Parameter Heatmap](../examples/Parameter Heatmap.html)
1318
14-
These tutorials are also available as live notebooks:
19+
These tutorials are also available to test as live Jupyter notebooks:
1520
[![Binder](https://mybinder.org/badge_logo.svg)][binder]
1621
1722
[binder]: \
@@ -22,6 +27,11 @@
2227
2328
* (contributions welcome)
2429
30+
## FAQ
31+
32+
Potentially outdated answers to popular questions can be found on the
33+
[issue tracker](https://github.com/kernc/backtesting.py/issues?q=label%3Aquestion).
34+
2535
## License
2636
2737
This software is licensed under the terms of [AGPL 3.0]{: rel=license},
@@ -39,6 +49,6 @@
3949
except ImportError:
4050
pass # Package not installed
4151

42-
from .backtesting import Backtest, Strategy, Orders, Position # noqa: F401
52+
from .backtesting import Backtest, Strategy # noqa: F401
4353
from . import lib # noqa: F401
4454
from ._plotting import set_bokeh_output # noqa: F401

0 commit comments

Comments
 (0)