Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Order/Trade/Position API #47

Merged
merged 12 commits into from
Jul 15, 2020
Merged
47 changes: 25 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ from backtesting.test import SMA, GOOG

class SmaCross(Strategy):
def init(self):
Close = self.data.Close
self.ma1 = self.I(SMA, Close, 10)
self.ma2 = self.I(SMA, Close, 20)
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):
Expand All @@ -44,8 +44,8 @@ class SmaCross(Strategy):
self.sell()


bt = Backtest(GOOG, SmaCross,
cash=10000, commission=.002)
bt = Backtest(GOOG, SmaCross, commission=.002,
exclusive_orders=True)
bt.run()
bt.plot()
```
Expand All @@ -56,30 +56,33 @@ Results in:
Start 2004-08-19 00:00:00
End 2013-03-01 00:00:00
Duration 3116 days 00:00:00
Exposure [%] 94.29
Equity Final [$] 69665.12
Equity Peak [$] 69722.15
Return [%] 596.65
Exposure Time [%] 94.27
Equity Final [$] 68935.12
Equity Peak [$] 68991.22
Return [%] 589.35
Buy & Hold Return [%] 703.46
Max. Drawdown [%] -33.61
Avg. Drawdown [%] -5.68
Max. Drawdown Duration 689 days 00:00:00
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 [%] 56.98
Worst Trade [%] -17.03
Avg. Trade [%] 2.44
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
Expectancy [%] 6.92
SQN 1.77
Sharpe Ratio 0.22
Sortino Ratio 0.54
Calmar Ratio 0.07
_strategy SmaCross
Profit Factor 2.13
Expectancy [%] 6.91
SQN 1.78
Sharpe Ratio 0.18
Sortino Ratio 0.44
Calmar Ratio 0.06
_strategy SmaCross(n1=10, n2=20)
_equity_curve Equ...
_trades Size EntryB...
```
[![plot of trading simulation](https://i.imgur.com/q6OSQD8.png)](https://kernc.github.io/backtesting.py/#example)
[![plot of trading simulation](https://i.imgur.com/xRFNHfg.png)](https://kernc.github.io/backtesting.py/#example)

Find more usage examples in the [documentation].

Expand Down
14 changes: 12 additions & 2 deletions backtesting/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
"""
# Backtesting.py Documentation
.. warning:: v0.2.0 breaking changes
Version 0.2.0 introduced some **breaking API changes**. For quick ways to
migrate existing 0.1.x code, see the implementing
[pull request](https://github.com/kernc/backtesting.py/pull/47/).
## Manuals
* [**Quick Start User Guide**](../examples/Quick Start User Guide.html)
Expand All @@ -11,7 +16,7 @@
* [Multiple Time Frames](../examples/Multiple Time Frames.html)
* [Parameter Heatmap](../examples/Parameter Heatmap.html)
These tutorials are also available as live notebooks:
These tutorials are also available to test as live Jupyter notebooks:
[![Binder](https://mybinder.org/badge_logo.svg)][binder]
[binder]: \
Expand All @@ -22,6 +27,11 @@
* (contributions welcome)
## FAQ
Potentially outdated answers to popular questions can be found on the
[issue tracker](https://github.com/kernc/backtesting.py/issues?q=label%3Aquestion).
## License
This software is licensed under the terms of [AGPL 3.0]{: rel=license},
Expand All @@ -39,6 +49,6 @@
except ImportError:
pass # Package not installed

from .backtesting import Backtest, Strategy, Orders, Position # noqa: F401
from .backtesting import Backtest, Strategy # noqa: F401
from . import lib # noqa: F401
from ._plotting import set_bokeh_output # noqa: F401
Loading