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

template<typename T, typename I = unsigned long>
struct SlopeVisitor;
        
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 slope of the diff. The slope indicator measures the rise-over-run of a linear regression, which is the line of best fit for a price series. Fluctuating above and below zero, the Slope indicator best resembles a momentum oscillator without boundaries. It is not well suited for overbought/oversold levels, but can measure the direction and strength of a trend. It can also be used with other indicators to identify potential entry points within an ongoing trend.
The result is a vector of values with same number of items as the given column. The first periods items, in the result, will be NAN.
    explicit
    SlopeVisitor(std::size_t periods = 1,
                 bool as_angle = false,
                 bool in_degrees = false)
        
T: Column data type
I: Index type
static void test_SlopeVisitor()  {

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

    typedef StdDataFrame<std::string> StrDataFrame;

    StrDataFrame    df;

    try  {
        df.read("IBM.csv", io_format::csv2);

        SlopeVisitor<double, std::string>   s_v (10, true, true);

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

        assert(s_v.get_result().size() == 5031);
        assert(std::isnan(s_v.get_result()[0]));
        assert(std::isnan(s_v.get_result()[9]));
        assert(std::abs(s_v.get_result()[10] - 4.64508) < 0.00001);
        assert(std::abs(s_v.get_result()[29] - -40.5718) < 0.0001);
        assert(std::abs(s_v.get_result()[34] - -47.07) < 0.001);
        assert(std::abs(s_v.get_result()[5030] - -54.9783) < 0.0001);
        assert(std::abs(s_v.get_result()[5026] - -56.2923) < 0.0001);
        assert(std::abs(s_v.get_result()[5021] - 19.341) < 0.001);
    }
    catch (const DataFrameError &ex)  {
        std::cout << ex.what() << std::endl;
    }
}
C++ DataFrame