Traders who are interested in the Japanese market, and use the
quantmod library in R to analyze the stock market, will find that there is no source for financial data on the Japanese market. This has changed with
quantmod version 0.4-3, in which my code to download stock data from Yahoo! Japan has been added.
At the moment, version 0.4-3 has not been pushed to CRAN yet, but you can still install it from R-Forge. To do this, enter the following in your R console:
Then, when you load the library with
library(quantmod), you’ll be able to use the
getSymbols() function to retrieve stock data from the Japanese market, using the
src="yahooj" parameter. The ticker symbols you need, can be found in the URL of the stock information page on Yahoo! Japan. For example, if you open the Sony stock data page, you’ll see that there is a
code=6758.T in the URL. This is your ticker symbol.
So in order to download Sony stock data from January 2013 into R, do the following:
getSymbols("6758.T", src="yahooj", from="2013-01-01")
This will download the data, and put them in a variable called
YJ6758.T in your R environment.
For more information on the
getSymbols function, you can check the online reference. When the online reference for the
getSymbols.yahooj function becomes available, I will link it here, but until then you can check it in the R Help system if you have
quantmod 0.4-3 installed.
3 thoughts on “Download Japanese stock market data into R”
Hi. Nice work. Is the data dividend adjusted?
Thanks! There is an Adjusted column, just like other OHLC data you are used to from quantmod’s getSymbols. These are adjusted for splits, not for dividends. I don’t think I have seen dividend data in Yahoo Japan’s stock data.
Thank you for this – absolutely awesome, works great.
(note though that I dare to slightly disagree with your comment, i expect the last column to be total returns, i.e. adjusted for dividends as well, but i have not formally checked this yet – so i could be totally wrong of course – however, in other markets that column serves as total returns).
This said, looking at your GitHub repo, and the source code, at https://github.com/wthielen/YJStocks/blob/master/getSymbols.yahooj.R I see the following lines, 74 to 76:
# Available columns
cols <- c('Open','High','Low','Close','Volume','Adjusted')
if (grepl(".O$", Symbols.name)) cols <- cols[-(5:6)]
cols have been hard coded and indeed, many securities will follow that format. However, there are quite a few securities that do not. Here is one example for instance:
It's a public fund that users of the Toranotec (http://toranotec.com/) app can invest in. Therefore, it has only 2 fields: 基準価額 純資産（百万） (NAV and AUM) in lieu of the 4 or 6 coded above.
Do you feel that downloading this type of securities is something your code could accommodate easily and it would not be too much trouble for you to implement it?