File size: 3,338 Bytes
cbcc7c5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
"""
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"]])