nag_tsa_inhom_iema_all (g13mfc) (PDF version)
g13 Chapter Contents
g13 Chapter Introduction
NAG Library Manual

NAG Library Function Document

nag_tsa_inhom_iema_all (g13mfc)

+ Contents

    1  Purpose
    7  Accuracy

1  Purpose

nag_tsa_inhom_iema_all (g13mfc) calculates the iterated exponential moving average for an inhomogeneous time series, returning the intermediate results.

2  Specification

#include <nag.h>
#include <nagg13.h>
void  nag_tsa_inhom_iema_all (Nag_OrderType order, Integer nb, const double z[], double iema[], Integer pdiema, const double t[], double tau, Integer m1, Integer m2, const double sinit[], const Nag_TS_Interpolation inter[], Nag_TS_Transform ftype, double *p, const double x[], Integer *pn, double rcomm[], NagError *fail)

3  Description

nag_tsa_inhom_iema_all (g13mfc) calculates the iterated exponential moving average for an inhomogeneous time series. The time series is represented by two vectors of length n: a vector of times, t; and a vector of values, z. Each element of the time series is therefore composed of the pair of scalar values ti,zi, for i=1,2,,n. Time can be measured in any arbitrary units, as long as all elements of t use the same units.
The exponential moving average (EMA), with parameter τ, is an average operator, with the exponentially decaying kernel given by
e -ti/τ τ .
The exponential form of this kernel gives rise to the following iterative formula (Zumbach and Müller (2001)) for the EMA operator:
EMA τ ; y ti = μ EMA τ;y ti-1 + ν-μ yi-1 + 1-ν yi
where
μ = e-α   and   α = ti - ti-1 τ .
The value of ν depends on the method of interpolation chosen and the relationship between y and the input series z depends on the transformation function chosen. nag_tsa_inhom_iema_all (g13mfc) gives the option of three interpolation methods:
1. Previous point: ν=1;
2. Linear: ν= 1-μ / α ;
3. Next point: ν=μ.
and three transformation functions:
1. Identity: yi = zi p ;
2. Absolute value: yi = zi p ;
3. Absolute difference: yi = zi - xi p ;
where the notation p is used to denote the integer nearest to p. In the case of the absolute difference x is a user-supplied vector of length n and therefore each element of the time series is composed of the triplet of scalar values, ti,zi,xi.
The m-iterated exponential moving average, EMAτ,m;yti, is defined using the recursive formula:
EMA τ,m ; y ti = EMA τ ; EMA τ,m-1 ; y ti ti
with
EMA τ,1;y ti = EMA τ;y ti .
For large datasets or where all the data is not available at the same time, z,t and, where required, x can be split into arbitrary sized blocks and nag_tsa_inhom_iema_all (g13mfc) 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:     orderNag_OrderTypeInput
On entry: the order argument specifies the two-dimensional storage scheme being used, i.e., row-major ordering or column-major ordering. C language defined storage is specified by order=Nag_RowMajor. See Section 3.2.1.3 in the Essential Introduction for a more detailed explanation of the use of this argument.
Constraint: order=Nag_RowMajor or Nag_ColMajor.
2:     nbIntegerInput
On entry: b, 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 nag_tsa_inhom_iema_all (g13mfc).
Constraint: nb0.
3:     z[nb]const doubleInput
On entry: zi, the current block of observations, for i=k+1,,k+b, where k is the number of observations processed so far, i.e., the value supplied in pn on entry.
Constraint: if ftype=Nag_Identity or Nag_AbsVal and p<0.0, z[i-1]0, for i=1,2,,nb.
4:     iema[dim]doubleOutput
Note: the dimension, dim, of the array iema must be at least pdiema×.
Where IEMAi,j appears in this document, it refers to the array element
  • iema[j-1×pdiema+i-1] when order=Nag_ColMajor;
  • iema[i-1×pdiema+j-1] when order=Nag_RowMajor.
