Signature | Description | Parameters |
---|---|---|
#include <DataFrame/DataFrameFinancialVisitors.h> template<typename T, typename I = unsigned long> struct VortexVisitor; // ------------------------------------- template<typename T, typename I = unsigned long> using vtx_v = VortexVisitor<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 rolling values of Vortex trading indicator. It requires 3 input columns in the order of low, high, close. The result() method returns the positive indicator. The first roll_period elements of all results are NaN. A vortex pattern may be observed in any market by connecting the lows of that market's price bars with the consecutive bars’ highs, and then price bar highs with consecutive lows. The greater the distance between the low of a price bar and the subsequent bar's high, the greater the upward or positive Vortex movement (VM+). Similarly, the greater the distance between a price bar's high and the subsequent bar's low, the greater the downward or negative Vortex movement (VM-). There are 3 other methods: get_result() // It returns the positive trend indicator get_plus_indicator() // It returns the positive trend indicator get_minus_indicator() // It returns the negative trend indicator explicit VortexVisitor(size_t roll_period = 14); roll_period: Rolling period |
T: Column data type I: Index type |
static void test_VortexVisitor() { std::cout << "\nTesting VortexVisitor{ } ..." << std::endl; typedef StdDataFrame<std::string> StrDataFrame; StrDataFrame df; try { df.read("data/SHORT_IBM.csv", io_format::csv2); vtx_v<double, std::string> vtx; df.single_act_visit<double, double, double>("IBM_Low", "IBM_High", "IBM_Close", vtx); assert(vtx.get_result().size() == 1721); assert(std::isnan(vtx.get_plus_indicator()[0])); assert(std::isnan(vtx.get_plus_indicator()[12])); assert(std::abs(vtx.get_plus_indicator()[20] - 0.7804) < 0.0001); assert(std::abs(vtx.get_plus_indicator()[25] - 0.7063) < 0.0001); assert(std::abs(vtx.get_plus_indicator()[35] - 1.2725) < 0.0001); assert(std::abs(vtx.get_plus_indicator()[1720] - 0.6619) < 0.0001); assert(std::abs(vtx.get_plus_indicator()[1712] - 0.8658) < 0.0001); assert(std::abs(vtx.get_plus_indicator()[1707] - 0.9571) < 0.0001); assert(vtx.get_minus_indicator().size() == 1721); assert(std::isnan(vtx.get_minus_indicator()[0])); assert(std::isnan(vtx.get_minus_indicator()[12])); assert(std::abs(vtx.get_minus_indicator()[20] - 1.1256) < 0.0001); assert(std::abs(vtx.get_minus_indicator()[25] - 1.1854) < 0.0001); assert(std::abs(vtx.get_minus_indicator()[35] - 0.7427) < 0.0001); assert(std::abs(vtx.get_minus_indicator()[1720] - 1.187) < 0.0001); assert(std::abs(vtx.get_minus_indicator()[1712] - 1.016) < 0.0001); assert(std::abs(vtx.get_minus_indicator()[1707] - 0.9819) < 0.0001); } catch (const DataFrameError &ex) { std::cout << ex.what() << std::endl; } }