Shortcuts for quantmod

[This article was first published on Quintuitive » R, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

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 their blog: Quintuitive » R.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)