Intrinio Financial Data in R and RStudio

Andrew Carpenter
September 26, 2016

Data analysts everywhere know that most of their time is spent gathering, cleaning, and formatting data. The actual analysis and interpreting the results is fun, fast, and easy once the data is structured how you need it. This blog shows how easy Intrinio makes it to complete the nasty part of analysis by using the Intrinio API to pull financial data into R.

Intrinio provides many data feeds via API and if you learn to use the API in conjunction with R, you can spend a lot more of your time running the analysis and analyzing the results and a lot less time on data entry.

If you don't use R this might not be the blog for you, but if you do, this blog will show you in step by step fashion how to save yourself a lot of money, and make yourself a lot of time, by using the Intrinio API in the R terminal or RStudio.

Update: Feel free to skip ahead to this recently released package that does the hard work for you.

I prefer to work in R studio since I am really a beginner but the following instructions are just as valid in the terminal. I am in the process of creating a Github repository of this code and expect to have that available by December. For now, feel free to copy this code and please comment if you find more efficient ways of pulling in the data.

Step 1: Setting up your environment

Run these three lines of code in a new script:


The previous three commands clean up your environment to remove any objects from a previous session, install the httr package, and make sure you have the httr library active respectively. After the first time you install httr you can delete that line of code in your script.

Step 2: API username and API password

Go to and create an account. It's free and just requires an email. If you want more information about how Intrinio works, here is a blog explaining things at a high level.

You are able to access many of our feeds in our free developer sandbox. For now, you should click the icons, one at a time, that have red arrows pointing to them. This will copy your API keys to the clipboard - go ahead and paste them into R.

You're going to want to make them into objects, so your code should look like this:

username <- "a543b029ec930ab0c7add95bfa1ea3ac"
password <- "991d8ca925d74ecfbe7f78b4784d88b0"

The only difference should be you are using your username and password, not mine.

Step 3: Creating your API call

If you haven't used an API before, and haven't read through Intrinio's documentation, here is a blog about getting started with the Intrinio API that will help you make sense of this next step. Create the following objects - no changes this time, copy them just like this:

base <- ""
endpoint <- "data_point"
stock <- "aapl"
item1 <- "close_price"
item2 <- "pricetoearnings"
call1 <- paste(base,endpoint,"?","ticker","=", stock, "&","item","=",item1, sep="")
call2 <- paste(base,endpoint,"?","ticker","=", stock, "&","item","=",item2, sep="")

Go ahead and print call1 and call2 so you can look at them. The paste function combined each of the objects you created into two different API calls, one for Apple's close_price, or most recent stock price, and another for Apple's price to earnings ratio. The full API calls should look like this:

Step 4. Making the API calls

Create the following objects:

apple_price <- get(call1, authenticate(username,password, type = "basic"))
apple_pricetoearnings <- get(call2, authenticate(username,password, type = "basic"))

Those objects combine your API calls with your username and password to use httr's GET function to send your request to Intrinio's database.

Step 5. Parsing out the return value

The following code parses out the data sent over from Intrinio's server so you can analyze it:

test1 <- unlist(content(apple_price,"parsed"))
test2 <- unlist(content(apple_pricetoearnings,"parsed"))

Now that you have the data parsed, you can put it into a dataframe for analysis:

df <- data.frame(test1,test2)

If you followed along, what you will have in your dataframe are the latest stock price for Apple (EOD if after hours) as well as the latest price to earnings ratio.

I designed the syntax to make it easy to make more calls by varying the "item" object and using it to make different API calls. If you repeat that process, and learn the different tags that Intrinio uses, you can very quickly pull in historical data for any stock, valuation metrics, balance sheet data, or any other data type that Intrinio provides.

As you can see, this is just the tip of the iceberg. These calls used 2 of my allotted API calls. My plan is to build a dashboard next that prints a full analysis of a stock.

Update 10/10/16- Check out this blog showing how to create custom functions to pull historical data in R.

Update 05/22/16- Check out this blog showing how to create a for loop in R to get multiple pages of data via API. This example shows the best way (known to the author) to parse JSON from an API in R.