Download altman_model.py from thisisbbln/Altman: direct link, hf CLI and curl.
- Browser
- Download file 3.34 kB
-
https://huggingface.co/datasets/thisisbbln/Altman/resolve/main/altman_model.py
- Command line
-
hf download hf://datasets/thisisbbln/Altman/altman_model.py
-
curl -L -o altman_model.py https://huggingface.co/datasets/thisisbbln/Altman/resolve/main/altman_model.py
3.34 kB
| """ | |
| altman_model.py | |
| Subagent 2: Solvency & Altman Analysis Engine | |
| Implements Altman Z''-Score for Emerging / Non-Manufacturing Markets: | |
| Z'' = 6.56*X1 + 3.26*X2 + 6.72*X3 + 1.05*X4 | |
| Compares accounting surplus (讞讜拽 讛讞讘专讜转 - 诪讘讞谉 讛专讜讜讞) against economic solvency (诪讘讞谉 讬讻讜诇转 讛驻讬专注讜谉). | |
| """ | |
| import pandas as pd | |
| import numpy as np | |
| def calculate_altman_z_double_prime(wc, total_assets, retained_earnings, ebit, bv_equity, total_liabilities): | |
| """ | |
| Altman Z''-Score for Non-Manufacturing / Emerging Markets: | |
| X1 = Working Capital / Total Assets | |
| X2 = Retained Earnings / Total Assets | |
| X3 = EBIT / Total Assets | |
| X4 = Book Value of Equity / Total Liabilities | |
| Z'' = 6.56*X1 + 3.26*X2 + 6.72*X3 + 1.05*X4 | |
| """ | |
| x1 = wc / total_assets | |
| x2 = retained_earnings / total_assets | |
| x3 = ebit / total_assets | |
| x4 = bv_equity / total_liabilities | |
| z_score = 6.56 * x1 + 3.26 * x2 + 6.72 * x3 + 1.05 * x4 | |
| status = "Safe" if z_score > 2.6 else ("Grey Zone" if z_score >= 1.1 else "Distressed / Insolvent") | |
| return { | |
| "X1_WC_TA": x1, | |
| "X2_RE_TA": x2, | |
| "X3_EBIT_TA": x3, | |
| "X4_BVE_TL": x4, | |
| "Z_Score": z_score, | |
| "Status": status | |
| } | |
| def analyze_company_solvency(dividends_list): | |
| """ | |
| Runs solvency analysis for each dividend distribution event. | |
| """ | |
| results = [] | |
| for d in dividends_list: | |
| metrics = calculate_altman_z_double_prime( | |
| wc=d["working_capital_nis_m"], | |
| total_assets=d["total_assets_nis_m"], | |
| retained_earnings=d["retained_earnings_nis_m"], | |
| ebit=d["ebit_nis_m"], | |
| bv_equity=d["bv_equity_nis_m"], | |
| total_liabilities=d["total_liabilities_nis_m"] | |
| ) | |
| res_row = { | |
| "Date": d["date"], | |
| "Dividend_Amount_NIS_M": d["amount_nis_m"], | |
| "Accounting_Surplus_NIS_M": d["accounting_surplus_nis_m"], | |
| "Accounting_Profit_Test": "PASSED (Positive Surplus)" if d["accounting_surplus_nis_m"] > 0 else "FAILED", | |
| "Working_Capital_NIS_M": d["working_capital_nis_m"], | |
| "Total_Assets_NIS_M": d["total_assets_nis_m"], | |
| "Retained_Earnings_NIS_M": d["retained_earnings_nis_m"], | |
| "EBIT_NIS_M": d["ebit_nis_m"], | |
| "BV_Equity_NIS_M": d["bv_equity_nis_m"], | |
| "Total_Liabilities_NIS_M": d["total_liabilities_nis_m"], | |
| "X1": metrics["X1_WC_TA"], | |
| "X2": metrics["X2_RE_TA"], | |
| "X3": metrics["X3_EBIT_TA"], | |
| "X4": metrics["X4_BVE_TL"], | |
| "Altman_Z_Double_Prime": metrics["Z_Score"], | |
| "Economic_Solvency_Status": metrics["Status"], | |
| "Economic_Solvency_Test": "FAILED (Distress Z'' < 1.1)" if metrics["Z_Score"] < 1.1 else "PASSED" | |
| } | |
| results.append(res_row) | |
| return pd.DataFrame(results) | |
| if __name__ == "__main__": | |
| from data_collector import get_company_data | |
| dataset = get_company_data() | |
| for name, comp in dataset.items(): | |
| print(f"\n=================== {comp['name']} ===================") | |
| df_res = analyze_company_solvency(comp["dividends"]) | |
| print(df_res[["Date", "Dividend_Amount_NIS_M", "Accounting_Surplus_NIS_M", "Accounting_Profit_Test", "Altman_Z_Double_Prime", "Economic_Solvency_Status"]]) | |