Calcbench API

Calcbench is has created a couple of API endpoints. The API serves normalized and as-reported financial information in JSON.

Calcbench uses cookie based authentication, you will need to use a client that handles cookies, an example using Python's requests package is below.

In [15]:
import requests
import json
import pandas as pd
cb_email = "your_calcbench_username" # put your calcbench username here
cb_password = "your_calcbench_password" # put your calcbench password here
r = requests.post('https://www.calcbench.com/account/LogOnAjax', 
                  {'email' : cb_email, 'strng' : cb_password, 'rememberMe' : 'true'}, 
                  verify=True)
assert r.text == 'true', 'login failed'

Get tickers by industry.

In [204]:
pharma_SIC_code = 2834
pharma_companies = requests.get("https://www.calcbench.com/api/companies?siccodes={0}".format(pharma_SIC_code)).json()
pharma_tickers = [co['ticker'] for co in pharma_companies]

Normalized Data

In [206]:
metrics = ['revenue', 'netincome', 'assets', 'stockholdersequity']
payload = {"start_year" : 2010,
           'start_period' : 1,
           'end_year' : 2014,
           'end_period' : 4,
           'company_identifiers' : pharma_tickers,
           'metrics' : metrics,
           }
data = requests.post("https://www.calcbench.com/api/NormalizedValues", 
                     data=json.dumps(payload), 
                     headers={'content-type' : 'application/json'}).json()

Build dataframe

In [207]:
pharma_data = pd.DataFrame(data)
pharma_data.set_index(keys=[ 'ticker', 'metric', 'calendar_year', 'calendar_period'], inplace=True)
pharma_data = pharma_data.unstack('metric')['value']
pharma_data = pharma_data[metrics]

Compute Return On Equity

