[R-SIG-Finance] rename a large number of stock codes
Marco Sun
hs13322 at my.bristol.ac.uk
Thu Dec 4 09:58:30 CET 2014
Hi, sorry for the previous emails, I am now opening a new topic to demonstrate my problem clearly.
I wish to retrieve a bunch of Chinese stock through getSymbols.
symbols<-c("600089.SS","600202.SS")
getSymbols(symbols)
These stock codes are not easily recognised nor being processed in further analysis, i.e. R does not recognise 600089.SS, instead, it recognises `600089.SS`.
> 600089.SS
Error: unexpected symbol in "600089.SS"
> class(`600089.SS`)
[1] "xts" "zoo"
`
Therefore, I wish to replace symbols with some simple tickers called stockcodes. I can easily replace the name of 600089.SS via:
stockcodes<-c("TBDG","HKT")
TBDG<-`600089.SS`
However, it could take a lot while if I have a large portfolio and I do have a well-diversified portfolio under analysis.
Another approach came up to me was using setSymbolLookup like this:
> setSymbolLookup(TBDG=list(name="600089.SS"))
> getSymbols("TBDG")
[1] "TBDG"
But I got error when I was trying to use for loop as the following:
for(i in 1:2)
{
setSymbolLookup(stockcodes[i]=list(name=symbols[i]))
getSymbols(stockcodes[i])
}
Any comment would be appreciated.
Cheers,
Marco
[[alternative HTML version deleted]]
More information about the R-SIG-Finance
mailing list