[R-SIG-Finance] insert element in IBrokers/XTS time series?

Jeff Ryan jeff.a.ryan at gmail.com
Mon Jul 6 15:54:49 CEST 2009


If you are simply looking to make an irregular series 'regular' per
some time-scale (e.g. days), you can merge with a zero-width xts
object or a time-based vector:

?merge.xts and example(merge.xts) will give you some tips.

> reg.time <- timeBasedSeq('20090625/20090703')    # creates a 'Date' vector, use retclass to override if needed
> reg.time
[1] "2009-06-25" "2009-06-26" "2009-06-27" "2009-06-28" "2009-06-29"
[6] "2009-06-30" "2009-07-01" "2009-07-02" "2009-07-03"

# get some daily data
> getSymbols("AAPL", from='2009-06-25')
> AAPL
           AAPL.Open AAPL.High AAPL.Low AAPL.Close AAPL.Volume AAPL.Adjusted
2009-06-25    135.75    140.20   135.21     139.86    21051700        139.86
2009-06-26    139.79    143.56   139.74     142.44    15692300        142.44
2009-06-29    143.46    143.95   141.54     141.97    20272000        141.97
2009-06-30    142.58    143.80   141.80     142.43    15508000        142.43
2009-07-01    143.50    144.66   142.52     142.83    14792100        142.83
2009-07-02    141.25    142.83   139.79     140.02    13231400        140.02

> merge(AAPL,reg.time)
           AAPL.Open AAPL.High AAPL.Low AAPL.Close AAPL.Volume AAPL.Adjusted
2009-06-25    135.75    140.20   135.21     139.86    21051700        139.86
2009-06-26    139.79    143.56   139.74     142.44    15692300        142.44
2009-06-27        NA        NA       NA         NA          NA            NA
2009-06-28        NA        NA       NA         NA          NA            NA
2009-06-29    143.46    143.95   141.54     141.97    20272000        141.97
2009-06-30    142.58    143.80   141.80     142.43    15508000        142.43
2009-07-01    143.50    144.66   142.52     142.83    14792100        142.83
2009-07-02    141.25    142.83   139.79     140.02    13231400        140.02
2009-07-03        NA        NA       NA         NA          NA            NA

HTH,
Jeff
On Fri, Jul 3, 2009 at 7:01 PM, Michael<comtech.usa at gmail.com> wrote:
> Hi all,
>
> Let's say I have the following timeseres in IBrokers and XTS:
>
> 2009-06-25      18038      18350     18011       18327         5396     18183
> 2009-06-26      18420      18708     18331       18515         7367     18499
> 2009-06-29      18546      18688     18423       18577        28728     18555
> 2009-07-03      17951      18198     17866       18149        38019     18059
>
> I want to add a few more rows, indexed by
>
> "2009-06-30", "2009-07-01", "2009-07-02", and using NA's,
>
> I did the following:
>
> myhist["2009-07-01",]=c(NA, NA, NA, NA, NA, NA, NA, NA)
>
> But it didn't really work.
>
> What's the good way to insert missing points in time series?
>
> Thanks!
>
> _______________________________________________
> R-SIG-Finance at 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.
>



-- 
Jeffrey Ryan
jeffrey.ryan at insightalgo.com

ia: insight algorithmics
www.insightalgo.com



More information about the R-SIG-Finance mailing list