In [208]:
pharma_data['profitmargin'] = (pharma_data['netincome'] ) / pharma_data['revenue']
pharma_data['assetturnover'] = pharma_data['revenue'] / pharma_data['assets']
pharma_data['financial_leverage'] = pharma_data['assets'] / pharma_data['stockholdersequity']
pharma_data['return_on_equity'] = pharma_data['profitmargin'] * pharma_data['assetturnover'] * pharma_data['financial_leverage']
In [209]:
pharma_data[pharma_data['return_on_equity'].notnull()]
Out[209]:
metric revenue netincome assets stockholdersequity profitmargin assetturnover financial_leverage return_on_equity
ticker calendar_year calendar_period
ABMC 2010 4 2339000 -342000 6015000 2657000 -0.146216 0.388861 2.263831 -0.128717
2011 2 2486000 123000 5889000 2381000 0.049477 0.422143 2.473331 0.051659
3 2365000 -28000 5892000 2372000 -0.011839 0.401392 2.483980 -0.011804
4 2374000 -15000 5636000 2370000 -0.006318 0.421221 2.378059 -0.006329
2012 1 2296000 -206000 5694000 2171000 -0.089721 0.403231 2.622754 -0.094887
2 2462000 -77000 5940000 2110000 -0.031275 0.414478 2.815166 -0.036493
3 2283000 -264000 5720000 1916000 -0.115637 0.399126 2.985386 -0.137787
4 2302000 -565000 4779000 1364000 -0.245439 0.481691 3.503666 -0.414223
2013 1 2125000 -424000 5158000 1262000 -0.199529 0.411981 4.087163 -0.335975
2 2380000 -294000 5266000 993000 -0.123529 0.451956 5.303122 -0.296073
3 2257000 -213000 4525000 796000 -0.094373 0.498785 5.684673 -0.267588
4 2132000 145000 4966000 1338000 0.068011 0.429319 3.711510 0.108371
2014 1 2043000 9000 4743000 1381000 0.004405 0.430740 3.434468 0.006517
2 1811000 -41000 4390000 1350000 -0.022639 0.412528 3.251852 -0.030370
ACAD 2010 4 35404000 29141000 38394000 29688000 0.823099 0.922123 1.293250 0.981575
2011 2 460000 -6556000 41309000 32821000 -14.252174 0.011136 1.258615 -0.199750
3 584000 -5076000 37022000 28144000 -8.691781 0.015774 1.315449 -0.180358
4 588000 -5300000 32114000 23362000 -9.013605 0.018310 1.374625 -0.226864
2012 1 450000 -6218000 26519000 17585000 -13.817778 0.016969 1.508047 -0.353597
2 599000 -5419000 21874000 12708000 -9.046745 0.027384 1.721278 -0.426424
3 3478000 -2402000 23750000 17664000 -0.690627 0.146442 1.344543 -0.135983
4 380000 -6810000 108590000 84984000 -17.921053 0.003499 1.277770 -0.080133
2013 1 417000 -6123000 103015000 79662000 -14.683453 0.004048 1.293151 -0.076862
2 451000 -9081000 206909000 181475000 -20.135255 0.002180 1.140152 -0.050040
3 240000 -10695000 199285000 180754000 -44.562500 0.001204 1.102521 -0.059169
4 37000 -12049000 189118000 182131000 -325.648649 0.000196 1.038362 -0.066156
2014 1 30000 -17828000 373506000 365460000 -594.266667 0.000080 1.022016 -0.048782
2 28000 -21495000 359465000 350108000 -767.678571 0.000078 1.026726 -0.061395
ACHN 2010 4 2005000 -6244000 58235000 50544000 -3.114214 0.034429 1.152164 -0.123536
2011 2 56000 -11250000 102834000 92004000 -200.892857 0.000545 1.117712 -0.122277
... ... ... ... ... ... ... ... ... ... ...
wcui 2014 1 18919 -3923115 6042781 5209066 -207.363761 0.003131 1.160051 -0.753132
2 70576 -497000 6241314 5112921 -7.042054 0.011308 1.220694 -0.097205
xoma 2010 4 9600000 -17758000 74252000 23591000 -1.849792 0.129289 3.147471 -0.752745
2011 2 16525000 -8130000 79598000 24138000 -0.491982 0.207606 3.297622 -0.336813
3 16229000 -6543000 77185000 21661000 -0.403167 0.210261 3.563317 -0.302064
4 9847000 -11735000 78036000 15011000 -1.191734 0.126185 5.198588 -0.781760
2012 1 9865000 -30425000 101322000 19488000 -3.084136 0.097363 5.199200 -1.561217
2 9275000 -16155000 85917000 3863000 -1.741779 0.107953 22.241004 -4.181983
3 7251000 -26851000 79357000 -20280000 -3.703075 0.091372 -3.913067 1.324014
4 7391000 2366000 105676000 21467000 0.320119 0.069940 4.922719 0.110216
2013 1 9453000 -24887000 88946000 -909000 -2.632709 0.106278 -97.850385 27.378438
2 7151000 -17248000 76947000 -16862000 -2.411970 0.092934 -4.563338 1.022892
3 6312000 -29624000 91006000 -13543000 -4.693283 0.069358 -6.719781 2.187403
4 12535000 -52299000 134782000 -3987000 -4.172238 0.093002 -33.805367 13.117381
2014 1 3410000 -4687000 107629000 1740000 -1.374487 0.031683 61.855747 -2.693678
2 5973000 -11897000 89925000 -7572000 -1.991796 0.066422 -11.875990 1.571183
zlcs 2010 4 1317000 -11969000 82669000 62997000 -9.088079 0.015931 1.312269 -0.189993
2011 2 1848000 -11314000 91113000 62538000 -6.122294 0.020283 1.456922 -0.180914
3 2428000 -9251000 81457000 53948000 -3.810132 0.029807 1.509917 -0.171480
4 2637000 -10767000 79883000 43913000 -4.083049 0.033011 1.819120 -0.245189
2012 1 2320000 -13542000 82059000 45746000 -5.837069 0.028272 1.793796 -0.296026
2 2924000 -10324000 71695000 39022000 -3.530780 0.040784 1.837297 -0.264569
3 3518000 -12174000 71685000 38938000 -3.460489 0.049076 1.841004 -0.312651
4 3788000 -8287000 61375000 31026000 -2.187698 0.061719 1.978180 -0.267099
2013 1 3674000 -8047000 48203000 23504000 -2.190256 0.076219 2.050842 -0.342367
2 3891000 -10562000 40510000 16589000 -2.714469 0.096050 2.441980 -0.636687
3 3400000 -10529000 36457000 15499000 -3.096765 0.093261 2.352216 -0.679334
4 3766000 -9479000 32106000 14182000 -2.516994 0.117299 2.263856 -0.668382
2014 1 1603000 -3790000 16121000 10656000 -2.364317 0.099436 1.512857 -0.355668
2 1132000 3341000 16674000 14314000 2.951413 0.067890 1.164874 0.233408

