Skip to content

Commit a3772c3

Browse files
CI: Update docs for 0.6.2 (cf596b4)
1 parent 1344c20 commit a3772c3

File tree

10 files changed

+210
-106
lines changed

10 files changed

+210
-106
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@ <h2 class="section-title" id="header-classes">Classes</h2>
132132
<p>If <code>finalize_trades</code> is <code>True</code>, the trades that are still
133133
<a href="https://kernc.github.io/backtesting.py/doc/backtesting/backtesting.html#backtesting.backtesting.Strategy.trades">active and ongoing</a> at the end of the backtest will be closed on
134134
the last bar and will contribute to the computed backtest statistics.</p></div>
135+
<h3>Subclasses</h3>
136+
<ul class="hlist">
137+
<li><a title="backtesting.lib.FractionalBacktest" href="lib.html#backtesting.lib.FractionalBacktest">FractionalBacktest</a></li>
138+
</ul>
135139
<h3>Methods</h3>
136140
<dl>
137141
<dt id="backtesting.backtesting.Backtest.optimize"><code class="name flex">
@@ -778,7 +782,7 @@ <h4><code><a title="backtesting.backtesting.Trade" href="#backtesting.backtestin
778782
</main>
779783
<footer id="footer">
780784
<p>
781-
<a href="https://kernc.github.io/backtesting.py/"><cite>backtesting</cite> 0.6.1</a>
785+
<a href="https://kernc.github.io/backtesting.py/"><cite>backtesting</cite> 0.6.2</a>
782786
<span style="color:#ddd">&#21328;</span>
783787
</p>
784788
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script>

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,19 @@ <h2 id="tutorials">Tutorials</h2>
6464
<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>
6565
<a href="https://colab.research.google.com/github/kernc/backtesting.py/"><img alt="Google Colab" src="https://colab.research.google.com/assets/colab-badge.png"></a>
6666
<br>In Colab, you might have to <code>!pip install backtesting</code>.</p>
67+
<h2 id="video-tutorials">Video Tutorials</h2>
68+
<ul>
69+
<li>Some <a href="https://github.com/kernc/backtesting.py/discussions/677"><strong>coverage on YouTube</strong></a>.</li>
70+
<li><a href="https://www.youtube.com/?q=%22backtesting.py%22">YouTube search</a></li>
71+
</ul>
6772
<h2 id="example-strategies">Example Strategies</h2>
6873
<ul>
6974
<li>(contributions welcome)</li>
7075
</ul>
7176
<div class="admonition tip">
7277
<p class="admonition-title">Tip</p>
7378
<p>For an overview of recent changes, see
74-
<a href="https://github.com/kernc/backtesting.py/blob/master/CHANGELOG.md">What's New</a>.</p>
79+
<a href="https://github.com/kernc/backtesting.py/blob/master/CHANGELOG.md">What's New, i.e. the <strong>Change Log</strong></a>.</p>
7580
</div>
7681
<h2 id="faq">FAQ</h2>
7782
<p>Some answers to frequent and popular questions can be found on the
@@ -127,6 +132,7 @@ <h2 class="section-title" id="header-submodules">Sub-modules</h2>
127132
<ul>
128133
<li><a href="#manuals">Manuals</a></li>
129134
<li><a href="#tutorials">Tutorials</a></li>
135+
<li><a href="#video-tutorials">Video Tutorials</a></li>
130136
<li><a href="#example-strategies">Example Strategies</a></li>
131137
<li><a href="#faq">FAQ</a></li>
132138
<li><a href="#license">License</a></li>
@@ -146,7 +152,7 @@ <h2 class="section-title" id="header-submodules">Sub-modules</h2>
146152
</main>
147153
<footer id="footer">
148154
<p>
149-
<a href="https://kernc.github.io/backtesting.py/"><cite>backtesting</cite> 0.6.1</a>
155+
<a href="https://kernc.github.io/backtesting.py/"><cite>backtesting</cite> 0.6.2</a>
150156
<span style="color:#ddd">&#21328;</span>
151157
</p>
152158
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script>

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

