The function may be called by the names: g13mec or nag_tsa_inhom_iema.
3Description
g13mec calculates the iterated exponential moving average for an inhomogeneous time series. The time series is represented by two vectors of length ; a vector of times, ; and a vector of values, . Each element of the time series is, therefore, composed of the pair of scalar values , for . Time can be measured in any arbitrary units, as long as all elements of use the same units.
The exponential moving average (EMA), with parameter , is an average operator, with the exponentially decaying kernel given by
The exponential form of this kernel gives rise to the following iterative formula for the EMA operator (see Zumbach and Müller (2001)):
where
The value of depends on the method of interpolation chosen. g13mec gives the option of three interpolation methods:
1.
Previous point:
;
2.
Linear:
;
3.
Next point:
.
The -iterated exponential moving average, , , is defined using the recursive formula:
with
For large datasets or where all the data is not available at the same time, and can be split into arbitrary sized blocks and g13mec called multiple times.
4References
Dacorogna M M, Gencay R, Müller U, Olsen R B and Pictet O V (2001) An Introduction to High-frequency Finance Academic Press
Zumbach G O and Müller U A (2001) Operators on inhomogeneous time series International Journal of Theoretical and Applied Finance4(1) 147–178
5Arguments
1: – IntegerInput
On entry: , the number of observations in the current block of data. The size of the block of data supplied in iema and t can vary;, therefore, nb can change between calls to g13mec.
Constraint:
.
2: – doubleInput/Output
On entry: , the current block of observations, for , where is the number of observations processed so far, i.e., the value supplied in pn on entry.
On exit: the iterated EMA, with .
3: – const doubleInput
On entry: , the times for the current block of observations, for , where is the number of observations processed so far, i.e., the value supplied in pn on entry.
If , NE_NOT_STRICTLY_INCREASING will be returned, but g13mec will continue as if was strictly increasing by using the absolute value.
4: – doubleInput
On entry: , the parameter controlling the rate of decay, which must be sufficiently large that , can be calculated without overflowing, for all .
Constraint:
.
5: – IntegerInput
On entry: , the number of times the EMA operator is to be iterated.
Constraint:
.
6: – const doubleInput
On entry: if , the values used to start the iterative process, with
On entry: the type of interpolation used with indicating the interpolation method to use when calculating and the interpolation method to use when calculating , .
Three types of interpolation are possible:
Previous point, with .
Linear, with .
Next point, .
Zumbach and Müller (2001) recommend that linear interpolation is used in second and subsequent iterations, i.e., , irrespective of the interpolation method used at the first iteration, i.e., the value of .
Constraint:
, or , for .
8: – Integer *Input/Output
On entry: , the number of observations processed so far. On the first call to g13mec, or when starting to summarise a new dataset, pn must be set to . On subsequent calls it must be the same value as returned by the last call to g13mec.
On exit: , the updated number of observations processed so far.
Constraint:
.
9: – doubleCommunication Array
Note: the dimension, dim, of the array rcomm
must be at least
, when ;
, otherwise.
On entry: communication array, used to store information between calls to g13mec. If then pn must be set to zero and all the data must be supplied in one go.
10: – NagError *Input/Output
The NAG error argument (see Section 7 in the Introduction to the NAG Library CL Interface).
6Error Indicators and Warnings
NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 3.1.2 in the Introduction to the NAG Library CL Interface for further information.
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
See Section 7.5 in the Introduction to the NAG Library CL Interface for further information.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library CL Interface for further information.
NE_NOT_STRICTLY_INCREASING
On entry, , and .
Constraint: t should be strictly increasing.
NE_PREV_CALL
If then inter must be unchanged since previous call.
On entry, .
On entry at previous call, .
Constraint: if then m must be unchanged since previous call.
On entry, .
On exit from previous call, .
Constraint: if then pn must be unchanged since previous call.
On entry, .
On entry at previous call, .
Constraint: if then tau must be unchanged since previous call.
NE_REAL
On entry, .
Constraint: .
NE_REAL_ARRAY
On entry, , and .
Constraint: if linear interpolation is being used.
NW_OVERFLOW_WARN
Truncation occurred to avoid overflow, check for extreme values in t, iema or for tau. Results are returned using the truncated values.
7Accuracy
Not applicable.
8Parallelism and Performance
Background information to multithreading can be found in the Multithreading documentation.
g13mec is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
g13mec makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
Please consult the X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this function. Please also consult the Users' Note for your implementation for any additional implementation-specific information.
9Further Comments
Approximately real elements are internally allocated by g13mec.
The more data you supply to g13mec in one call, i.e., the larger nb is, the more efficient the function will be.
Checks are made during the calculation of to avoid overflow. If a potential overflow is detected the offending value is replaced with a large positive or negative value, as appropriate, and the calculations performed based on the replacement values. In such cases NW_OVERFLOW_WARN is returned. This should not occur in standard usage and will only occur if extreme values of iema, t or tau are supplied.
10Example
The example reads in a simulated time series, and calculates the iterated exponential moving average.
This example plot shows the exponential moving average for the same data using three different values of and illustrates the effect on the EMA of altering this argument.