NAG Library Routine Document
G13MFF
1 Purpose
G13MFF calculates the iterated exponential moving average for an inhomogeneous time series, returning the intermediate results.
2 Specification
SUBROUTINE G13MFF ( |
SORDER, NB, Z, IEMA, LDIEMA, T, TAU, M1, M2, SINIT, INTER, FTYPE, P, X, PN, RCOMM, LRCOMM, IFAIL) |
INTEGER |
SORDER, NB, LDIEMA, M1, M2, INTER(2), FTYPE, PN, LRCOMM, IFAIL |
REAL (KIND=nag_wp) |
Z(NB), IEMA(LDIEMA,*), T(NB), TAU, SINIT(M2+2), P, X(*), RCOMM(LRCOMM) |
|
3 Description
G13MFF 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 . The 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 (
Zumbach and Müller (2001)) for the EMA operator:
where
The value of
depends on the method of interpolation chosen and the relationship between
and the input series
depends on the transformation function chosen. G13MFF gives the option of three interpolation methods:
1. |
Previous point: |
; |
2. |
Linear: |
; |
3. |
Next point: |
. |
and three transformation functions:
1. |
Identity: |
; |
2. |
Absolute value: |
; |
3. |
Absolute difference: |
; |
where the notation
is used to denote the integer nearest to
. In the case of the absolute difference
is a user-supplied vector of length
and therefore each element of the time series is composed of the triplet of scalar values,
.
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, where required, can be split into arbitrary sized blocks and G13MFF 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: SORDER – INTEGERInput
On entry: determines the storage order of output returned in
IEMA.
Constraint:
or .
- 2: NB – INTEGERInput
On entry:
, the number of observations in the current block of data. At each call the size of the block of data supplied in
Z,
T and
X can vary; therefore
NB can change between calls to G13MFF.
Constraint:
.
- 3: Z(NB) – REAL (KIND=nag_wp) arrayInput
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.
- 4: IEMA(LDIEMA,) – REAL (KIND=nag_wp) arrayOutput
Note: the second dimension of the array
IEMA must be at least
if
, otherwise at least
NB.
On exit: the iterated exponential moving average.
If , .
If , .
For
,
and
is the number of observations processed so far, i.e., the value supplied in
PN on entry.
- 5: LDIEMA – INTEGERInput
On entry: the first dimension of the array
IEMA as declared in the (sub)program from which G13MFF is called.
Constraints:
- if , ;
- otherwise .
- 6: T(NB) – 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 , a warning will be issued, but G13MFF will continue as if was strictly increasing by using the absolute value.
- 7: TAU – REAL (KIND=nag_wp)Input
On entry: , the parameter controlling the rate of decay. must be sufficiently large that , can be calculated without overflowing, for all .
Constraint:
.
- 8: M1 – INTEGERInput
On entry: the minimum number of times the EMA operator is to be iterated.
Constraint:
.
- 9: M2 – INTEGERInput
On entry: the maximum number of times the EMA operator is to be iterated. Therefore G13MFF returns , for .
Constraint:
.
- 10: SINIT() – REAL (KIND=nag_wp) arrayInput
On entry: if
, the values used to start the iterative process, with
- ,
- ,
- , .
If
then
SINIT is not referenced.
Constraint:
if , , for .
- 11: INTER() – 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 .
- 12: FTYPE – INTEGERInput
On entry: the function type used to define the relationship between
and
when calculating
. Three functions are provided:
- The identity function, with .
- The absolute value, with .
- The absolute difference, with , where the vector is supplied in X.
Constraint:
, or .
- 13: P – REAL (KIND=nag_wp)Input/Output
On entry: , the power used in the transformation function.
On exit: if
, then
, the actual power used in the transformation function is returned, otherwise
P is unchanged.
Constraint:
.
- 14: X() – REAL (KIND=nag_wp) arrayInput
Note: the dimension of the array
X
must be at least
if
.
On entry: if
,
, the vector used to shift 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
then
X is not referenced.
Constraint:
if and , , for .
- 15: PN – INTEGERInput/Output
On entry:
, the number of observations processed so far. On the first call to G13MFF, or when starting to summarise a new dataset,
PN should be set to
. On subsequent calls it must be the same value as returned by the last call to G13MFF.
On exit: , the updated number of observations processed so far.
Constraint:
.
- 16: RCOMM(LRCOMM) – REAL (KIND=nag_wp) arrayCommunication Array
On entry: communication array, used to store information between calls to G13MFF. If
,
RCOMM is not referenced,
PN must be set to
and all the data must be supplied in one go.
- 17: LRCOMM – INTEGERInput
On entry: the dimension of the array
RCOMM as declared in the (sub)program from which G13MFF is called.
Constraint:
or .
- 18: IFAIL – 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: or .
-
On entry, .
Constraint: .
-
On entry, , and .
Constraint: .
On entry, , and .
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
M1 must be unchanged since previous call.
-
On entry, and .
Constraint: .
-
On entry,
.
On entry at previous call,
.
Constraint: if
then
M2 must be unchanged since previous call.
-
On entry, , and .
Constraint: if , , for .
-
On entry, .
Constraint: , or .
-
On entry, .
Constraint: , or .
-
On entry,
and
.
On entry at previous call,
,
.
Constraint: if
,
INTER must be unchanged since the last call.
-
On entry, .
Constraint: , or .
-
On entry,
, On entry at previous call,
.
Constraint: if
,
FTYPE must be unchanged since the previous call.
-
On entry,
.
Constraint: absolute value of
P must be representable as an integer.
-
On entry, .
Constraint: if , . If , .
-
On entry, , and .
Constraint: if or and for all then .
-
On entry, , , and .
Constraint: if and for all then .
-
On entry,
.
On exit from previous call,
.
Constraint: if
then
P must be unchanged since 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 then .
-
Truncation occurred to avoid overflow, check for extreme values in
T,
Z X or for
TAU. Results are returned using the truncated values.
-
Dynamic memory allocation failed.
7 Accuracy
Not applicable.
Approximately real elements are internally allocated by G13MFF.
The more data you supply to G13MFF 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
and
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
Z,
T or
TAU are supplied.
9 Example
This example reads in three blocks of simulated data from an inhomogeneous time series, then calculates and prints the iterated EMA for between and .
9.1 Program Text
Program Text (g13mffe.f90)
9.2 Program Data
Program Data (g13mffe.d)
9.3 Program Results
Program Results (g13mffe.r)