Variance in Ornstein Uhlenbeck process

14 views (last 30 days)
Adam Calhoun
Adam Calhoun on 27 Sep 2012
I don't know if anyone here will be able to help me, but I'm trying to simulate an Ornstein Uhlenbeck process using the code found here:
X_free = cumsum(sqrt(2*D*dt)*randn(size(t)));
X_filt = filter([0 g*dt], [1 -1+g*dt] , X_free);
X_OU = X_free-X_filt;
Here, D is the diffusion constant and g is the rate of mean reversion. I know that the variance in the process should be:
(2*D / (2*g)) * (1 - exp(-2*g*t)
(See, for example But this seems to not work; for example, when D=.1, g=.01, and t = 1:10000, the variance in the process is roughly ~7.5 (on average), when the equation says that it should be 10. Anyone have any idea why I'm getting a different variance than expected?

Answers (1)

Ben Petschel
Ben Petschel on 29 Sep 2012
That's an interesting method, though it's not obvious to me how it works and I couldn't see any reference to it in the planet math article. I would first check that X_OU returns exactly the same value when calculated by a simple FOR loop using the same randn values.
Failing that, I would check that dt is small enough for accurate results, and that you are calculating the variance of the values X_OU(end) returned from multiple runs (not the variance of X_OU).

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!