Signature | Description | Parameters |
---|---|---|
#include <DataFrame/DataFrameFinancialVisitors.h> template<typename T, typename I = unsigned long, std::size_t A = 0> struct PriceDistanceVisitor; // ------------------------------------- template<typename T, typename I = unsigned long, std::size_t A = 0> using pdist_v = PriceDistanceVisitor<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 Price Distance 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 item in the result will be NAN. It Evaluates the “distance” covered by price movements overnight and during the day |
T: Column data type I: Index type A: Memory alignment boundary for vectors. Default is system default alignment |
static void test_PriceDistanceVisitor() { std::cout << "\nTesting PriceDistanceVisitor{ } ..." << std::endl; StrDataFrame df; try { df.read("data/SHORT_IBM.csv", io_format::csv2); pdist_v<double, std::string> pdist; df.single_act_visit<double, double, double, double>("IBM_Low", "IBM_High", "IBM_Open", "IBM_Close", pdist); assert(pdist.get_result().size() == 1721); assert(std::isnan(pdist.get_result()[0])); assert(std::abs(pdist.get_result()[13] - 13.84) < 0.0001); assert(std::abs(pdist.get_result()[14] - 5.54) < 0.0001); assert(std::abs(pdist.get_result()[18] - 5.73) < 0.0001); assert(std::abs(pdist.get_result()[25] - 4.34) < 0.0001); assert(std::abs(pdist.get_result()[1720] - 5.35) < 0.0001); assert(std::abs(pdist.get_result()[1712] - 9.91) < 0.0001); assert(std::abs(pdist.get_result()[1707] - 4.55) < 0.0001); } catch (const DataFrameError &ex) { std::cout << ex.what() << std::endl; } }