NAG Library Routine Document
G13MEF
1 Purpose
G13MEF calculates the iterated exponential moving average for an inhomogeneous time series.
2 Specification
SUBROUTINE G13MEF ( |
NB, IEMA, T, TAU, M, SINIT, INTER, PN, RCOMM, LRCOMM, IFAIL) |
INTEGER |
NB, M, INTER(2), PN, LRCOMM, IFAIL |
REAL (KIND=nag_wp) |
IEMA(NB), T(NB), TAU, SINIT(M+2), RCOMM(LRCOMM) |
|
3 Description
G13MEF 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. G13MEF 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 G13MEF called multiple times.
4 References
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 Finance 4(1) 147–178
5 Parameters
- 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 G13MEF.
Constraint:
.
- 2: – REAL (KIND=nag_wp) arrayInput/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: – REAL (KIND=nag_wp) arrayInput
-
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 , will be returned, but G13MEF will continue as if was strictly increasing by using the absolute value.
- 4: – REAL (KIND=nag_wp)Input
-
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: – REAL (KIND=nag_wp) arrayInput
-
On entry: if
, the values used to start the iterative process, with
- ,
- ,
- , for .
If
,
SINIT is not referenced.
- 7: – INTEGER arrayInput
-
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: – INTEGERInput/Output
-
On entry:
, the number of observations processed so far. On the first call to G13MEF, 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 G13MEF.
On exit: , the updated number of observations processed so far.
Constraint:
.
- 9: – REAL (KIND=nag_wp) arrayCommunication Array
-
On entry: communication array, used to store information between calls to G13MEF.
If
,
RCOMM is not referenced,
PN must be set to
and all the data must be supplied in one go.
- 10: – INTEGERInput
-
On entry: the dimension of the array
RCOMM as declared in the (sub)program from which G13MEF is called.
Constraint:
or .
- 11: – INTEGERInput/Output
-
On entry:
IFAIL must be set to
,
. If you are unfamiliar with this parameter you should refer to
Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value
is recommended. If the output of error messages is undesirable, then the value
is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is
.
When the value is used it is essential to test the value of IFAIL on exit.
On exit:
unless the routine detects an error or a warning has been flagged (see
Section 6).
6 Error Indicators and Warnings
If on entry
or
, explanatory error messages are output on the current error message unit (as defined by
X04AAF).
Errors or warnings detected by the routine:
-
On entry, .
Constraint: .
-
On entry,
,
and
.
Constraint:
T should be strictly increasing.
-
On entry, , and .
Constraint: if linear interpolation is being used.
-
On entry, .
Constraint: .
-
On entry,
.
On entry at previous call,
.
Constraint: if
then
TAU must be unchanged since previous call.
-
On entry, .
Constraint: .
-
On entry,
.
On entry at previous call,
.
Constraint: if
then
M must be unchanged since previous call.
-
On entry, .
Constraint: , or .
-
On entry, .
Constraint: , or .
-
On entry,
and
.
On entry at previous call,
,
.
Constraint: if
,
INTER must be unchanged since the previous call.
-
On entry, .
Constraint: .
-
On entry,
.
On exit from previous call,
.
Constraint: if
then
PN must be unchanged since previous call.
-
RCOMM has been corrupted between calls.
-
On entry, , and .
Constraint: if , or .
-
On entry, , and .
Constraint: if , .
-
Truncation occurred to avoid overflow, check for extreme values in
T,
IEMA or for
TAU. Results are returned using the truncated values.
An unexpected error has been triggered by this routine. Please
contact
NAG.
See
Section 3.8 in the Essential Introduction for further information.
Your licence key may have expired or may not have been installed correctly.
See
Section 3.7 in the Essential Introduction for further information.
Dynamic memory allocation failed.
See
Section 3.6 in the Essential Introduction for further information.
7 Accuracy
Not applicable.
8 Parallelism and Performance
G13MEF is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
G13MEF 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 routine. Please also consult the
Users' Note for your implementation for any additional implementation-specific information.
Approximately real elements are internally allocated by G13MEF.
The more data you supply to G13MEF in one call, i.e., the larger
NB is, the more efficient the routine will be, particularly if the routine is being run using more than one thread.
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
is returned. This should not occur in standard usage and will only occur if extreme values of
IEMA,
T or
TAU are supplied.
10 Example
The example reads in a simulated time series, and calculates the iterated exponential moving average.
10.1 Program Text
Program Text (g13mefe.f90)
10.2 Program Data
Program Data (g13mefe.d)
10.3 Program Results
Program Results (g13mefe.r)
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 parameter.