Skip to content

Commit ac6c41b

Browse files
CI: Update docs for 0.3.0 (6b33ce5)
1 parent 66c5787 commit ac6c41b

File tree

10 files changed

+15662
-164
lines changed

10 files changed

+15662
-164
lines changed

β€Ždoc/backtesting/backtesting.htmlβ€Ž

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,6 @@ <h1 class="title">Module <code>backtesting.backtesting</code></h1>
3939
module directly, e.g.</p>
4040
<pre><code>from backtesting import Backtest, Strategy
4141
</code></pre>
42-
<div class="admonition warning">
43-
<p class="admonition-title">Warning:&ensp;v0.2.0 breaking changes</p>
44-
<p>Version 0.2.0 introduced some <strong>breaking API changes</strong>. For quick ways to
45-
migrate existing 0.1.x code, see the implementing
46-
<a href="https://github.com/kernc/backtesting.py/pull/47/">pull request</a>.</p>
47-
</div>
4842
</section>
4943
<section>
5044
</section>
@@ -101,17 +95,30 @@ <h2 class="section-title" id="header-classes">Classes</h2>
10195
<h3>Methods</h3>
10296
<dl>
10397
<dt id="backtesting.backtesting.Backtest.optimize"><code class="name flex">
104-
<span>def <span class="ident">optimize</span></span>(<span>self, maximize='SQN', constraint=None, return_heatmap=False, **kwargs)</span>
98+
<span>def <span class="ident">optimize</span></span>(<span>self, *, maximize='SQN', method='grid', max_tries=None, constraint=None, return_heatmap=False, return_optimization=False, random_state=None, **kwargs)</span>
10599
</code></dt>
106100
<dd>
107-
<div class="desc"><p>Optimize strategy parameters to an optimal combination using
108-
parallel exhaustive search. Returns result <code>pd.Series</code> of
109-
the best run.</p>
101+
<div class="desc"><p>Optimize strategy parameters to an optimal combination.
102+
Returns result <code>pd.Series</code> of the best run.</p>
110103
<p><code>maximize</code> is a string key from the
111104
<code><a title="backtesting.backtesting.Backtest.run" href="#backtesting.backtesting.Backtest.run">Backtest.run()</a></code>-returned results series,
112105
or a function that accepts this series object and returns a number;
113106
the higher the better. By default, the method maximizes
114107
Van Tharp's <a href="https://google.com/search?q=System+Quality+Number">System Quality Number</a>.</p>
108+
<p><code>method</code> is the optimization method. Currently two methods are supported:</p>
109+
<ul>
110+
<li><code>"grid"</code> which does an exhaustive (or randomized) search over the
111+
cartesian product of parameter combinations, and</li>
112+
<li><code>"skopt"</code> which finds close-to-optimal strategy parameters using
113+
<a href="https://scikit-optimize.github.io/stable/auto_examples/bayesian-optimization.html">model-based optimization</a>, making at most <code>max_tries</code> evaluations.</li>
114+
</ul>
115+
<p><code>max_tries</code> is the maximal number of strategy runs to perform.
116+
If <code>method="grid"</code>, this results in randomized grid search.
117+
If <code>max_tries</code> is a floating value between (0, 1], this sets the
118+
number of runs to approximately that fraction of full grid space.
119+
Alternatively, if integer, it denotes the absolute maximum number
120+
of evaluations. If unspecified (default), grid search is exhaustive,
121+
whereas for <code>method="skopt"</code>, <code>max_tries</code> is set to 200.</p>
115122
<p><code>constraint</code> is a function that accepts a dict-like object of
116123
parameters (with values) and returns <code>True</code> when the combination
117124
is admissible to test with. By default, any parameters combination
@@ -121,6 +128,13 @@ <h3>Methods</h3>
121128
of all admissible parameter combinations, which can be further
122129
inspected or projected onto 2D to plot a heatmap
123130
(see <code><a title="backtesting.lib.plot_heatmaps" href="lib.html#backtesting.lib.plot_heatmaps">plot_heatmaps()</a></code>).</p>
131+
<p>If <code>return_optimization</code> is True and <code>method = 'skopt'</code>,
132+
in addition to result series (and maybe heatmap), return raw
133+
<a href="https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.OptimizeResult.html"><code>scipy.optimize.OptimizeResult</code></a> for further
134+
inspection, e.g. with <a href="https://scikit-optimize.github.io">scikit-optimize</a>
135+
<a href="https://scikit-optimize.github.io/stable/modules/plots.html">plotting tools</a>.</p>
136+
<p>If you want reproducible optimization results, set <code>random_state</code>
137+
to a fixed integer or a <code>numpy.random.RandomState</code> object.</p>
124138
<p>Additional keyword arguments represent strategy arguments with
125139
list-like collections of possible values. For example, the following
126140
code finds and returns the "best" of the 7 admissible (of the
@@ -130,16 +144,11 @@ <h3>Methods</h3>
130144
</code></pre>
131145
<div class="admonition todo">
132146
<p class="admonition-title">TODO</p>
133-
<p>Add parameter <code>max_tries: Union[int, float] = None</code> which switches
134-
from exhaustive grid search to random search. See notes in the source.</p>
135-
</div>
136-
<div class="admonition todo">
137-
<p class="admonition-title">TODO</p>
138147
<p>Improve multiprocessing/parallel execution on Windos with start method 'spawn'.</p>
139148
</div></div>
140149
</dd>
141150
<dt id="backtesting.backtesting.Backtest.plot"><code class="name flex">
142-
<span>def <span class="ident">plot</span></span>(<span>self, *, results=None, filename=None, plot_width=None, plot_equity=True, plot_pl=True, plot_volume=True, plot_drawdown=False, smooth_equity=False, relative_equity=True, superimpose=True, resample=True, reverse_indicators=False, show_legend=True, open_browser=True)</span>
151+
<span>def <span class="ident">plot</span></span>(<span>self, *, results=None, filename=None, plot_width=None, plot_equity=True, plot_return=False, plot_pl=True, plot_volume=True, plot_drawdown=False, smooth_equity=False, relative_equity=True, superimpose=True, resample=True, reverse_indicators=False, show_legend=True, open_browser=True)</span>
143152
</code></dt>
144153
<dd>
145154
<div class="desc"><p>Plot the progression of the last backtest run.</p>
@@ -155,7 +164,11 @@ <h3>Methods</h3>
155164
the plot is made to span 100% of browser width. The height is
156165
currently non-adjustable.</p>
157166
<p>If <code>plot_equity</code> is <code>True</code>, the resulting plot will contain
158-
an equity (cash plus assets) graph section.</p>
167+
an equity (initial cash plus assets) graph section. This is the same
168+
as <code>plot_return</code> plus initial 100%.</p>
169+
<p>If <code>plot_return</code> is <code>True</code>, the resulting plot will contain
170+
a cumulative return graph section. This is the same
171+
as <code>plot_equity</code> minus initial 100%.</p>
159172
<p>If <code>plot_pl</code> is <code>True</code>, the resulting plot will contain
160173
a profit/loss (P/L) indicator section.</p>
161174
<p>If <code>plot_volume</code> is <code>True</code>, the resulting plot will contain
@@ -208,6 +221,11 @@ <h3>Methods</h3>
208221
Equity Peak [$] 75787.4
209222
Return [%] 419.599
210223
Buy &amp; Hold Return [%] 703.458
224+
Return (Ann.) [%] 21.328
225+
Volatility (Ann.) [%] 36.5383
226+
Sharpe Ratio 0.583718
227+
Sortino Ratio 1.09239
228+
Calmar Ratio 0.444518
211229
Max. Drawdown [%] -47.9801
212230
Avg. Drawdown [%] -5.92585
213231
Max. Drawdown Duration 584 days 00:00:00
@@ -222,9 +240,6 @@ <h3>Methods</h3>
222240
Profit Factor 2.08802
223241
Expectancy [%] 8.79171
224242
SQN 0.916893
225-
Sharpe Ratio 0.179141
226-
Sortino Ratio 0.55887
227-
Calmar Ratio 0.049056
228243
_strategy SmaCross
229244
_equity_curve Eq...
230245
_trades Size EntryB...
@@ -669,7 +684,7 @@ <h4><code><a title="backtesting.backtesting.Trade" href="#backtesting.backtestin
669684
</main>
670685
<footer id="footer">
671686
<p>
672-
<a href="https://kernc.github.io/backtesting.py/"><cite>backtesting</cite> 0.2.4</a>
687+
<a href="https://kernc.github.io/backtesting.py/"><cite>backtesting</cite> 0.3.0</a>
673688
<span style="color:#ddd">&#21328;</span>
674689
</p>
675690
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script>

β€Ždoc/backtesting/index.htmlβ€Ž

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" />
66
<meta name="generator" content="pdoc 0.9.1" />
77
<title>backtesting API documentation</title>
8-
<meta name="description" content="Backtesting.py Documentation …" />
8+
<meta name="description" content="Manuals …" />
99
<link rel="preload stylesheet" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/11.0.1/sanitize.min.css" integrity="sha256-PK9q560IAAa6WVRRh76LtCaI8pjTJ2z11v0miyNNjrs=" crossorigin>
1010
<link rel="preload stylesheet" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/11.0.1/typography.min.css" integrity="sha256-7l/o7C8jubJiy74VsKTidCy1yBkRtiUGbVkYBylBqUg=" crossorigin>
1111
<link rel="stylesheet preload" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/styles/github.min.css" crossorigin>
@@ -32,13 +32,6 @@
3232
<h1 class="title">Package <code>backtesting</code></h1>
3333
</header>
3434
<section id="section-intro">
35-
<h1 id="backtestingpy-documentation">Backtesting.py Documentation</h1>
36-
<div class="admonition warning">
37-
<p class="admonition-title">Warning:&ensp;v0.2.0 breaking changes</p>
38-
<p>Version 0.2.0 introduced some <strong>breaking API changes</strong>. For quick ways to
39-
migrate existing 0.1.x code, see the implementing
40-
<a href="https://github.com/kernc/backtesting.py/pull/47/">pull request</a>.</p>
41-
</div>
4235
<h2 id="manuals">Manuals</h2>
4336
<ul>
4437
<li><a href="../examples/Quick Start User Guide.html"><strong>Quick Start User Guide</strong></a></li>
@@ -47,15 +40,22 @@ <h2 id="tutorials">Tutorials</h2>
4740
<ul>
4841
<li><a href="../examples/Strategies Library.html">Library of Utilities and Composable Base Strategies</a></li>
4942
<li><a href="../examples/Multiple Time Frames.html">Multiple Time Frames</a></li>
50-
<li><a href="../examples/Parameter Heatmap.html">Parameter Heatmap</a></li>
51-
<li><a href="../examples/Trading with Machine Learning.html"><strong>Trading with Machine Learning</strong></a></li>
43+
<li><a href="../examples/Parameter Heatmap &amp; Optimization.html"><strong>Parameter Heatmap &amp; Optimization</strong></a></li>
44+
<li><a href="../examples/Trading with Machine Learning.html">Trading with Machine Learning</a></li>
5245
</ul>
53-
<p>These tutorials are also available to test as live Jupyter notebooks:
54-
<a href="https://mybinder.org/v2/gh/kernc/backtesting.py/master?urlpath=lab%2Ftree%2Fdoc%2Fexamples%2FQuick%20Start%20User%20Guide.ipynb"><img alt="Binder" src="https://mybinder.org/badge_logo.svg"></a></p>
46+
<p>These tutorials are also available as live Jupyter notebooks:
47+
<a href="https://mybinder.org/v2/gh/kernc/backtesting.py/master?urlpath=lab%2Ftree%2Fdoc%2Fexamples%2FQuick%20Start%20User%20Guide.ipynb"><img alt="Binder" src="https://mybinder.org/badge_logo.svg"></a>
48+
<a href="https://colab.research.google.com/github/kernc/backtesting.py/"><img alt="Google Colab" src="https://colab.research.google.com/assets/colab-badge.svg"></a>
49+
<br>In Colab, you might have to <code>!pip install backtesting</code>.</p>
5550
<h2 id="example-strategies">Example Strategies</h2>
5651
<ul>
5752
<li>(contributions welcome)</li>
5853
</ul>
54+
<div class="admonition tip">
55+
<p class="admonition-title">Tip</p>
56+
<p>For an overview of recent changes, see
57+
<a href="https://github.com/kernc/backtesting.py/blob/master/CHANGELOG.md">What's New</a>.</p>
58+
</div>
5959
<h2 id="faq">FAQ</h2>
6060
<p>Potentially outdated answers to frequent and popular questions can be found on the
6161
<a href="https://github.com/kernc/backtesting.py/issues?q=label%3Aquestion+-label%3Ainvalid">issue tracker</a>.</p>
@@ -107,14 +107,11 @@ <h2 class="section-title" id="header-submodules">Sub-modules</h2>
107107
<h1>Index</h1>
108108
<div class="toc">
109109
<ul>
110-
<li><a href="#backtestingpy-documentation">Backtesting.py Documentation</a><ul>
111110
<li><a href="#manuals">Manuals</a></li>
112111
<li><a href="#tutorials">Tutorials</a></li>
113112
<li><a href="#example-strategies">Example Strategies</a></li>
114113
<li><a href="#faq">FAQ</a></li>
115114
<li><a href="#license">License</a></li>
116-
</ul>
117-
</li>
118115
<li><a href="#api-reference-documentation">API Reference Documentation</a></li>
119116
</ul>
120117
</div>
@@ -131,7 +128,7 @@ <h1>Index</h1>
131128
</main>
132129
<footer id="footer">
133130
<p>
134-
<a href="https://kernc.github.io/backtesting.py/"><cite>backtesting</cite> 0.2.4</a>
131+
<a href="https://kernc.github.io/backtesting.py/"><cite>backtesting</cite> 0.3.0</a>
135132
<span style="color:#ddd">&#21328;</span>
136133
</p>
137134
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script>

β€Ždoc/backtesting/lib.htmlβ€Ž

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,12 @@ <h2 class="section-title" id="header-functions">Functions</h2>
106106
<p>When projecting the n-dimensional heatmap onto 2D, the values are
107107
aggregated by 'max' function by default. This can be tweaked
108108
with <code>agg</code> parameter, which accepts any argument pandas knows
109-
how to aggregate by.</p></div>
109+
how to aggregate by.</p>
110+
<div class="admonition todo">
111+
<p class="admonition-title">TODO</p>
112+
<p>Lay heatmaps out lower-triangular instead of in a simple grid.
113+
Like <a href="https://scikit-optimize.github.io/stable/modules/plots.html#plot-objective"><code>skopt.plots.plot_objective()</code></a> does.</p>
114+
</div></div>
110115
</dd>
111116
<dt id="backtesting.lib.quantile"><code class="name flex">
112117
<span>def <span class="ident">quantile</span></span>(<span>series, quantile=None)</span>
@@ -381,7 +386,7 @@ <h4><code><a title="backtesting.lib.TrailingStrategy" href="#backtesting.lib.Tra
381386
</main>
382387
<footer id="footer">
383388
<p>
384-
<a href="https://kernc.github.io/backtesting.py/"><cite>backtesting</cite> 0.2.4</a>
389+
<a href="https://kernc.github.io/backtesting.py/"><cite>backtesting</cite> 0.3.0</a>
385390
<span style="color:#ddd">&#21328;</span>
386391
</p>
387392
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script>

β€Ždoc/backtesting/test/index.htmlβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ <h1>Index</h1>
9999
</main>
100100
<footer id="footer">
101101
<p>
102-
<a href="https://kernc.github.io/backtesting.py/"><cite>backtesting</cite> 0.2.4</a>
102+
<a href="https://kernc.github.io/backtesting.py/"><cite>backtesting</cite> 0.3.0</a>
103103
<span style="color:#ddd">&#21328;</span>
104104
</p>
105105
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script>

β€Ždoc/examples/Multiple Time Frames.htmlβ€Ž

Lines changed: 30 additions & 26 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
Β (0)