Financial Data in R: A Package To Access Financial Data in R

If you are looking to analyze financial data in R, the Intrinio API is a great solution. This article explains how to install a package that makes it easy to pull the data, shows some examples using the package, and provides the code for the package so you can see what is going on in the background.

Installing the Package

Intrinio will be releasing official SDKs in numerous languages in 2018, so we didn't take the time to submit this package to CRAN. That means you'll have to install it from GitHub. First, make sure you have dev tools installed and required, then load the package itself and require it:

Using the Package to Pull Financial Data in R

Using the getintrinio function requires 3 parameters. The first is rest API endpoint, or URL. If you are unfamiliar with rest APIs or the endpoints available from Intrinio, this article provides a good overview with helpful links to the documentation. You'll notice that an API call like this can be used to pull Apple's stock price:

Or this, for Apple's price history:

There are millions of other financial data points that can be pulled with these and other Intrinio API calls.

The next input to the formula is your API username and then your API password. You can get these from your Intrinio account page. Just click the file icon to copy and paste them:

financial data in R

When you insert them into the R function, it looks like this:

This same package can be used to pull any Intrinio REST API endpoint. Just remember to use your own API username and password and to change the URL to suit your needs.

What is Going On In The Background

Intrinio's rest API uses paging, meaning large requests are split over multiple pages of results. This article explains paging and shows a step by step example of pulling multiple pages of price history for Apple.

The package shown in this article takes this paging function one step further and automatically pulls all pages of data for any API request. If there is only 1 page, or only 1 item, it won't pull multiple pages. You can view the source code on GitHub or check it out here: