I have mean reverting data (Difference of 2 stock prices, that I want to do pairs trading on). I want to simulate my own mean reverting data as similar as possible to the real data that I have.

The approach that I want to take is Least Squares Regression. Maximum Likelihood is too complicated.

Thank you all.


3 Answers 3


Similar to Juan Gil's answer but a bit differently I would say the following based on this:

The OU process $$dX_t = \kappa(\theta-X_t)dt + \sigma dW_t$$ can be (Euler-Maryuama discretization) discretized at times $n \Delta t,n=1,\ldots,\infty $ which gives with $t = k \Delta t$ $$ X_{k+1} - X_k = \kappa \theta \Delta t -\kappa X_k \Delta t + \sigma (W_{k+1} - W_k), $$ rearranging and setting $\sigma (W_{k+1} - W_k) = \sigma \sqrt{\Delta t} \epsilon_k $ we get: $$ X_{k+1} = \kappa \theta \Delta t - (\kappa \Delta t - 1) X_k + \sigma \sqrt{\Delta t} \epsilon_k. $$ So you can model an AR(1) process and then identify the parameters using the equation above.

Thinking about it again one can probably leave $X_{k+1} - X_k$ on the lhs and then one simply does a regression but I don't know exactly about the error terms in this case.

I have found this with R code, there an MLE approach is used. You find various solutions in this Stack Overflow question.


For a Ornstein-Uhlenbeck process, the maximum likelihood parameters are the ones from least squares regression.

If your process is:

$$ dX=\kappa (\theta-X)dt+\sigma dW $$

you can do a linear regression in the form

$$ \frac{dX}{dt}=a+bX+\epsilon $$

So your parameters will be:

$$ \kappa=-b $$

$$ \theta=-\frac{a}{b} $$

$$ \sigma=std(\epsilon dt) $$

  • $\begingroup$ After reading Richard's answer I've done a small edition in mine: each $\epsilon$ has to be multiplied by its $dt$ (especially if not all the $dt$ in your data are equal) to get the right volatility (the result would be in the units you are measuring $dt$) $\endgroup$ Commented Apr 1, 2015 at 15:36
  • 1
    $\begingroup$ I know this is old, but doesn't Juan mean to divide each $\epsilon$ by $dt$, not times? Since each error is $N(0,\sigma^2 dt)$ we should be correcting for this by division, surely? $\endgroup$
    – Patty
    Commented Jul 24, 2017 at 21:59

The previous estimator relying on regression is effective only when the degree of mean reversion is sufficiently high that the influence of volatility noise on the calculation is minimal. However, an alternative method proposed by Falk, based on robust statistics, is designed to operate effectively even in the presence of real-world data.[Falk, 1997] Falk, M. (1997). On mad and comedians. Annals of the Institute of Statistical Mathematics, 49(4):615–644.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.