来自损益表和资产负债表的比率

用 Python 分析财务报表

Rohan Chatterjee

Risk modeler

资产周转率

  • 收入与资产之比
  • 衡量企业利用资产创造收入的效率

公式:

$$\dfrac{\text{Total Revenue}}{\text{Total Assets}}$$

用 Python 分析财务报表

用 pandas 计算资产周转率

merged_dat = pd.merge(income_statement, balance_sheet, on = ["Year", "company"])
  • 现在可使用merged_dat计算比率,并将其作为新列加入DataFrame
merged_dat["asset_turnover"] = merged_dat["Total Revenue"] / merged_dat["Total Assets"]
用 Python 分析财务报表

自定义函数计算比率

  • 手动创建下列列会较为重复
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"]
  • 为避免反复输入,可封装为自定义函数
用 Python 分析财务报表

自定义函数计算比率

def compute_ratio(df, numerator, denominator, ratio_name):
      df[ratio_name] = df[numerator]/df[denominator]
      return df

使用compute_ratio从DataFramebalance_sheet计算流动比率与资产负债率:

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")
用 Python 分析财务报表

自定义函数计算比率

  • 将分子、分母和比率名称分别定义为列表:
    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"]
    
  • 遍历列表并调用函数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)
    
用 Python 分析财务报表

Passons à la pratique !

用 Python 分析财务报表

Preparing Video For Download...