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?


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

d <- read.csv("http://chart.yahoo.com/table.csv?s=IBM&g=d&x=.csv")
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))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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