Shortcuts for quantmod

May 28, 2014
By

(This article was first published on Quintuitive » R, and kindly contributed to R-bloggers)

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;)).

To leave a comment for the author, please follow the link and comment on his blog: Quintuitive » R.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.