Download Japanese stock market data into R

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:

install.packages("quantmod", repos="")

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.


これはオランダ語の記事から翻訳したものです。原作者はGaston Dorren(ガストン・ドルン)。



Continue reading 意味のある沈黙

MySQL pager configuration

Have you ever typed in a SQL query that returns thousands and thousands of results, and you had to Ctrl-C to stop it, which would then also terminate your MySQL console process? Annoying, isn’t it!

Well, there is actually a pager configuration for MySQL. My favorite pager is less, ’cause less is more, right? Paradoxically, it has more features than more, for in more you wouldn’t be able to scroll up, for example.

To make MySQL use less as the pager, you should add the following line to your my.cnf file, in the [client] block:

pager = "less -X -F"

Here is what the arguments do:

  • -X: prevent less from clearing the screen when exiting. This is useful when you want to have the results on screen after quitting less, to be able to compose your next SQL command
  • -F: tells less to quit immediately if the buffer fits on one screen. Without this, you’d have to quit less first before you can type the next SQL command, even though it fitted perfectly on one screen.

MySQL configuration tips and tricks

A web developer often has to access different MySQL databases for different projects. To quickly navigate through them, I like to use project-specific MySQL configuration snippets and aliases. My projects usually have some kind of a namespace, a 2-3 character code specific to that project. Just to give an example, let’s call my project Xylophone Ytterbium Zeta, and its namespace code is XYZ.

I would create a my.cnf file in my project’s directory with the following content:

host = localhost
user = xyzuser
password = xyzpassword
database = xyzdatabase

If I now run:

$ mysql --defaults-file=~/projects/xyz/my.cnf

I will be logged into the project’s database immediately, without having to enter my credentials.

However, the --defaults-file argument is quite a long argument to type in every time, so I would create a bash alias, so that all I need to do is:

$ myxyz

to get into the database. To create this bash alias, I’d simply add the following line to my ~/.bash_aliases file:

alias myxyz="mysql --defaults-file=~/projects/xyz/my.cnf"

Of course your .bash_rc file needs to know about this file, so check if you have the following snippet in there:

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases

The latest Ubuntu versions should have that already prepared for you.

A meaningful silence

Translated from Dutch. Original article by Gaston Dorren.

When I told my friends that I had joined a sign language course, there were two kinds of surprising reactions. Firstly, they showed much more interest than when I was learning Danish, Spanish, Russian, Norwegian, Romanian or Czech. (No, I don’t speak those languages. And yes, my friends got a lot to digest.) Sign languages seem to entice a lot of curiosity.

Secondly, even though my friend circles consist of a lot of master degree holders, and a doctor, I heard quite a few distressingly misinformed remarks about sign language. Despite so much evangelism in the beginning of the eighties by linguists and sign language advocates, many of the first misconceptions are still around. This is why I have set myself a simple goal: I will summarize seven common, but incorrect assumptions, and will deal with every one of them.

Continue reading A meaningful silence