Skip to content

Commit 7e229d6

Browse files
committed
DOC: Update docs and examples
1 parent 70bdf5c commit 7e229d6

9 files changed

+1376
-755
lines changed

backtesting/backtesting.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
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
@@ -909,7 +909,7 @@ def __init__(self,
909909
To run the backtest using e.g. 50:1 leverge that your broker allows,
910910
set margin to `0.02` (1 / leverage).
911911
912-
If `trade_on_close` is `True`, market orders will be executed
912+
If `trade_on_close` is `True`, market orders will be filled
913913
with respect to the current bar's closing price instead of the
914914
next bar's open.
915915
"""
@@ -1097,7 +1097,7 @@ def __getattr__(self, item):
10971097
raise ValueError('No admissible parameter combinations to test')
10981098

10991099
if len(param_combos) > 300:
1100-
warnings.warn('Searching best of {} configurations.'.format(len(param_combos)),
1100+
warnings.warn('Searching for best of {} configurations.'.format(len(param_combos)),
11011101
stacklevel=2)
11021102

11031103
heatmap = pd.Series(np.nan,
@@ -1287,7 +1287,7 @@ def plot(self, *, results: pd.Series = None, filename=None, plot_width=None,
12871287
a separate drawdown graph section.
12881288
12891289
If `smooth_equity` is `True`, the equity graph will be
1290-
interpolated between points of cash-only positions,
1290+
interpolated between fixed points at trade closing times,
12911291
unaffected by any interim asset volatility.
12921292
12931293
If `relative_equity` is `True`, scale and label equity graph axis

doc/examples/Multiple Time Frames.ipynb

+169-113
Large diffs are not rendered by default.

doc/examples/Multiple Time Frames.py

+12-8
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).

doc/examples/Parameter Heatmap.ipynb

+270-220
Large diffs are not rendered by default.

doc/examples/Parameter Heatmap.py

+12-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# extension: .py
77
# format_name: light
88
# format_version: '1.5'
9-
# jupytext_version: 1.3.0
9+
# jupytext_version: 1.3.5
1010
# kernelspec:
1111
# display_name: Python 3
1212
# language: python
@@ -21,10 +21,9 @@
2121
# [basic _backtesting.py_ usage](https://kernc.github.io/backtesting.py/doc/examples/Quick Start User Guide.html).
2222
#
2323
# First, let's again import our helper moving average function.
24-
# In practice, one can use functions from any indicator library, such as
25-
# [TA-Lib](https://github.com/mrjbq7/ta-lib),
26-
# [Tulipy](https://tulipindicators.org),
27-
# PyAlgoTrade, ...
24+
# In practice, one should use functions from an indicator library, such as
25+
# [TA-Lib](https://github.com/mrjbq7/ta-lib) or
26+
# [Tulipy](https://tulipindicators.org).
2827

2928
from backtesting.test import SMA
3029

@@ -33,7 +32,7 @@
3332
# but we will use four moving averages in total:
3433
# two moving averages whose relationship determines a general trend
3534
# (we only trade long when the shorter MA is above the longer one, and vice versa),
36-
# and two moving averages whose cross-over with Close prices determine the signal to enter or exit the position.
35+
# and two moving averages whose cross-over with daily _close_ prices determine the signal to enter or exit the position.
3736

3837
# +
3938
from backtesting import Strategy
@@ -121,7 +120,7 @@ def next(self):
121120

122121
heatmap.sort_values().iloc[-3:]
123122

124-
# But people have this enormous faculty of vision, used to make judgements on much larger data sets much faster.
123+
# But we use vision to make judgements on larger data sets much faster.
125124
# Let's plot the whole heatmap by projecting it on two chosen dimensions.
126125
# Say we're mostly interested in how parameters `n1` and `n2`, on average, affect the outcome.
127126

@@ -152,3 +151,9 @@ def next(self):
152151

153152

154153
plot_heatmaps(heatmap, agg='mean')
154+
# -
155+
156+
# Learn more by exploring further
157+
# [examples](https://kernc.github.io/backtesting.py/doc/backtesting/index.html#tutorials)
158+
# or find more framework options in the
159+
# [full API reference](https://kernc.github.io/backtesting.py/doc/backtesting/index.html#header-submodules).

doc/examples/Quick Start User Guide.ipynb

+650-205
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)