Signature | Description | Parameters |
---|---|---|
#include <DataFrame/DataFrameStatsVisitors.h> template<typename T, typename I = unsigned long> struct RSIVisitor; // ------------------------------------- template<typename T, typename I = unsigned long> using rsi_v = RSIVisitor<<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. Relative Strength Index (RSI) is a technical indicator used in the analysis of financial markets. It is intended to chart the current and historical strength or weakness of a stock or market based on the closing prices of a recent trading period. The indicator should not be confused with relative strength. The RSI is classified as a momentum oscillator, measuring the velocity and magnitude of price movements. The RSI is most typically used on a 14-day (a parameter in this visitor) time frame, measured on a scale from 0 to 100. Traditional interpretation and usage of the RSI are that values of 70 or above indicate that a security is becoming overbought or overvalued and may be primed for a trend reversal or corrective pullback in price. An RSI reading of 30 or below indicates an oversold or undervalued condition. NOTE: The input (column) to this visitor is assumed to be instrument prices. NOTE: The length of the result vector is length of column - avg_period. explicit RSIVisitor(return_policy rp, std::size_t avg_period = 14); |
T: Column data type. I: Index type. |
#include <DataFrame/DataFrameStatsVisitors.h> template<typename T, typename I = unsigned long> struct RSXVisitor; // ------------------------------------- template<typename T, typename I = unsigned long> using rsx_v = RSXVisitor<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. RSI is a popular indicator, yet it can be very noisy, inducing false signals and triggers. RSX is superior, providing an ultra smooth, low lag trend strength indicator. The code implemented is based on published code found at 'prorealcode.com'. explicit RSXVisitor(std::size_t avg_period = 14); |
T: Column data type. I: Index type. |
static void test_RSIVisitor() { std::cout << "\nTesting RSIVisitor{ } ..." << std::endl; const size_t item_cnt = 32; MyDataFrame df; RandGenParams<double> p; p.mean = 5.6; p.std = 0.5; p.seed = 123; p.min_value = 0; p.max_value = 8; df.load_data(MyDataFrame::gen_sequence_index(0, item_cnt, 1), std::make_pair("normal", gen_normal_dist<double>(item_cnt, p))); RSIVisitor<double> rsi(return_policy::percentage); const auto rsi_result = df.single_act_visit<double>("normal", rsi).get_result(); std::vector<double> result { 61.7415, 60.4834, 61.9366, 59.6913, 57.6219, 60.7955, 59.3452, 59.975, 58.261, 52.4888, 54.3424, 55.912, 54.6126, 54.3072, 52.3504, 56.7229, 52.4376, 51.8158 }; for (size_t idx = 0; idx < result.size(); ++idx) assert(fabs(result[idx] - rsi_result[idx]) < 0.0001); }
// ----------------------------------------------------------------------------- static void test_RSXVisitor() { std::cout << "\nTesting RSXVisitor{ } ..." << std::endl; typedef StdDataFrame<std::string> StrDataFrame; StrDataFrame df; try { df.read("data/IBM.csv", io_format::csv2); RSXVisitor<double, std::string> rsx_v; df.single_act_visit<double>("IBM_Close", rsx_v); assert(rsx_v.get_result().size() == 5031); assert(std::isnan(rsx_v.get_result()[0])); assert(std::isnan(rsx_v.get_result()[12])); assert(rsx_v.get_result()[13] == 0); assert(rsx_v.get_result()[14] == 50.0); assert(rsx_v.get_result()[26] == 50.0); assert(std::abs(rsx_v.get_result()[29] - 44.2103) < 0.0001); assert(std::abs(rsx_v.get_result()[34] - 37.4583) < 0.0001); assert(std::abs(rsx_v.get_result()[5030] - 21.0277) < 0.0001); assert(std::abs(rsx_v.get_result()[5026] - 31.1071) < 0.0001); } catch (const DataFrameError &ex) { std::cout << ex.what() << std::endl; } }