/* nag_rngs_arma_time_series (g05pac) Example Program. * * Copyright 2001 Numerical Algorithms Group. * * Mark 7, 2001. */ #include #include #include #include int main(void) { /* Scalars */ double avar, var, xmean; Integer i, igen, ip, iq, n, nr; Integer exit_status = 0; NagError fail; /* Arrays */ double *phi = 0, *r = 0, *theta = 0, *x = 0; Integer iseed[4]; INIT_FAIL(fail); printf( "nag_rngs_arma_time_series (g05pac) Example Program Results\n\n"); ip = 2; iq = 0; n = 10; nr = ip+iq+5+ip; /* allocate memory */ if (!(phi = NAG_ALLOC(ip, double)) || !(r = NAG_ALLOC(nr, double)) || !(theta = NAG_ALLOC(1, double)) || !(x = NAG_ALLOC(n, double))) { printf("Allocation failure\n"); exit_status = -1; goto END; } /* Set the ARMA model parameters */ xmean = 0.0; phi[0] = 0.4; phi[1] = 0.2; avar = 1.0; /* Initialise the seed to a repeatable sequence */ iseed[0] = 1762543; iseed[1] = 9324783; iseed[2] = 4234401; iseed[3] = 742355; /* igen identifies the stream. */ igen = 1; /* nag_rngs_init_repeatable (g05kbc). * Initialize seeds of a given generator for random number * generating functions (that pass seeds explicitly) to give * a repeatable sequence */ nag_rngs_init_repeatable(&igen, iseed); /* Set up the reference vector */ /* nag_rngs_arma_time_series (g05pac). * Generates a realization of a time series from an ARMA * model */ nag_rngs_arma_time_series(0, xmean, ip, phi, iq, theta, avar, &var, n, x, igen, iseed, r, &fail); if (fail.code != NE_NOERROR) { printf("Error from nag_rngs_arma_time_series (g05pac).\n%s\n", fail.message); exit_status = 1; goto END; } /* Generate a sample of 10 observations */ /* nag_rngs_arma_time_series (g05pac), see above. */ nag_rngs_arma_time_series(1, xmean, ip, phi, iq, theta, avar, &var, n, x, igen, iseed, r, &fail); if (fail.code != NE_NOERROR) { printf("Error from nag_rngs_arma_time_series (g05pac).\n%s\n", fail.message); exit_status = 1; goto END; } for (i = 0; i < n; ++i) { printf("%12.4f\n", x[i]); } END: if (phi) NAG_FREE(phi); if (r) NAG_FREE(r); if (theta) NAG_FREE(theta); if (x) NAG_FREE(x); return exit_status; }