Introduction to the
income statement
A N A LY Z I N G F I N A N C I A L STAT E M E N T S I N P Y T H O N
Rohan Chatterjee
Risk Modeler
ANALYZING FINANCIAL STATEMENTS IN PYTHON
The income statement
Shows company's revenue and expenses over a period of time
Expenses:
Operating expenses
Non-operating expenses
ANALYZING FINANCIAL STATEMENTS IN PYTHON
ANALYZING FINANCIAL STATEMENTS IN PYTHON
Gross margin
Ratio of total revenue after taking out cost
of goods sold to total revenue
Proportion of revenue left after subtracting
cost incurred to earn the revenue
Formula:
TotalRevenue
TotalRevenue-CostofGoodsSold
ANALYZING FINANCIAL STATEMENTS IN PYTHON
Operating margin
Ratio of total revenue after taking out
operating expenses to total revenue
Proportion of revenue left after operating
expenses
Formula:
TotalRevenue
TotalRevenue-OperatingExpenses
ANALYZING FINANCIAL STATEMENTS IN PYTHON
Family of ratios
Efficiency ratio
Measures company's ability to generate income via its resources
For example:
Gross margin
Operating margin
Ratios from the
income statement
and balance sheet
A N A LY Z I N G F I N A N C I A L STAT E M E N T S I N P Y T H O N
Rohan Chatterjee
Risk modeler
ANALYZING FINANCIAL STATEMENTS IN PYTHON
Asset turnover ratio
Ratio of revenue to assets
Measures how efficiently a company is
using its assets to generate revenue
Formula:
TotalAssets
TotalRevenue
ANALYZING FINANCIAL STATEMENTS IN PYTHON
Computing asset turnover ratio using pandas
merged_dat = pd.merge(income_statement, balance_sheet, on = ["Year", "company"])
merged_dat can now be used to compute the ratio and add it as another column in the
DataFrame
merged_dat["asset_turnover"] = merged_dat["Total Revenue"] / merged_dat["Total Assets"]
ANALYZING FINANCIAL STATEMENTS IN PYTHON
User-defined functions to compute ratios
Creating the columns below can become repetitive
balance_sheet["current_ratio"] = balance_sheet["Total Current Assets"] / balance_sheet["Total Current Liabilities"]
balance_sheet["debt_to_equity"] = balance_sheet["Total Liab"] / balance_sheet["Total Stockholder Equity"]
To avoid having to type this code again and again, we can package this into a user-defined
function
ANALYZING FINANCIAL STATEMENTS IN PYTHON
User-defined functions to compute ratios
def compute_ratio(df, numerator, denominator, ratio_name):
df[ratio_name] = df[numerator]/df[denominator]
return df
Compute the current ratio and debt-to equity ratio from the DataFrame balance_sheet using
compute_ratio :
balance_sheet = compute_ratio(balance_sheet, "Total Current Assets",
"Total Current Liabilities", "current_ratio")
balance_sheet = compute_ratio(balance_sheet, "Total Liab",
"Total Stockholder Equity", "debt_to_equity")
ANALYZING FINANCIAL STATEMENTS IN PYTHON
User-defined functions to compute ratios
Define the numerators, denominators and the ratio names in separate lists:
list_of_numerators = ["Total Current Assets", "Total Liab"]
list_of_denominators = ["Total Current Liabilities",
"Total Stockholder Equity"]
list_of_ratio_names = ["current_ratio", "debt_to_equity"]
Loop over the lists and call the function compute_ratio :
for numerator, denominator, ratio_name in zip(list_of_numerators,
list_of_denominators,
list_of_ratio_names):
balance_sheet = compute_ratio(balance_sheet,
numerator,
denominator,
ratio_name)
Visualizing ratios for
within-company
analysis
A N A LY Z I N G F I N A N C I A L STAT E M E N T S I N P Y T H O N
Rohan Chatterjee
Risk modeler
ANALYZING FINANCIAL STATEMENTS IN PYTHON
Visualizing financial ratios
Bar plots are helpful for
visualizing financial ratios for a company on average, and
assessing performance relative to the industry average
ANALYZING FINANCIAL STATEMENTS IN PYTHON
Preparing data for plotting
Using pivot_table to compute the average of the ratios by company:
avg_company_ratio = plot_dat.pivot_table(index=["comp_type",
"company"],
values=["Gross Margin", "Operating Margin",
"Debt-to-equity", "Equity Multiplier"],
aggfunc="mean").reset_index()
print(avg_company_ratio.head())
ANALYZING FINANCIAL STATEMENTS IN PYTHON
Preparing data for plotting
Use pivot_table to compute the average ratio by industry:
avg_industry_ratio = plot_dat.pivot_table(index="comp_type",
values=["Gross Margin", "Operating Margin",
"Debt-to-equity",
"Equity Multiplier"],
aggfunc="mean").reset_index()
print(avg_industry_ratio.head())
ANALYZING FINANCIAL STATEMENTS IN PYTHON
Preparing data for plotting
Plotting data in seaborn requires the data to be in a "long" format. Use pd.melt to melt
the DataFrames avg_industry_ratio and avg_company_ratio into long format:
molten_plot_company = pd.melt(avg_company_ratio, id_vars=["comp_type",
"company"])
molten_plot_industry = pd.melt(avg_industry_ratio,
id_vars=["comp_type"])
ANALYZING FINANCIAL STATEMENTS IN PYTHON
print(molten_plot_company.head())
print(molten_plot_industry.head())
ANALYZING FINANCIAL STATEMENTS IN PYTHON
Preparing data for plotting
Seaborn requires all the data we want to plot in one DataFrame
We use pd.concat to concatenate molten_plot_company and molten_plot_industry
molten_plot_industry does not have the company DataFrame because it contains the
average of the ratios per industry overall
pd.concat requires both DataFrames should to have the same columns, so we add the
column company to molten_plot_industry
molten_plot_industry["company"] = "Industry Average"
molten_plot = pd.concat([molten_plot_company, molten_plot_industry])
ANALYZING FINANCIAL STATEMENTS IN PYTHON
Make the bar graph
sns.barplot(data=molten_plot, y="variable", x="value", hue="company", ci=None)
plt.xlabel(""), plt.ylabel("")
plt.show()