Signature | Description | Parameters |
---|---|---|
#include <DataFrame/DataFrameFinancialVisitors.h> template<typename T, typename I = unsigned long, std::size_t A = 0> struct GarmanKlassVolVisitor; // ------------------------------------- template<typename T, typename I = unsigned long, std::size_t A = 0> using gk_vol_v = GarmanKlassVolVisitor<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 visitor calculates the rolling values of Garman Klass volatility. It requires 4 input columns in the order of low, high, open, close. The result is a vector of values with same number of items as the given columns. The first roll_count items, in the result, will be NAN. The values are annulaized by trading_periods The Garman and Klass estimator for estimating historical volatility assumes Brownian motion with zero drift and no opening jumps (i.e. the opening = close of the previous period). This estimator is 7.4 times more efficient than the close-to-close estimator. explicit GarmanKlassVolVisitor(std::size_t roll_count = 30, std::size_t trading_periods = 252); |
T: Column data type I: Index type A: Memory alignment boundary for vectors. Default is system default alignment |
static void test_GarmanKlassVolVisitor() { std::cout << "\nTesting GarmanKlassVolVisitor{ } ..." << std::endl; typedef StdDataFrame<std::string> StrDataFrame; StrDataFrame df; try { df.read("IBM.csv", io_format::csv2); GarmanKlassVolVisitor<double, std::string> gkv_v; df.single_act_visit<double, double, double, double>("IBM_Low", "IBM_High", "IBM_Open", "IBM_Close", gkv_v); assert(gkv_v.get_result().size() == 5031); assert(std::isnan(gkv_v.get_result()[0])); assert(std::isnan(gkv_v.get_result()[28])); assert(std::abs(gkv_v.get_result()[29] - 0.392054) < 0.00001); assert(std::abs(gkv_v.get_result()[34] - 0.401494) < 0.00001); assert(std::abs(gkv_v.get_result()[5030] - 0.230028) < 0.00001); assert(std::abs(gkv_v.get_result()[5026] - 0.221514) < 0.00001); assert(std::abs(gkv_v.get_result()[5021] - 0.216817) < 0.00001); } catch (const DataFrameError &ex) { std::cout << ex.what() << std::endl; } }