Generates a time series from a specific ARMA model.
#include <imsls.h>
float *imsls_f_random_arma (int n_observations, int p, float ar[], int q, float ma[], ..., 0)
The type double function is imsls_d_random_arma.
int
n_observations (Input)
Number
of observations to be generated. Parameter n_observations must be greater than or equal to one.
int
p (Input)
Number of
autoregressive parameters. Paramater p must be greater than or equal to zero.
float
ar[] (Input)
Array of length
p containing the autoregressive parameters.
int
q (Input)
Number of moving
average parameters. Parameter q must be greater than or equal to zero.
float ma[]
(Input)
Array of length q containing the moving average parameters.
An array of length n_observations containing the generated time series.
#include <imsls.h>
float
*imsls_f_random_arma (int
n_observations,
int
p,
float
ar[],
int q,
float ma[],
IMSLS_ARMA_CONSTANT,
float
constant,
IMSLS_VAR_NOISE,
float
*a_variance,
IMSLS_INPUT_NOISE,
float
*a_input,
IMSLS_OUTPUT_NOISE,
float
**a_return,
IMSLS_OUTPUT_NOISE_USER,
float
a_return[],
IMSLS_NONZERO_ARLAGS,
int
*ar_lags,
IMSLS_NONZERO_MALAGS,
int
*ma_lags,
IMSLS_INITIAL_W,
float
*w_initial,
IMSLS_ACCEPT_REJECT_METHOD,
IMSLS_RETURN_USER,
float w[],
0)
IMSLS_ARMA_CONSTANT, float constant
(Input)
Overall constant. See “Description”.
Default: constant =
0.
IMSLS_VAR_NOISE, float
a_variance (Input)
If IMSLS_VAR_NOISE is
specified (and IMSLS_INPUT_NOISE is
not specified) the noise at will be generated from a normal
distribution with mean 0 and variance a_variance.
Default:
a_variance =
1.0
IMSLS_INPUT_NOISE, float *a_input
(Input)
If IMSLS_INPUT_NOISE is
specified, the user will provide an array of length n_observations +
max (ma_lags[i])
containing the random noises. If this option is specified, then IMSLS_VAR_NOISE should
not be specified (a warning message will be issued and the option IMSLS_VAR_NOISE will
be ignored).
IMSLS_OUTPUT_NOISE, float
**a_return (Output)
An address of a pointer to an
internally allocated array of length n_observations + max
(ma_lags[i])
containing the random noises.
IMSLS_OUTPUT_NOISE_USER, float
a_return[] (Output)
Storage for array a_return is provided
by user. See IMSLS_OUTPUT_NOISE.
IMSLS_NONZERO_ARLAGS, int ar_lags[]
(Input)
An array of length p containing the order
of the nonzero autoregressive parameters.
Default: ar_lags = [1,
2, ..., p]
IMSLS_NONZERO_MALAGS, int ma_lags
(Input)
An array of length q containing the order
of the nonzero moving average parameters.
Default: ma_lags = [1, 2, ...,
q]
IMSLS_INITIAL_W, float
w_initial[] (Input)
Array of length max (ar_lags[i])
containing the initial values of the time series.
Default: all the elements
in w_initial =
constant/(1 − ar [0] − ar [1] − … − ar [p − 1])
IMSLS_ACCEPT_REJECT_METHOD
(Input)
If IMSLS_ACCEPT_REJECT_METHOD
is specified, the random noises will be generated from a normal distribution
using an acceptance/rejection method. If IMSLS_ACCEPT_REJECT_METHOD
is not specified, the random noises will be generated using an inverse
normal CDF method. This argument will be ignored if IMSLS_INPUT_NOISE is
specified.
IMSLS_RETURN_USER, float r[]
(Output)
User-supplied array of length n_random containing
the generated time series.
Function imsls_f_random_arma simulates an ARMA(p, q) process, {Wt}, for t = 1, 2, ..., n (with n = n_observations, p = p, and q = q). The model is
Let μ be the mean of the time series {Wt}. The overall constant θ0 (constant) is
Time series whose innovations have a nonnormal distribution may be simulated by providing the appropriate innovations in a_input and start values in w_initial.
The time series is generated according to the followng model:
X[i] = constant + ar[0] ∙ X[i − ar_lags[0] ] + … +
ar[p − 1] ∙ X[i − ar_lags[p − 1] ] +
A[i] − ma[0] ∙ A[i − ma_lags[0] ] − … −
ma[q − 1] ∙ A[i − ma_lags[q − 1] ]
where the constant is related to the mean of the series,
as follows:
and where
X[t] = W[t], t = 0, 1, …, n_observations − 1
and
W[t] = w_initial[t + p], t = −p, −p + 1, …, −2, −1
and A is either a_input (if IMSLS_INPUT_NOISE is specified) or a_return (otherwise).
In this example, imsls_f_random_arma is used to generate a time series of length five, using an ARMA model with three autoregressive parameters and two moving average parameters. The start values are 0.1000, 0.0500, and 0.0375.
#include <stdio.h>
#include <imsls.h>
int main()
{
int n_random = 5;
int np = 3;
float phi[3] = {0.5, 0.25, 0.125};
int nq = 2;
float theta[2] = {-0.5, -0.25};
float *r;
imsls_random_seed_set(123457);
r = imsls_f_random_arma(n_random, np, phi, nq, theta, 0);
imsls_f_write_matrix("ARMA random deviates:",
1, n_random, r, IMSLS_NO_COL_LABELS, 0);
}
ARMA random deviates:
0.863 0.809 1.904 0.110 2.266
In this example, a time series of length 5 is generated using an ARMA model with 4 autoregressive parameters and 2 moving average parameters. The start values are 0.1, 0.05 and 0.0375.
#include <stdio.h>
#include <imsls.h>
int main()
{
int n_random = 5;
int np = 3;
float phi[3] = {0.5, 0.25, 0.125};
int nq = 2;
float theta[2] = {-0.5, -0.25};
float wi[3] = {0.1, 0.05, 0.0375};
float theta0 = 1.0;
float avar = 0.1;
float *r;
imsls_random_seed_set(123457);
r = imsls_f_random_arma(n_random, np, phi, nq, theta,
IMSLS_ACCEPT_REJECT_METHOD,
IMSLS_INITIAL_W, wi,
IMSLS_ARMA_CONSTANT, theta0,
IMSLS_VAR_NOISE, avar,
0);
imsls_f_write_matrix("ARMA random deviates:",
1, n_random, r, IMSLS_NO_COL_LABELS, 0);
}
ARMA random deviates:
1.403 2.220 2.286 2.888 2.832
IMSLS_RNARM_NEG_VAR VAR(a) = “a_variance” = #, VAR(a) must be greater than 0. The absolute value of # is used for VAR(a).
IMSLS_RNARM_IO_NOISE Both IMSLS_INPUT_NOISE and IMSLS_OUTPUT_NOISE are specified. IMSLS_INPUT_NOISE is used.