randomArma

Generates a time series from a specific ARMA model.

Synopsis

randomArma (nObservations, ar, ma)

Required Arguments

int nObservations (Input)
Number of observations to be generated. Parameter nObservations must be greater than or equal to one.
float ar[] (Input)
Array of length p containing the autoregressive parameters.
float ma[] (Input)
Array of length q containing the moving average parameters.

Return Value

An array of length nObservations containing the generated time series.

Optional Arguments

armaConstant, float (Input)

Overall constant. See Description.

Default: armaConstant = 0.

varNoise, float (Input)

If varNoise is specified (and inputNoise is not specified) the noise \(a_t\) will be generated from a normal distribution with mean 0 and variance varNoise.

Default: varNoise = 1.0

or

inputNoise, float (Input)
If inputNoise is specified, the user will provide an array of length nObservations + max (nonzeroMalags[i]) containing the random noises. If this option is specified, then varNoise should not be specified (a warning message will be issued and the option varNoise will be ignored).
outputNoise, float (Output)
An an array of length nObservations + max (nonzeroMalags[i]) containing the random noises.
nonzeroArlags, int[] (Input)

An array of length p containing the order of the nonzero autoregressive parameters.

Default: nonzeroArlags = [1, 2, …, p]

nonzeroMalags, int (Input)

An array of length q containing the order of the nonzero moving average parameters.

Default: nonzeroMalags = [1, 2, …, q]

initialW, float[] (Input)

Array of length max (nonzeroArlags[i]) containing the initial values of the time series.

Default: all the elements in initialW = armaConstant/(1 − ar [0] − ar [1] − … − ar [p − 1])

acceptRejectMethod, (Input)
If acceptRejectMethod is specified, the random noises will be generated from a normal distribution using an acceptance/rejection method. If acceptRejectMethod is not specified, the random noises will be generated using an inverse normal CDF method. This argument will be ignored if inputNoise is specified.

Description

Function randomArma simulates an \(\text{ARMA}(p,q)\) process, \(\{W_t\}\), for \(t=1,2,\ldots,n\) (with n = nObservations, p = p, and q = q). The model is

\[\begin{split}\begin{array}{l} \phi(B) W_t = \theta_0 + \theta(B) A_t \phantom{...} t \in Z \\ \phi(B) = 1 - \phi_1B - \phi_2B^2 - \ldots - \phi_pB^P \\ \theta(B) = 1 - \theta_1B - \theta_2B^2 - \ldots - \theta_qB^q \end{array}\end{split}\]

Let μ be the mean of the time series \(\{W_t\}\). The overall constant \(\theta_0\) (armaConstant) is

\[\begin{split}\theta_0 = \begin{cases} \mu & p = 0 \\ \mu\left(1 = \sum\nolimits_{i=1}^{p} \phi_i\right) & p > 0 \end{cases}\end{split}\]

Time series whose innovations have a nonnormal distribution may be simulated by providing the appropriate innovations in inputNoise and start values in initialW.

The time series is generated according to the following model:

\[X[i] = \texttt{armaConstant} + \texttt{ar[0]} ∙ X[i − \texttt{nonzeroArlags[0]} ] + … +\]
\[\texttt{ar[p} − \texttt{1]} ∙ X[i − \texttt{nonzeroArlags[p} − \texttt{1]} ] +\]
\[A[i] − \texttt{ma[0]} ∙ A[i − \texttt{nonzeroMalags[0]} ] − … −\]
\[\texttt{ma[q} − \texttt{1]} ∙ A[i − \texttt{nonzeroMalags[q} − \texttt{1]} ]\]

where the constant is related to the mean of the series,

\[\overline{W}\]

as follows:

\[\mathtt{constant} = \overline{W} \cdot (1 - \mathtt{ar}[0] - \ldots - \mathtt{ar}[q-11])\]

and where

\[X[t] = W[t], t = 0, 1, …, \texttt{nObservation}s − 1\]

and

\[W[t] = \texttt{initialW}[t + p],     t = −p, −p + 1, …, −2, −1\]

and A is either inputNoise (if inputNoise is specified) or outputNoise (otherwise).

Examples

Example 1

In this example, randomArma is used to generate a time series of length five, using an ARMA model with three autoregressive parameters and two moving average parameters.

from numpy import *
from pyimsl.stat.randomSeedSet import randomSeedSet
from pyimsl.stat.randomArma import randomArma
from pyimsl.stat.writeMatrix import writeMatrix

n_random = 5
np = 3
phi = [0.5, 0.25, 0.125]
nq = 2
theta = [-0.5, -0.25]
randomSeedSet(123457)
r = randomArma(n_random, phi, theta)
writeMatrix("ARMA random deviates:", r, noColLabels=True)

Output

 
                     ARMA random deviates:
      0.863        0.809        1.904        0.110        2.266

Example 2

In this example, a time series of length 5 is generated using an ARMA model with 3 autoregressive parameters and 2 moving average parameters. The start values are 0.1, 0.05 and 0.0375. Constant and noise are also input.

from numpy import *
from pyimsl.stat.randomArma import randomArma
from pyimsl.stat.randomSeedSet import randomSeedSet
from pyimsl.stat.writeMatrix import writeMatrix

n_random = 5
np = 3
phi = [0.5, 0.25, 0.125]
nq = 2
theta = [-0.5, -0.25]
wi = [0.1, 0.05, 0.0375]
theta0 = 1.0
avar = 0.1
randomSeedSet(123457)
r = randomArma(n_random, phi, theta,
               acceptRejectMethod=True,
               initialW=wi,
               armaConstant=theta0,
               varNoise=avar)
writeMatrix("ARMA random deviates:", r, noColLabels=True)

Output

 
                     ARMA random deviates:
      1.403        2.220        2.286        2.888        2.832

Warning Errors

IMSLS_RNARM_NEG_VAR VAR(a) = “varNoise” = #, VAR(a) must be greater than 0. The absolute value of # is used for VAR(a).
IMSLS_RNARM_IO_NOISE Both inputNoise and outputNoise are specified. inputNoise is used.