Back to Documentations

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

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

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

template<typename T, typename I = unsigned long>
using ehpf_v = EhlersHighPassFilterVisitor<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 is a transformer visitor. It means the column(s) passed to this visitor is not read-only and its values will change

This functor class applies Ehlers' high-pass smoothing filter to the input. Ehlers suggested a way to improve trend identification using high-pass filters. The basic smoothers like SMA , low-pass filters, have considerable lag in their display. Mr. Ehlers applied the high-pass filter and subtracted the high-pass filter output from the time series input. Doing these steps he removed high-frequency short-wavelength components (the ones causing the wiggles) from the time series.

    explicit
    EhlersHighPassFilterVisitor(value_type period = 20);
        
T: Column data type.
I: Index type.
#include <DataFrame/DataFrameTransformVisitors.h>

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

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

template<typename T, typename I = unsigned long>
using ebpf_v = EhlersBandPassFilterVisitor<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 is a transformer visitor. It means the column(s) passed to this visitor is not read-only and its values will change

This functor class applies Ehlers' band-pass smoothing filter to the input. The band-pass indicator is an oscillator-type indicator. It makes full use of the digital computational power of your computer and therefore is superior to conventional oscillators such as the relative strength index (RSI) or the stochastic indicator when the market is in a cycle mode. If you were to stop and think about what an oscillator does, you would conclude that it performs two functions: it detrends the price, and it does some smoothing.

    explicit
    EhlersBandPassFilterVisitor(value_type period = 20,
                                value_type bandwidth = 0.3);
        
T: Column data type.
I: Index type.
static void test_EhlersHighPassFilterVisitor()  {

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

    typedef StdDataFrame64<std::string> StrDataFrame;

    StrDataFrame    df;

    try  {
        df.read("SHORT_IBM.csv", io_format::csv2);
        df.load_column<double>("Smooth Close",
                               { df.get_column<double>("IBM_Close").begin(),
                                 df.get_column<double>("IBM_Close").end() });

        EhlersHighPassFilterVisitor<double, std::string>    ehpf;

        df.single_act_visit<double>("Smooth Close", ehpf);

        const auto  &smooth_close = df.get_column<double>("Smooth Close");

        assert(smooth_close.size() == 1721);
        assert(std::abs(smooth_close[0] - 185.53) < 0.0001);
        assert(std::abs(smooth_close[1] - 185.3782) < 0.0001);
        assert(std::abs(smooth_close[19] - 179.8812) < 0.0001);
        assert(std::abs(smooth_close[20] - 179.2847) < 0.0001);
        assert(std::abs(smooth_close[24] - 175.4347) < 0.0001);
        assert(std::abs(smooth_close[25] - 174.8728) < 0.0001);
        assert(std::abs(smooth_close[1720] - 111.7708) < 0.0001);
        assert(std::abs(smooth_close[1712] - 126.7447) < 0.0001);
        assert(std::abs(smooth_close[1707] - 126.108) < 0.0001);
    }
    catch (const DataFrameError &ex)  {
        std::cout << ex.what() << std::endl;
    }
}

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

static void test_EhlersBandPassFilterVisitor()  {

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

    typedef StdDataFrame64<std::string> StrDataFrame;

    StrDataFrame    df;

    try  {
        df.read("SHORT_IBM.csv", io_format::csv2);
        df.load_column<double>("Smooth Close",
                               { df.get_column<double>("IBM_Close").begin(),
                                 df.get_column<double>("IBM_Close").end() });

        ebpf_v<double, std::string> ebpf(14, 0.8);

        df.single_act_visit<double>("Smooth Close", ebpf);

        const auto  &smooth_close = df.get_column<double>("Smooth Close");

        assert(smooth_close.size() == 1721);
        assert(std::abs(smooth_close[0] - 185.53) < 0.001);
        assert(std::abs(smooth_close[1] - 186.64) < 0.001);
        assert(std::abs(smooth_close[2] - 185.928) < 0.001);
        assert(std::abs(smooth_close[19] - 180.851) < 0.001);
        assert(std::abs(smooth_close[20] - 178.903) < 0.001);
        assert(std::abs(smooth_close[24] - 174.9) < 0.001);
        assert(std::abs(smooth_close[25] - 176.41) < 0.001);
        assert(std::abs(smooth_close[1720] - 113.541) < 0.001);
        assert(std::abs(smooth_close[1712] - 119.954) < 0.001);
        assert(std::abs(smooth_close[1707] - 123.239) < 0.001);
    }
    catch (const DataFrameError &ex)  {
        std::cout << ex.what() << std::endl;
    }
}

C++ DataFrame