Find $X_t = c_1 X_{t-1} + \dots + c_n X_{t-n} + n_t$ for given $c_i$, initial conditions $(X_1, \dots, X_n)$, and distribution for i.i.d. $n_t$.
I would like to know if there is a more efficient or elegant way to code this than using a for loop.
|
Find $X_t = c_1 X_{t-1} + \dots + c_n X_{t-n} + n_t$ for given $c_i$, initial conditions $(X_1, \dots, X_n)$, and distribution for i.i.d. $n_t$. I would like to know if there is a more efficient or elegant way to code this than using a for loop. |
|||||
|
|
Generating an autoregressive time series is not the same as "finding" it, since you have the parameters. If I understand you correctly, this is an application made for Here is a simple AR(1) process to illustrate the technique:
For example
For an AR($p$) process with $p>1$, something like this would work:
Where Multivariate processes (i.e. simulation of data from a VAR to get a vector of length $p$ at each time period) can be handled similarly except of course that
|
|||||||
|
|
A straightforward way would be using recursion and memoization. An example:
|
||||
|
|
|
I like @RM 's approach. Another one, with a more "mathematical" notation (but I must say I'm not certain of the random behaviour of the way I'm getting the numbers) could be the following First we create the discrete noise
Now, If you do Now, just use
|
|||
|
|