4
$\begingroup$

I would like to preface this by saying I am preparing for an upcoming internship this summer so I am extremely new to Quant Finance.

At my university we have access to Datastream by Thomson Reuters and Compustat. With either of those two software can I download historical financial statements going back 20+ years so I can backtest screens in R.

I am looking for historical financial statements so I can backtest ratios such as ROE, Inventory turnover, and etc. This is why the free Yahoo! API which only has price changes and volume doesn't help me out.

Thank you.

$\endgroup$
6
$\begingroup$

Both free and paid access to data sets conatianing company financial statement items is available from Quandl. The free data sets are sourced from the SEC based on compnay electronic filings and go back about five years. For example, you could obtain five years of MSFT's quarterly net income using the R call

Quandl("RAYMOND/MSFT_NET_INCOME_Q")

Lists of available financial data and more detail on using Quandl is available at https://www.quandl.com/help/api-for-stock-data

$\endgroup$
0
$\begingroup$

You can get that data from Intrinio in R as well. There is documentation, including how to actually make the API calls in R with examples, here. Here is an example of pulling Apple's income statement for Q1 2017- you just need to get your own API keys and add them to the code (it's free):

#Cleaning up the environment

rm(list=ls())

#Skip this installation if you already have httr installed. This package makes using APIs in R easier
install.packages("httr")
#Require the package so you can use it
require("httr")

#Skip this installation if you already have jsonlite installed. This package makes parsing JSON easy
install.packages("jsonlite")

#Require the package so you can use it
require("jsonlite")

#Create variables for your usename and password, get those at intrinio.com/login. 
#Replace them here or the code won't run! They need to be in ""

username <- "Your_API_Username_Here"
password <- "Your_API_Password_Here"

#These variables will be pasted together to make our API call. You can replace the "stock" variable with any US ticker symbol

base <- "https://api.intrinio.com/"
endpoint <- "financials/standardized"
stock <- "identifier=AAPL"
statement <- "statement=income_statement"
fiscal_period <- "fiscal_period=Q1"
fiscal_year <- "fiscal_year=2017"

#Pasting them together to make the API call. 
call1 <- paste(base,endpoint,"?",stock,"&", statement, "&", fiscal_period, "&", fiscal_year, sep="")

#This line of code uses the httr package's GET function to query Intrinio's API, passing your username and password as variables
get_prices <- GET(call1, authenticate(username,password, type = "basic"))

#The content function parses the API response to text. You can parse to other formats, but this format is the easiest to work with. Text is equivalent to JSON
get_prices_text <- content(get_prices, "text")

#This line of code uses the JSONlite function fromJSON to parse the JSON into a flat form. Flat means rows and coloumns instead of nested JSON
get_prices_json <- fromJSON(get_prices_text, flatten = TRUE)

#Converting the data to a dataframe
get_prices_df <- as.data.frame(get_prices_json)

The result is a dataframe that looks like this:Apple's financial statement

Now that you can get the statements via API (for free), you can go to town analyzing them.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.