Signature | Description | Parameters |
---|---|---|
#include <DataFrame/DataFrameFinancialVisitors.h> template<typename T, typename I = unsigned long, std::size_t A = 0> struct PrettyGoodOsciVisitor; // ------------------------------------- template<typename T, typename I = unsigned long, std::size_t A = 0> using pgo_v = PrettyGoodOsciVisitor<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 so-called pretty good oscillator. It requires 3 input columns in the order of low, high, close. The result is a vector of values with same number of items as the given columns. The first rolling periods - 1 items in the result will be NaN The “Pretty Good Oscillator” (PGO) by Mark Johnson measures the distance of the current close from its simple moving average of period average, expressed in terms of an average true range (see Average True Range) over a similar period. For instance, a PGO value of +2.5 would mean the current close is 2.5 average days’ range above the SMA. Johnson’s approach was to use it as a breakout system for longer-term trades. If the PGO rises above 3.0, then go long, or below -3.0, then go short, and in both cases exit on returning to zero (which is a close back at the SMA). The Pretty Good Oscillator is an Oscillator indicator, and it measures the distance between the present close and its N-day simple moving average. It is also possible to catch divergences with the Pretty Good Oscillator, and they occur when the indicator and price do not move in the same direction. explicit PrettyGoodOsciVisitor (size_t roll_period = 14); |
T: Column data type I: Index type A: Memory alignment boundary for vectors. Default is system default alignment |
static void test_PrettyGoodOsciVisitor() { std::cout << "\nTesting PrettyGoodOsciVisitor{ } ..." << std::endl; typedef StdDataFrame<std::string> StrDataFrame; StrDataFrame df; try { df.read("data/SHORT_IBM.csv", io_format::csv2); pgo_v<double, std::string> pgo; df.single_act_visit<double, double, double>("IBM_Low", "IBM_High", "IBM_Close", pgo); assert(pgo.get_result().size() == 1721); assert(std::isnan(pgo.get_result()[0])); assert(std::isnan(pgo.get_result()[12])); assert(std::abs(pgo.get_result()[14] - -1.3523) < 0.0001); assert(std::abs(pgo.get_result()[20] - -1.8941) < 0.0001); assert(std::abs(pgo.get_result()[25] - -0.2143) < 0.0001); assert(std::abs(pgo.get_result()[35] - 1.3048) < 0.0001); assert(std::abs(pgo.get_result()[1720] - -1.7059) < 0.0001); assert(std::abs(pgo.get_result()[1712] - -2.2014) < 0.0001); assert(std::abs(pgo.get_result()[1707] - 0.652) < 0.0001); } catch (const DataFrameError &ex) { std::cout << ex.what() << std::endl; } }