Shortcuts for quantmod

Over the years, there have been a couple of issues I have been trying to address in my daily use of this excellent package. Both are “cosmetic” improvements, they only improve the usability of the package. Let me share them and see whether they can be improved further.:)

First, let’s reduce the typing involved with getSymbols. Compare what I used to use vs what I use now:

# quantmod interface
spy = getSymbols("SPY", from="1900-01-01", src="yahoo", auto.assign=F)

# the new interface
spy = gys("spy")

Much easier to type. If you wonder, gys stands for “get Yahoo symbol”. The second improvement is transparent – instead of doing a round trip to the server (Yahoo in the above case), my new interface does some caching. It uses a well-known directory (a variable which is also part of the script or the package containing the code) and looks into the directory first. If a file for the symbol exists – no downloading. Unless it’s “forced”:

# the new interface, forcing refresh of the data
spy = gys("spy", force=T)

The complete source code is available on GitHub and contains the multi-symbol interface as well, you guessed it right – gyss.:) I have similar shortcuts for my data providers which pass me csv files. The code resides in a package, which I pretty much load on each startup (my package loads quantmod so no extra typing here;)).

Leave a Reply