<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Bollinger Bands]]></title><description><![CDATA[<p dir="auto">Hi, I would like to code a mean reverting system based on bands similar to Bolliger bands. Do you have an example for coding Bollinger bands?</p>
]]></description><link>http://quantiacs.com/community/topic/68/bollinger-bands</link><generator>RSS for Node</generator><lastBuildDate>Tue, 15 Sep 2026 10:06:46 GMT</lastBuildDate><atom:link href="http://quantiacs.com/community/topic/68.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 14 May 2021 11:16:43 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Bollinger Bands on Thu, 20 May 2021 16:46:28 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="http://quantiacs.com/community/uid/20">@antinomy</a> wow, thank you so much, this is awesome!</p>
]]></description><link>http://quantiacs.com/community/post/294</link><guid isPermaLink="true">http://quantiacs.com/community/post/294</guid><dc:creator><![CDATA[anthony_m]]></dc:creator><pubDate>Thu, 20 May 2021 16:46:28 GMT</pubDate></item><item><title><![CDATA[Reply to Bollinger Bands on Fri, 14 May 2021 13:19:15 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="http://quantiacs.com/community/uid/10">@anthony_m</a><br />
Bollinger Bands are actually quite easy to calculate.<br />
The middle band is just the simple moving average, the default period is 20.<br />
For the other bands you need the standard deviation for the same period.<br />
The upper band is middle + multiplier * std<br />
The lower band is middle - multiplier * std<br />
Where the default for the multiplier is 2.</p>
<p dir="auto">There's an article on the formula for Bollinger Bands on <a href="https://www.investopedia.com/terms/b/bollingerbands.asp" rel="nofollow ugc">Investopedia</a> - they use the 'typical price' (high + low + close) / 3 but I think most people just use the close price.</p>
<p dir="auto">For the code it depends if you only need the latest values or the history.<br />
Using pandas the code for the first alternative could be:</p>
<pre><code>def strategy(data):
    close = data.sel(field='close').copy().to_pandas().ffill().bfill().fillna(0) 

    # let's just use the default 20 period:
    period = 20
    sma = close.iloc[-period:].mean()
    std = close.iloc[-period:].std()

    # and the default multiplier of 2:
    multiplier = 2
    upper = sma + multiplier * std
    lower = sma - multiplier * std
</code></pre>
<p dir="auto">If you need more than the last values you can use pandas.rolling:</p>
<pre><code>def strategy(data):
    close = data.sel(field='close').copy().to_pandas().ffill().bfill().fillna(0)

    # let's just use the default 20 period:
    period = 20
    sma = close.rolling(period).mean()
    std = close.rolling(period).std()

    # and the default multiplier of 2:
    multiplier = 2
    upper = sma + multiplier * std
    lower = sma - multiplier * std
</code></pre>
]]></description><link>http://quantiacs.com/community/post/281</link><guid isPermaLink="true">http://quantiacs.com/community/post/281</guid><dc:creator><![CDATA[antinomy]]></dc:creator><pubDate>Fri, 14 May 2021 13:19:15 GMT</pubDate></item></channel></rss>