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

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

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

template<typename T, typename I = unsigned long>
using hexpo_v = HurstExponentVisitor<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 functor calculates the Hurst exponent for the given column.
A hurst exponent, H, between 0 to 0.5 is said to correspond to a mean reverting process (anti-persistent), H=0.5 corresponds to Geometric Brownian Motion (Random Walk), while H >= 0.5 corresponds to a process which is trending (persistent).

    explicit
    HurstExponentVisitor(std::vector<size_t> &&ranges)
        
ranges: A vector of column length divisors. For example, {1, 2, 4 } means calculate Hurst exponent in 3 steps. It divides the time-series column to 1 chunk, 2 chunks and 4 chunks.
T: Column data type.
I: Index type.
static void test_HurstExponentVisitor()  {

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

    RandGenParams<double>   p;

    p.seed = 123;
    p.min_value = 0;
    p.max_value = 30;

    std::vector<double> d1 = gen_uniform_real_dist<double>(1024, p);
    std::vector<double> d2 = { 0.04, 0.02, 0.05, 0.08, 0.02, -0.17, 0.05, 0.0 };
    std::vector<double> d3 = { 0.04, 0.05, 0.055, 0.06, 0.061, 0.072, 0.073, 0.8 };

    MyDataFrame df;

    df.load_index(std::move(MyDataFrame::gen_sequence_index(0, 1024, 1)));
    df.load_column("d1_col", std::move(d1), nan_policy::dont_pad_with_nans);
    df.load_column("d2_col", std::move(d2), nan_policy::dont_pad_with_nans);
    df.load_column("d3_col", std::move(d3), nan_policy::dont_pad_with_nans);

    HurstExponentVisitor<double>    he_v1 ({ 1, 2, 4 });
    auto                            result1 = df.single_act_visit<double>("d2_col", he_v1).get_result();

    assert(result1 - 0.865926 < 0.00001);

    HurstExponentVisitor<double>    he_v2 ({ 1, 2, 4, 5, 6, 7 });
    auto                            result2 = df.single_act_visit<double>("d1_col", he_v2).get_result();

    assert(result2 - 0.487977 < 0.00001);

    HurstExponentVisitor<double>    he_v3 ({ 1, 2, 4 });
    auto                            result3 = df.single_act_visit<double>("d3_col", he_v3).get_result();

    assert(result3 - 0.903057 < 0.00001);
}