statsmodels.tsa.arima_process.arma_generate_sample

statsmodels.tsa.arima_process.arma_generate_sample(ar, ma, nsample, sigma=1, distrvs=<built-in method randn of mtrand.RandomState object>, burnin=0)[source]

Generate a random sample of an ARMA process

Parameters
ararray_like, 1d

coefficient for autoregressive lag polynomial, including zero lag

maarray_like, 1d

coefficient for moving-average lag polynomial, including zero lag

nsampleint

length of simulated time series

sigmafloat

standard deviation of noise

distrvsfunction, random number generator

function that generates the random numbers, and takes sample size as argument default: np.random.randn TODO: change to size argument

burnininteger

Burn in observations at the generated and dropped from the beginning of the sample

Returns
samplearray

sample of ARMA process given by ar, ma of length nsample

Notes

As mentioned above, both the AR and MA components should include the coefficient on the zero-lag. This is typically 1. Further, due to the conventions used in signal processing used in signal.lfilter vs. conventions in statistics for ARMA processes, the AR parameters should have the opposite sign of what you might expect. See the examples below.

Examples

>>> import numpy as np
>>> np.random.seed(12345)
>>> arparams = np.array([.75, -.25])
>>> maparams = np.array([.65, .35])
>>> ar = np.r_[1, -arparams] # add zero-lag and negate
>>> ma = np.r_[1, maparams] # add zero-lag
>>> y = sm.tsa.arma_generate_sample(ar, ma, 250)
>>> model = sm.tsa.ARMA(y, (2, 2)).fit(trend='nc', disp=0)
>>> model.params
array([ 0.79044189, -0.23140636,  0.70072904,  0.40608028])