← Back to Documentations

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

template<typename T, typename I = unsigned long,
         std::size_t A = 0>
struct AroonVisitor;

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

template<typename T, typename I = unsigned long,
         std::size_t A = 0>
using aroon_v = AroonVisitor<T, I, A>;
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 Aroon indicator, which consists of three series: Aroon Up, Aroon Down and the Aroon Oscillator. It requires 2 input columns in the order of low, high. Aroon measures how recently the price made a new high or a new low. For each bar, it looks at a window made of the current bar plus the previous period bars (so period + 1 bars in all). Aroon Up is based on how many bars ago the highest high in that window occurred, and Aroon Down is based on how many bars ago the lowest low occurred. Both are scaled from 0 to 100: A value of 100 means the extreme happened on the current bar. A value of 0 means the extreme happened exactly period bars ago, at the very edge of the window. Values in between decline linearly as the extreme gets older.

get_result() and get_aroon_up() return Aroon Up.
get_aroon_down() returns Aroon Down..
get_aroon_oscillator() returns the oscillator.
All results are vectors with the same number of items as the given columns. The first period items of every result are NaN. A window that contains a NaN value in the relevant column gives NaN for that bar.
explicit
AroonVisitor(size_type period = 25);

period: Look-back used to find the highest high and lowest low. It must be
        greater than 0 and smaller than the column size
        
T: Column data type
I: Index type
A: Memory alignment boundary for vectors. Default is system default alignment
static void test_AroonVisitor()  {

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

    StrDataFrame    df;

    try  {
        df.read("IBM.csv", io_format::csv2);
    }
    catch (const DataFrameError &ex)  {
        std::cout << ex.what() << std::endl;
        ::exit(-1);
    }

    AroonVisitor<double, std::string>   aroon;

    df.single_act_visit<double, double>("IBM_Low", "IBM_High", aroon);

    // Same as calling get_aroon_up()
    //
    assert(aroon.get_result().size() == 5031);
    assert(std::isnan(aroon.get_result()[0]));
    assert(std::isnan(aroon.get_result()[24]));
    assert(std::abs(aroon.get_result()[25] - 92.0) < 0.001);
    assert(std::abs(aroon.get_result()[30] - 72.0) < 0.001);
    assert(std::abs(aroon.get_result()[40] - 32.0) < 0.001);
    assert(std::abs(aroon.get_result()[51] - 68.0) < 0.001);
    assert(std::abs(aroon.get_result()[101] - 0.0) < 0.001);
    assert(std::abs(aroon.get_result()[5022] - 68.0) < 0.001);
    assert(std::abs(aroon.get_result()[5029] - 40.0) < 0.001);
    assert(std::abs(aroon.get_result()[5030] - 36.0) < 0.001);

    assert(std::isnan(aroon.get_aroon_down()[0]));
    assert(std::isnan(aroon.get_aroon_down()[24]));
    assert(std::abs(aroon.get_aroon_down()[25] - 32.0) < 0.001);
    assert(std::abs(aroon.get_aroon_down()[30] - 96.0) < 0.001);
    assert(std::abs(aroon.get_aroon_down()[40] - 80.0) < 0.001);
    assert(std::abs(aroon.get_aroon_down()[51] - 36.0) < 0.001);
    assert(std::abs(aroon.get_aroon_down()[101] - 80.0) < 0.001);
    assert(std::abs(aroon.get_aroon_down()[5022] - 28.0) < 0.001);
    assert(std::abs(aroon.get_aroon_down()[5029] - 96.0) < 0.001);
    assert(std::abs(aroon.get_aroon_down()[5030] - 92.0) < 0.001);

    assert(std::isnan(aroon.get_aroon_oscillator()[0]));
    assert(std::isnan(aroon.get_aroon_oscillator()[24]));
    assert(std::abs(aroon.get_aroon_oscillator()[25] - 60.0) < 0.001);
    assert(std::abs(aroon.get_aroon_oscillator()[30] - -24.0) < 0.001);
    assert(std::abs(aroon.get_aroon_oscillator()[40] - -48.0) < 0.001);
    assert(std::abs(aroon.get_aroon_oscillator()[51] - 32.0) < 0.001);
    assert(std::abs(aroon.get_aroon_oscillator()[101] - -80.0) < 0.001);
    assert(std::abs(aroon.get_aroon_oscillator()[5022] - 40.0) < 0.001);
    assert(std::abs(aroon.get_aroon_oscillator()[5029] - -56.0) < 0.001);
    assert(std::abs(aroon.get_aroon_oscillator()[5030] - -56.0) < 0.001);
}

C++ DataFrame