Signature | Description | Parameters |
---|---|---|
#include <DataFrame/DataFrameFinancialVisitors.h> template<typename T, typename I = unsigned long, std::size_t A = 0> struct OnBalanceVolumeVisitor; // ------------------------------------- template<typename T, typename I = unsigned long, std::size_t A = 0> using obv_v = OnBalanceVolumeVisitor<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 On Balance Volume (OBV) indicator. It requires 2 input columns in order of price, volume. The result is a vector of values with same number of items as the given column. On-balance volume (OBV) is a technical trading momentum indicator that uses volume flow to predict changes in stock price. Joseph Granville first developed the OBV metric in the 1963 book Granville's New Key to Stock Market Profits. Granville believed that volume was the key force behind markets and designed OBV to project when major moves in the markets would occur based on volume changes. In his book, he described the predictions generated by OBV as "a spring being wound tightly." He believed that when volume increases sharply without a significant change in the stock's price, the price will eventually jump upward or fall downward. |
T: Column data type I: Index type A: Memory alignment boundary for vectors. Default is system default alignment |
static void test_OnBalanceVolumeVisitor() { std::cout << "\nTesting OnBalanceVolumeVisitor{ } ..." << std::endl; typedef StdDataFrame<std::string> StrDataFrame; StrDataFrame df; try { df.read("data/SHORT_IBM.csv", io_format::csv2); obv_v<double, std::string> obv; std::future<obv_v<double, std::string> &> fut = df.single_act_visit_async<double, long>("IBM_Close", "IBM_Volume", obv); fut.get(); assert(obv.get_result().size() == 1721); assert(std::abs(obv.get_result()[0] - 4546500) < 0.001); assert(std::abs(obv.get_result()[19] - -21855500) < 0.001); assert(std::abs(obv.get_result()[20] - -27048900) < 0.001); assert(std::abs(obv.get_result()[24] - -29581000) < 0.001); assert(std::abs(obv.get_result()[25] - -24888100) < 0.001); assert(std::abs(obv.get_result()[1720] - -18817000) < 0.001); assert(std::abs(obv.get_result()[1712] - -12925800) < 0.001); assert(std::abs(obv.get_result()[1707] - 10998800) < 0.001); } catch (const DataFrameError &ex) { std::cout << ex.what() << std::endl; } }