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 VWBASVisitor;
        
This functor class calculates VWBAS (Volume Weighted Bid-Ask Spread) – and more - between the four column values. The first column is the index (assumed to represent time). The second column is assumed to be bid price. The third column is assumed to be ask price. The fourth column is assumed to be bid size. The fifth column is assumed to be ask size.
The constructor takes:
  • The interval value for the bucket. VWBAS is calculated for buckets of interval time. 0 means everything is in one bucket.
  • Max Volume: Excludes trades whose size is equal or greater than Max Volume. 0 means include everything.
  • A function to calculates the difference between two index values. The default is a simple subtraction.
  VWBASVisitor(double interval,
               double max_volume = 0,
               distance_func f =
                   [](const I &idx1, const I &idx2) -> double {
                       return (static_cast(idx2 - idx1));
                   })
        
The result is a vector of following structs:
  struct  VWBAS  {
      value_type    spread;
      value_type    percent_spread; // with respect to bid side
      value_type    vwbas;
      value_type    percent_vwbas; // with respect to bid side
      index_type    index_value;
      size_type     event_count;
      value_type    total_ask_volume;
      value_type    total_bid_volume;
      value_type    high_ask_price;
      value_type    low_ask_price;
      value_type    high_bid_price;
      value_type    low_bid_price;
      value_type    cumulative_vwbas;
      size_type     cumulative_event_count;
      value_type    cumulative_total_ask_volume;
      value_type    cumulative_total_bid_volume;
      value_type    cumulative_high_ask_price;
      value_type    comulative_low_ask_price;
      value_type    cumulative_high_bid_price;
      value_type    comulative_low_bid_price;
  }
T: Column data type.
I: Index type.
static void test_VWBAS()  {

    std::cout << "\nTesting VWBASVisitor{ } ..." << std::endl;

    RandGenParams<double>   bprice_p;

    bprice_p.mean = 1.0;
    bprice_p.std = 0.005;
    bprice_p.seed = 10;
    bprice_p.min_value = 100.0;
    bprice_p.max_value = 102.0;

    RandGenParams<double>   aprice_p = bprice_p;

    aprice_p.seed = 200;
    aprice_p.min_value = 102.0;
    aprice_p.max_value = 104.0;

    RandGenParams<double>   asize_p = bprice_p;

    asize_p.std = 1;
    asize_p.seed = 500;
    asize_p.min_value = 50.0;
    asize_p.max_value = 2000.0;

    RandGenParams<double>   bsize_p = asize_p;

    asize_p.std = 1;
    asize_p.seed = 123456;
    asize_p.min_value = 50.0;
    asize_p.max_value = 2000.0;
    MyDataFrame df;

    df.load_data(
        MyDataFrame::gen_sequence_index(100, 1124, 1),
        std::make_pair("bid_price", gen_uniform_real_dist<double>(1024, bprice_p)),
        std::make_pair("ask_price", gen_uniform_real_dist<double>(1024, aprice_p)),
        std::make_pair("bid_size", gen_uniform_real_dist<double>(1024, bsize_p)),
        std::make_pair("ask_size", gen_uniform_real_dist<double>(1024, asize_p)));

    VWBASVisitor<double>    v1(100);
    const MyDataFrame       const_df = df;
    auto                    fut =
        const_df.visit_async<double, double, double, double>("bid_price", "ask_price", "bid_size", "ask_size", v1);
    auto                    result = fut.get().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].cumulative_event_count == 200);
    assert(result[1].index_value == 200);
    assert(result[10].event_count == 24);
    assert(result[10].index_value == 1100);

    assert(fabs(result[0].spread - 2.11835) < 0.00001);
    assert(fabs(result[0].percent_spread - 2.0998) < 0.0001);
    assert(fabs(result[0].vwbas - 2.15156) < 0.00001);
    assert(fabs(result[0].percent_vwbas - 2.13298) < 0.00001);
    assert(fabs(result[0].high_bid_price - 101.966) < 0.001);
    assert(fabs(result[0].low_ask_price - 102.012) < 0.001);
    assert(fabs(result[0].cumulative_vwbas - 2.15156) < 0.00001);

    assert(fabs(result[5].spread - 1.92471) < 0.00001);
    assert(fabs(result[5].percent_spread - 1.90509) < 0.0001);
    assert(fabs(result[5].vwbas - 1.9199) < 0.0001);
    assert(fabs(result[5].percent_vwbas - 1.90052) < 0.00001);
    assert(fabs(result[5].high_bid_price - 101.987) < 0.001);
    assert(fabs(result[5].low_ask_price - 102.04) < 0.01);
    assert(fabs(result[5].cumulative_vwbas - 2.07029) < 0.00001);

    assert(fabs(result[10].spread - 1.98223) < 0.00001);
    assert(fabs(result[10].percent_spread - 1.96279) < 0.0001);
    assert(fabs(result[10].vwbas - 2.05129) < 0.0001);
    assert(fabs(result[10].percent_vwbas - 2.03336) < 0.00001);
    assert(fabs(result[10].high_bid_price - 101.997) < 0.001);
    assert(fabs(result[10].low_ask_price - 102.12) < 0.01);
    assert(fabs(result[10].cumulative_vwbas - 2.02198) < 0.00001);
}