The objective of this post is to present an alternative to getting data in R besides the great packages like quantmod and TFX see more options on this post. This packages used Yahoo and Google services, that even if they are accurate are not scalable. In my particular case I wanted data from more than 3 fiscal years, something that neither of those services offer.

Also this post is for those that don’t have a programming background, since the function I am going to be explaining might seem simple for those that are use to using APIs. However I find that even if you have a programming background if you are working with R this function might be useful.

For this purpose I’m going to be using Intrinio API that offers free plans perfect for students, start-ups or development phase. I use it for company valuation for Towers Capital Group. I think that they offer best balance between affordability and scalability. If you want to follow along you can get a free account and API key in their webpage.

API athentification

The API’s in lay terms is a interface to access a service, in this case we want to retrieve financial information. To do so, we need to access an standardized links created depending on what the information we want. See it as a particular webpage that has the particular information you want and then you copy and paste that information for your use.

However since this drain resources the API uses a username and a KEY so that they control the access to the information. To authenticate in R we use the httr as follows:

library(httr)
## Warning: package 'httr' was built under R version 3.4.2
username <- "81956e74baabf633764478abdb0fd5d9"
password <- "30cbd96968dba7ca824880a27b0daa62"
link <- "https://api.intrinio.com/financials/standardized?identifier=AAPL&statement=income_statement&fiscal_year=2015&fiscal_period=FY"
 tp <- GET(link, authenticate(username, password, type = "basic"))

The “link” variable is the actual link to an API information. If you copy and paste that link in your browser you will you will be prompted to authenticate. The tp is going to be a connection to that link, the authenticate function serve to authenticate in the link.