Signature | Description | Parameters |
---|---|---|
#include <DataFrame/DataFrameFinancialVisitors.h> template<typename T, typename I = unsigned long> struct BalanceOfPowerVisitor; // ------------------------------------- template<typename T, typename I = unsigned long> using bop_v = BalanceOfPowerVisitor<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 balance of power 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 - 1 items, in the result will be NAN, if rolling_avg is true. Balance of Power (BOP) is a price-based indicator used by technical analysts to evaluate the overall strength of buyers and sellers in the market. BOP oscillates around zero line, where positive values indicate Bull market dominance and negative values indicate Bear market dominance. On its own, BOP is not a particularly smooth indicator, and is therefore best paired with an indicator that can counter this by providing essential smoothness. By pairing the BOP with the Simple Moving Average, for example, the result is a smooth, proper analysis for viewing. explicit BalanceOfPowerVisitor(bool rolling_avg = false, size_t rolling_period = 14); rolling_avg: Apply rolling average to the result vector rolling_period: Rolling average period |
T: Column data type I: Index type |
static void test_BalanceOfPowerVisitor() { std::cout << "\nTesting BalanceOfPowerVisitor{ } ..." << std::endl; typedef StdDataFrame<std::string> StrDataFrame; StrDataFrame df; try { df.read("data/SHORT_IBM.csv", io_format::csv2); bop_v<double, std::string> bop; df.single_act_visit<double, double, double, double>("IBM_Low", "IBM_High", "IBM_Open", "IBM_Close", bop); assert(bop.get_result().size() == 1721); assert(std::abs(bop.get_result()[0] - -0.7636) < 0.0001); assert(std::abs(bop.get_result()[14] - 0.4319) < 0.0001); assert(std::abs(bop.get_result()[18] - 0.1591) < 0.0001); assert(std::abs(bop.get_result()[25] - 0.6466) < 0.0001); assert(std::abs(bop.get_result()[1720] - 0.9284) < 0.0001); assert(std::abs(bop.get_result()[1712] - -0.7341) < 0.0001); assert(std::abs(bop.get_result()[1707] - -0.5465) < 0.0001); bop_v<double, std::string> bop2 (true); df.single_act_visit<double, double, double, double>("IBM_Low", "IBM_High", "IBM_Open", "IBM_Close", bop2); assert(bop2.get_result().size() == 1721); assert(std::isnan(bop2.get_result()[0])); assert(std::isnan(bop2.get_result()[12])); assert(std::abs(bop2.get_result()[13] - -0.0328) < 0.0001); assert(std::abs(bop2.get_result()[18] - -0.0743) < 0.0001); assert(std::abs(bop2.get_result()[25] - -0.0421) < 0.0001); assert(std::abs(bop2.get_result()[1720] - -0.1183) < 0.0001); assert(std::abs(bop2.get_result()[1712] - -0.0729) < 0.0001); assert(std::abs(bop2.get_result()[1707] - -0.0102) < 0.0001); } catch (const DataFrameError &ex) { std::cout << ex.what() << std::endl; } }