Signature | Description | Parameters |
---|---|---|
#include <DataFrame/DataFrameFinancialVisitors.h> template<typename T, typename I = unsigned long, typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type> struct VWAPVisitor; |
This functor class calculates VWAP – and more - between the two column values. The first column is the index (assumed to represent time). The second column is assumed to be trade price. The third column is assumed to be trade size The constructor takes:
VWAPVisitor(double interval, double max_volume = 0, double total_volume_limit = 0, distance_func f = [](const I &idx1, const I &idx2) -> double { return (static_castThe result is a vector of following structs: struct VWAP { value_type vwap; index_type index_value; size_type event_count; value_type total_volume; value_type high_price; value_type low_price; value_type cumulative_vwap; size_type cumulative_event_count; value_type cumulative_total_volume; value_type cumulative_high_price; value_type comulative_low_price; } |
T: Column data type. I: Index type. |
static void test_VWAP() { std::cout << "\nTesting VWAPVisitor{ } ..." << std::endl; RandGenParams<double> price_p; price_p.mean = 1.0; price_p.std = 0.005; price_p.seed = 10; price_p.min_value = 500.0; price_p.max_value = 580.0; RandGenParams<double> size_p = price_p; size_p.std = 1; size_p.min_value = 50.0; size_p.max_value = 2000.0; MyDataFrame df; df.load_data( MyDataFrame::gen_sequence_index(100, 1124, 1), std::make_pair("price", gen_uniform_real_dist<double>(1024, price_p)), std::make_pair("size", gen_uniform_real_dist<double>(1024, size_p))); VWAPVisitor<double> v1(100); auto result = df.visit<double, double>("price", "size", v1).get_result(); assert(result.size() == 11); assert(result[0].event_count == 100); assert(result[0].index_value == 100); assert(result[1].event_count == 100); assert(result[1].index_value == 200); assert(result[10].event_count == 24); assert(result[10].index_value == 1100); assert(fabs(result[0].vwap - 548.091) < 0.001); assert(fabs(result[0].average_price - 535.331) < 0.001); assert(fabs(result[0].cumulative_vwap - 548.091) < 0.001); assert(fabs(result[4].vwap - 551.923) < 0.001); assert(fabs(result[4].average_price - 537.798) < 0.001); assert(fabs(result[4].cumulative_vwap - 550.347) < 0.001); assert(fabs(result[10].vwap - 553.196) < 0.001); assert(fabs(result[10].average_price - 539.629) < 0.001); assert(fabs(result[10].cumulative_vwap - 552.067) < 0.001); }