Signature | Description | Parameters |
---|---|---|
#include <DataFrame/DataFrameFinancialVisitors.h> template<typename T, typename I = unsigned long, std::size_t A = 0> struct EldersForceIndexVisitor; // ------------------------------------- template<typename T, typename I = unsigned long, std::size_t A = 0> using efi_v = EldersForceIndexVisitor<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 Elder's Force Index (EFI) indicator. It requires 2 input columns in order of close price, volume. The result is a vector of values with same number of items as the given column. Alexander Elder force index is an oscillator that measures the force, or power, of bulls behind particular market rallies and of bears behind every decline. The three key components of the force index are the direction of price change, the extent of the price change, and the trading volume. When the force index is used in conjunction with a moving average, the resulting figure can accurately measure significant changes in the power of bulls and bears. In this way, Elder has taken an extremely useful solitary indicator, the moving average, and combined it with his force index for even greater predictive success. The force index is calculated by subtracting yesterday's close from today's close and multiplying the result by today's volume. If closing prices are higher today than yesterday, the force is positive. If closing prices are lower than yesterday's, the force is negative. The strength of the force is determined either by a larger change in price or a larger volume; either situation can independently influence the value and the change in force index. explicit EldersForceIndexVisitor(size_t roll_period = 13); roll_period: The averaging period |
T: Column data type I: Index type A: Memory alignment boundary for vectors. Default is system default alignment |
static void test_EldersForceIndexVisitor() { std::cout << "\nTesting EldersForceIndexVisitor{ } ..." << std::endl; typedef StdDataFrame64<std::string> StrDataFrame; StrDataFrame df; try { df.read("data/SHORT_IBM.csv", io_format::csv2); efi_v<double, std::string, 64> efi; df.single_act_visit<double, long>("IBM_Close", "IBM_Volume", efi); assert(efi.get_result().size() == 1721); assert(efi.get_result()[0] == 0.0); assert(std::abs(efi.get_result()[3] - 7630650.068) < 0.001); assert(std::abs(efi.get_result()[19] - -7822999.003) < 0.001); assert(std::abs(efi.get_result()[20] - -7180495.225) < 0.001); assert(std::abs(efi.get_result()[24] - -5227380.416) < 0.001); assert(std::abs(efi.get_result()[25] - -2697304.674) < 0.001); assert(std::abs(efi.get_result()[1720] - -8226876.372) < 0.001); assert(std::abs(efi.get_result()[1712] - -19336452.513) < 0.001); assert(std::abs(efi.get_result()[1707] - 12182529.448) < 0.001); } catch (const DataFrameError &ex) { std::cout << ex.what() << std::endl; } }