用R获取上市公司的财政报表
用R软件协助举办投资阐明时经常要用到上市公司的财政报表,对付许多小我私家投资者而言获取上市公司的财政报表有诸多坚苦,有时候只能获取Word版本的财政报表。这就给数据阐明造成了障碍。
不外,R中的quantmod包提供了getFin函数,基于getFin函数,我们可以直接从Google Finance数据库中直接获取上市公司的财政报表,包罗资产欠债表(Balance Sheet)、利润表(Income Statement)和现金流量表(Cash Flow Statements)。这里先容一下getFin函数的利用要领。
获取财政报表
获取这三张表的函数是getFin函数,其用法如下:
getFinancials(Symbol, env = .GlobalEnv, src = "google", auto.assign = TRUE, ...)
个中,主要函数为Symbol为指定的股票代码可能股票简称。
举个例子,获取中国移动公司的财政报表,代码如下:
library(quantmod) #载入quantmod Loading required package: Defaults Loading required package: xts Loading required package: zoo Attaching package: ‘zoo’ The following object(s) are masked from ‘package:base’: as.Date Loading required package: TTR > getFin("CHL") #获取中国移动的财政报表 [1] "CHL.f"
财政报表数据存储在CHL.f中。
查察资产欠债表
查察资产负载表的函数为viewFin(),其用法如下:
>viewFinancials(x, type=c('BS','IS','CF'), period=c('A','Q'), subset = NULL)
个中,x为getFin()函数获取的功效。type参数共有三个选项,别离对应BS(Balance Sheets),IS(Income Statement),CF(Cash Flow Statements)。period参数有两个选项,别离对应年报和季报。
举个例子:
> viewFin(CHL.f,"BS","A") Annual Balance Sheet for CHL 2010-12-31 2009-12-31 Cash & Equivalents NA NA Short Term Investments 210846.00 194584.00 Cash and Short Term Investments 292346.00 264507.00 Accounts Receivable - Trade, Net 7925.00 6430.00 Receivables - Other NA NA Total Receivables, Net 15136.00 9937.00 Total Inventory 4249.00 3847.00 Prepaid Expenses 10151.00 9064.00 Other Current Assets, Total NA NA Total Current Assets 321882.00 287355.00 Property/Plant/Equipment, Total - Gross 858072.00 756361.00 Accumulated Depreciation, Total -417908.00 -350192.00 Goodwill, Net 36894.00 36894.00 Intangibles, Net 12853.00 11928.00 Long Term Investments 40260.00 83.00 Other Long Term Assets, Total 9882.00 8939.00 Total Assets 861935.00 751368.00 Accounts Payable 112198.00 96750.00 Accrued Expenses 22656.00 16154.00 Notes Payable/Short Term Debt 0.00 0.00 Current Port. of LT Debt/Capital Leases 5049.00 68.00 Other Current liabilities, Total 115727.00 96833.00 Total Current Liabilities 255630.00 209805.00 Long Term Debt 4982.00 9918.00 Capital Lease Obligations NA NA Total Long Term Debt 4982.00 9918.00 Total Debt 10031.00 9986.00 Deferred Income Tax 39.00 61.00 Minority Interest 1246.00 886.00 Other Liabilities, Total 23881.00 23950.00 Total Liabilities 285778.00 244620.00 Redeemable Preferred Stock, Total NA NA Preferred Stock - Non Redeemable, Net NA NA Common Stock, Total 2139.00 2139.00 Additional Paid-In Capital 94496.00 94403.00 Retained Earnings (Accumulated Deficit) 479522.00 410206.00 Treasury Stock - Common NA NA Other Equity, Total NA NA Total Equity 576157.00 506748.00 Total Liabilities & Shareholders' Equity 861935.00 751368.00 Shares Outs - Common Stock Primary Issue NA NA Total Common Shares Outstanding 20065.42 20060.85 2008-12-31 2007-12-31 Cash & Equivalents NA 78859.00 Short Term Investments 133825.00 109685.00 Cash and Short Term Investments 218259.00 188544.00 Accounts Receivable - Trade, Net 7022.00 7063.00 Receivables - Other NA NA Total Receivables, Net 10776.00 10116.00 Total Inventory 3494.00 3295.00 Prepaid Expenses 7641.00 5680.00 Other Current Assets, Total NA NA Total Current Assets 240170.00 207635.00 Property/Plant/Equipment, Total - Gross 666058.00 549077.00 Accumulated Depreciation, Total -302793.00 -244487.00 Goodwill, Net 36894.00 36894.00 Intangibles, Net 10400.00 8852.00 Long Term Investments 84.00 77.00 Other Long Term Assets, Total 7614.00 6121.00 Total Assets 658427.00 564169.00 Accounts Payable 81841.00 66002.00 Accrued Expenses 11577.00 6912.00 Notes Payable/Short Term Debt 0.00 0.00 Current Port. of LT Debt/Capital Leases 68.00 68.00 Other Current liabilities, Total 90073.00 84737.00 Total Current Liabilities 183559.00 157719.00 Long Term Debt 9920.00 NA Capital Lease Obligations NA NA Total Long Term Debt 9920.00 0.00 Total Debt 9988.00 68.00 Deferred Income Tax 80.00 122.00 Minority Interest 629.00 488.00 Other Liabilities, Total 24217.00 34179.00 Total Liabilities 218405.00 192508.00 Redeemable Preferred Stock, Total NA NA Preferred Stock - Non Redeemable, Net NA NA Common Stock, Total 2138.00 2136.00 Additional Paid-In Capital 94272.00 93587.00 Retained Earnings (Accumulated Deficit) 343612.00 275938.00 Treasury Stock - Common NA NA Other Equity, Total NA NA Total Equity 440022.00 371661.00 Total Liabilities & Shareholders' Equity 658427.00 564169.00 Shares Outs - Common Stock Primary Issue NA NA Total Common Shares Outstanding 20054.38 20031.91 attr(,"col_desc") [1] "As of 2010-12-31" "As of 2009-12-31" "As of 2008-12-31" [4] "As of 2007-12-31"
查察利润表
#p#分页标题#e#
查察利润表也用viewFin函数。详细如下:
> viewFin(CHL.f,"IS","A") Annual Income Statement for CHL 2010-12-31 2009-12-31 Revenue 463784.00 432066.00 Other Revenue, Total 21447.00 20037.00 Total Revenue 485231.00 452103.00 Cost of Revenue, Total 25783.00 24853.00 Gross Profit 438001.00 407213.00 Selling/General/Admin. Expenses, Total 160512.00 142991.00 Research & Development NA NA Depreciation/Amortization 86292.00 80235.00 Interest Expense(Income) - Net Operating NA NA Unusual Expense (Income) 2763.00 4504.00 Other Operating Expenses, Total 59127.00 52512.00 Total Operating Expense 334477.00 305095.00 Operating Income 150754.00 147008.00 Interest Income(Expense), Net Non-Operating NA NA Gain (Loss) on Sale of Assets NA NA Other, Net 3010.00 2118.00 Income Before Tax 159071.00 153836.00 Income After Tax 120024.00 115423.00 Minority Interest -384.00 -257.00 Equity In Affiliates NA NA Net Income Before Extra. Items 119640.00 115166.00 Accounting Change NA NA Discontinued Operations NA NA Extraordinary Item NA NA Net Income 119640.00 115166.00 Preferred Dividends NA NA Income Available to Common Excl. Extra Items 119640.00 115166.00 Income Available to Common Incl. Extra Items 119640.00 115166.00 Basic Weighted Average Shares NA NA Basic EPS Excluding Extraordinary Items NA NA Basic EPS Including Extraordinary Items NA NA Dilution Adjustment 0.00 0.00 Diluted Weighted Average Shares 20321.33 20312.46 Diluted EPS Excluding Extraordinary Items 5.89 5.67 Diluted EPS Including Extraordinary Items NA NA Dividends per Share - Common Stock Primary Issue 2.60 2.47 Gross Dividends - Common Stock NA NA Net Income after Stock Based Comp. Expense NA NA Basic EPS after Stock Based Comp. Expense NA NA Diluted EPS after Stock Based Comp. Expense NA NA Depreciation, Supplemental NA NA Total Special Items NA NA Normalized Income Before Taxes NA NA Effect of Special Items on Income Taxes NA NA Income Taxes Ex. Impact of Special Items NA NA Normalized Income After Taxes NA NA Normalized Income Avail to Common NA NA Basic Normalized EPS NA NA Diluted Normalized EPS 5.99 5.84 2008-12-31 2007-12-31 Revenue 391896.00 339471.00 Other Revenue, Total 19914.00 18006.00 Total Revenue 411810.00 357477.00 Cost of Revenue, Total 24905.00 23830.00 Gross Profit 366991.00 315641.00 Selling/General/Admin. Expenses, Total 125078.00 18277.00 Research & Development NA NA Depreciation/Amortization 71713.00 67354.00 Interest Expense(Income) - Net Operating NA NA Unusual Expense (Income) 3242.00 NA Other Operating Expenses, Total 44477.00 124303.00 Total Operating Expense 269415.00 233764.00 Operating Income 142395.00 123713.00 Interest Income(Expense), Net Non-Operating NA NA Gain (Loss) on Sale of Assets NA NA Other, Net 2693.00 2980.00 Income Before Tax 149523.00 128883.00 Income After Tax 112788.00 86740.00 Minority Interest -161.00 -117.00 Equity In Affiliates NA NA Net Income Before Extra. Items 112627.00 86623.00 Accounting Change NA NA Discontinued Operations NA NA Extraordinary Item NA NA Net Income 112627.00 86623.00 Preferred Dividends NA NA Income Available to Common Excl. Extra Items 112627.00 86623.00 Income Available to Common Incl. Extra Items 112627.00 86623.00 Basic Weighted Average Shares NA NA Basic EPS Excluding Extraordinary Items NA NA Basic EPS Including Extraordinary Items NA NA Dilution Adjustment 0.00 0.00 Diluted Weighted Average Shares 20356.13 20339.43 Diluted EPS Excluding Extraordinary Items 5.53 4.26 Diluted EPS Including Extraordinary Items NA NA Dividends per Share - Common Stock Primary Issue 2.42 1.90 Gross Dividends - Common Stock NA NA Net Income after Stock Based Comp. Expense NA NA Basic EPS after Stock Based Comp. Expense NA NA Diluted EPS after Stock Based Comp. Expense NA NA Depreciation, Supplemental NA NA Total Special Items NA NA Normalized Income Before Taxes NA NA Effect of Special Items on Income Taxes NA NA Income Taxes Ex. Impact of Special Items NA NA Normalized Income After Taxes NA NA Normalized Income Avail to Common NA NA Basic Normalized EPS NA NA Diluted Normalized EPS 5.65 4.26 attr(,"col_desc") [1] "12 months ending 2010-12-31" "12 months ending 2009-12-31"
查察现金流量表
#p#分页标题#e#
查察现金流量表:
> viewFin(CHL.f,"CF","A") Annual Cash Flow Statement for CHL 2010-12-31 2009-12-31 2008-12-31 Net Income/Starting Line 159071 153836 149523 Depreciation/Depletion 86230 80179 71509 Amortization 360 317 483 Deferred Taxes NA NA NA Non-Cash Items 1530 4297 3414 Changes in Working Capital -15812 -31506 -31282 Cash from Operating Activities 231379 207123 193647 Capital Expenditures -114500 -117159 -122851 Other Investing Cash Flow Items, Total -57072 -48768 -16175 Cash from Investing Activities -171572 -165927 -139026 Financing Cash Flow Items -943 -1292 -1589 Total Cash Dividends Paid -50201 -48614 -44560 Issuance (Retirement) of Stock, Net 93 132 465 Issuance (Retirement) of Debt, Net NA NA NA Cash from Financing Activities -51051 -49774 -45684 Foreign Exchange Effects -107 46 -370 Net Change in Cash 8649 -8532 8567 Cash Interest Paid, Supplemental 919 1292 1569 Cash Taxes Paid, Supplemental 38868 42939 41159 2007-12-31 Net Income/Starting Line 129238 Depreciation/Depletion 67354 Amortization 580 Deferred Taxes NA Non-Cash Items 5256 Changes in Working Capital -33816 Cash from Operating Activities 168612 Capital Expenditures -99579 Other Investing Cash Flow Items, Total -23460 Cash from Investing Activities -123039 Financing Cash Flow Items -1802 Total Cash Dividends Paid -34088 Issuance (Retirement) of Stock, Net 1614 Issuance (Retirement) of Debt, Net -3000 Cash from Financing Activities -37276 Foreign Exchange Effects -605 Net Change in Cash 7692 Cash Interest Paid, Supplemental 1802 Cash Taxes Paid, Supplemental 35672 attr(,"col_desc") [1] "12 months ending 2010-12-31" "12 months ending 2009-12-31" [3] "12 months ending 2008-12-31" "12 months ending 2007-12-31"
质料筹备就绪,就可以据此对财政报表举办可视化了可能布局性预测了,而这是代价投资的重头戏。
原文:http://yishuo.org/2012/03/download-financial-statements-with-r/