Signature | Description | Parameters |
---|---|---|
#include <DataFrame/DataFrameFinancialVisitors.h> template<typename S_RT, // Short duration rolling adopter typename L_RT, // Longer duration rolling adopter typename T, typename I = unsigned long, std::size_t A = 0> struct DoubleCrossOver; // ------------------------------------- template<typename S_RT, // Short duration rolling adopter typename L_RT, // Longer duration rolling adopter typename T, typename I = unsigned long, std::size_t A = 0> using dco_v = DoubleCrossOver<S_RT, L_RT, 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 functor class calculates the crossover of a data vector with two of its moving averages. It could be used to generate signals within financial applications. The constructor takes the two adopters: DoubleCrossOver(S_RT &&short_moving, L_RT &&long_moving)There are 3 methods that give you the results:
|
S_RT: A short term moving average adopter. For example, a simple moving adopter using a geometric mean L_RT: A longer term moving average adopter. For example, an exponential moving adopter using a simple mean T: Column data type I: Index type A: Memory alignment boundary for vectors. Default is system default alignment |
static void test_DoubleCrossOver() { std::cout << "\nTesting DoubleCrossOver{ } ..." << std::endl; MyDataFrame::set_thread_level(10); StlVecType<unsigned long> idx = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 31, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 }; StlVecType<double> d1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 19, 18, 17, 17, 16, 15, 14, 13, 14, 13, 12, 11, 12, 10, 9, 8, 7, 6, 7, 5 }; MyDataFrame df; df.load_data(std::move(idx), std::make_pair("col_1", d1)); using geo_mean_t = GeometricMeanVisitor<double>; using short_roller_t = SimpleRollAdopter<geo_mean_t, double>; using long_roller_t = ewm_v<double>; using double_cross_t = dco_v<short_roller_t, long_roller_t, double>; double_cross_t visitor(short_roller_t(geo_mean_t(), 3), long_roller_t(exponential_decay_spec::span, 1.5)); df.single_act_visit<double>("col_1", visitor); auto &raw_to_short = visitor.get_raw_to_short_term(); auto &raw_to_long = visitor.get_raw_to_long_term(); auto &short_to_long = visitor.get_short_term_to_long_term(); assert(raw_to_short.size() == 40); assert(std::isnan(raw_to_short[1])); assert(fabs(raw_to_short[8] - 1.04189) < 0.00001); assert(fabs(raw_to_short[12] - 1.02784) < 0.00001); assert(fabs(raw_to_short[39] - -0.943922) < 0.00001); assert(fabs(raw_to_short[38] - 0.3506) < 0.00001); assert(raw_to_long.size() == 40); assert(fabs(raw_to_long[2] - 0.24) < 0.001); assert(fabs(raw_to_long[8] - 0.249999) < 0.000001); assert(fabs(raw_to_long[12] - 0.25) < 0.001); assert(fabs(raw_to_long[39] - -0.370008) < 0.00001); assert(fabs(raw_to_long[38] - 0.149962) < 0.00001); assert(short_to_long.size() == 40); assert(std::isnan(short_to_long[0])); assert(std::isnan(short_to_long[1])); assert(fabs(short_to_long[8] - -0.791886) < 0.00001); assert(fabs(short_to_long[12] - -0.777842) < 0.00001); assert(fabs(short_to_long[39] - 0.573914) < 0.00001); assert(fabs(short_to_long[38] - -0.200639) < 0.00001); MyDataFrame::set_thread_level(0); }