Lines changed: 90 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,92 @@ <h2 class="section-title" id="header-functions">Functions</h2>
245245
<section>
246246
<h2 class="section-title" id="header-classes">Classes</h2>
247247
<dl>
248+
<dt id="backtesting.lib.FractionalBacktest"><code class="flex name class">
249+
<span>class <span class="ident">FractionalBacktest</span></span>
250+
<span>(</span><span>data, *args, satoshi=100000000, **kwargs)</span>
251+
</code></dt>
252+
<dd>
253+
<div class="desc"><p>A <code>backtesting.Backtest</code> that supports fractional share trading
254+
by simple composition. It applies roughly the transformation:</p>
255+
<pre><code>df = (df / satoshi).assign(Volume=df.Volume * satoshi)
256+
</code></pre>
257+
<p>as unchallenged in <a href="https://github.com/kernc/backtesting.py/issues/134">this FAQ entry on GitHub</a>,
258+
then passes <code>data</code>, <code>args*</code>, and <code>**kwargs</code> to its super.</p>
259+
<p>Parameter <code>satoshi</code> tells the amount of scaling to do. E.g. for
260+
ΞΌBTC trading, pass <code>satoshi=1e6</code>.</p>
261+
<p>Initialize a backtest. Requires data and a strategy to test.</p>
262+
<p><code>data</code> is a <code>pd.DataFrame</code> with columns:
263+
<code>Open</code>, <code>High</code>, <code>Low</code>, <code>Close</code>, and (optionally) <code>Volume</code>.
264+
If any columns are missing, set them to what you have available,
265+
e.g.</p>
266+
<pre><code>df['Open'] = df['High'] = df['Low'] = df['Close']
267+
</code></pre>
268+
<p>The passed data frame can contain additional columns that
269+
can be used by the strategy (e.g. sentiment info).
270+
DataFrame index can be either a datetime index (timestamps)
271+
or a monotonic range index (i.e. a sequence of periods).</p>
272+
<p><code>strategy</code> is a <code><a title="backtesting.backtesting.Strategy" href="backtesting.html#backtesting.backtesting.Strategy">Strategy</a></code>
273+
<em>subclass</em> (not an instance).</p>
274+
<p><code>cash</code> is the initial cash to start with.</p>
275+
<p><code>spread</code> is the the constant bid-ask spread rate (relative to the price).
276+
E.g. set it to <code>0.0002</code> for commission-less forex
277+
trading where the average spread is roughly 0.2‰ of the asking price.</p>
278+
<p><code>commission</code> is the commission rate. E.g. if your broker's commission
279+
is 1% of order value, set commission to <code>0.01</code>.
280+
The commission is applied twice: at trade entry and at trade exit.
281+
Besides one single floating value, <code>commission</code> can also be a tuple of floating
282+
values <code>(fixed, relative)</code>. E.g. set it to <code>(100, .01)</code>
283+
if your broker charges minimum $100 + 1%.
284+
Additionally, <code>commission</code> can be a callable
285+
<code>func(order_size: int, price: float) -&gt; float</code>
286+
(note, order size is negative for short orders),
287+
which can be used to model more complex commission structures.
288+
Negative commission values are interpreted as market-maker's rebates.</p>
289+
<div class="admonition note">
290+
<p class="admonition-title">Note</p>
291+
<p>Before v0.4.0, the commission was only applied once, like <code>spread</code> is now.
292+
If you want to keep the old behavior, simply set <code>spread</code> instead.</p>
293+
</div>
294+
<div class="admonition note">
295+
<p class="admonition-title">Note</p>
296+
<p>With nonzero <code>commission</code>, long and short orders will be placed
297+
at an adjusted price that is slightly higher or lower (respectively)
298+
than the current price. See e.g.
299+
<a href="https://github.com/kernc/backtesting.py/issues/153">#153</a>,
300+
<a href="https://github.com/kernc/backtesting.py/issues/538">#538</a>,
301+
<a href="https://github.com/kernc/backtesting.py/issues/633">#633</a>.</p>
302+
</div>
303+
<p><code>margin</code> is the required margin (ratio) of a leveraged account.
304+
No difference is made between initial and maintenance margins.
305+
To run the backtest using e.g. 50:1 leverge that your broker allows,
306+
set margin to <code>0.02</code> (1 / leverage).</p>
307+
<p>If <code>trade_on_close</code> is <code>True</code>, market orders will be filled
308+
with respect to the current bar's closing price instead of the
309+
next bar's open.</p>
310+
<p>If <code>hedging</code> is <code>True</code>, allow trades in both directions simultaneously.
311+
If <code>False</code>, the opposite-facing orders first close existing trades in
312+
a <a href="https://www.investopedia.com/terms/n/nfa-compliance-rule-2-43b.asp">FIFO</a> manner.</p>
313+
<p>If <code>exclusive_orders</code> is <code>True</code>, each new order auto-closes the previous
314+
trade/position, making at most a single trade (long or short) in effect
315+
at each time.</p>
316+
<p>If <code>finalize_trades</code> is <code>True</code>, the trades that are still
317+
<a href="https://kernc.github.io/backtesting.py/doc/backtesting/backtesting.html#backtesting.backtesting.Strategy.trades">active and ongoing</a> at the end of the backtest will be closed on
318+
the last bar and will contribute to the computed backtest statistics.</p></div>
319+
<h3>Ancestors</h3>
320+
<ul class="hlist">
321+
<li><a title="backtesting.backtesting.Backtest" href="backtesting.html#backtesting.backtesting.Backtest">Backtest</a></li>
322+
</ul>
323+
<h3>Inherited members</h3>
324+
<ul class="hlist">
325+
<li><code><b><a title="backtesting.backtesting.Backtest" href="backtesting.html#backtesting.backtesting.Backtest">Backtest</a></b></code>:
326+
<ul class="hlist">
327+
<li><code><a title="backtesting.backtesting.Backtest.optimize" href="backtesting.html#backtesting.backtesting.Backtest.optimize">optimize</a></code></li>
328+
<li><code><a title="backtesting.backtesting.Backtest.plot" href="backtesting.html#backtesting.backtesting.Backtest.plot">plot</a></code></li>
329+
<li><code><a title="backtesting.backtesting.Backtest.run" href="backtesting.html#backtesting.backtesting.Backtest.run">run</a></code></li>
330+
</ul>
331+
</li>
332+
</ul>
333+
</dd>
248334
<dt id="backtesting.lib.SignalStrategy"><code class="flex name class">
249335
<span>class <span class="ident">SignalStrategy</span></span>
250336
</code></dt>
@@ -396,6 +482,9 @@ <h3>Inherited members</h3>
396482
<li><h3><a href="#header-classes">Classes</a></h3>
397483
<ul>
398484
<li>
485+
<h4><code><a title="backtesting.lib.FractionalBacktest" href="#backtesting.lib.FractionalBacktest">FractionalBacktest</a></code></h4>
486+
</li>
487+
<li>
399488
<h4><code><a title="backtesting.lib.SignalStrategy" href="#backtesting.lib.SignalStrategy">SignalStrategy</a></code></h4>
400489
<ul class="">
401490
<li><code><a title="backtesting.lib.SignalStrategy.set_signal" href="#backtesting.lib.SignalStrategy.set_signal">set_signal</a></code></li>
@@ -415,7 +504,7 @@ <h4><code><a title="backtesting.lib.TrailingStrategy" href="#backtesting.lib.Tra
415504
</main>
416505
<footer id="footer">
417506
<p>
418-
<a href="https://kernc.github.io/backtesting.py/"><cite>backtesting</cite> 0.6.1</a>
507+
<a href="https://kernc.github.io/backtesting.py/"><cite>backtesting</cite> 0.6.2</a>
419508
<span style="color:#ddd">&#21328;</span>
420509
</p>
421510
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script>

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ <h1 class="title">Module <code>backtesting.test</code></h1>
5353
<section>
5454
<h2 class="section-title" id="header-variables">Global variables</h2>
5555
<dl>
56+
<dt id="backtesting.test.BTCUSD"><code class="name">var <span class="ident">BTCUSD</span></code></dt>
57+
<dd>
58+
<div class="desc"><p>DataFrame of monthly BTC/USD histrical index data from 2012 through 2024 (12 years).</p></div>
59+
</dd>
5660
<dt id="backtesting.test.EURUSD"><code class="name">var <span class="ident">EURUSD</span></code></dt>
5761
<dd>
5862
<div class="desc"><p>DataFrame of hourly EUR/USD forex data from April 2017 to February 2018.</p></div>
@@ -98,6 +102,7 @@ <h2 class="section-title" id="header-functions">Functions</h2>
98102
</li>
99103
<li><h3><a href="#header-variables">Global variables</a></h3>
100104
<ul class="">
105+
<li><code><a title="backtesting.test.BTCUSD" href="#backtesting.test.BTCUSD">BTCUSD</a></code></li>
101106
<li><code><a title="backtesting.test.EURUSD" href="#backtesting.test.EURUSD">EURUSD</a></code></li>
102107
<li><code><a title="backtesting.test.GOOG" href="#backtesting.test.GOOG">GOOG</a></code></li>
103108
</ul>
@@ -112,7 +117,7 @@ <h2 class="section-title" id="header-functions">Functions</h2>
112117
</main>
113118
<footer id="footer">
114119
<p>
115-
<a href="https://kernc.github.io/backtesting.py/"><cite>backtesting</cite> 0.6.1</a>
120+
<a href="https://kernc.github.io/backtesting.py/"><cite>backtesting</cite> 0.6.2</a>
116121
<span style="color:#ddd">&#21328;</span>
117122
</p>
118123
<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: 17 additions & 17 deletions
Large diffs are not rendered by default.

β€Ždoc/examples/Parameter Heatmap & Optimization.htmlβ€Ž

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

β€Ždoc/examples/Quick Start User Guide.htmlβ€Ž

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

β€Ždoc/examples/Strategies Library.htmlβ€Ž

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

β€Ždoc/examples/Trading with Machine Learning.htmlβ€Ž

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

β€Žsitemap.txtβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ https://kernc.github.io/backtesting.py/doc/backtesting/lib.html
66
https://kernc.github.io/backtesting.py/doc/backtesting/test/
77
https://kernc.github.io/backtesting.py/doc/examples/Multiple Time Frames.html
88
https://kernc.github.io/backtesting.py/doc/examples/Parameter Heatmap & Optimization.html
9-
https://kernc.github.io/backtesting.py/doc/examples/Parameter Heatmap.html
109
https://kernc.github.io/backtesting.py/doc/examples/Quick Start User Guide.html
1110
https://kernc.github.io/backtesting.py/doc/examples/Strategies Library.html
1211
https://kernc.github.io/backtesting.py/doc/examples/Trading with Machine Learning.html
1312
https://kernc.github.io/backtesting.py/example.html
13+
https://kernc.github.io/backtesting.py/plx.gif.html

0 commit comments

Comments
Β (0)