NAG C Library Function Document
nag_tsa_inhom_ma (g13mgc)
1
Purpose
nag_tsa_inhom_ma (g13mgc) provides a moving average, moving norm, moving variance and moving standard deviation operator for an inhomogeneous time series.
2
Specification
#include <nag.h> |
#include <nagg13.h> |
void |
nag_tsa_inhom_ma (Integer nb,
double ma[],
const double t[],
double tau,
Integer m1,
Integer m2,
const double sinit[],
const Nag_TS_Interpolation inter[],
Nag_TS_Transform ftype,
double *p,
Integer *pn,
double wma[],
double rcomm[],
NagError *fail) |
|
3
Description
nag_tsa_inhom_ma (g13mgc) provides a number of operators 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 main operator available, the moving average (MA), with parameter
is defined as
where
,
and
are user-supplied integers controlling the amount of lag and smoothing respectively, with
and
is the iterated exponential moving average operator.
The iterated exponential moving average,
, is defined using the recursive formula:
with
and
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.
nag_tsa_inhom_ma (g13mgc) 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 addition, if either the absolute value or absolute difference transformation are used then the resulting moving average can be scaled by
.
The various parameter options allow a number of different operators to be applied by
nag_tsa_inhom_ma (g13mgc), a few of which are:
(i) |
Moving Average (MA), as defined in (1) (obtained by setting and ). |
(ii) |
Moving Norm (MNorm), defined as
(obtained by setting , and ). |
(iii) |
Moving Variance (MVar), defined as
(obtained by setting , and ). |
(iv) |
Moving Standard Deviation (MSD), defined as
(obtained by setting , and ). |
For large datasets or where all the data is not available at the same time, and can be split into arbitrary sized blocks and nag_tsa_inhom_ma (g13mgc) 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:
– 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
ma and
t can vary; therefore
nb can change between calls to
nag_tsa_inhom_ma (g13mgc).
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 moving average:
- if or
- ,
- otherwise
- .
- 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
nag_tsa_inhom_ma (g13mgc) will continue as if
was strictly increasing by using the absolute value. The lagged difference,
must be sufficiently small that
,
can be calculated without overflowing, for all
.
- 4:
– doubleInput
-
On entry: , the parameter controlling the rate of decay. must be sufficiently large that , can be calculated without overflowing, for all , where .
Constraint:
.
- 5:
– IntegerInput
-
On entry: , the iteration of the EMA operator at which the sum is started.
Constraint:
.
- 6:
– IntegerInput
-
On entry: , the iteration of the EMA operator at which the sum is ended.
Constraint:
.
- 7:
– const doubleInput
-
Note: the dimension,
dim, of the array
sinit
must be at least
- when or ;
- when , or ;
- sinit may be NULL when .
On entry: if
, the values used to start the iterative process, with
- ,
- ,
- , for .
In addition, if
or
then
- ,
-
, for .
i.e., initial values based on the original data
as opposed to the transformed data
.
If
,
sinit is not referenced and may be
NULL.
Constraint:
if , , for .
- 8:
– const Nag_TS_InterpolationInput
-
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 .
- 9:
– Nag_TS_TransformInput
-
On entry: the function type used to define the relationship between
and
when calculating
. Three functions are provided:
- The identity function, with .
- or
- The absolute value, with .
- or
- The absolute difference, with .
If
or
then the resulting vector of averages is scaled by
as described in
ma.
Constraint:
, , , or .
- 10:
– double *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:
.
- 11:
– Integer *Input/Output
-
On entry:
, the number of observations processed so far. On the first call to
nag_tsa_inhom_ma (g13mgc), 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
nag_tsa_inhom_ma (g13mgc).
On exit: , the updated number of observations processed so far.
Constraint:
.
- 12:
– doubleOutput
-
On exit: either the moving average or exponential moving average, depending on the value of
ftype.
- if or
-
- otherwise
- .
- 13:
– 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
nag_tsa_inhom_ma (g13mgc).
If
then
pn must be set to zero
and all the data must be supplied in one go.
- 14:
– NagError *Input/Output
-
The NAG error argument (see
Section 3.7 in How to Use the NAG Library and its Documentation).
6
Error Indicators and Warnings
- NE_ALLOC_FAIL
-
Dynamic memory allocation failed.
See
Section 2.3.1.2 in How to Use the NAG Library and its Documentation for further information.
- NE_BAD_PARAM
-
On entry, argument had an illegal value.
- NE_ILLEGAL_COMM
-
rcomm has been corrupted between calls.
- NE_INT
-
On entry, .
Constraint: .
On entry, .
Constraint: .
On entry, .
Constraint: .
- NE_INT_2
-
On entry, and .
Constraint: .
- 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.
See
Section 2.7.6 in How to Use the NAG Library and its Documentation for further information.
- NE_NO_LICENCE
-
Your licence key may have expired or may not have been installed correctly.
See
Section 2.7.5 in How to Use the NAG Library and its Documentation for further information.
- NE_NOT_STRICTLY_INCREASING
-
On entry,
,
and
.
Constraint:
t should be strictly increasing.
- NE_PREV_CALL
-
If
then
ftype must be unchanged since previous call.
If
then
inter must be unchanged since previous call.
On entry,
.
On entry at previous call,
.
Constraint: if
then
m1 must be unchanged since previous call.
On entry,
.
On entry at previous call,
.
Constraint: if
then
m2 must be unchanged since previous call.
On entry,
.
On exit from previous call,
.
Constraint: if
then
p 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, , and .
Constraint: if , or and for any then .
On entry, , , and .
Constraint: if , , for any .
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, .
Constraint: .
- NE_REAL_ARRAY
-
On entry, , and .
Constraint: if , , for .
On entry, , and .
Constraint: if linear interpolation is being used.
- NW_OVERFLOW_WARN
-
Truncation occurred to avoid overflow, check for extreme values in
t,
ma or for
tau. Results are returned using the truncated values.
7
Accuracy
Not applicable.
8
Parallelism and Performance
nag_tsa_inhom_ma (g13mgc) is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
nag_tsa_inhom_ma (g13mgc) 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.
Approximately
real elements are internally allocated by
nag_tsa_inhom_ma (g13mgc). If
or
then a further
nb real elements are also allocated.
The more data you supply to
nag_tsa_inhom_ma (g13mgc) in one call, i.e., the larger
nb is, the more efficient the function will be.
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
NW_OVERFLOW_WARN is returned. This should not occur in standard usage and will only occur if extreme values of
ma,
t or
tau are supplied.
10
Example
The example reads in a simulated time series, and calculates the moving average. The data is supplied in three blocks of differing sizes.
10.1
Program Text
Program Text (g13mgce.c)
10.2
Program Data
Program Data (g13mgce.d)
10.3
Program Results
Program Results (g13mgce.r)