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

template<typename T, typename I = unsigned long>
struct TrueRangeVisitor;
        
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 price range based on low, high, and close. It requires 3 input columns in order of low, highme, close.
The result is a vector of values with same number of items as the given column. The first item in the result is NaN.
The true range indicator is taken as the greatest of the following: current high less the current low; the absolute value of the current high less the previous close; and the absolute value of the current low less the previous close.
T: Column data type
I: Index type
static void test_TrueRangeVisitor()  {

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

    typedef StdDataFrame<std::string> StrDataFrame;

    StrDataFrame    df;

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

        TrueRangeVisitor<double, std::string>   tr;

        std::future<TrueRangeVisitor<double, std::string> &>    fut = df.single_act_visit_async<double, double, double>("IBM_Low", "IBM_High", "IBM_Close", tr);

        fut.get();
        assert(tr.get_result().size() == 1721);
        assert(std::isnan(tr.get_result()[0]));
        assert(std::abs(tr.get_result()[19] - 1.5) < 0.1);
        assert(std::abs(tr.get_result()[20] - 2.5) < 0.1);
        assert(std::abs(tr.get_result()[24] - 1.06001) < 0.00001);
        assert(std::abs(tr.get_result()[25] - 2.89) < 0.01);
        assert(std::abs(tr.get_result()[1720] - 4.05) < 0.01);
        assert(std::abs(tr.get_result()[1712] - 8.68) < 0.01);
        assert(std::abs(tr.get_result()[1707] - 2.75) < 0.01);
    }
    catch (const DataFrameError &ex)  {
        std::cout << ex.what() << std::endl;
    }
}