On exit: the iterated exponential moving average.
If order=Nag_ColMajor, IEMAi,j = EMA τ,j+m1-1 ; y ti+k .
If order=Nag_RowMajor, IEMAj,i = EMA τ,j+m1-1 ; y ti+k .
For i=1,2,,nb, j=1,2,,m2-m1+1 and k is the number of observations processed so far, i.e., the value supplied in pn on entry.
5:     pdiemaIntegerInput
On entry: the stride separating row or column elements (depending on the value of order) in the array iema.
Constraints:
  • if order=Nag_ColMajor, pdiemanb;
  • otherwise pdiemam2-m1+1.
6:     t[nb]const doubleInput
On entry: ti, the times for the current block of observations, for i=k+1,,k+b, where k is the number of observations processed so far, i.e., the value supplied in pn on entry.
If titi-1, fail.code= NE_NOT_STRICTLY_INCREASING will be returned, but nag_tsa_inhom_iema_all (g13mfc) will continue as if t was strictly increasing by using the absolute value.
7:     taudoubleInput
On entry: τ, the parameter controlling the rate of decay. τ must be sufficiently large that e-α, α=ti-ti-1/τ can be calculated without overflowing, for all i.
Constraint: tau>0.0.
8:     m1IntegerInput
On entry: the minimum number of times the EMA operator is to be iterated.
Constraint: m11.
9:     m2IntegerInput
On entry: the maximum number of times the EMA operator is to be iterated. Therefore nag_tsa_inhom_iema_all (g13mfc) returns EMA τ,m;y , for m=m1,m1+1,,m2.
Constraint: m2m1.
10:   sinit[m2+2]const doubleInput
On entry: if pn=0, the values used to start the iterative process, with
  • sinit[0]=t0,
  • sinit[1]=y0,
  • sinit[j+1]= EMA τ,j ; y t0 , j=1,2,,m2.
If pn0 then sinit is not referenced and may be NULL.
Constraint: if ftypeNag_Identity, sinit[j-1]0, for j=2,3,,m2+2.
11:   inter[2]const Nag_TS_InterpolationInput
On entry: the type of interpolation used with inter[0] indicating the interpolation method to use when calculating EMAτ,1;z and inter[1] the interpolation method to use when calculating EMAτ,j;z, j>1.
Three types of interpolation are possible:
inter[i]=Nag_PreviousPoint
Previous point, with ν=1.
inter[i]=Nag_Linear
Linear, with ν=1-μ/α.
inter[i]=Nag_NextPoint
Next point, ν=μ.
Zumbach and Müller (2001) recommend that linear interpolation is used in second and subsequent iterations, i.e., inter[1]=Nag_Linear, irrespective of the interpolation method used at the first iteration, i.e., the value of inter[0].
Constraint: inter[i-1]=Nag_PreviousPoint, Nag_Linear or Nag_NextPoint, for i=1,2.
12:   ftypeNag_TS_TransformInput
On entry: the function type used to define the relationship between y and z when calculating EMAτ,1;y. Three functions are provided:
ftype=Nag_Identity
The identity function, with yi = zi p .
ftype=Nag_AbsVal
The absolute value, with yi = zi p .
ftype=Nag_AbsDiff
The absolute difference, with yi = zi - xi p , where the vector x is supplied in x.
Constraint: ftype=Nag_Identity, Nag_AbsVal or Nag_AbsDiff.
13:   pdouble *Input/Output
On entry: p, the power used in the transformation function.
On exit: if ftype=Nag_Identity, then p, the actual power used in the transformation function is returned, otherwise p is unchanged.
Constraint: p0.
14:   x[nb]const doubleInput
On entry: if ftype=Nag_AbsDiff, xi, the vector used to shift the current block of observations, for i=k+1,,k+b, where k is the number of observations processed so far, i.e., the value supplied in pn on entry.
If ftypeNag_AbsDiff then x is not referenced and may be NULL.
Constraint: if ftype=Nag_AbsDiff and p<0, x[i-1]z[i-1], for i=1,2,,nb.
15:   pnInteger *Input/Output
On entry: k, the number of observations processed so far. On the first call to nag_tsa_inhom_iema_all (g13mfc), or when starting to summarise a new dataset, pn must be set to 0. On subsequent calls it must be the same value as returned by the last call to nag_tsa_inhom_iema_all (g13mfc).
On exit: k+b, the updated number of observations processed so far.
Constraint: pn0.
16:   rcomm[m2+20]doubleCommunication Array
On entry: communication array, used to store information between calls to nag_tsa_inhom_iema_all (g13mfc). If rcommisNULL then pn must be set to zero and all the data must be supplied in one go.
17:   failNagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

