-
-
Notifications
You must be signed in to change notification settings - Fork 308
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5844fba
commit 62354a7
Showing
5 changed files
with
222 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
<!-- | ||
Copyright (c) 2019-2022, Hossein Moein | ||
All rights reserved. | ||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
* Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
* Redistributions in binary form must reproduce the above copyright | ||
notice, this list of conditions and the following disclaimer in the | ||
documentation and/or other materials provided with the distribution. | ||
* Neither the name of Hossein Moein and/or the DataFrame nor the | ||
names of its contributors may be used to endorse or promote products | ||
derived from this software without specific prior written permission. | ||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL Hossein Moein BE LIABLE FOR ANY | ||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
--> | ||
<!DOCTYPE html> | ||
<html> | ||
<body> | ||
<table align="center" border="1"> | ||
|
||
<tr bgcolor="lightblue"> | ||
<th>Signature</th> <th>Description</th> <th>Parameters</th> | ||
</tr> | ||
<tr bgcolor="lightgrey"> | ||
<td bgcolor="maroon"> <font color="white"> | ||
<PRE><B>#include <DataFrame/DataFrameFinancialVisitors.h> | ||
|
||
template<typename T, typename I = unsigned long> | ||
struct ArnaudLegouxMAVisitor; | ||
|
||
// ------------------------------------- | ||
|
||
template<typename T, typename I = unsigned long> | ||
using alma_v = ArnaudLegouxMAVisitor<T, I>; | ||
</B></PRE></font> | ||
</td> | ||
<td> | ||
This is a “single action visitor”, meaning it is passed the whole data vector in one call and you must use the single_act_visit() interface.<BR><BR> | ||
This visitor calculates the rolling values of Arnaud Legoux Moving Average. It requires 1 input column.<BR> | ||
The result is a vector of values with same number of items as the given column. The first roll_count items, in the result, will be NAN.<BR> | ||
The ALMA is a technical analysis tool that aims to give investors and traders a more reliable trading signal by reducing the noise that can interfere with traditional moving averages. It eliminates the small fluctuations in an asset price to make the trend clearer. The ALMA reduces price lag and creates a smoother line than other moving averages. Rather than a straightforward moving average for a certain period, it applies a moving average twice – from left to right as well as right to left.<BR> | ||
<I> | ||
<PRE> | ||
explicit | ||
ArnaudLegouxMAVisitor(size_t roll_count = 10, T sigma = 6.0, T dist_offset = 0.85) | ||
|
||
<B>roll_count</B>: Moving average period | ||
<B>sigma</B>: The standard deviation applied to the combo line. It makes the combo line sharper. | ||
<B>dis_offset</B>: Offset is the Gaussian applied to the combo line and it is 0.85 by default. | ||
Setting offset at 1 makes it fully aligned to the current price just | ||
like the exponential moving average. | ||
</PRE> | ||
</I> | ||
</td> | ||
<td width="12%"> | ||
<B>T</B>: Column data type<BR> | ||
<B>I</B>: Index type | ||
</td> | ||
</tr> | ||
|
||
</table> | ||
|
||
<pre style='color:#000000;background:#ffffff;'><span style='color:#800000; font-weight:bold; '>static</span> <span style='color:#800000; font-weight:bold; '>void</span> test_ArnaudLegouxMAVisitor<span style='color:#808030; '>(</span><span style='color:#808030; '>)</span> <span style='color:#800080; '>{</span> | ||
|
||
<span style='color:#666616; '>std</span><span style='color:#800080; '>::</span><span style='color:#603000; '>cout</span> <span style='color:#808030; '><</span><span style='color:#808030; '><</span> <span style='color:#800000; '>"</span><span style='color:#0f69ff; '>\n</span><span style='color:#0000e6; '>Testing ArnaudLegouxMAVisitor{ } ...</span><span style='color:#800000; '>"</span> <span style='color:#808030; '><</span><span style='color:#808030; '><</span> <span style='color:#666616; '>std</span><span style='color:#800080; '>::</span><span style='color:#603000; '>endl</span><span style='color:#800080; '>;</span> | ||
|
||
<span style='color:#800000; font-weight:bold; '>typedef</span> StdDataFrame<span style='color:#800080; '><</span><span style='color:#666616; '>std</span><span style='color:#800080; '>::</span><span style='color:#603000; '>string</span><span style='color:#800080; '>></span> StrDataFrame<span style='color:#800080; '>;</span> | ||
|
||
StrDataFrame df<span style='color:#800080; '>;</span> | ||
|
||
<span style='color:#800000; font-weight:bold; '>try</span> <span style='color:#800080; '>{</span> | ||
df<span style='color:#808030; '>.</span>read<span style='color:#808030; '>(</span><span style='color:#800000; '>"</span><span style='color:#0000e6; '>data/SHORT_IBM.csv</span><span style='color:#800000; '>"</span><span style='color:#808030; '>,</span> io_format<span style='color:#800080; '>::</span>csv2<span style='color:#808030; '>)</span><span style='color:#800080; '>;</span> | ||
|
||
alma_v<span style='color:#800080; '><</span><span style='color:#800000; font-weight:bold; '>double</span><span style='color:#808030; '>,</span> <span style='color:#666616; '>std</span><span style='color:#800080; '>::</span><span style='color:#603000; '>string</span><span style='color:#800080; '>></span> alma<span style='color:#800080; '>;</span> | ||
|
||
df<span style='color:#808030; '>.</span>single_act_visit<span style='color:#800080; '><</span><span style='color:#800000; font-weight:bold; '>double</span><span style='color:#800080; '>></span><span style='color:#808030; '>(</span><span style='color:#800000; '>"</span><span style='color:#0000e6; '>IBM_Close</span><span style='color:#800000; '>"</span><span style='color:#808030; '>,</span> alma<span style='color:#808030; '>)</span><span style='color:#800080; '>;</span> | ||
|
||
assert<span style='color:#808030; '>(</span>alma<span style='color:#808030; '>.</span>get_result<span style='color:#808030; '>(</span><span style='color:#808030; '>)</span><span style='color:#808030; '>.</span>size<span style='color:#808030; '>(</span><span style='color:#808030; '>)</span> <span style='color:#808030; '>=</span><span style='color:#808030; '>=</span> <span style='color:#008c00; '>1721</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span> | ||
assert<span style='color:#808030; '>(</span><span style='color:#666616; '>std</span><span style='color:#800080; '>::</span>isnan<span style='color:#808030; '>(</span>alma<span style='color:#808030; '>.</span>get_result<span style='color:#808030; '>(</span><span style='color:#808030; '>)</span><span style='color:#808030; '>[</span><span style='color:#008c00; '>0</span><span style='color:#808030; '>]</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span> | ||
assert<span style='color:#808030; '>(</span><span style='color:#666616; '>std</span><span style='color:#800080; '>::</span>isnan<span style='color:#808030; '>(</span>alma<span style='color:#808030; '>.</span>get_result<span style='color:#808030; '>(</span><span style='color:#808030; '>)</span><span style='color:#808030; '>[</span><span style='color:#008c00; '>9</span><span style='color:#808030; '>]</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span> | ||
assert<span style='color:#808030; '>(</span><span style='color:#666616; '>std</span><span style='color:#800080; '>::</span><span style='color:#603000; '>abs</span><span style='color:#808030; '>(</span>alma<span style='color:#808030; '>.</span>get_result<span style='color:#808030; '>(</span><span style='color:#808030; '>)</span><span style='color:#808030; '>[</span><span style='color:#008c00; '>10</span><span style='color:#808030; '>]</span> <span style='color:#808030; '>-</span> <span style='color:#008000; '>187.533</span><span style='color:#808030; '>)</span> <span style='color:#808030; '><</span> <span style='color:#008000; '>0.001</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span> | ||
assert<span style='color:#808030; '>(</span><span style='color:#666616; '>std</span><span style='color:#800080; '>::</span><span style='color:#603000; '>abs</span><span style='color:#808030; '>(</span>alma<span style='color:#808030; '>.</span>get_result<span style='color:#808030; '>(</span><span style='color:#808030; '>)</span><span style='color:#808030; '>[</span><span style='color:#008c00; '>14</span><span style='color:#808030; '>]</span> <span style='color:#808030; '>-</span> <span style='color:#008000; '>186.359</span><span style='color:#808030; '>)</span> <span style='color:#808030; '><</span> <span style='color:#008000; '>0.001</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span> | ||
assert<span style='color:#808030; '>(</span><span style='color:#666616; '>std</span><span style='color:#800080; '>::</span><span style='color:#603000; '>abs</span><span style='color:#808030; '>(</span>alma<span style='color:#808030; '>.</span>get_result<span style='color:#808030; '>(</span><span style='color:#808030; '>)</span><span style='color:#808030; '>[</span><span style='color:#008c00; '>25</span><span style='color:#808030; '>]</span> <span style='color:#808030; '>-</span> <span style='color:#008000; '>176.892</span><span style='color:#808030; '>)</span> <span style='color:#808030; '><</span> <span style='color:#008000; '>0.001</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span> | ||
assert<span style='color:#808030; '>(</span><span style='color:#666616; '>std</span><span style='color:#800080; '>::</span><span style='color:#603000; '>abs</span><span style='color:#808030; '>(</span>alma<span style='color:#808030; '>.</span>get_result<span style='color:#808030; '>(</span><span style='color:#808030; '>)</span><span style='color:#808030; '>[</span><span style='color:#008c00; '>1720</span><span style='color:#808030; '>]</span> <span style='color:#808030; '>-</span> <span style='color:#008000; '>117.841</span><span style='color:#808030; '>)</span> <span style='color:#808030; '><</span> <span style='color:#008000; '>0.001</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span> | ||
assert<span style='color:#808030; '>(</span><span style='color:#666616; '>std</span><span style='color:#800080; '>::</span><span style='color:#603000; '>abs</span><span style='color:#808030; '>(</span>alma<span style='color:#808030; '>.</span>get_result<span style='color:#808030; '>(</span><span style='color:#808030; '>)</span><span style='color:#808030; '>[</span><span style='color:#008c00; '>1712</span><span style='color:#808030; '>]</span> <span style='color:#808030; '>-</span> <span style='color:#008000; '>127.677</span><span style='color:#808030; '>)</span> <span style='color:#808030; '><</span> <span style='color:#008000; '>0.001</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span> | ||
assert<span style='color:#808030; '>(</span><span style='color:#666616; '>std</span><span style='color:#800080; '>::</span><span style='color:#603000; '>abs</span><span style='color:#808030; '>(</span>alma<span style='color:#808030; '>.</span>get_result<span style='color:#808030; '>(</span><span style='color:#808030; '>)</span><span style='color:#808030; '>[</span><span style='color:#008c00; '>1707</span><span style='color:#808030; '>]</span> <span style='color:#808030; '>-</span> <span style='color:#008000; '>121.435</span><span style='color:#808030; '>)</span> <span style='color:#808030; '><</span> <span style='color:#008000; '>0.001</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span> | ||
<span style='color:#800080; '>}</span> | ||
<span style='color:#800000; font-weight:bold; '>catch</span> <span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>const</span> DataFrameError <span style='color:#808030; '>&</span>ex<span style='color:#808030; '>)</span> <span style='color:#800080; '>{</span> | ||
<span style='color:#666616; '>std</span><span style='color:#800080; '>::</span><span style='color:#603000; '>cout</span> <span style='color:#808030; '><</span><span style='color:#808030; '><</span> ex<span style='color:#808030; '>.</span>what<span style='color:#808030; '>(</span><span style='color:#808030; '>)</span> <span style='color:#808030; '><</span><span style='color:#808030; '><</span> <span style='color:#666616; '>std</span><span style='color:#800080; '>::</span><span style='color:#603000; '>endl</span><span style='color:#800080; '>;</span> | ||
<span style='color:#800080; '>}</span> | ||
<span style='color:#800080; '>}</span> | ||
</pre> | ||
<!--Created using ToHtml.com on 2021-07-12 15:55:00 UTC --> | ||
|
||
</body> | ||
</html> | ||
|
||
<!-- | ||
Local Variables: | ||
mode:HTML | ||
tab-width:4 | ||
c-basic-offset:4 | ||
End: | ||
--> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters