Google Ad sense



All source codes in this blog are also available in Gregory Choi's Github Source code Repository


  

Wednesday, March 30, 2016

Getting financial statement in R (Income Statement, Balance Sheet)

One of my headache during my MBA course is to get financial statement from the internet. I am a fan of Yahoo Finance, but it was hassle to type all the income statements or the balance sheets to my excel.

Here's the simple tip to make you easier to do that with R.

First, you need to install Quantmod first. (If you haven't installed it)
> install.packages("quantmod")

It gets the data from google finance. As long as google finance lasts, you can get for free.

If I want to get the quarterly income statement of Facebook, here's the step.

> library("quantmod")
> getFinancials('FB')
[1] "FB.f"

meaning that the financial data have stored at the variable "FB.f" All we need to do is to request quarterly income statement.

> result <- viewFinancials(FB.f, c("IS"), c("Q"))
#IS means Income Statement, Q means Quarterly
#If you want to get annual data you can replace "Q" with "A"
Quarterly Income Statement for FB
> head(result)
                                       2015-12-31 2015-09-30 2015-06-30 2015-03-31 2014-12-31
Revenue                                      5841       4501       4042       3543       3851
Other Revenue, Total                           NA         NA         NA         NA         NA
Total Revenue                                5841       4501       4042       3543       3851
Cost of Revenue, Total                        824        720        668        654        653
Gross Profit                                 5017       3781       3374       2889       3198
Selling/General/Admin. Expenses, Total       1143        925        806        769        954

If you want to get quarterly balance sheet, you can use "BS" instead of "IS"

> balance_sheet_facebook <- viewFinancials(FB.f, c("BS"), c("Q"))
Quarterly Balance Sheet for FB
> head(balance_sheet_facebook)
                                 2015-12-31 2015-09-30 2015-06-30 2015-03-31 2014-12-31
Cash & Equivalents                       NA         NA         NA         NA         NA
Short Term Investments                16731      13147      11825       9769       9037
Cash and Short Term Investments       18434      15834      14125      12413      11199
Accounts Receivable - Trade, Net       2559       2010       1815       1508       1678
Receivables - Other                      NA         NA         NA         NA         NA
Total Receivables, Net                 2559       2010       1815       1508       1678

If you want to get total leverage ratio, you can just type 
> balance_sheet_facebook[27,1] / balance_sheet_facebook[17,1]
[1] 0.002307365

This is because 17th row and 1st column denotes the total asset in 2015-12-31 and
27th row and 1st column denotes the total liability in 2015-12-31

(You can just count the number from the first row)


No comments:

Post a Comment