Signature | Description | Parameters |
---|---|---|
#include <DataFrame/DataFrameFinancialVisitors.h> template<typename T, typename I = unsigned long, std::size_t A = 0> struct DetrendPriceOsciVisitor; // ------------------------------------- template<typename T, typename I = unsigned long, std::size_t A = 0> using dpo_v = DetrendPriceOsciVisitor<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 Detrend Price Oscillator. A detrended price oscillator, used in technical analysis, strips out price trends in an effort to estimate the length of price cycles from peak to peak or trough to trough. Unlike other oscillators, such as the stochastic or moving average convergence divergence (MACD), the DPO is not a momentum indicator. It instead highlights peaks and troughs in price, which are used to estimate buy and sell points in line with the historical cycle. The detrended price oscillator seeks to help a trader identify an asset's price cycle. It does this by comparing an SMA to a historical price that is near the middle of the look-back period. By looking at historical peaks and troughs on the indicator, which aligned with peaks and troughs in price, traders will typically draw vertical lines at these junctures and then count how much time elapsed between them. explicit DetrendPriceOsciVisitor(size_t roll_period = 20); |
T: Column data type I: Index type A: Memory alignment boundary for vectors. Default is system default alignment |
static void test_DetrendPriceOsciVisitor() { std::cout << "\nTesting DetrendPriceOsciVisitor{ } ..." << std::endl; StrDataFrame df; try { df.read("data/SHORT_IBM.csv", io_format::csv2); dpo_v<double, std::string> dpo; df.single_act_visit<double>("IBM_Close", dpo); assert(dpo.get_result().size() == 1721); assert(std::isnan(dpo.get_result()[0])); assert(std::isnan(dpo.get_result()[29])); assert(std::abs(dpo.get_result()[30] - -0.746) < 0.0001); assert(std::abs(dpo.get_result()[35] - 2.24) < 0.0001); assert(std::abs(dpo.get_result()[38] - 5.2955) < 0.0001); assert(std::abs(dpo.get_result()[45] - 7.763546) < 0.0001); assert(std::abs(dpo.get_result()[1720] - -11.133) < 0.0001); assert(std::abs(dpo.get_result()[1712] - -3.958) < 0.0001); assert(std::abs(dpo.get_result()[1707] - 3.004) < 0.0001); } catch (const DataFrameError &ex) { std::cout << ex.what() << std::endl; } }