Signature | Description | Parameters |
---|---|---|
#include <DataFrame/DataFrameFinancialVisitors.h> template<typename T, typename I = unsigned long, std::size_t A = 0> struct RelativeVigorIndexVisitor; // ------------------------------------- template<typename T, typename I = unsigned long, std::size_t A = 0> using rvgi_v = RelativeVigorIndexVisitor<T, I, A>; |
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 Relative Vigor Index indicator. It requires 4 input columns in the order of low, high, open, close. The result is a vector of values with same number of items as the given columns. The first roll_peiord items, in the result will be NAN. The Relative Vigor Index indicator (RVGI) is an oscillator that gauges the strength behind a price move. It attempts to provide a guide to the propensity of the market, to persist in the same direction of that move – or for the price move to break down. It's based on the principle that in a rising market, we expect the closing price to be on balance and in general, higher than the opening price. Similarly, in a falling market, we expect the closing price to be, more often than not, lower than the opening price. In other words, at its core, this indicator tries to gauge whether a market is bullish or bearish in character. get_result() returns the vector of RVGI indicators. get_signal() returns the signal line explicit RelativeVigorIndexVisitor(size_t roll_period = 14, size_t swma_period = 4); rolling_period: Applied to the final rolling summation calculation swma_period: Applied to the symmetric moving average calculations, which is used by this visitor instead of simple moving average |
T: Column data type I: Index type A: Memory alignment boundary for vectors. Default is system default alignment |
static void test_RelativeVigorIndexVisitor() { std::cout << "\nTesting RelativeVigorIndexVisitor{ } ..." << std::endl; StrDataFrame df; try { df.read("data/SHORT_IBM.csv", io_format::csv2); rvgi_v<double, std::string, 256> rvgi; df.single_act_visit<double, double, double, double>("IBM_Low", "IBM_High", "IBM_Open", "IBM_Close", rvgi); assert(rvgi.get_result().size() == 1721); assert(std::isnan(rvgi.get_result()[0])); assert(std::isnan(rvgi.get_result()[12])); assert(std::abs(rvgi.get_result()[13] - 0.0319) < 0.0001); assert(std::abs(rvgi.get_result()[14] - 0.0434) < 0.0001); assert(std::abs(rvgi.get_result()[18] - 0.0077) < 0.0001); assert(std::abs(rvgi.get_result()[25] - -0.0333) < 0.0001); assert(std::abs(rvgi.get_result()[1720] - -0.3375) < 0.0001); assert(std::abs(rvgi.get_result()[1712] - -0.0634) < 0.0001); assert(std::abs(rvgi.get_result()[1707] - -0.0097) < 0.0001); assert(rvgi.get_signal().size() == 1721); assert(std::isnan(rvgi.get_signal()[0])); assert(std::isnan(rvgi.get_signal()[29])); assert(std::abs(rvgi.get_signal()[30] - 0.0435) < 0.0001); assert(std::abs(rvgi.get_signal()[31] - 0.0454) < 0.0001); assert(std::abs(rvgi.get_signal()[35] - -0.0359) < 0.0001); assert(std::abs(rvgi.get_signal()[1720] - 0.0405) < 0.0001); assert(std::abs(rvgi.get_signal()[1712] - -0.1096) < 0.0001); assert(std::abs(rvgi.get_signal()[1707] - -0.0946) < 0.0001); } catch (const DataFrameError &ex) { std::cout << ex.what() << std::endl; } }