Houyang Xia
Houyang Xia

Reputation: 11

Quantmod getSymbols systematically returns missing value on Chinese stocks

Today(2019-2-27), I discovered that almost all the stock price of Chinese companies listed in Shanghai/Shenzhen cannot be completely downloaded by "getSymbols" function in quantmod, which always generated a warning message of missing data. However, Neither US companies nor Chinese companies listed in US were affected. As far as I can remember, this is the first time I encounter this issue. I was thinking which parts of this process went wrong. Yahoo finance database or getSymbols??? Examples I tried were actually some of the biggest companies, so I assume their stock data are fully available.

> getSymbols("BABA") ### Alibaba listed in US, not affected
[1] "BABA"
> getSymbols("BILI")  
[1] "BILI"
> getSymbols("0700.hk") ### Tencent listed in HK, affected.
[1] "0700.HK"
Warning message:
0700.hk contains missing values. Some functions will not work if objects contain missing values in the middle of the series. Consider using na.omit(), na.approx(), na.fill(), etc to remove or replace them. 
> getSymbols("601398.SS")
[1] "601398.SS"
Warning message:
601398.SS contains missing values. Some functions will not work if objects contain missing values in the middle of the series. Consider using na.omit(), na.approx(), na.fill(), etc to remove or replace them. 
> getSymbols("601318.SS")
[1] "601318.SS"
Warning message:
601318.SS contains missing values. Some functions will not work if objects contain missing values in the middle of the series. Consider using na.omit(), na.approx(), na.fill(), etc to remove or replace them. 

Upvotes: 1

Views: 1733

Answers (2)

Houyang Xia
Houyang Xia

Reputation: 11

Yes,as mentioned above by @phiver, the data quality from yahoo finance database are not satisfying. Meanwhile, google finance has stoped providing support to quantmod since March 2018. Thus I was looking for another data source within the framework of quantmod.

I found that tiingo database started to support quantmod as google finance exits. https://www.r-bloggers.com/goodbye-google-hello-tiingo/

  1. go to tiingo website to create an account, then you have you api.
  2. use getSymbols.tiingo(ticker,api.key="your key") to download data

by the way,the ticker of Chinese stocks is a bit different in getSymbol.tiingo compared with getSymbols. You don't need to indicate which stock exchange, ss or sz.

getSymbols("000001.SS")

getSymbols.tiingo("000001",api.key="xxxxx")

also you might need to store your api.key, I recommend you to create a snippet, this is the most efficient way i have found so far. Further details can be seen in my another answer on how to store api.key in Rstudio.

Upvotes: 0

phiver
phiver

Reputation: 23608

It is a yahoo issue. If you look at the december 2011 data from tencent on the historical data tab of yahoo, you can see that yahoo doesn't have the data for the 24th and the 31st of December. Which are two of the 3 records that are missing data. The other is for 2008-08-22.

You do know, that the default request with getSymbols for yahoo starts at 2007-01-01. So you could change that to a more recent date. But it is free data. You can not expect the same data quality as other data providers. And it happens more often with yahoo for other tickers as well.

Upvotes: 1

Related Questions