[R-SIG-Finance] Combining instrument data into one xts
G See
gsee000 at gmail.com
Sun Dec 16 06:28:31 CET 2012
A common way to do this is to store your data in its own environment. Then,
use eapply to get a list of close prices. Finally, construct a merge call
with do.call
s <- c("SPY", "AAPL")
myEnv <- new.env()
getSymbols(s, src='yahoo', env=myEnv)
p <- do.call(merge, eapply(myEnv, Cl))
this is like calling merge(Cl(SPY), Cl(AAPL)), but it will work for any number
of symbols.
Similarly, if your data are stored in your globalenv(), you can create a list
of Close prices and merge them together using do.call.
s <- c("SPY", "AAPL")
getSymbols(s, src="yahoo")
p <- do.call(merge, lapply(s, function(x) Cl(get(x, pos=globalenv()))))
I also happen to have a function that does this for you in one line in my qmao
package on R-Forge. https://r-forge.r-project.org/R/?group_id=1113
library(qmao)
p <- PF(getSymbols(c("SPY", "AAPL")), silent=TRUE)
HTH,
Garrett
On Sat, Dec 15, 2012 at 11:06 PM, Robert A'gata <rhelpacc at gmail.com> wrote:
> Hi,
>
> 1) When I call getSymbols with multiple symbols, is there any way I can
> obtain everything into one xts. Says, I want only close data from google
> for c("SPY","AAPL"). Is there anyway I can get an xts with 2 columns
> corresponding to SPY and AAPL close prices?
> 2) Similar to #1, if I have all symbols loaded from files (.RData), is
> there any better way to combiing them than merging them one-by-one using
> xts?
>
> Thank you.
>
> Robert
>
> [[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.
More information about the R-SIG-Finance
mailing list