[R] fitting Ornstein-Uhlenbeck process by MAXIMUM LIKELYHOOD

cesare orsini castjam at hotmail.it
Sat Jul 21 00:04:30 CEST 2012


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.......

ouFit.ML=function(spread) { 
  n=length(spread)
  delta=n/n 
  Sx=sum(spread[1:n-1]) 
  Sy=sum(spread[2: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.



More information about the R-help mailing list