Signature | Description | Parameters |
---|---|---|
#include <DataFrame/DataFrameFinancialVisitors.h> template<typename T, typename I = unsigned long> struct YangZhangVolVisitor; |
This visitor calculates the rolling values of Yang Zhang 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 Yang Zhang is a historical volatility estimator that handles both opening jumps and the drift and has a minimum estimation error. We can think of the Yang-Zhang volatility as the combination of the overnight (close-to-open volatility) and a weighted average of the Rogers-Satchell volatility and the day’s open-to-close volatility. It is considered to be 14 times more efficient than the close-to-close estimator. explicit YangZhangVolVisitor(size_type roll_count = 30, size_type trading_periods = 252); |
T: Column data type I: Index type |
static void test_YangZhangVolVisitor() { std::cout << "\nTesting YangZhangVolVisitor{ } ..." << std::endl; typedef StdDataFrame<std::string> StrDataFrame; StrDataFrame df; try { df.read("FORD.csv", io_format::csv2); YangZhangVolVisitor<double, std::string> yz_v; df.single_act_visit<double, double, double, double>("FORD_Low", "FORD_High", "FORD_Open", "FORD_Close", yz_v); assert(yz_v.get_result().size() == 12265); assert(std::isnan(yz_v.get_result()[0])); assert(std::isnan(yz_v.get_result()[29])); assert(std::abs(yz_v.get_result()[30] - 0.169461) < 0.00001); assert(std::abs(yz_v.get_result()[35] - 0.181149) < 0.00001); assert(std::abs(yz_v.get_result()[12264] - 0.292034) < 0.00001); assert(std::abs(yz_v.get_result()[12260] - 0.279347) < 0.00001); assert(std::abs(yz_v.get_result()[12255] - 0.293528) < 0.00001); } catch (const DataFrameError &ex) { std::cout << ex.what() << std::endl; } }