NAG FL Interface
g13mff (inhom_iema_all)
1
Purpose
g13mff calculates the iterated exponential moving average for an inhomogeneous time series, returning the intermediate results.
2
Specification
Fortran Interface
Subroutine g13mff ( |
sorder, nb, z, iema, ldiema, t, tau, m1, m2, sinit, inter, ftype, p, x, pn, rcomm, lrcomm, ifail) |
Integer, Intent (In) |
:: |
sorder, nb, ldiema, m1, m2, inter(2), ftype, lrcomm |
Integer, Intent (Inout) |
:: |
pn, ifail |
Real (Kind=nag_wp), Intent (In) |
:: |
z(nb), t(nb), tau, sinit(m2+2), x(*) |
Real (Kind=nag_wp), Intent (Inout) |
:: |
iema(ldiema,*), p, rcomm(lrcomm) |
|
C Header Interface
#include <nag.h>
void |
g13mff_ (const Integer *sorder, const Integer *nb, const double z[], double iema[], const Integer *ldiema, const double t[], const double *tau, const Integer *m1, const Integer *m2, const double sinit[], const Integer inter[], const Integer *ftype, double *p, const double x[], Integer *pn, double rcomm[], const Integer *lrcomm, Integer *ifail) |
|
C++ Header Interface
#include <nag.h> extern "C" {
void |
g13mff_ (const Integer &sorder, const Integer &nb, const double z[], double iema[], const Integer &ldiema, const double t[], const double &tau, const Integer &m1, const Integer &m2, const double sinit[], const Integer inter[], const Integer &ftype, double &p, const double x[], Integer &pn, double rcomm[], const Integer &lrcomm, Integer &ifail) |
}
|
The routine may be called by the names g13mff or nagf_tsa_inhom_iema_all.
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 . 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
Arguments
-
1:
– Integer
Input
-
On entry: determines the storage order of output returned in
iema.
Constraint:
or .
-
2:
– Integer
Input
-
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:
– Real (Kind=nag_wp) array
Input
-
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.
Constraint:
if or and , , for .
-
4:
– Real (Kind=nag_wp) array
Output
Note: the second dimension of the array
iema
must be at least
if
, and at least
otherwise.
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:
– Integer
Input
-
On entry: the first dimension of the array
iema as declared in the (sub)program from which
g13mff is called.
Constraints:
- if , ;
- otherwise .
-
6:
– Real (Kind=nag_wp) array
Input
-
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 g13mff will continue as if was strictly increasing by using the absolute value.
-
7:
– 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:
– Integer
Input
-
On entry: the minimum number of times the EMA operator is to be iterated.
Constraint:
.
-
9:
– Integer
Input
-
On entry: the maximum number of times the EMA operator is to be iterated. Therefore g13mff returns , for .
Constraint:
.
-
10:
– Real (Kind=nag_wp) array
Input
-
On entry: if
, the values used to start the iterative process, with
- ,
- ,
- , .
If
then
sinit is not referenced.
Constraint:
if , , for .
-
11:
– Integer array
Input
-
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:
– Integer
Input
-
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:
– 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:
– Real (Kind=nag_wp) array
Input
-
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:
– Integer
Input/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 must 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:
– Real (Kind=nag_wp) array
Communication 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:
– Integer
Input
-
On entry: the dimension of the array
rcomm as declared in the (sub)program from which
g13mff is called.
Constraint:
or .
-
18:
– Integer
Input/Output
-
On entry:
ifail must be set to
,
or
to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of means that an error message is printed while a value of means that it is not.
If halting is not appropriate, the value
or
is recommended. If message printing is undesirable, then the value
is recommended. Otherwise, the value
is recommended.
When the value or 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 , the nearest integer to must not be .
-
On entry, , and .
Constraint: if or and for any then .
-
On entry, , , and .
Constraint: if and for any 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.
An unexpected error has been triggered by this routine. Please
contact
NAG.
See
Section 7 in the Introduction to the NAG Library FL Interface for further information.
Your licence key may have expired or may not have been installed correctly.
See
Section 8 in the Introduction to the NAG Library FL Interface for further information.
Dynamic memory allocation failed.
See
Section 9 in the Introduction to the NAG Library FL Interface for further information.
7
Accuracy
Not applicable.
8
Parallelism and Performance
g13mff is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
g13mff 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 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,
x or
tau are supplied.
10
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 .
10.1
Program Text
10.2
Program Data
10.3
Program Results