[prev in list] [next in list] [prev in thread] [next in thread] 

List:       r-sig-finance
Subject:    Re: [R-SIG-Finance] Fast way of replacing missing data points
From:       Benczik Sandor <sandor.benczik () crabel ! ro>
Date:       2009-11-19 17:25:03
Message-ID: 1258651503.3341.23.camel () localhost ! localdomain
[Download RAW message or body]

For the first one try something along the lines:

replacement.far <- lag(SP$Far) + SP$Near - lag(SP$Near)
SP$Far[is.na(SP$Far)] <- replacement.far[is.na(SP$Far)]

The last one is simple locf as Brian said. 

HTH,
Sandor


On Thu, 2009-11-19 at 14:06 +0000, wob wu wrote:
> 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@braverock.com> schrieb am Do, 19.11.2009:
> 
> > Von: Brian G. Peterson <brian@braverock.com>
> > Betreff: Re: [R-SIG-Finance] Fast way of replacing missing data points in xts \
> >                 object
> > An: "wob wu" <wobwu22@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
> > 
> > 
> > 
> 
> 
> 
> 
> _______________________________________________
> R-SIG-Finance@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only.
> -- If you want to post, subscribe first.

_______________________________________________
R-SIG-Finance@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
-- Subscriber-posting only.
-- If you want to post, subscribe first.


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic