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
nObservationsmust be greater than or equal to one. - float
ar[](Input) - Array of length
pcontaining the autoregressive parameters. - float
ma[](Input) - Array of length
qcontaining 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
varNoiseis specified (andinputNoiseis not specified) the noise \(a_t\) will be generated from a normal distribution with mean 0 and variancevarNoise.Default:
varNoise= 1.0
or
inputNoise, float (Input)- If
inputNoiseis specified, the user will provide an array of lengthnObservations+ max (nonzeroMalags[i]) containing the random noises. If this option is specified, thenvarNoiseshould not be specified (a warning message will be issued and the optionvarNoisewill 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
pcontaining the order of the nonzero autoregressive parameters.Default:
nonzeroArlags= [1, 2, …,p]nonzeroMalags, int (Input)An array of length
qcontaining 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
acceptRejectMethodis specified, the random noises will be generated from a normal distribution using an acceptance/rejection method. IfacceptRejectMethodis not specified, the random noises will be generated using an inverse normal CDF method. This argument will be ignored ifinputNoiseis 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
Let μ be the mean of the time series \(\{W_t\}\). The overall constant
\(\theta_0\) (armaConstant) is
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:
where the constant is related to the mean of the series,
as follows:
and where
and
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. |