Window Aggregate ATR

The Average True Range (ATR) is calculated using the algorithm described in the following Wikipedia page: http://en.wikipedia.org/wiki/Moving_average

The true range is the largest of the:

The ATR at the moment of time t is expressed by the following formula:

The first ATR value is expressed with the arithmetic mean formula:

The eXtremeDB runtime computes the ATR using following iterative formula:

 
    ATR[i] = ATR[i-1] * (n-1)
     

where

 
    n = min( i+1, window_size )
 

For example, applying the ATR calculation to the following input sequence of values:

 
    {335, 808, 45, 402, 732, 48, 805, 450, 385, 420, 367, 69}
            
     

with the interval argument of 7 produces the following result sequence:

 
    {335, 571.5, 396, 397.5, 464.4, 395,
    453.571429, 453.061224, 443.338192, 440.004165, 429.574999, 378.064284}
     

Note that the first 6 values (highlighted above) should be ignored for this interval of 7 (see note in the Window versus Grid Aggregate page).