How to handle hyphens in Yahoo finance tickers in Quantmod

When executing the following commands, a hyphen in the HM-B.ST ticker is interpreted as a minus sign. I tried to rename the xts object to another, but failed. Does anyone know a solution for this?

>library(quantmod) >getSymbols("HM-B.ST") >chartSeries(HM-B.ST) Error in inherits(x, "xts") : object 'HM' not found 
+6
source share
1 answer

The cleanest way to handle this is to not rely on the default automatic assignment behavior of getSymbols() 'and instead assign the time series object to more standard names of your choice. For instance:

 HM.B.ST <- getSymbols("HM-B.ST", auto.assign=FALSE) # ht Joshua Ulrich chartSeries(HM.B.ST) 

If for some reason you want time series to keep their hyphen name by default, you can access it by doing the following:

 chartSeries(`HM-B.ST`) 

The reason it works is because the return signals signal the R parser, that the characters between them should be parsed as one name (aka symbol), and not as two names separated by a subtraction operator.

To expand this point at home once and for all, try the following:

 assign("a really stupidly constructed name!*&^", 5) `a really stupidly constructed name!*&^` # [1] 5 
+7
source

Source: https://habr.com/ru/post/955844/


All Articles