# How to simulate cointegrated prices

Is there any simple way to simulate cointegrated prices?

-
There are some previous questions about correlation rather than cointegration that may be helpful: How to simulate correlated assets for illustrating portfolio diversification? and How to generate a random price series with a specified range and correlation with an actual price? – chrisaycock♦ Aug 9 '12 at 13:52

2
One of the easier ways to think about it is simulating a bivariate VAR system in (ln) levels where there is contemporaneous correlation. So you would begin by simulating the correlated errors (per chrisaycock's link) and then add back in the autoregressive structure. This would give you the simulated log levels, so then just take $exp$ to convert to prices. – John Aug 9 '12 at 15:19
@John Could you please re-post your comment as an answer. – Tal Fishman Aug 9 '12 at 18:28

1
– user508 Aug 9 '12 at 19:13

## 2 Answers

One way to construct cointegrated timeseries it to use the error-correction representation (see Engle, Granger 1987 for details of the equivalence).

To generate two timeseries that are cointegrated, start with your cointegrating vector $(\alpha_1, \alpha_2)$ so that you want $\alpha_1x_t + \alpha_2y_t$ to be stationary; choose initial values $x_0, y_0$ and a parameter $\gamma\in (0,1)$ that controls how strongly cointegrated the series are. Then generate each timestep as:

$x_{t+1} = x_t - \gamma (x_t + (\alpha_2/\alpha_1)y_t) + \epsilon_{1t}$

$y_{t+1} = y_t - \gamma (y_t + (\alpha_1/\alpha_2)x_t) + \epsilon_{2t}$

For price series, it's generally the cumulative returns that you want to be cointegrated. To generate prices, as John mentioned in his comment above, follow the above procedure for log-prices, then exponentiate.

-

Consider a $T \times N$ matrix of potentially cointegrating prices $P$. Define $Y_{t}\equiv ln\left(P_{t}\right)$. In the multivariate framework, there are two basic methods to estimate the cointegrating relationships. The first is an error correction framework of the form $$\Delta Y_{t} = \beta_{0}+\beta_{1}\Delta Y_{t-1}+\beta_{2}Y_{t-1}+\varepsilon_{t}$$ that is most convenient when attempting to perform statistical tests on the coefficients. The alternate approach is a vector autoregressive model of the form $$Y_{t} = \beta_{0}+\beta_{1}Y_{t-1}+\varepsilon_{t}.$$ For the purposes of simulation, they are effectively equivalent. One must estimate $\beta_{0}$ and $\beta_{1}$ and solve for $\varepsilon_{t}$. There are many potential distribution assumptions that one could make about the behavior of $\varepsilon_{t}$, but a simple one would be that it follows a multivariate normal distribution with a mean of zero and a covariance matrix equal to the sample covariance matrix. More complicated assumptions might be that the variances and correlations are time-varying or that there are fat tails. For financial time series, these may be important to consider.

To simulate $\widetilde{Y}_{t+1}$, you thus obtain $\widetilde{\varepsilon}_{t+1}$ by whatever means are appropriate and calculate $$\widetilde{Y}_{t+1} = \beta_{0}+\beta_{1}Y_{t}+\widetilde{\varepsilon}_{t+1}$$

For $i>1$, one would need to be careful to incorporate the simulated values from the previous period so that $$\widetilde{Y}_{t+i} = \beta_{0}+\beta_{1}\widetilde{Y}_{t+i-1}+\widetilde{\varepsilon}_{t+i}$$ in order to ensure the autoregressive features in each simulated path.

After calculating the simulated values of $\widetilde{Y}_{t+i}$, one would want to convert them back to prices by calculating $\widetilde{P}_{t+i}\equiv \mathrm{exp}\left(\widetilde{Y}_{t+i}\right)$.

-
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 19, "mathjax_display_tex": 4, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.3, "absolute_threshold": 20, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "github"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "english_confidence": 0.9135063886642456, "perplexity_flag": "head"}