Databases – an Ideal Application for R6?

May 20, 2015

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

Over the years I have tried to simplify and streamline my access to financial historic data. All different solutions I tried (see here, for example) so far have been unsatisfactory, at least to some degree. That however changed after I started using R6. Here is an example of using the R6 class for the same task as before:

ydb = YahooDb$new("~/yahoo.db")
# "g" is just a shortcut for "get.symbol"
spy = ydb$g("spy")

The advantage of using objects comes handy to keep relevant things logically coupled, to simplify the API and to minimize the external configuration (not too obvious when using SQLite, but try using a database server, like MySQL where we have to deal with a URL, user, password, etc). As in the older version, the above code first checks the database, and only if the symbol requested is not available there, it requests the data from Yahoo Finance. Notice, the database format is different from what quantmod uses. In my version, all daily data is stored into a single table.

Last, I added the YahooDb class to the btutils package, where the code will be kept up-to-date.

The post Databases – an Ideal Application for R6? appeared first on Quintuitive.

To leave a comment for the author, please follow the link and comment on their blog: Quintuitive » R. offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, 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.


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)