A small demo of the things you can do using the quantmod package in R. For almost all the examples I will use the Google stock symbol GOOG
library(quantmod)
## Loading required package: Defaults
## Loading required package: xts
## Loading required package: zoo
##
## Attaching package: 'zoo'
##
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
##
## Loading required package: TTR
## Version 0.4-0 included new data defaults. See ?getSymbols.
sym <- "GOOG" #Change this to generate the same report for another symbol
You can pull company financial statements directly from Google finance using the getFinancials. This will pull the past 4 years of Google financial statements
financials <- getFinancials(sym, auto.assign=F)
For example, the yearly Balance Sheets for the past 4 years from Google
viewFinancials(financials, type="BS")
## Annual Balance Sheet for GOOG
## 2013-12-31 2012-12-31
## Cash & Equivalents 8989.00 6712
## Short Term Investments 39819.00 33310
## Cash and Short Term Investments 58717.00 48088
## Accounts Receivable - Trade, Net 8882.00 7885
## Receivables - Other NA NA
## Total Receivables, Net 9390.00 8585
## Total Inventory 426.00 505
## Prepaid Expenses 2595.00 2132
## Other Current Assets, Total 1758.00 1144
## Total Current Assets 72886.00 60454
## Property/Plant/Equipment, Total - Gross 23837.00 17697
## Accumulated Depreciation, Total -7313.00 -5843
## Goodwill, Net 11492.00 10537
## Intangibles, Net 6066.00 7473
## Long Term Investments 1976.00 1469
## Other Long Term Assets, Total 1976.00 2011
## Total Assets 110920.00 93798
## Accounts Payable 2453.00 2012
## Accrued Expenses 6253.00 5497
## Notes Payable/Short Term Debt 3000.00 2549
## Current Port. of LT Debt/Capital Leases 9.00 NA
## Other Current liabilities, Total 4193.00 4279
## Total Current Liabilities 15908.00 14337
## Long Term Debt 1990.00 2988
## Capital Lease Obligations 246.00 NA
## Total Long Term Debt 2236.00 2988
## Total Debt 5245.00 5537
## Deferred Income Tax 1947.00 1872
## Minority Interest NA NA
## Other Liabilities, Total 3520.00 2886
## Total Liabilities 23611.00 22083
## Redeemable Preferred Stock, Total NA NA
## Preferred Stock - Non Redeemable, Net 0.00 0
## Common Stock, Total 0.33 22835
## Additional Paid-In Capital 25921.67 NA
## Retained Earnings (Accumulated Deficit) 61262.00 48342
## Treasury Stock - Common NA NA
## Other Equity, Total 75.00 -66
## Total Equity 87309.00 71715
## Total Liabilities & Shareholders' Equity 110920.00 93798
## Shares Outs - Common Stock Primary Issue NA NA
## Total Common Shares Outstanding 671.66 660
## 2011-12-31 2010-12-31
## Cash & Equivalents 4712.0 4652.0
## Short Term Investments 34643.0 21345.0
## Cash and Short Term Investments 44626.0 34975.0
## Accounts Receivable - Trade, Net 5427.0 4252.0
## Receivables - Other NA NA
## Total Receivables, Net 6172.0 5002.0
## Total Inventory 35.0 NA
## Prepaid Expenses 1710.0 1326.0
## Other Current Assets, Total 215.0 259.0
## Total Current Assets 52758.0 41562.0
## Property/Plant/Equipment, Total - Gross 14400.0 11771.0
## Accumulated Depreciation, Total -4797.0 -4012.0
## Goodwill, Net 7346.0 6256.0
## Intangibles, Net 1578.0 1044.0
## Long Term Investments 790.0 523.0
## Other Long Term Assets, Total 499.0 707.0
## Total Assets 72574.0 57851.0
## Accounts Payable 588.0 483.0
## Accrued Expenses 3188.0 2371.0
## Notes Payable/Short Term Debt 1218.0 3465.0
## Current Port. of LT Debt/Capital Leases NA NA
## Other Current liabilities, Total 3919.0 3677.0
## Total Current Liabilities 8913.0 9996.0
## Long Term Debt 2986.0 0.0
## Capital Lease Obligations NA NA
## Total Long Term Debt 2986.0 0.0
## Total Debt 4204.0 3465.0
## Deferred Income Tax 287.0 0.0
## Minority Interest NA NA
## Other Liabilities, Total 2243.0 1614.0
## Total Liabilities 14429.0 11610.0
## Redeemable Preferred Stock, Total NA NA
## Preferred Stock - Non Redeemable, Net 0.0 0.0
## Common Stock, Total 20264.0 18235.0
## Additional Paid-In Capital NA NA
## Retained Earnings (Accumulated Deficit) 37605.0 27868.0
## Treasury Stock - Common NA NA
## Other Equity, Total -51.0 44.0
## Total Equity 58145.0 46241.0
## Total Liabilities & Shareholders' Equity 72574.0 57851.0
## Shares Outs - Common Stock Primary Issue NA NA
## Total Common Shares Outstanding 649.8 642.6
## attr(,"col_desc")
## [1] "As of 2013-12-31" "As of 2012-12-31" "As of 2011-12-31"
## [4] "As of 2010-12-31"
Or I can look quarterly
viewFinancials(financials, type="BS", period="Q")
## Quarterly Balance Sheet for GOOG
## 2014-03-31 2013-12-31
## Cash & Equivalents 14536.0 8989.00
## Short Term Investments 42740.0 39819.00
## Cash and Short Term Investments 57276.0 58717.00
## Accounts Receivable - Trade, Net 7827.0 8882.00
## Receivables - Other NA NA
## Total Receivables, Net 8421.0 9390.00
## Total Inventory 337.0 426.00
## Prepaid Expenses 2054.0 2595.00
## Other Current Assets, Total 7226.0 1758.00
## Total Current Assets 75314.0 72886.00
## Property/Plant/Equipment, Total - Gross 25719.0 23837.00
## Accumulated Depreciation, Total -7842.0 -7313.00
## Goodwill, Net 14177.0 11492.00
## Intangibles, Net 5317.0 6066.00
## Long Term Investments 2123.0 1976.00
## Other Long Term Assets, Total 1718.0 1976.00
## Total Assets 116526.0 110920.00
## Accounts Payable 1623.0 2453.00
## Accrued Expenses 4818.0 6253.00
## Notes Payable/Short Term Debt 3009.0 3000.00
## Current Port. of LT Debt/Capital Leases NA 9.00
## Other Current liabilities, Total 6820.0 4193.00
## Total Current Liabilities 16270.0 15908.00
## Long Term Debt 2991.0 1990.00
## Capital Lease Obligations 243.0 246.00
## Total Long Term Debt 3234.0 2236.00
## Total Debt 6243.0 5245.00
## Deferred Income Tax 1848.0 1947.00
## Minority Interest NA NA
## Other Liabilities, Total 3463.0 3520.00
## Total Liabilities 24815.0 23611.00
## Redeemable Preferred Stock, Total NA NA
## Preferred Stock - Non Redeemable, Net 0.0 0.00
## Common Stock, Total 26652.0 0.33
## Additional Paid-In Capital NA 25921.67
## Retained Earnings (Accumulated Deficit) 64714.0 61262.00
## Treasury Stock - Common NA NA
## Other Equity, Total 145.0 75.00
## Total Equity 91711.0 87309.00
## Total Liabilities & Shareholders' Equity 116526.0 110920.00
## Shares Outs - Common Stock Primary Issue NA NA
## Total Common Shares Outstanding 674.5 671.66
## 2013-09-30 2013-06-30
## Cash & Equivalents 7822.00 9451.00
## Short Term Investments 41281.00 38268.00
## Cash and Short Term Investments 56523.00 54432.00
## Accounts Receivable - Trade, Net 7921.00 7321.00
## Receivables - Other NA NA
## Total Receivables, Net 8592.00 8163.00
## Total Inventory 235.00 342.00
## Prepaid Expenses 2216.00 2483.00
## Other Current Assets, Total 1292.00 1441.00
## Total Current Assets 68858.00 66861.00
## Property/Plant/Equipment, Total - Gross 21722.00 19255.00
## Accumulated Depreciation, Total -6855.00 -6343.00
## Goodwill, Net 11426.00 11396.00
## Intangibles, Net 6290.00 6558.00
## Long Term Investments 1843.00 1564.00
## Other Long Term Assets, Total 1784.00 1891.00
## Total Assets 105068.00 101182.00
## Accounts Payable 2124.00 1758.00
## Accrued Expenses 5055.00 5103.00
## Notes Payable/Short Term Debt 3009.00 3000.00
## Current Port. of LT Debt/Capital Leases NA NA
## Other Current liabilities, Total 4287.00 5468.00
## Total Current Liabilities 14475.00 15329.00
## Long Term Debt 2238.00 1989.00
## Capital Lease Obligations NA NA
## Total Long Term Debt 2238.00 1989.00
## Total Debt 5247.00 4989.00
## Deferred Income Tax 2097.00 1905.00
## Minority Interest NA NA
## Other Liabilities, Total 3269.00 3107.00
## Total Liabilities 22079.00 22330.00
## Redeemable Preferred Stock, Total NA NA
## Preferred Stock - Non Redeemable, Net 0.00 0.00
## Common Stock, Total 0.33 0.33
## Additional Paid-In Capital 25003.67 24333.67
## Retained Earnings (Accumulated Deficit) 57886.00 54916.00
## Treasury Stock - Common NA NA
## Other Equity, Total 30.00 -189.00
## Total Equity 82989.00 78852.00
## Total Liabilities & Shareholders' Equity 105068.00 101182.00
## Shares Outs - Common Stock Primary Issue NA NA
## Total Common Shares Outstanding 668.31 666.27
## 2013-03-31
## Cash & Equivalents 15375.00
## Short Term Investments 34723.00
## Cash and Short Term Investments 50098.00
## Accounts Receivable - Trade, Net 7612.00
## Receivables - Other NA
## Total Receivables, Net 8670.00
## Total Inventory 648.00
## Prepaid Expenses 2074.00
## Other Current Assets, Total 1318.00
## Total Current Assets 62808.00
## Property/Plant/Equipment, Total - Gross 18260.00
## Accumulated Depreciation, Total -5960.00
## Goodwill, Net 10595.00
## Intangibles, Net 7324.00
## Long Term Investments 1470.00
## Other Long Term Assets, Total 2195.00
## Total Assets 96692.00
## Accounts Payable 2094.00
## Accrued Expenses 4438.00
## Notes Payable/Short Term Debt 2150.00
## Current Port. of LT Debt/Capital Leases NA
## Other Current liabilities, Total 4570.00
## Total Current Liabilities 13252.00
## Long Term Debt 2989.00
## Capital Lease Obligations NA
## Total Long Term Debt 2989.00
## Total Debt 5139.00
## Deferred Income Tax 1978.00
## Minority Interest NA
## Other Liabilities, Total 3000.00
## Total Liabilities 21219.00
## Redeemable Preferred Stock, Total NA
## Preferred Stock - Non Redeemable, Net 0.00
## Common Stock, Total 0.33
## Additional Paid-In Capital 23428.67
## Retained Earnings (Accumulated Deficit) 51688.00
## Treasury Stock - Common NA
## Other Equity, Total -147.00
## Total Equity 75473.00
## Total Liabilities & Shareholders' Equity 96692.00
## Shares Outs - Common Stock Primary Issue NA
## Total Common Shares Outstanding 662.02
## attr(,"col_desc")
## [1] "As of 2014-03-31" "As of 2013-12-31" "As of 2013-09-30"
## [4] "As of 2013-06-30" "As of 2013-03-31"
Similarly, I can do the same actions for Income Statements and Cash Flow Statements
viewFinancials(financials, type="IS", period="A")
## Annual Income Statement for GOOG
## 2013-12-31 2012-12-31
## Revenue 59825.00 50175.00
## Other Revenue, Total NA NA
## Total Revenue 59825.00 50175.00
## Cost of Revenue, Total 25824.00 20505.00
## Gross Profit 34001.00 29670.00
## Selling/General/Admin. Expenses, Total 12002.00 9741.00
## Research & Development 7910.00 6593.00
## Depreciation/Amortization NA NA
## Interest Expense(Income) - Net Operating NA NA
## Unusual Expense (Income) 123.00 576.00
## Other Operating Expenses, Total NA NA
## Total Operating Expense 45859.00 37415.00
## Operating Income 13966.00 12760.00
## Interest Income(Expense), Net Non-Operating NA NA
## Gain (Loss) on Sale of Assets -57.00 188.00
## Other, Net 63.00 58.00
## Income Before Tax 14496.00 13386.00
## Income After Tax 12214.00 10788.00
## Minority Interest NA NA
## Equity In Affiliates NA NA
## Net Income Before Extra. Items 12214.00 10788.00
## Accounting Change NA NA
## Discontinued Operations NA NA
## Extraordinary Item NA NA
## Net Income 12920.00 10737.00
## Preferred Dividends NA NA
## Income Available to Common Excl. Extra Items 12214.00 10788.00
## Income Available to Common Incl. Extra Items 12920.00 10737.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 NA
## Diluted Weighted Average Shares 677.62 664.61
## Diluted EPS Excluding Extraordinary Items 18.02 16.23
## Diluted EPS Including Extraordinary Items NA NA
## Dividends per Share - Common Stock Primary Issue 0.00 0.00
## 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 18.25 16.70
## 2011-12-31 2010-12-31
## Revenue 37905.00 29321.00
## Other Revenue, Total NA NA
## Total Revenue 37905.00 29321.00
## Cost of Revenue, Total 13188.00 10417.00
## Gross Profit 24717.00 18904.00
## Selling/General/Admin. Expenses, Total 7313.00 4761.00
## Research & Development 5162.00 3762.00
## Depreciation/Amortization NA NA
## Interest Expense(Income) - Net Operating NA NA
## Unusual Expense (Income) 610.00 0.00
## Other Operating Expenses, Total NA NA
## Total Operating Expense 26273.00 18940.00
## Operating Income 11632.00 10381.00
## Interest Income(Expense), Net Non-Operating NA NA
## Gain (Loss) on Sale of Assets 0.00 0.00
## Other, Net 65.00 11.00
## Income Before Tax 12326.00 10796.00
## Income After Tax 9737.00 8505.00
## Minority Interest NA NA
## Equity In Affiliates NA NA
## Net Income Before Extra. Items 9737.00 8505.00
## Accounting Change NA NA
## Discontinued Operations NA NA
## Extraordinary Item NA NA
## Net Income 9737.00 8505.00
## Preferred Dividends NA NA
## Income Available to Common Excl. Extra Items 9737.00 8505.00
## Income Available to Common Incl. Extra Items 9737.00 8505.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 654.43 646.50
## Diluted EPS Excluding Extraordinary Items 14.88 13.16
## Diluted EPS Including Extraordinary Items NA NA
## Dividends per Share - Common Stock Primary Issue 0.00 0.00
## 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 15.61 13.16
## attr(,"col_desc")
## [1] "12 months ending 2013-12-31" "12 months ending 2012-12-31"
## [3] "12 months ending 2011-12-31" "12 months ending 2010-12-31"
viewFinancials(financials, type="CF", period="A")
## Annual Cash Flow Statement for GOOG
## 2013-12-31 2012-12-31 2011-12-31
## Net Income/Starting Line 12920 10737 9737
## Depreciation/Depletion 2781 1988 1396
## Amortization 1158 974 455
## Deferred Taxes -437 -266 343
## Non-Cash Items 2268 2288 2004
## Changes in Working Capital -31 898 630
## Cash from Operating Activities 18659 16619 14565
## Capital Expenditures -7358 -3273 -3438
## Other Investing Cash Flow Items, Total -6321 -9783 -15603
## Cash from Investing Activities -13679 -13056 -19041
## Financing Cash Flow Items -300 -99 81
## Total Cash Dividends Paid NA NA NA
## Issuance (Retirement) of Stock, Net NA 0 0
## Issuance (Retirement) of Debt, Net -557 1328 726
## Cash from Financing Activities -857 1229 807
## Foreign Exchange Effects -3 3 22
## Net Change in Cash 4120 4795 -3647
## Cash Interest Paid, Supplemental 72 74 40
## Cash Taxes Paid, Supplemental 1932 2034 1471
## 2010-12-31
## Net Income/Starting Line 8505
## Depreciation/Depletion 1067
## Amortization 329
## Deferred Taxes 9
## Non-Cash Items 1270
## Changes in Working Capital -99
## Cash from Operating Activities 11081
## Capital Expenditures -4018
## Other Investing Cash Flow Items, Total -6662
## Cash from Investing Activities -10680
## Financing Cash Flow Items 388
## Total Cash Dividends Paid NA
## Issuance (Retirement) of Stock, Net -801
## Issuance (Retirement) of Debt, Net 3463
## Cash from Financing Activities 3050
## Foreign Exchange Effects -19
## Net Change in Cash 3432
## Cash Interest Paid, Supplemental 0
## Cash Taxes Paid, Supplemental 2175
## attr(,"col_desc")
## [1] "12 months ending 2013-12-31" "12 months ending 2012-12-31"
## [3] "12 months ending 2011-12-31" "12 months ending 2010-12-31"
Ok thats cool. What else can you do?
Well… how about pulling stock quotes on a particular symbol?
options("getSymbols.warning4.0"=FALSE)
prc <- getSymbols(sym, auto.assign=F, src="google")
Here are a snippet the daily High, Low, and Open and Close prices for Google for the past 7 years
dat <- data.frame(High=Hi(prc), Low=Lo(prc), Open=Op(prc), Close=Cl(prc))
head(dat)
## GOOG.High GOOG.Low GOOG.Open GOOG.Close
## 2007-01-03 238.1 230.3 232.8 233.6
## 2007-01-04 241.7 233.9 234.3 241.4
## 2007-01-05 243.5 238.8 241.0 243.3
## 2007-01-08 244.7 240.9 243.6 241.6
## 2007-01-09 243.9 240.4 242.5 242.5
## 2007-01-10 246.5 240.8 242.0 244.5
tail(dat)
## GOOG.High GOOG.Low GOOG.Open GOOG.Close
## 2014-07-09 576.7 569.4 571.6 576.1
## 2014-07-10 576.6 565.0 565.9 571.1
## 2014-07-11 580.9 571.4 571.9 579.2
## 2014-07-14 585.2 578.0 582.6 584.9
## 2014-07-15 585.8 576.6 585.7 584.8
## 2014-07-16 588.4 582.2 588.0 582.7
What else? Maybe you’re interested in trading commodities, in particual, you really, really like trading metals. Well, getting the prices of metals is easy! Let’s say you wanted to look at Gold and Silver prices from the past 100 days
gld <- getMetals("GOLD", from=Sys.Date()-100, to=Sys.Date(), base.currency="CAD", auto.assign=F)
slv <- getMetals("SILVER", from=Sys.Date()-100, to=Sys.Date(), base.currency="CAD", auto.assign=F)
print(cbind(gld, slv))
## XAU.CAD XAG.CAD
## 2014-04-08 1428 21.86
## 2014-04-09 1430 21.94
## 2014-04-10 1429 21.77
## 2014-04-11 1437 21.90
## 2014-04-12 1444 21.93
## 2014-04-13 1449 21.98
## 2014-04-14 1449 21.98
## 2014-04-15 1455 21.96
## 2014-04-16 1441 21.70
## 2014-04-17 1431 21.53
## 2014-04-18 1431 21.60
## 2014-04-19 1428 21.69
## 2014-04-20 1430 21.73
## 2014-04-21 1430 21.73
## 2014-04-22 1421 21.41
## 2014-04-23 1419 21.41
## 2014-04-24 1418 21.48
## 2014-04-25 1418 21.48
## 2014-04-26 1430 21.69
## 2014-04-27 1439 21.83
## 2014-04-28 1439 21.83
## 2014-04-29 1435 21.69
## 2014-04-30 1424 21.45
## 2014-05-01 1417 21.20
## 2014-05-02 1411 20.95
## 2014-05-03 1413 21.07
## 2014-05-04 1427 21.41
## 2014-05-05 1427 21.41
## 2014-05-06 1435 21.50
## 2014-05-07 1431 21.43
## 2014-05-08 1421 21.32
## 2014-05-09 1403 20.97
## 2014-05-10 1400 20.83
## 2014-05-11 1407 20.95
## 2014-05-12 1407 20.95
## 2014-05-13 1408 21.12
## 2014-05-14 1411 21.29
## 2014-05-15 1417 21.47
## 2014-05-16 1416 21.41
## 2014-05-17 1408 21.13
## 2014-05-18 1406 21.06
## 2014-05-19 1406 21.06
## 2014-05-20 1408 21.14
## 2014-05-21 1408 21.10
## 2014-05-22 1411 21.20
## 2014-05-23 1412 21.28
## 2014-05-24 1408 21.20
## 2014-05-25 1405 21.17
## 2014-05-26 1405 21.17
## 2014-05-27 1405 21.14
## 2014-05-28 1391 20.93
## 2014-05-29 1372 20.75
## 2014-05-30 1364 20.64
## 2014-05-31 1359 20.57
## 2014-06-01 1358 20.45
## 2014-06-02 1358 20.45
## 2014-06-03 1355 20.42
## 2014-06-04 1358 20.55
## 2014-06-05 1362 20.59
## 2014-06-06 1365 20.69
## 2014-06-07 1370 20.85
## 2014-06-08 1371 20.83
## 2014-06-09 1371 20.83
## 2014-06-10 1370 20.85
## 2014-06-11 1370 20.87
## 2014-06-12 1374 20.95
## 2014-06-13 1374 20.99
## 2014-06-14 1383 21.28
## 2014-06-15 1388 21.45
## 2014-06-16 1388 21.45
## 2014-06-17 1389 21.44
## 2014-06-18 1378 21.35
## 2014-06-19 1381 21.47
## 2014-06-20 1395 21.81
## 2014-06-21 1419 22.46
## 2014-06-22 1415 22.47
## 2014-06-23 1415 22.47
## 2014-06-24 1412 22.40
## 2014-06-25 1415 22.49
## 2014-06-26 1414 22.47
## 2014-06-27 1409 22.50
## 2014-06-28 1408 22.55
## 2014-06-29 1405 22.41
## 2014-06-30 1405 22.41
## 2014-07-01 1406 22.35
## 2014-07-02 1415 22.49
## 2014-07-03 1413 22.47
## 2014-07-04 1409 22.50
## 2014-07-05 1405 22.52
## 2014-07-06 1407 22.54
## 2014-07-07 1407 22.56
## 2014-07-08 1403 22.40
## 2014-07-09 1409 22.48
## 2014-07-10 1412 22.52
## 2014-07-11 1422 22.72
## 2014-07-12 1427 22.89
## 2014-07-13 1438 23.05
## 2014-07-14 1438 23.05
## 2014-07-15 1419 22.71
## 2014-07-16 1402 22.44
## 2014-07-17 1397 22.32
You can also plot pretty pictures. For example, a time series chart of the google stock
chartSeries(prc, type="candlesticks")