Signature | Description | Parameters |
---|---|---|
#include <DataFrame/DataFrameStatsVisitors.h> template<typename T, typename I = unsigned long> struct ZeroLagMovingMeanVisitorz; // ------------------------------------- template<typename T, typename I = unsigned long> using zlmm_v = ZeroLagMovingMeanVisitorz<T, I>; |
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. This visitor calculates the zero lag moving average based on exponential moving average. The result is a vector of values with same number of items as the given columns. The first approx. rolling periods / 2 items in the result will be NaN The zero lag exponential moving average indicator was created by John Ehlers and Ric Way. The idea is do a regular exponential moving average (EMA) calculation but on a de-lagged data instead of doing it on the regular data. Data is de-lagged by removing the data from "lag" days ago thus removing (or attempting to) the cumulative effect of the moving average. explicit ZeroLagMovingMeanVisitor (size_t roll_period); |
T: Column data type I: Index type |
static void test_ZeroLagMovingMeanVisitor() { std::cout << "\nTesting ZeroLagMovingMeanVisitor{ } ..." << std::endl; typedef StdDataFrame<std::string> StrDataFrame; StrDataFrame df; try { df.read("data/SHORT_IBM.csv", io_format::csv2); zlmm_v<double, std::string> zlmm(10); df.single_act_visit<double>("IBM_Close", zlmm); assert(zlmm.get_result().size() == 1721); assert(std::isnan(zlmm.get_result()[0])); assert(std::isnan(zlmm.get_result()[3])); assert(std::abs(zlmm.get_result()[14] - 184.6943) < 0.0001); assert(std::abs(zlmm.get_result()[20] - 175.7459) < 0.0001); assert(std::abs(zlmm.get_result()[25] - 174.5764) < 0.0001); assert(std::abs(zlmm.get_result()[35] - 183.6864) < 0.0001); assert(std::abs(zlmm.get_result()[1720] - 108.6729) < 0.0001); assert(std::abs(zlmm.get_result()[1712] - 122.576) < 0.0001); assert(std::abs(zlmm.get_result()[1707] - 127.9991) < 0.0001); } catch (const DataFrameError &ex) { std::cout << ex.what() << std::endl; } }