Signature | Description | Parameters |
---|---|---|
#include <DataFrame/DataFrameFinancialVisitors.h> template<typename T, typename I = unsigned long, std::size_t A = 0> struct RSIVisitor; // ------------------------------------- template<typename T, typename I = unsigned long, std::size_t A = 0> using rsi_v = RSIVisitor<<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. 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. A: Memory alignment boundary for vectors. Default is system default alignment |
#include <DataFrame/DataFrameFinancialVisitors.h> template<typename T, typename I = unsigned long, std::size_t A = 0> struct RSXVisitor; // ------------------------------------- template<typename T, typename I = unsigned long, std::size_t A = 0> using rsx_v = RSXVisitor<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. 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. A: Memory alignment boundary for vectors. Default is system default alignment |
#include <DataFrame/DataFrameFinancialVisitors.h> template<typename T, typename I = unsigned long, std::size_t A = 0> struct RVIVisitor; // ------------------------------------- template<typename T, typename I = unsigned long, std::size_t A = 0> using rvi_v = RVIVisitor<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. The Relative Volatility Index is the Relative Strength Index (RSI) calculated with a standard deviation over several last bars used instead of price change. The RVI can be used as a confirming indicator since it uses a measurement other than price as a means to interpret market strength. The RVI measures the direction of volatility on a scale from 0 to 100. Readings greater than 50 indicate that the volatility is more to the upside. Readings lower than 50 indicate that the direction of volatility is to the downside. The input columns to this visitor are close, high, and low. explicit RVIVisitor(std::size_t avg_period = 14); |
T: Column data type. I: Index type. A: Memory alignment boundary for vectors. Default is system default alignment |
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; } }
// ----------------------------------------------------------------------------- static void test_RVIVisitor() { std::cout << "\nTesting RVIVisitor{ } ..." << std::endl; StrDataFrame df; try { df.read("data/SHORT_IBM.csv", io_format::csv2); RVIVisitor<double, std::string> rvi; // Here we use exponentially weighted mean and also adjust for // finite series // df.single_act_visit<double, double, double>("IBM_Close", "IBM_High", "IBM_Low", rvi); assert(rvi.get_result().size() == 1721); assert(std::isnan(rvi.get_result()[0])); assert(std::isnan(rvi.get_result()[12])); assert(rvi.get_result()[13] == 0); assert(std::abs(rvi.get_result()[14] - 100.0) < 0.0001); assert(std::abs(rvi.get_result()[15] - 41.8105) < 0.0001); assert(std::abs(rvi.get_result()[18] - 20.4976) < 0.0001); assert(std::abs(rvi.get_result()[25] - 42.6008) < 0.0001); assert(std::abs(rvi.get_result()[1720] - 43.5703) < 0.0001); assert(std::abs(rvi.get_result()[1712] - 38.7802) < 0.0001); assert(std::abs(rvi.get_result()[1707] - 32.3759) < 0.0001); } catch (const DataFrameError &ex) { std::cout << ex.what() << std::endl; } }