# Estimating Carma(2,1) parameters (using yuima package)

I am very new to R, and particularly to the yuima package, so I was hoping someone would be able to help me.

I have some data (daily prices) that I wish to fit to a Carma(2,1) model by estimating the parameters.

Suppose I have

d <- read.csv("http://chart.yahoo.com/table.csv?s=IBM&g=d&x=.csv")


What I then thought I should do is

y <- setYuima(data = setData(d$Close), model = setCarma(2,1)) x <- qmle(y, start = list(a1 = 1, a2 = 1, b0 = 1))  (but with some other parameters). However when I do this, I get the following error in the first (y <- ...) line: Error in if (dim(data@original.data)[2] == 1) { : argument is of length zero  I have no idea why this is, and what the setYuima function expects. Can anyone tell me how to do this? ## 1 Answer It is just a problem of how you pass times series to yuima. Just one more thing, if you want to estimate a CARMA driven by a Brownian motion, it is better to work with log-prices instead of prices. Indeed, in the considered model, we have a non zero probability assigned to negative values of the process. Try the following code require(yuima) library(xts) d <- read.csv("http://chart.yahoo.com/table.csv?s=IBM&g=d&x=.csv") head(d) tail(d) # data are reversed !!! take care, you need to handle data ibm <- xts(d$Close, order.by=as.Date(d\$Date, "%Y-%m-%d")) # this is too long
ibm <- ibm[time(ibm)>=as.Date("2007-01-03","%Y-%m-%d"),] # cut as above
# delta is very important in estimation set always to 1/252 for daily data
mydata3 <- setData(log(ibm)-rep(log(ibm[1]), dim(ibm)[1]),delta=1/252)
y3 <- setYuima(data = mydata3, model = setCarma(2,1))
x3 <- qmle(y3, start = list(a1 = 0.1, a2 = 0.1, b0 = 0.1,b1=0.1))
coef(x3)