[R-SIG-Finance] Fast way of replacing missing data points in xts object

wob wu wobwu22 at yahoo.de
Thu Nov 19 14:55:12 CET 2009


Hello,
I keep on having the same problem over and over again and couldn't find a satisfying solution yet. I have some missing datapoints in my financial time series and am replacing them currently in the following way:

for (i in 2:length(SP$Far)) {
    if (is.na(SP$Far[i])) {SP$Far[i] <- as.numeric(SP$Far[i-1]) + (as.numeric(SP$Near[i])-as.numeric(SP$Near[i-1]))}
    if (is.na(SP$Near[i])) {SP$Near[i] <- as.numeric(SP$Near[i-1]) + (as.numeric(SP$Far[i])-as.numeric(SP$Far[i-1]))}
    if (is.na(SP$Vix[i])) {SP$Vix[i] <- as.numeric(SP$Vix[i-1])}    
}

SP is a xts object.

This works fine but is slow. Does anyone knows a better solution?

Thank you

Wob

-- 
Wob Wu



__________________________________________________
Do You Yahoo!?
Sie sind
Massenmails. 
http://mail.yahoo.com



More information about the R-SIG-Finance mailing list