Signature Description Parameters
#include <DataFrame/DataFrameFinancialVisitors.h>

template<typename T, typename I = unsigned long>
struct VarIdxDynAvgVisitor;

// -------------------------------------

template<typename T, typename I = unsigned long>
using vidya_v = VarIdxDynAvgVisitor<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 Variable Index Dynamic Average (VIDYA) indicator.
The result is a vector of values with same number of items as the given column. The first roll_period items in the result are NaN.

Variable Index Dynamic Average Technical Indicator (VIDYA) was developed by Tushar Chande. It is an original method of calculating the Exponential Moving Average (EMA) with the dynamically changing period of averaging. Period of averaging depends on the market volatility; as the measure of volatility Chande Momentum Oscillator (CMO) was chosen. This oscillator measures the ratio between the sum of positive increments and sum of negative increments for a certain period (CMO period). CMO value is used as the ratio to the smoothing factor EMA. Thus VIDYA has to setup parameters: period of CMO and period of EMA.

    explicit
    VarIdxDynAvgVisitor(size_type roll_period = 14);
        
T: Column data type
I: Index type
static void test_VarIdxDynAvgVisitor()  {

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

    typedef StdDataFrame<std::string> StrDataFrame;

    StrDataFrame    df;

    try  {
        df.read("data/SHORT_IBM.csv", io_format::csv2);

        VarIdxDynAvgVisitor<double, std::string>    vidya_v;

        df.single_act_visit<double>("IBM_Close", vidya_v);

        assert(vidya_v.get_result().size() == 1721);

        assert(std::isnan(vidya_v.get_result()[0]));
        assert(std::isnan(vidya_v.get_result()[12]));
        assert(vidya_v.get_result()[13] == 0);
        assert(std::abs(vidya_v.get_result()[14] - 2.70068) < 0.00001);
        assert(std::abs(vidya_v.get_result()[21] - 57.6682) < 0.0001);
        assert(std::abs(vidya_v.get_result()[31] - 106.451) < 0.001);
        assert(std::abs(vidya_v.get_result()[1720] - 118.962) < 0.001);
        assert(std::abs(vidya_v.get_result()[1712] - 123.811) < 0.001);
        assert(std::abs(vidya_v.get_result()[1707] - 123.712) < 0.001);
    }
    catch (const DataFrameError &ex)  {
        std::cout << ex.what() << std::endl;
    }
}