CBOE Emulator  1.0
Public Member Functions | Static Public Attributes | List of all members
Maths::RateOfChange< Observation, RoC > Struct Template Reference

A structure for calculating the Rate of Change (ROC) over a rolling window. More...

#include <rate_of_change.hpp>

Public Member Functions

 RateOfChange (std::size_t length)
 Initialize a new RoC with given history length \(n\). More...
 
std::size_t get_length () const
 Return the length of the rate of change history. More...
 
RoC get_rate_of_change () const
 Return the current rate of change (RoC). More...
 
void reset ()
 Reset the history to its initial state.
 
void process (Observation observation)
 Calculate the next RoC based on observation \(o_t\). More...
 

Static Public Attributes

static constexpr std::size_t LENGTH_MIN = 2
 the inclusive minimal size for the length of the history
 
static constexpr std::size_t LENGTH_MAX = std::numeric_limits<uint16_t>::max() - 1
 the inclusive maximal size for the length of the history
 

Detailed Description

template<typename Observation = double, typename RoC = double>
struct Maths::RateOfChange< Observation, RoC >

A structure for calculating the Rate of Change (ROC) over a rolling window.

Template Parameters
Observationthe type for the observations
RoCthe type for the rate of change to be calculated in

The Rate of Change (ROC), i.e., momentum, is a technical analysis indicator measuring the difference between values in a time series window. A moving window of values, i.e., history vector \(\boldsymbol{h}^n\), stores of the last \(n\) observations. An indexing variable \(i\) determines the head of the circular moving window. For a new observation \(o_t\) at time \(t\), the history vector is updated with the observation \(\boldsymbol{h_i} \gets o_t\). The RoC is calculated from the current observation \(\boldsymbol{h}_i\) and the oldest observation \(\boldsymbol{h}_{(i + 1) \bmod n}\) as:

\[ r_t = \frac{\boldsymbol{h}_i - \boldsymbol{h}_{(i + 1) \bmod n}}{\boldsymbol{h}_{(i + 1) \bmod n}}\]

The index is updated as \(i \gets (i + 1) \bmod n\).

Constructor & Destructor Documentation

◆ RateOfChange()

template<typename Observation = double, typename RoC = double>
Maths::RateOfChange< Observation, RoC >::RateOfChange ( std::size_t  length)
inlineexplicit

Initialize a new RoC with given history length \(n\).

Parameters
lengththe length of the history window \(n\)

Member Function Documentation

◆ get_length()

template<typename Observation = double, typename RoC = double>
std::size_t Maths::RateOfChange< Observation, RoC >::get_length ( ) const
inline

Return the length of the rate of change history.

Returns
the length of the history window \(n\)

◆ get_rate_of_change()

template<typename Observation = double, typename RoC = double>
RoC Maths::RateOfChange< Observation, RoC >::get_rate_of_change ( ) const
inline

Return the current rate of change (RoC).

Returns
the current RoC \(r_t\)

◆ process()

template<typename Observation = double, typename RoC = double>
void Maths::RateOfChange< Observation, RoC >::process ( Observation  observation)
inline

Calculate the next RoC based on observation \(o_t\).

Parameters
observationthe observation \(o_t\) to integrate into the RoC

The documentation for this struct was generated from the following file: