Upload altman_model.py
Browse files- altman_model.py +82 -0
altman_model.py
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
altman_model.py
|
| 3 |
+
Subagent 2: Solvency & Altman Analysis Engine
|
| 4 |
+
Implements Altman Z''-Score for Emerging / Non-Manufacturing Markets:
|
| 5 |
+
Z'' = 6.56*X1 + 3.26*X2 + 6.72*X3 + 1.05*X4
|
| 6 |
+
Compares accounting surplus (讞讜拽 讛讞讘专讜转 - 诪讘讞谉 讛专讜讜讞) against economic solvency (诪讘讞谉 讬讻讜诇转 讛驻讬专注讜谉).
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
import pandas as pd
|
| 10 |
+
import numpy as np
|
| 11 |
+
|
| 12 |
+
def calculate_altman_z_double_prime(wc, total_assets, retained_earnings, ebit, bv_equity, total_liabilities):
|
| 13 |
+
"""
|
| 14 |
+
Altman Z''-Score for Non-Manufacturing / Emerging Markets:
|
| 15 |
+
X1 = Working Capital / Total Assets
|
| 16 |
+
X2 = Retained Earnings / Total Assets
|
| 17 |
+
X3 = EBIT / Total Assets
|
| 18 |
+
X4 = Book Value of Equity / Total Liabilities
|
| 19 |
+
|
| 20 |
+
Z'' = 6.56*X1 + 3.26*X2 + 6.72*X3 + 1.05*X4
|
| 21 |
+
"""
|
| 22 |
+
x1 = wc / total_assets
|
| 23 |
+
x2 = retained_earnings / total_assets
|
| 24 |
+
x3 = ebit / total_assets
|
| 25 |
+
x4 = bv_equity / total_liabilities
|
| 26 |
+
|
| 27 |
+
z_score = 6.56 * x1 + 3.26 * x2 + 6.72 * x3 + 1.05 * x4
|
| 28 |
+
|
| 29 |
+
status = "Safe" if z_score > 2.6 else ("Grey Zone" if z_score >= 1.1 else "Distressed / Insolvent")
|
| 30 |
+
|
| 31 |
+
return {
|
| 32 |
+
"X1_WC_TA": x1,
|
| 33 |
+
"X2_RE_TA": x2,
|
| 34 |
+
"X3_EBIT_TA": x3,
|
| 35 |
+
"X4_BVE_TL": x4,
|
| 36 |
+
"Z_Score": z_score,
|
| 37 |
+
"Status": status
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
def analyze_company_solvency(dividends_list):
|
| 41 |
+
"""
|
| 42 |
+
Runs solvency analysis for each dividend distribution event.
|
| 43 |
+
"""
|
| 44 |
+
results = []
|
| 45 |
+
for d in dividends_list:
|
| 46 |
+
metrics = calculate_altman_z_double_prime(
|
| 47 |
+
wc=d["working_capital_nis_m"],
|
| 48 |
+
total_assets=d["total_assets_nis_m"],
|
| 49 |
+
retained_earnings=d["retained_earnings_nis_m"],
|
| 50 |
+
ebit=d["ebit_nis_m"],
|
| 51 |
+
bv_equity=d["bv_equity_nis_m"],
|
| 52 |
+
total_liabilities=d["total_liabilities_nis_m"]
|
| 53 |
+
)
|
| 54 |
+
res_row = {
|
| 55 |
+
"Date": d["date"],
|
| 56 |
+
"Dividend_Amount_NIS_M": d["amount_nis_m"],
|
| 57 |
+
"Accounting_Surplus_NIS_M": d["accounting_surplus_nis_m"],
|
| 58 |
+
"Accounting_Profit_Test": "PASSED (Positive Surplus)" if d["accounting_surplus_nis_m"] > 0 else "FAILED",
|
| 59 |
+
"Working_Capital_NIS_M": d["working_capital_nis_m"],
|
| 60 |
+
"Total_Assets_NIS_M": d["total_assets_nis_m"],
|
| 61 |
+
"Retained_Earnings_NIS_M": d["retained_earnings_nis_m"],
|
| 62 |
+
"EBIT_NIS_M": d["ebit_nis_m"],
|
| 63 |
+
"BV_Equity_NIS_M": d["bv_equity_nis_m"],
|
| 64 |
+
"Total_Liabilities_NIS_M": d["total_liabilities_nis_m"],
|
| 65 |
+
"X1": metrics["X1_WC_TA"],
|
| 66 |
+
"X2": metrics["X2_RE_TA"],
|
| 67 |
+
"X3": metrics["X3_EBIT_TA"],
|
| 68 |
+
"X4": metrics["X4_BVE_TL"],
|
| 69 |
+
"Altman_Z_Double_Prime": metrics["Z_Score"],
|
| 70 |
+
"Economic_Solvency_Status": metrics["Status"],
|
| 71 |
+
"Economic_Solvency_Test": "FAILED (Distress Z'' < 1.1)" if metrics["Z_Score"] < 1.1 else "PASSED"
|
| 72 |
+
}
|
| 73 |
+
results.append(res_row)
|
| 74 |
+
return pd.DataFrame(results)
|
| 75 |
+
|
| 76 |
+
if __name__ == "__main__":
|
| 77 |
+
from data_collector import get_company_data
|
| 78 |
+
dataset = get_company_data()
|
| 79 |
+
for name, comp in dataset.items():
|
| 80 |
+
print(f"\n=================== {comp['name']} ===================")
|
| 81 |
+
df_res = analyze_company_solvency(comp["dividends"])
|
| 82 |
+
print(df_res[["Date", "Dividend_Amount_NIS_M", "Accounting_Surplus_NIS_M", "Accounting_Profit_Test", "Altman_Z_Double_Prime", "Economic_Solvency_Status"]])
|