Skip to content

Commit

Permalink
Uses Indicator Window in Timeseries Examples
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexCatarino committed Sep 7, 2024
1 parent 6fe917c commit b310bc4
Show file tree
Hide file tree
Showing 7 changed files with 173 additions and 307 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<p>You need to <a href="/docs/v2/research-environment/indicators/data-point-indicators#03-Create-Subscriptions">subscribe to some market data</a> and create an indicator in order to calculate a timeseries of indicator values. In this example, use a 20-period 2-standard-deviation <code>BollingerBands</code> indicator.</p>
<div class="section-example-container">
<pre class="csharp">var bb = new BollingerBands(20, 2);</pre>
<pre class="python">bb = BollingerBands(20, 2)</pre>
</div>

<?
$variableName='bb';
$pythonImage='<img class="python docs-image" src="https://cdn.quantconnect.com/i/tu/indicator-datapoint-py-helper-bb.png" alt="Historical bollinger band data">';

$setWindowSizeExampleContainer='
<div class="section-example-container">
<pre class="csharp">// Set the window.size to the desired timeseries length
bb.Window.Size=50;
bb.LowerBand.Window.Size=50;
bb.MiddleBand.Window.Size=50;
bb.UpperBand.Window.Size=50;
bb.BandWidth.Window.Size=50;
bb.PercentB.Window.Size=50;
bb.StandardDeviation.Window.Size=50;
bb.Price.Window.Size=50;</pre>
<pre class="python"># Set the window.size to the desired timeseries length
bb.window.size=50
bb.lower_band.window.size=50
bb.middle_band.window.size=50
bb.upper_band.window.size=50
bb.band_width.window.size=50
bb.percent_b.window.size=50
bb.standard_deviation.window.size=50
bb.price.window.size=50</pre>
</div>';

$dataDisplayStep = '
<li class="csharp">Display the data.</li>
<div class="csharp section-example-container">
<pre class="csharp">foreach (var i in Enumerable.Range(0, 5).Reverse())
{
Console.WriteLine($"{bb[i].EndTime:yyyyMMdd} {bb[i].Value:f4} {bb.LowerBand[i].Value:f4} {bb.MiddleBand[i].Value:f4} {bb.UpperBand[i].Value:f4} {bb.BandWidth[i].Value:f4} {bb.PercentB[i].Value:f4} {bb.StandardDeviation[i].Value:f4} {bb.Price[i].Value:f4}");
}</pre>
</div>
<img class="csharp docs-image" src="https://cdn.quantconnect.com/i/tu/indicator-datapoint-cs-classic-bb.png" alt="Historical bollinger band data">
<li class="python">Populate a <code>DataFrame</code> with the data in the <code>Indicator</code> object.</li>
<div class="python section-example-container">
<pre class="python">bb_dataframe = pd.DataFrame({
"current": pd.Series({x.end_time: x.value for x in bb}),
"lower_band": pd.Series({x.end_time: x.value for x in bb.lower_band}),
"middle_band": pd.Series({x.end_time: x.value for x in bb.middle_band}),
"upper_band": pd.Series({x.end_time: x.value for x in bb.upper_band}),
"band_width": pd.Series({x.end_time: x.value for x in bb.band_width}),
"percent_b": pd.Series({x.end_time: x.value for x in bb.percent_b}),
"standard_deviation": pd.Series({x.end_time: x.value for x in bb.standard_deviation}),
"price": pd.Series({x.end_time: x.value for x in bb.price})
}).sort_index()</pre>
</div>
<img class="python docs-image" src="https://cdn.quantconnect.com/i/tu/indicator-datapoint-py-classic-bb.png" alt="Historical bollinger band data"';
include(DOCS_RESOURCES."/indicators/create-indicator-timeseries.php");
?>

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<p>You need to <a href="/docs/v2/research-environment/indicators/bar-indicators#03-Create-Subscriptions">subscribe to some market data</a> and create an indicator in order to calculate a timeseries of indicator values. In this example, use a 20-period <code>AverageTrueRange</code> indicator.</p>
<div class="section-example-container">
<pre class="csharp">var atr = new AverageTrueRange(20);</pre>
<pre class="python">atr = AverageTrueRange(20)</pre>
</div>

<?
$variableName='atr';
$pythonImage='<img class="python docs-image" src="https://cdn.quantconnect.com/i/tu/indicator-bar-py-helper-atr.png" alt="Historical average true range data">';

$setWindowSizeExampleContainer='
<div class="section-example-container">
<pre class="csharp">// Set the window.size to the desired timeseries length
atr.Window.Size = 50;
atr.TrueRange.Window.Size = 50;</pre>
<pre class="python"># Set the window.size to the desired timeseries length
atr.window.size = 50
atr.true_range.window.size = 50</pre>
</div>';

$dataDisplayStep = '
<li class="csharp">Display the data.</li>
<div class="csharp section-example-container">
<pre class="csharp">foreach (var i in Enumerable.Range(0, 5).Reverse())
{
Console.WriteLine($"{atr[i].EndTime:yyyyMMdd} {atr[i].Value:f4} {atr.TrueRange[i].Value:f4}");
}</pre>
</div>
<img class="csharp docs-image" src="https://cdn.quantconnect.com/i/tu/indicator-bar-cs-classic-atr.png" alt="Historical average true range data">
<li class="python">Populate a <code>DataFrame</code> with the data in the <code>Indicator</code> object.</li>
<div class="python section-example-container">
<pre class="python">atr_dataframe = pd.DataFrame({
"current": pd.Series({x.end_time: x.value for x in atr}),
"truerange": pd.Series({x.end_time: x.value for x in atr.true_range})
}).sort_index()</pre>
</div>
<img class="python docs-image" src="https://cdn.quantconnect.com/i/tu/indicator-bar-py-classic-atr.png" alt="Historical average true range data">';
include(DOCS_RESOURCES."/indicators/create-indicator-timeseries.php");
?>
Loading

0 comments on commit b310bc4

Please sign in to comment.