|
Hi all,
I would need to put datas downloaded with quantmod into a matrix or a data frame. Suppose to start from here: require(quantmod) ticker.list <- c('AAA', 'ALTSALES', 'AMBNS', 'AMBSL', 'BAA', 'EMRATIO', 'FEDFUNDS', 'GASPRICE', 'GS1', 'GS10', 'GS20', 'LNS14100000', 'MORTG', 'NAPM', 'NPPTTL', 'OILPRICE', 'PAYEMS', 'TB3MS', 'UNRATE') series <- getSymbols(ticker.list, src= 'FRED') May you tell me how could I put each time series into a matrix or a data frame keeping the dates' alignment? Thank you
|
|
Load the data into an environment, then merge them using do.call():
series.env <- new.env() getSymbols(ticker.list, src='FRED', env=series.env) series <- do.call(merge, as.list(series.env)) HTH, -- Joshua Ulrich | FOSS Trading: www.fosstrading.com On Sat, Jul 7, 2012 at 7:00 AM, Cren <[hidden email]> wrote: > Hi all, > > I would need to put datas downloaded with quantmod into a matrix or a data > frame. > > Suppose to start from here: > > *require(quantmod) > > ticker.list <- c('AAA', 'ALTSALES', 'AMBNS', 'AMBSL', 'BAA', 'EMRATIO', > 'FEDFUNDS', 'GASPRICE', 'GS1', 'GS10', 'GS20', 'LNS14100000', 'MORTG', > 'NAPM', 'NPPTTL', 'OILPRICE', 'PAYEMS', 'TB3MS', 'UNRATE') > > series <- getSymbols(ticker.list, src= 'FRED')* > > May you tell me how could I put each time series into a matrix or a data > frame keeping the dates' alignment? > > Thank you > > -- > View this message in context: http://r.789695.n4.nabble.com/Getting-objects-from-quantmod-ticker-list-tp4635708.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > [hidden email] mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. |
Thank you very much, Joshua: this works very well! Thank you :) |
|
# One more question, Joshua: let instead of merging tickers
# I would like to put prices from an OHLC object # in weekly format, then selecting just the close prices. # What would be a code to do it? # I guess: data = new.env() ticker.list <- c('SPY', 'TLT', 'GLD') getSymbols(ticker.list, env = data) X <- do.call(to.weekly, list(data)) # or something like this, but it doesn't work. # What could I do? |
|
On Wed, Jul 11, 2012 at 1:49 PM, Cren <[hidden email]> wrote:
> # One more question, Joshua: let instead of merging tickers > # I would like to put prices from an OHLC object > # in weekly format, then selecting just the close prices. > # What would be a code to do it? > # I guess: > > data = new.env() > ticker.list <- c('SPY', 'TLT', 'GLD') > getSymbols(ticker.list, env = data) > X <- do.call(to.weekly, list(data)) I think you need do.call(rbind, as.list(eapply(data, function(x) Cl(to.weekly(x))))) Working from the inside out: to.weekly -- go to weekly frequency Cl -- take the close eapply -- do this to each element of the data environment as.list -- convert to list do.call(cbind, ...) -- put them all together. Though there may be something simpler. Best, Michael > > # or something like this, but it doesn't work. > # What could I do? > > -- > View this message in context: http://r.789695.n4.nabble.com/Getting-objects-from-quantmod-ticker-list-tp4635708p4636162.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > [hidden email] mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. |
|
On Wed, Jul 11, 2012 at 3:07 PM, R. Michael Weylandt
<[hidden email]> wrote: > On Wed, Jul 11, 2012 at 1:49 PM, Cren <[hidden email]> wrote: >> # One more question, Joshua: let instead of merging tickers >> # I would like to put prices from an OHLC object >> # in weekly format, then selecting just the close prices. >> # What would be a code to do it? >> # I guess: >> >> data = new.env() >> ticker.list <- c('SPY', 'TLT', 'GLD') >> getSymbols(ticker.list, env = data) >> X <- do.call(to.weekly, list(data)) > > I think you need > > do.call(rbind, as.list(eapply(data, function(x) Cl(to.weekly(x))))) My apologies: that should be rbind() Also, you might want to re-attach names: names(X) <- ticker.list Best, Michael > > Working from the inside out: > > to.weekly -- go to weekly frequency > Cl -- take the close > eapply -- do this to each element of the data environment > as.list -- convert to list > do.call(cbind, ...) -- put them all together. > > Though there may be something simpler. > > Best, > Michael > >> >> # or something like this, but it doesn't work. >> # What could I do? >> >> -- >> View this message in context: http://r.789695.n4.nabble.com/Getting-objects-from-quantmod-ticker-list-tp4635708p4636162.html >> Sent from the R help mailing list archive at Nabble.com. >> >> ______________________________________________ >> [hidden email] mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. |
|
On Wed, Jul 11, 2012 at 3:08 PM, R. Michael Weylandt
<[hidden email]> wrote: > On Wed, Jul 11, 2012 at 3:07 PM, R. Michael Weylandt > <[hidden email]> wrote: >> On Wed, Jul 11, 2012 at 1:49 PM, Cren <[hidden email]> wrote: >>> # One more question, Joshua: let instead of merging tickers >>> # I would like to put prices from an OHLC object >>> # in weekly format, then selecting just the close prices. >>> # What would be a code to do it? >>> # I guess: >>> >>> data = new.env() >>> ticker.list <- c('SPY', 'TLT', 'GLD') >>> getSymbols(ticker.list, env = data) >>> X <- do.call(to.weekly, list(data)) >> >> I think you need >> >> do.call(rbind, as.list(eapply(data, function(x) Cl(to.weekly(x))))) > > My apologies: that should be rbind() Damnit.... cbind() Michael > > Also, you might want to re-attach names: > > names(X) <- ticker.list > > Best, > Michael > >> >> Working from the inside out: >> >> to.weekly -- go to weekly frequency >> Cl -- take the close >> eapply -- do this to each element of the data environment >> as.list -- convert to list >> do.call(cbind, ...) -- put them all together. >> >> Though there may be something simpler. >> >> Best, >> Michael >> >>> >>> # or something like this, but it doesn't work. >>> # What could I do? >>> >>> -- >>> View this message in context: http://r.789695.n4.nabble.com/Getting-objects-from-quantmod-ticker-list-tp4635708p4636162.html >>> Sent from the R help mailing list archive at Nabble.com. >>> >>> ______________________________________________ >>> [hidden email] mailing list >>> https://stat.ethz.ch/mailman/listinfo/r-help >>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >>> and provide commented, minimal, self-contained, reproducible code. ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. |
| Powered by Nabble | Edit this page |
