naginterfaces.library.tsa.inhom_ma¶
- naginterfaces.library.tsa.inhom_ma(ma, t, tau, m1, m2, inter, ftype, p, sinit=None, pn=0, comm=None)[source]¶
inhom_ma
provides a moving average, moving norm, moving variance and moving standard deviation operator for an inhomogeneous time series.For full information please refer to the NAG Library document for g13mg
https://support.nag.com/numeric/nl/nagdoc_30.3/flhtml/g13/g13mgf.html
- Parameters
- mafloat, array-like, shape
, the current block of observations, for , where is the number of observations processed so far, i.e., the value supplied in on entry.
- tfloat, array-like, shape
, the times for the current block of observations, for , where is the number of observations processed so far, i.e., the value supplied in on entry.
If , = 31 will be returned, but
inhom_ma
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 .
- taufloat
, the parameter controlling the rate of decay. must be sufficiently large that , can be calculated without overflowing, for all , where .
- m1int
, the iteration of the EMA operator at which the sum is started.
- m2int
, the iteration of the EMA operator at which the sum is ended.
- interint, array-like, shape
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 .
- ftypeint
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 .
- pfloat
, the power used in the transformation function.
- sinitNone or float, array-like, shape , optional
Note: the required length for this argument is determined as follows: if : ; otherwise: .
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 , is not referenced.
- pnint, optional
, the number of observations processed so far. On the first call to
inhom_ma
, or when starting to summarise a new dataset, must be set to . On subsequent calls it must be the same value as returned by the last call toinhom_ma
.- commNone or dict, communication object, optional, modified in place
Communication structure.
On initial entry: need not be set.
- Returns
- mafloat, ndarray, shape
The moving average:
if or
,
otherwise
.
- pfloat
If , then , the actual power used in the transformation function is returned, otherwise is unchanged.
- pnint
, the updated number of observations processed so far.
- wmafloat, ndarray, shape
Either the moving average or exponential moving average, depending on the value of .
if or
otherwise
.
- Raises
- NagValueError
- (errno )
On entry, .
Constraint: .
- (errno )
On entry, , and .
Constraint: if linear interpolation is being used.
- (errno )
On entry, .
Constraint: .
- (errno )
On entry, .
On entry at previous call, .
Constraint: if then must be unchanged since previous call.
- (errno )
On entry, .
Constraint: .
- (errno )
On entry, .
On entry at previous call, .
Constraint: if then must be unchanged since previous call.
- (errno )
On entry, and .
Constraint: .
- (errno )
On entry, .
On entry at previous call, .
Constraint: if then must be unchanged since previous call.
- (errno )
On entry, , and .
Constraint: if , , for .
- (errno )
On entry, .
Constraint: , or .
- (errno )
On entry, .
Constraint: , or .
- (errno )
On entry, and .
On entry at previous call, , .
Constraint: if , must be unchanged since the last call.
- (errno )
On entry, .
Constraint: , , , or .
- (errno )
On entry, , On entry at previous call, .
Constraint: if , must be unchanged since the previous call.
- (errno )
On entry, .
Constraint: absolute value of must be representable as an integer.
- (errno )
On entry, .
Constraint: if , . If , the nearest integer to must not be .
- (errno )
On entry, , and .
Constraint: if , or and for any then .
- (errno )
On entry, , , and .
Constraint: if , , for any .
- (errno )
On entry, .
On exit from previous call, .
Constraint: if then must be unchanged since previous call.
- (errno )
On entry, .
Constraint: .
- (errno )
On entry, .
On exit from previous call, .
Constraint: if then must be unchanged since previous call.
- (errno )
[‘rcomm’] has been corrupted between calls.
- (errno )
On entry, , and .
Constraint: if , or .
- (errno )
On entry, , and .
Constraint: if , .
- Warns
- NagAlgorithmicWarning
- (errno )
On entry, , and .
Constraint: should be strictly increasing.
- (errno )
Truncation occurred to avoid overflow, check for extreme values in , or for .
- Notes
inhom_ma
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.
inhom_ma
gives the option of three interpolation methods:Previous point:
.
Linear:
.
Next point:
.
and three transformation functions:
Identity:
.
Absolute value:
.
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
inhom_ma
, a few of which are:Moving Average (MA), as defined in [equation] (obtained by setting and ).
Moving Norm (MNorm), defined as
(obtained by setting , and ).
Moving Variance (MVar), defined as
(obtained by setting , and ).
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
inhom_ma
called multiple times.
- 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