# [R] fitting Ornstein-Uhlenbeck process by MAXIMUM LIKELYHOOD

Sat Jul 21 10:54:11 CEST 2012

```Hello,

When computing Sxx, Syy and you are mistaking the square of the sum for
the sum of squares. The same goes for the crossed term Sxy, it's the sum
of the products, not the product of the sums Sx and Sy.

Hope this helps,

Em 20-07-2012 23:04, cesare orsini escreveu:
> Dear friends
>
> i am trying to fit an Ornstein-Uhlenbeck process by MAXIMUM LIKELYHOOD
> method.
>
> i found these formulas on
> http://www.sitmo.com/article/calibrating-the-ornstein-uhlenbeck-model/
> this is the mean-reverting process
>
> http://r.789695.n4.nabble.com/file/n4637271/process.txt process.txt
>
> and this is the script that i am using.......
>
>    delta=n/n
>    Sxx=(Sx)^2
>    Syy=(Sy)^2
>    Sxy=Sx*Sy
>    mu = (Sy*Sxx - Sx*Sxy) / ( n*(Sxx - Sxy) - (Sx^2 - Sx*Sy) )
>    lambda = -log( (Sxy - mu*Sx - mu*Sy + n*mu^2) / (Sxx -2*mu*Sx + n*mu^2)
> )/delta
>    a = exp(-lambda*delta)
>    sigmah2 = (Syy - 2*a*Sxy + a^2*Sxx - 2*mu*(1-a)*(Sy - a*Sx) +
> n*mu^2*(1-a)^2)/n;
>    sigma = sqrt((sigmah2)*2*lambda/(1-a^2))
>    theta=list(lambda=lambda, mu=mu,sigma=sigma,sigmah2=sigmah2)
>    return(theta)
> }
>
> where is my error?
> is there some other script to obtain a good result by the same method?
>
> thank you!!! :-)
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/fitting-Ornstein-Uhlenbeck-process-by-MAXIMUM-LIKELYHOOD-tp4637271.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

```