Signature | Description | Parameters |
---|---|---|
#include <DataFrame/DataFrameFinancialVisitors.h> template<typename T, typename I = unsigned long> struct HodgesTompkinsVolVisitor; // ------------------------------------- template<typename T, typename I = unsigned long> using ht_vol_v = HodgesTompkinsVolVisitor<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. This visitor calculates the rolling values of Hodges-Tompkins volatility. It requires 1 input columns. The result is a vector of values with same number of items as the given columns. The first "roll_count - 1" items, in the result, will be NAN. The values are annulaized by trading_periods Hodges Tompkins volatility estimator is basically the close to close volatility adjusted for sampling bias. explicit HodgesTompkinsVolVisitor(std::size_t roll_count = 30, std::size_t trading_periods = 252); |
T: Column data type I: Index type |
static void test_HodgesTompkinsVolVisitor() { std::cout << "\nTesting HodgesTompkinsVolVisitor{ } ..." << std::endl; typedef StdDataFrame<std::string> StrDataFrame; StrDataFrame df; try { df.read("data/SHORT_IBM.csv", io_format::csv2); ht_vol_v<double, std::string> ht; df.single_act_visit<double>("IBM_Close", ht); assert(ht.get_result().size() == 1721); assert(std::isnan(ht.get_result()[0])); assert(std::isnan(ht.get_result()[28])); assert(std::abs(ht.get_result()[29] - 0.187655) < 0.0001); assert(std::abs(ht.get_result()[30] - 0.187132) < 0.0001); assert(std::abs(ht.get_result()[31] - 0.186253) < 0.0001); assert(std::abs(ht.get_result()[35] - 0.177077) < 0.0001); assert(std::abs(ht.get_result()[1720] - 0.365188) < 0.0001); assert(std::abs(ht.get_result()[1712] - 0.326883) < 0.0001); assert(std::abs(ht.get_result()[1707] - 0.298478) < 0.0001); } catch (const DataFrameError &ex) { std::cout << ex.what() << std::endl; } }