Signature | Description | Parameters |
---|---|---|
#include <DataFrame/DataFrameFinancialVisitors.h> template<typename T, typename I = unsigned long> struct ParkinsonVolVisitor; // ------------------------------------- template<typename T, typename I = unsigned long> using p_vol_v = ParkinsonVolVisitor<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 Parkinson volatility. It requires 2 input columns in the order of low, high. 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 Parkinson volatility is a volatility measure that uses the stock’s high and low price of the day. The main difference between regular volatility and Parkinson volatility is that the latter uses high and low prices for a day, rather than only the closing price. That is useful as close to close prices could show little difference while large price movements could have happened during the day. Thus Parkinson's volatility is considered to be more precise and requires less data for calculation than the close-close volatility. One drawback of this estimator is that it doesn't take into account price movements after market close. Hence it systematically undervalues volatility. That drawback is taken into account in the Garman-Klass's volatility estimator. explicit ParkinsonVolVisitor(std::size_t roll_count = 30, std::size_t trading_periods = 252); |
T: Column data type I: Index type |
static void test_ParkinsonVolVisitor() { std::cout << "\nTesting ParkinsonVolVisitor{ } ..." << std::endl; typedef StdDataFrame<std::string> StrDataFrame; StrDataFrame df; try { df.read("data/SHORT_IBM.csv", io_format::csv2); p_vol_v<double, std::string> pv; df.single_act_visit<double, double>("IBM_Low", "IBM_High", pv); assert(pv.get_result().size() == 1721); assert(std::isnan(pv.get_result()[0])); assert(std::isnan(pv.get_result()[28])); assert(std::abs(pv.get_result()[29] - 0.143397) < 0.00001); assert(std::abs(pv.get_result()[30] - 0.145651) < 0.00001); assert(std::abs(pv.get_result()[31] - 0.145266) < 0.00001); assert(std::abs(pv.get_result()[35] - 0.144596) < 0.00001); assert(std::abs(pv.get_result()[1720] - 0.225651) < 0.00001); assert(std::abs(pv.get_result()[1712] - 0.208081) < 0.00001); assert(std::abs(pv.get_result()[1707] - 0.236226) < 0.00001); } catch (const DataFrameError &ex) { std::cout << ex.what() << std::endl; } }