6  Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
NE_ARRAY_SIZE
On entry, order=Nag_ColMajor, pdiema=value and nb=value.
Constraint: pdiemanb.
On entry, order=Nag_RowMajor, pdiema=value and m2-m1+1=value.
Constraint: pdiemam2-m1+1.
NE_BAD_PARAM
On entry, argument value had an illegal value.
NE_ILLEGAL_COMM
rcomm has been corrupted between calls.
NE_INT
On entry, m1=value.
Constraint: m11.
On entry, nb=value.
Constraint: nb0.
On entry, pn=value.
Constraint: pn0.
NE_INT_2
On entry, m1=value and m2=value.
Constraint: m2m1.
NE_INTERNAL_ERROR
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.
NE_NOT_STRICTLY_INCREASING
On entry, i=value, t[i-2]=value and t[i-1]=value.
Constraint: t should be strictly increasing.
NE_PREV_CALL
If pn>0 then ftype must be unchanged since previous call.
If pn>0 then inter must be unchanged since previous call.
On entry, m1=value.
On entry at previous call, m1=value.
Constraint: if pn>0 then m1 must be unchanged since previous call.
On entry, m2=value.
On entry at previous call, m2=value.
Constraint: if pn>0 then m2 must be unchanged since previous call.
On entry, p=value.
On exit from previous call, p=value.
Constraint: if pn>0 then p must be unchanged since previous call.
On entry, pn=value.
On exit from previous call, pn=value.
Constraint: if pn>0 then pn must be unchanged since previous call.
On entry, tau=value.
On entry at previous call, tau=value.
Constraint: if pn>0 then tau must be unchanged since previous call.
NE_REAL
On entry, i=value, z[i-1]=value and p=value.
Constraint: if ftype=Nag_Identity or Nag_AbsVal and z[i]=0 for any i then p>0.0.
On entry, i=value, z[i-1]=value, x[i-1]=value and p=value.
Constraint: if ftype=Nag_AbsDiff and z[i]=x[i] for any i then p>0.0.
On entry, p=value.
Constraint: absolute value of p must be representable as an integer.
On entry, p=value.
Constraint: if ftypeNag_Identity, p0.0. If ftype=Nag_Identity, the nearest integer to p must not be 0.
On entry, tau=value.
Constraint: tau>0.0.
NE_REAL_ARRAY
On entry, ftypeNag_Identity, j=value and sinit[j-1]=value.
Constraint: if ftypeNag_Identity, sinit[j-1]0.0, for j=2,3,,m2+2.
On entry, i=value, t[i-2]=value and t[i-1]=value.
Constraint: t[i-1]t[i-2] if linear interpolation is being used.
NW_OVERFLOW_WARN
Truncation occurred to avoid overflow, check for extreme values in t, z, x or for tau. Results are returned using the truncated values.

7  Accuracy

Not applicable.

8  Parallelism and Performance

nag_tsa_inhom_iema_all (g13mfc) is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
nag_tsa_inhom_iema_all (g13mfc) 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 Users' Note for your implementation for any additional implementation-specific information.

9  Further Comments

Approximately 4×m2 real elements are internally allocated by nag_tsa_inhom_iema_all (g13mfc).
The more data you supply to nag_tsa_inhom_iema_all (g13mfc) in one call, i.e., the larger nb is, the more efficient the routine will be.
Checks are made during the calculation of α and yi 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 fail.code= NW_OVERFLOW_WARN 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 m between 2 and 6.

10.1  Program Text

Program Text (g13mfce.c)

10.2  Program Data

Program Data (g13mfce.d)

10.3  Program Results

Program Results (g13mfce.r)


nag_tsa_inhom_iema_all (g13mfc) (PDF version)
g13 Chapter Contents
g13 Chapter Introduction
NAG Library Manual

© The Numerical Algorithms Group Ltd, Oxford, UK. 2014