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

wob wu wobwu22 at yahoo.de
Thu Nov 19 15:06:17 CET 2009


I am sorry if this wasn't clear enough. The interpolation isn't the problem. The logic for it is stated below. I am looking for a faster/more elegant way to execute the loop and if statements given the logic in the loop.

--- Brian G. Peterson <brian at braverock.com> schrieb am Do, 19.11.2009:

> Von: Brian G. Peterson <brian at braverock.com>
> Betreff: Re: [R-SIG-Finance] Fast way of replacing missing data points in xts object
> An: "wob wu" <wobwu22 at yahoo.de>
> Datum: Donnerstag, 19. November 2009, 15:00
> wob wu wrote:
> > 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?
> >   
> See the list archives and the large variety of na
> interpolation actions in zoo.  They will work fine on
> your xts object.
> 
>    - Brian
> 
> -- Brian G. Peterson
> http://braverock.com/brian/
> Ph: 773-459-4973
> IM: bgpbraverock
> 
> 
> 






More information about the R-SIG-Finance mailing list