[R-SIG-Finance] expanding xts object - adding a day

Brian G. Peterson brian at braverock.com
Mon Oct 31 14:10:07 CET 2011


On Mon, 2011-10-31 at 13:58 +0100, Martin Bauer wrote:
> Hi Brian,
> 
> yes rbind finally but I thinking of something like this - not sure if that could lead to a solution


<snipped because it doesn't make any sense>

> I'm lost at this point

Clearly.

> getSymbols('SPY')
[1] "SPY"
> tail(SPY)
           SPY.Open SPY.High SPY.Low SPY.Close SPY.Volume SPY.Adjusted
2011-10-21   123.09   124.12  122.72    123.97  278872100       123.97
2011-10-24   124.17   125.80  124.06    125.49  202862400       125.49
2011-10-25   124.89   124.95  122.78    123.05  268433100       123.05
2011-10-26   124.35   124.77  122.21    124.30  288818700       124.30
2011-10-27   127.63   129.42  124.32    128.63  389788900       128.63
2011-10-28   128.00   128.85  127.80    128.60  225638800       128.60

>SPY<-rbind(SPY,xts(matrix(c(126.5,126.6,126.425,126.55,NA,NA),nrow=1),order.by=as.Date(Sys.Date())))

> tail(SPY)
           SPY.Open SPY.High SPY.Low SPY.Close SPY.Volume SPY.Adjusted
2011-10-24   124.17   125.80 124.060    125.49  202862400       125.49
2011-10-25   124.89   124.95 122.780    123.05  268433100       123.05
2011-10-26   124.35   124.77 122.210    124.30  288818700       124.30
2011-10-27   127.63   129.42 124.320    128.63  389788900       128.63
2011-10-28   128.00   128.85 127.800    128.60  225638800       128.60
2011-10-31   126.50   126.60 126.425    126.55         NA           NA

You don't need anything other than rbind and xts.

-- 
Brian



More information about the R-SIG-Finance mailing list