1.4.2 Generating Time SeriesSometimes we may need to generate a time series {x1, x2, ... , xn} from a given process in order to explore it theoretically or gain intuition about it. The simplest time series is a sequence of independently and identically distributed (IID) random numbers. We can use the function RandomSequence[,"""2", n] to generate a sequence of n random numbers distributed according to the normal distribution with mean and variance 2. Example 4.4 Generate a random sequence of length 6 distributed according to the normal distribution with mean =0 and variance 2=1 ( i.e., N(0, 1)). This generates a random sequence of length 6. Out[19]= | |
It is usually a good idea to seed the random number generator using SeedRandom[seed] before generating any random numbers so the calculation can be repeated if necessary. Example 4.5 Generate a tri-variate random sequence of length 5 distributed normally with mean ={0, 1, 0.5} and the covariance matrix ={{1, 0.5, 0}, {0.5, 1.2, 0.8}, {0, 0.8, 1.5}}. The random number generator is seeded first. This generates the random sequence. Out[21]= | |
Note that we have used SeedRandom so the above series can be reproduced if so desired. We reiterate that the covariance matrix must be a symmetric, positive definite matrix. Otherwise no random numbers will be generated. No random numbers are generated when the covariance matrix is not symmetric or positive definite. Out[22]= | |
Internally, RandomSequence uses RandomReal to generate a univariate random sequence of length n. The current default random number generator is used. Sequences generated prior to Version 6.0 of Mathematica can be obtained by including the option LegacySequence→True. We can similarly generate univariate random sequences according to the distributions of our choice. Please consult the Mathematica documentation for distributions included with Mathematica.
To generate a time series of length n, {x1, x2, ... , xn}, according to one of the models defined in earlier sections, we can use the function It generates the series by iterating The noise {zt} is generated from the normal distribution with zero mean and variance or covariance specified in model. For models with p≠0, p random numbers from the same distribution as the noise are used as the initial values {x-p+1, x-p+2, ... , x0}. We can also generate time series with specified initial values of the series using and with a specified noise sequence {z-q+1, z-q+2, ... , zn} using Note that both the p initial values and the noise sequence are enclosed in lists. For an m-variate series each xi or zi is a list of m numbers. Like RandomSequence, TimeSeries uses the current default random number generator. Series generated prior to Version 6.0 of Mathematica can be obtained by including the option LegacySequence→True. Example 4.6 Generate a time series of length 10 according to the ARIMA( 2, 1, 1) model (1-B)(1-0.5B+0.8B2)Xt=(1-0.5B)Zt where the noise variance is 1.2. The random number generator is seeded first. This generates the time series of length 10 from the given ARIMA( 2, 1, 1) model. Out[24]= | |
We can also generate a time series with a specified noise sequence. Here we generate a random sequence of length 9 distributed uniformly on the interval [-1, 1]. Out[25]= | |
This generates a time series with the noise sequence generated above. Note that here the noise variance can be omitted in the argument of the model object. Out[26]= | |
Example 4.7 Generate a bivariate AR(1) series of length 6 with 1={{0.3, -0.4}, {0.2, 1.2}}, noise covariance ={{0.5, 0.2}, {0.2, 1}}, and initial value x0={0.5, -0.1}. The random number generator is seeded first. We generate the required bivariate AR(1) time series of length 6. Note that the initial value x0 is enclosed in a list. Out[28]= | |
|