Signature | Description |
---|---|
enum class linreg_moving_mean_type : unsigned char { linreg = 1, forecast = 2, // Also called Correlation Trend Indicator slope = 3, intercept = 4, theta = 5, // arc-tan of slope degree = 6, // degree of slope }; |
This specifies what values to return when calculating Linear Regression moving average |
Signature | Description | Parameters |
---|---|---|
#include <DataFrame/DataFrameStatsVisitors.h> template<typename T, typename I = unsigned long, std::size_t A = 0> struct LinregMovingMeanVisitor; // ------------------------------------- template<typename T, typename I = unsigned long, std::size_t A = 0> using linregmm_v = LinregMovingMeanVisitor<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 calculates rolling means using linear regression. This is a simplified version of a Standard Linear Regression of one variable. A Standard Linear Regression is between two or more variables. explicit LinregMovingMeanVisitor(size_t roll_period = 14, linreg_moving_mean_type ltype = linreg_moving_mean_type::linreg); |
T: Column data type I: Index type A: Memory alignment boundary for vectors. Default is system default alignment |
static void test_LinregMovingMeanVisitor() { std::cout << "\nTesting LinregMovingMeanVisitor{ } ..." << std::endl; StrDataFrame df; try { df.read("data/SHORT_IBM.csv", io_format::csv2); linregmm_v<double, std::string> linreg; df.single_act_visit<double>("IBM_Close", linreg); assert(linreg.get_result().size() == 1721); assert(std::isnan(linreg.get_result()[0])); assert(std::isnan(linreg.get_result()[13])); assert(std::abs(linreg.get_result()[14] - 186.9714) < 0.0001); assert(std::abs(linreg.get_result()[15] - 185.8377) < 0.0001); assert(std::abs(linreg.get_result()[16] - 184.1874) < 0.0001); assert(std::abs(linreg.get_result()[18] - 180.6528) < 0.0001); assert(std::abs(linreg.get_result()[25] - 172.4149) < 0.0001); assert(std::abs(linreg.get_result()[1720] - 109.3095) < 0.0001); assert(std::abs(linreg.get_result()[1712] - 126.9701) < 0.0001); assert(std::abs(linreg.get_result()[1707] - 126.8379) < 0.0001); } catch (const DataFrameError &ex) { std::cout << ex.what() << std::endl; } }