3265 rows × 8 columns

As Reported Data

Get Data

In [5]:
ticker = "ibm"
statement_type = "income" # one of (income, balance, cash)
as_reported_url_template = 'https://www.calcbench.com/api/asreported/?companyIdentifier={0}&statementType={1}&periodType=annual'
response = requests.get(as_reported_url_template.format(ticker, statement_type), verify=True)
as_reported_data = json.loads(response.text)

Build DataFrame

In [8]:
columns = pd.PeriodIndex((start['period_start'] for start in as_reported_data['columns']), freq="A")
index = [li['label'] for li in as_reported_data['line_items']]
data = [[f['effective_value'] for f in line_item.get('facts', [])] for line_item in as_reported_data['line_items']]
as_reported_df = pd.DataFrame(data=data, index=index, columns=columns)
In [9]:
as_reported_df
Out[9]:
2013 2012 2011 2010
Revenue: NaN NaN NaN NaN
Services 5.765500e+10 5.945300e+10 6.072100e+10 5.686800e+10
Sales 4.004900e+10 4.301400e+10 4.406300e+10 4.073600e+10
Financing 2.047000e+09 2.040000e+09 2.132000e+09 2.267000e+09
Total revenue 9.975100e+10 1.045070e+11 1.069160e+11 9.987000e+10
Cost: NaN NaN NaN NaN
Services 3.756400e+10 3.916600e+10 4.074000e+10 3.838300e+10
Sales 1.257200e+10 1.395600e+10 1.497300e+10 1.437400e+10
Financing 1.110000e+09 1.087000e+09 1.065000e+09 1.100000e+09
Total cost 5.124600e+10 5.420900e+10 5.677800e+10 5.385700e+10
Gross profit 4.850500e+10 5.029800e+10 5.013800e+10 4.601400e+10
Expense and other income: NaN NaN NaN NaN
Selling, general and administrative 2.350200e+10 2.355300e+10 2.359400e+10 2.183700e+10
Research, development and engineering (Note O) 6.226000e+09 6.302000e+09 6.258000e+09 6.026000e+09
Intellectual property and custom development income 8.220000e+08 1.074000e+09 1.108000e+09 1.154000e+09
Other (income) and expense -3.270000e+08 -8.430000e+08 -2.000000e+07 -7.870000e+08
Interest expense (Note D&J) 4.020000e+08 4.590000e+08 4.110000e+08 3.680000e+08
Total expense and other (income) 2.898100e+10 2.839600e+10 2.913500e+10 2.629100e+10
Income before income taxes 1.952400e+10 2.190200e+10 2.100300e+10 1.972300e+10
Provision for income taxes (Note N) 3.041000e+09 5.298000e+09 5.148000e+09 4.890000e+09
Net income 1.648300e+10 1.660400e+10 1.585500e+10 1.483300e+10
Earnings per share of common stock: NaN NaN NaN NaN
Assuming dilution (in dollars per share) (Note P) 1.494000e+01 1.437000e+01 1.306000e+01 1.152000e+01
Basic (in dollars per share) (Note P) 1.506000e+01 1.453000e+01 1.325000e+01 1.169000e+01
ASSUMING DILUTION: NaN NaN NaN NaN
Earnings/(loss) per share of common stock, assuming dilution, continuing operations NaN NaN NaN NaN
Earnings/(loss) per share of common stock, assuming dilution, discontinued operations NaN NaN NaN NaN
BASIC: NaN NaN NaN NaN
Earnings/(loss) per share of common stock, basic, continuing operations NaN NaN NaN NaN
Earnings/(loss) per share of common stock, basic, discontinued operations NaN NaN NaN NaN
Weighted-average number of common shares outstanding: NaN NaN NaN NaN
Assuming dilution (in shares) 1.103042e+09 1.155449e+09 1.213768e+09 1.287355e+09
Basic (in shares) 1.094487e+09 1.142509e+09 1.196951e+09 1.268789e+09
Gross profit: NaN NaN NaN NaN
Income from continuing operations NaN NaN NaN NaN
DISCONTINUED OPERATIONS: NaN NaN NaN NaN
Income/(loss) from discontinued operations, net of tax NaN NaN NaN NaN