joshuaulrich / quantmod

Quantitative Financial Modelling Framework
http://www.quantmod.com/
GNU General Public License v3.0
794 stars 219 forks source link

getSymbols return value does not correspond to the name created #371

Closed ggrothendieck closed 1 year ago

ggrothendieck commented 1 year ago

This works:

library(quantmod)
tickers <- "AAPL"
tickers.out <- getSymbols(tickers)
L <- mget(tickers.out)

but this next one does not because the object it creates is called "IXIC" and not "^IXIC". The output of getSymbols should correspond to the object names that are created, not to the input symbols. Alternately make the output objects the same as the input object names.

library(quantmod)
tickers <- "^IXIC"
tickers.out <- getSymbols(tickers)
L <- mget(tickers.out)
## Error: value for ‘^IXIC’ not found
joshuaulrich commented 1 year ago

Thanks for bringing this up.

I agree with your point that the symbol it returns should be the same as the symbol it creates, and not the same as the input symbol.

And I strongly prefer that to the alternative solution. getSymbols() creates an object named IXIC because ^IXIC has to be back-quoted in order to access it, which is surprising to most users. The way getSymbols() changes symbols like these is a long-established pattern, so it would be very disruptive for getSymbols() to create an object named ^IXIC insteadof IXIC like it does now.