[R-SIG-Finance] expanding xts object - adding a day
Hans Grapenthin
hans at grapenthin.net
Sun Nov 6 18:37:58 CET 2011
Hello
this does it for one stock. I am struggling when I insert this expression in a
loop that worked before:
tickers <- c("MSFT","CSCO","GE")
getSymbols ( tickers, from="2011-07-01::")
qte <- getQuote ( tickers )
for(ticker in tickers) {
tacker <- rbind((ticker), xts(qte[ticker,c(5,6,7,2,82)],Sys.Date()))
...}
gives for tacker "Error in UseMethod("as.xts"), because ticker is read in this
context as class "character"
Any workaround to get "ticker" into class xts?
Thanks in advance
Hans
Am Donnerstag, 3. November 2011 17:01:56 schrieben Sie:
> Martin,
>
> You could use `getQuote` to do this a little less manually.
>
> > getSymbols("SPY", from='2011-10-31')
>
> [1] "SPY"
>
> > getQuote("SPY")
>
> Trade Time Last Change % Change Open High Low
> Volume
> SPY 2011-11-03 11:44:00 125.07 1.08 +0.87% 125.27 125.42 123.595
> 133878480
>
> > SPY <- rbind(SPY, xts(getQuote("SPY")[,c(5,6,7,2,8,2)], Sys.Date()))
> > SPY
>
> SPY.Open SPY.High SPY.Low SPY.Close SPY.Volume SPY.Adjusted
> 2011-10-31 127.16 128.62 125.320 125.50 227863700 125.50
> 2011-11-01 122.03 123.51 121.520 122.00 415376200 122.00
> 2011-11-02 123.83 124.40 122.790 123.99 244717600 123.99
> 2011-11-03 125.27 125.42 123.595 125.07 133878480 125.07
>
> Cheers,
> Garrett
>
> On Mon, Oct 31, 2011 at 8:10 AM, Brian G. Peterson <brian at braverock.com>wrote:
> > 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
> >
> > _______________________________________________
> > R-SIG-Finance at r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> > -- Subscriber-posting only. If you want to post, subscribe first.
> > -- Also note that this is not the r-help list where general R questions
> > should go.
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-SIG-Finance at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions
> should go.
-----------------------------------------------------------------------------------------------------------------------------------------
Hans Grapenthin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part.
URL: <https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20111106/38bbc803/attachment.bin>
More information about the R-SIG-Finance
mailing list