Skip to content

Commit 1cf1159

Browse files
committed
DOC: Update docs and examples
1 parent 5a89768 commit 1cf1159

11 files changed

+1394
-758
lines changed

backtesting/__init__.py

Lines changed: 11 additions & 1 deletion
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+
Release 0.2.0 introduced some **breaking API changes**. For quick ways to
6+
migrate your 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},

backtesting/backtesting.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
"""
2-
Core backtesting data structures.
3-
Objects from this module can be imported from the top-level
2+
Core framework data structures.
3+
Objects from this module can also be imported from the top-level
44
module directly, e.g.
55
66
from backtesting import Backtest, Strategy
7+
8+
.. warning:: v0.2.0 breaking changes
9+
Release 0.2.0 introduced some **breaking API changes**. For quick ways to
10+
migrate your existing 0.1.x code, see the implementing
11+
[pull request](https://github.com/kernc/backtesting.py/pull/47/).
712
"""
813
import multiprocessing as mp
914
import os
@@ -944,7 +949,7 @@ def __init__(self,
944949
To run the backtest using e.g. 50:1 leverge that your broker allows,
945950
set margin to `0.02` (1 / leverage).
946951
947-
If `trade_on_close` is `True`, market orders will be executed
952+
If `trade_on_close` is `True`, market orders will be filled
948953
with respect to the current bar's closing price instead of the
949954
next bar's open.
950955
"""
@@ -1135,7 +1140,7 @@ def __getattr__(self, item):
11351140
raise ValueError('No admissible parameter combinations to test')
11361141

11371142
if len(param_combos) > 300:
1138-
warnings.warn('Searching best of {} configurations.'.format(len(param_combos)),
1143+
warnings.warn('Searching for best of {} configurations.'.format(len(param_combos)),
11391144
stacklevel=2)
11401145

11411146
heatmap = pd.Series(np.nan,
@@ -1341,7 +1346,7 @@ def plot(self, *, results: pd.Series = None, filename=None, plot_width=None,
13411346
a separate drawdown graph section.
13421347
13431348
If `smooth_equity` is `True`, the equity graph will be
1344-
interpolated between points of cash-only positions,
1349+
interpolated between fixed points at trade closing times,
13451350
unaffected by any interim asset volatility.
13461351
13471352
If `relative_equity` is `True`, scale and label equity graph axis

backtesting/lib.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ def resample_apply(rule: str,
175175
a time frame to resample `series` to.
176176
177177
[Pandas offset string]: \
178-
http://pandas.pydata.org/pandas-docs/stable/timeseries.html#offset-aliases
178+
http://pandas.pydata.org/pandas-docs/stable/timeseries.html#offset-aliases
179179
180180
`func` is the indicator function to apply on the resampled series.
181181
@@ -202,7 +202,7 @@ def init(self):
202202
self.sma = resample_apply(
203203
'D', SMA, self.data.Close, 10, plot=False)
204204
205-
This short snippet is roughly equivalent to:
205+
The above short snippet is roughly equivalent to:
206206
207207
class System(Strategy):
208208
def init(self):

doc/examples/Multiple Time Frames.ipynb

Lines changed: 169 additions & 113 deletions
Large diffs are not rendered by default.

doc/examples/Multiple Time Frames.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# extension: .py
66
# format_name: light
77
# format_version: '1.5'
8-
# jupytext_version: 1.3.0
8+
# jupytext_version: 1.3.5
99
# kernelspec:
1010
# display_name: Python 3
1111
# language: python
@@ -16,22 +16,21 @@
1616
# ============
1717
#
1818
# The best trading strategies relying on technical analysis take into account the price action on multiple time frames.
19-
# This tutorial will show how to do that with _backtesting.py_, offloading most of the work to
19+
# This tutorial will show how to do that with backtesting.py, offloading most of the work to
2020
# [pandas resampling](http://pandas.pydata.org/pandas-docs/stable/timeseries.html#resampling).
2121
# It is assumed you're already familiar with
22-
# [basic _backtesting.py_ usage](https://kernc.github.io/backtesting.py/doc/examples/Quick Start User Guide.html).
22+
# [basic usage](https://kernc.github.io/backtesting.py/doc/examples/Quick Start User Guide.html).
2323
#
2424
# We will put to the test this long-only, supposed
2525
# [400%-a-year trading strategy](http://jbmarwood.com/stock-trading-strategy-300/),
2626
# which uses daily and weekly
2727
# [relative strength index](https://en.wikipedia.org/wiki/Relative_strength_index)
2828
# (RSI) values and moving averages (MA).
2929
#
30-
# Let's introduce the two indicators we'll be using.
31-
# In practice, one can use functions from any indicator library, such as
32-
# [TA-Lib](https://github.com/mrjbq7/ta-lib),
30+
# In practice, one should use functions from an indicator library, such as
31+
# [TA-Lib](https://github.com/mrjbq7/ta-lib) or
3332
# [Tulipy](https://tulipindicators.org),
34-
# PyAlgoTrade, ...
33+
# but among us, let's introduce the two indicators we'll be using.
3534

3635
# +
3736
import pandas as pd
@@ -138,5 +137,10 @@ def next(self):
138137

139138
# Better. While the strategy doesn't perform as well as simple buy & hold, it does so with significantly lower exposure (time in market).
140139
#
141-
# In conclusion, to test strategies on multiple time frames, you need to pass in data in the lowest time frame, then resample it to higher time frames, apply the indicators, then resample back to the lower time frame, filling in the in-betweens.
140+
# In conclusion, to test strategies on multiple time frames, you need to pass in OHLC data in the lowest time frame, then resample it to higher time frames, apply the indicators, then resample back to the lower time frame, filling in the in-betweens.
142141
# Which is what the function [`backtesting.lib.resample_apply()`](https://kernc.github.io/backtesting.py/doc/backtesting/lib.html#backtesting.lib.resample_apply) does for you.
142+
143+
# Learn more by exploring further
144+
# [examples](https://kernc.github.io/backtesting.py/doc/backtesting/index.html#tutorials)
145+
# or find more framework options in the
146+
# [full API reference](https://kernc.github.io/backtesting.py/doc/backtesting/index.html#header-submodules).

0 commit comments

Comments
 (0)