[R-SIG-Finance] Combining instrument data into one xts
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@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.
Re: [R-SIG-Finance] Combining instrument data into one xts
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 rhelp...@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@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. ___ R-SIG-Finance@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.
Re: [R-SIG-Finance] Combining instrument data into one xts
Thank you Garrett. On Sun, Dec 16, 2012 at 12:28 AM, G See gsee...@gmail.com wrote: 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 rhelp...@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@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@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.