Skip to content
Project: Building Financial Reports
  • AI Chat
  • Code
  • Report
  • Help your hedge fund manager!

    You have two datasets at your disposal: Balance_Sheet.xlsx and Income_Statement.xlsx. Both these datasets have three columns in common:

    • "Company": The company's ticker name.
    • "comp_type" The type of industry the company in question belongs to. It is either "tech" for companies in the technology industry, "fmcg" for companies in the fast-moving consumer goods industry, and "real_est" for companies in the real estate industry.
    • "Year": The year the company's information is from.

    The rest of the columns in the datasets contain information from the financial statement of the "Company" in question. Note that the columns in Balance_Sheet.xlsx only contain financial information from the balance sheet. Similarly, the columns in Income_Statement.xlsx only contain financial information from the income statement. The columns are named accordingly. For instance, the column "Total Liab" from Balance_Sheet.xlsx is the total liability.

    import numpy as np
    import pandas as pd
    import seaborn as sns
    # Read in the files
    balance_sheet = pd.read_excel("data/Balance_Sheet.xlsx")
    income_statement = pd.read_excel("data/Income_Statement.xlsx")
    display(balance_sheet.head())
    display(income_statement.head())
    # Merge both the dataframes and call it df_ratios
    df_ratios = pd.merge(income_statement, balance_sheet, on = ["Year", "company", "comp_type"])
    display(df_ratios)
    # Compute gross margin ratio
    df_ratios["profitability_ratio"] = (df_ratios["Total Revenue"] - df_ratios["Cost Of Goods Sold"])/df_ratios["Total Revenue"]
    df_ratios["profitability_ratio"][:10]
    # Compute operating margin ratio, but commenting it out
    df_ratios["profitability_ratio"] = (df_ratios["Total Revenue"] - df_ratios["Total Operating Expenses"])/df_ratios["Total Revenue"]
    df_ratios["profitability_ratio"][:10]
    # Compute debt-to-equity ratio
    df_ratios["leverage_ratio"] = df_ratios["Total Liab"]/df_ratios["Total Stockholder Equity"]
    # Compute equity multiplier ratio, but commenting it out
    df_ratios["leverage_ratio"] = df_ratios["Total Assets"]/df_ratios["Total Stockholder Equity"]
    # Using pivot table to see the "comp_type" with the lowest average profitability ratio
    print(df_ratios.pivot_table(index="comp_type", values="profitability_ratio"))
    lowest_profitability = "fmcg"
    # Using pivot table to see the "comp_type" with the highest average leverage ratio
    print(df_ratios.pivot_table(index="comp_type", values="leverage_ratio"))
    highest_leverage = "real_est"