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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
plot_generator.py
|
| 3 |
+
High-Impact Publication-Quality Matplotlib Visualizations for:
|
| 4 |
+
1. Altman Z''-Score vs Accounting Surplus Divergence (Delek & Africa Israel)
|
| 5 |
+
2. BSM Executive Option Valuation, Protection Asymmetry & Vega Expansion
|
| 6 |
+
3. Multi-Parameter Sensitivity Heatmaps (Moneyness vs Volatility Shocks)
|
| 7 |
+
|
| 8 |
+
Output Files:
|
| 9 |
+
- /home/dcor/omerazoulay/nini/altman_vs_accounting_surplus.png
|
| 10 |
+
- /home/dcor/omerazoulay/nini/option_value_vega_gain.png
|
| 11 |
+
- /home/dcor/omerazoulay/nini/sensitivity_heatmap.png
|
| 12 |
+
"""
|
| 13 |
+
|
| 14 |
+
import os
|
| 15 |
+
import numpy as np
|
| 16 |
+
import pandas as pd
|
| 17 |
+
import matplotlib.pyplot as plt
|
| 18 |
+
import matplotlib.patches as mpatches
|
| 19 |
+
|
| 20 |
+
# Import local analysis engines
|
| 21 |
+
from data_collector import get_company_data
|
| 22 |
+
from altman_model import calculate_altman_z_double_prime, analyze_company_solvency
|
| 23 |
+
from bsm_engine import black_scholes_call, simulate_dividend_impact, run_sensitivity_grid
|
| 24 |
+
|
| 25 |
+
# Configure global matplotlib aesthetics for academic publication quality
|
| 26 |
+
plt.rcParams.update({
|
| 27 |
+
'font.sans-serif': 'DejaVu Sans',
|
| 28 |
+
'font.family': 'sans-serif',
|
| 29 |
+
'font.size': 11,
|
| 30 |
+
'axes.titlesize': 13,
|
| 31 |
+
'axes.titleweight': 'bold',
|
| 32 |
+
'axes.labelsize': 11,
|
| 33 |
+
'axes.labelweight': 'bold',
|
| 34 |
+
'xtick.labelsize': 10,
|
| 35 |
+
'ytick.labelsize': 10,
|
| 36 |
+
'legend.fontsize': 10,
|
| 37 |
+
'figure.titlesize': 15,
|
| 38 |
+
'figure.titleweight': 'bold',
|
| 39 |
+
'figure.autolayout': False,
|
| 40 |
+
'savefig.dpi': 300,
|
| 41 |
+
'savefig.bbox': 'tight',
|
| 42 |
+
'axes.edgecolor': '#333333',
|
| 43 |
+
'axes.linewidth': 1.0,
|
| 44 |
+
'grid.color': '#E0E0E0',
|
| 45 |
+
'grid.linestyle': '--',
|
| 46 |
+
'grid.alpha': 0.7
|
| 47 |
+
})
|
| 48 |
+
|
| 49 |
+
OUTPUT_DIR = "/home/dcor/omerazoulay/nini"
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
def generate_altman_vs_accounting_surplus():
|
| 53 |
+
"""
|
| 54 |
+
Figure 1: altman_vs_accounting_surplus.png
|
| 55 |
+
Compares the apparent legal accounting surplus against the true economic solvency
|
| 56 |
+
(Altman Z''-Score) for Delek Real Estate and Africa Israel Investments.
|
| 57 |
+
Demonstrates the structural failure of the statutory profit test.
|
| 58 |
+
"""
|
| 59 |
+
dataset = get_company_data()
|
| 60 |
+
|
| 61 |
+
events = [
|
| 62 |
+
{"label": "Delek Real Estate\n2007 (Apr 10)", "company": "Delek_Group", "idx": 0, "surplus": 850.0, "div": 220.0},
|
| 63 |
+
{"label": "Delek Real Estate\n2008 (Apr 15)", "company": "Delek_Group", "idx": 1, "surplus": 420.0, "div": 180.0},
|
| 64 |
+
{"label": "Africa Israel\n2007 (Jun 30)", "company": "Africa_Israel", "idx": 0, "surplus": 2100.0, "div": 580.0},
|
| 65 |
+
{"label": "Africa Israel\n2008 (Mar 31)", "company": "Africa_Israel", "idx": 1, "surplus": 980.0, "div": 350.0}
|
| 66 |
+
]
|
| 67 |
+
|
| 68 |
+
z_scores = []
|
| 69 |
+
surpluses = []
|
| 70 |
+
dividends = []
|
| 71 |
+
labels = []
|
| 72 |
+
|
| 73 |
+
for ev in events:
|
| 74 |
+
div_data = dataset[ev["company"]]["dividends"][ev["idx"]]
|
| 75 |
+
z_res = calculate_altman_z_double_prime(
|
| 76 |
+
wc=div_data["working_capital_nis_m"],
|
| 77 |
+
total_assets=div_data["total_assets_nis_m"],
|
| 78 |
+
retained_earnings=div_data["retained_earnings_nis_m"],
|
| 79 |
+
ebit=div_data["ebit_nis_m"],
|
| 80 |
+
bv_equity=div_data["bv_equity_nis_m"],
|
| 81 |
+
total_liabilities=div_data["total_liabilities_nis_m"]
|
| 82 |
+
)
|
| 83 |
+
z_scores.append(z_res["Z_Score"])
|
| 84 |
+
surpluses.append(ev["surplus"])
|
| 85 |
+
dividends.append(ev["div"])
|
| 86 |
+
labels.append(ev["label"])
|
| 87 |
+
|
| 88 |
+
x = np.arange(len(labels))
|
| 89 |
+
width = 0.35
|
| 90 |
+
|
| 91 |
+
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(14, 6.2), gridspec_kw={'width_ratios': [1.1, 1.2]})
|
| 92 |
+
fig.suptitle("Empirical Solvency Divergence: Accounting Surplus vs. Altman Z''-Score\nDelek Real Estate & Africa Israel Distributions (2007–2008)", fontsize=14, y=0.98)
|
| 93 |
+
|
| 94 |
+
# --- Subplot 1: Accounting Surplus & Dividend Distributed (NIS M) ---
|
| 95 |
+
bars1 = ax1.bar(x - width/2, surpluses, width, label='Accounting Surplus (מבחן הרווח)', color='#1F77B4', edgecolor='#0D47A1', alpha=0.9)
|
| 96 |
+
bars2 = ax1.bar(x + width/2, dividends, width, label='Dividend Paid (סכום החלוקה)', color='#FF7F0E', edgecolor='#E65100', alpha=0.9)
|
| 97 |
+
|
| 98 |
+
ax1.set_title("A. Accounting Profit Test (Passed)\nStatutory Distributable Surplus & Dividend", fontsize=11, pad=10)
|
| 99 |
+
ax1.set_ylabel("NIS Millions (מיליוני ש\"ח)")
|
| 100 |
+
ax1.set_xticks(x)
|
| 101 |
+
ax1.set_xticklabels(labels, fontsize=9.5)
|
| 102 |
+
ax1.legend(loc='upper right', frameon=True, facecolor='white', framealpha=0.9)
|
| 103 |
+
ax1.grid(axis='y', linestyle='--', alpha=0.6)
|
| 104 |
+
ax1.set_ylim(0, 2400)
|
| 105 |
+
|
| 106 |
+
# Annotate bar values
|
| 107 |
+
for bar in bars1:
|
| 108 |
+
h = bar.get_height()
|
| 109 |
+
ax1.text(bar.get_x() + bar.get_width()/2., h + 30, f"{int(h):,}M", ha='center', va='bottom', fontsize=8.5, fontweight='bold', color='#0D47A1')
|
| 110 |
+
for bar in bars2:
|
| 111 |
+
h = bar.get_height()
|
| 112 |
+
ax1.text(bar.get_x() + bar.get_width()/2., h + 30, f"{int(h):,}M", ha='center', va='bottom', fontsize=8.5, fontweight='bold', color='#E65100')
|
| 113 |
+
|
| 114 |
+
# Status badges
|
| 115 |
+
for i in range(len(x)):
|
| 116 |
+
ax1.text(x[i], 120, "PASSED\nProfit Test", ha='center', va='center', fontsize=8, fontweight='bold',
|
| 117 |
+
bbox=dict(boxstyle="round,pad=0.3", fc="#E8F5E9", ec="#2E7D32", lw=1.2))
|
| 118 |
+
|
| 119 |
+
# --- Subplot 2: Altman Z''-Score Economic Solvency & Distress Zones ---
|
| 120 |
+
# Shaded Zones
|
| 121 |
+
ax2.axhspan(-1.5, 1.1, color='#FFCDD2', alpha=0.5, label='Distress Zone (Z\'\' < 1.1) [חדלות פירעון]')
|
| 122 |
+
ax2.axhspan(1.1, 2.6, color='#FFF9C4', alpha=0.5, label='Grey Zone (1.1 ≤ Z\'\' ≤ 2.6) [אזור אפור]')
|
| 123 |
+
ax2.axhspan(2.6, 4.0, color='#C8E6C9', alpha=0.5, label='Safe Zone (Z\'\' > 2.6) [אזור בטוח]')
|
| 124 |
+
|
| 125 |
+
# Threshold reference lines
|
| 126 |
+
ax2.axhline(1.1, color='#C62828', linestyle='--', linewidth=1.5)
|
| 127 |
+
ax2.axhline(2.6, color='#2E7D32', linestyle='--', linewidth=1.5)
|
| 128 |
+
|
| 129 |
+
# Plot Altman values as connected points with bars/markers
|
| 130 |
+
colors = ['#D32F2F' if z < 1.1 else '#FBC02D' for z in z_scores]
|
| 131 |
+
bar_z = ax2.bar(x, z_scores, width=0.45, color=colors, edgecolor='#555555', linewidth=1.2, zorder=3)
|
| 132 |
+
ax2.plot(x, z_scores, color='#212121', marker='o', markersize=8, linewidth=2, zorder=4)
|
| 133 |
+
|
| 134 |
+
ax2.set_title("B. Economic Solvency Test (Failed)\nAltman Z''-Score for Emerging / Non-Manufacturing", fontsize=11, pad=10)
|
| 135 |
+
ax2.set_ylabel("Altman Z''-Score")
|
| 136 |
+
ax2.set_xticks(x)
|
| 137 |
+
ax2.set_xticklabels(labels, fontsize=9.5)
|
| 138 |
+
ax2.set_ylim(-1.2, 3.5)
|
| 139 |
+
ax2.grid(True, linestyle='--', alpha=0.6)
|
| 140 |
+
|
| 141 |
+
# Value annotations on Altman plot
|
| 142 |
+
for i, z in enumerate(z_scores):
|
| 143 |
+
va = 'bottom' if z >= 0 else 'top'
|
| 144 |
+
y_offset = 0.12 if z >= 0 else -0.12
|
| 145 |
+
ax2.text(x[i], z + y_offset, f"Z'' = {z:.3f}\n(CRITICAL DISTRESS)", ha='center', va=va,
|
| 146 |
+
fontsize=8.5, fontweight='bold', color='#B71C1C',
|
| 147 |
+
bbox=dict(boxstyle="round,pad=0.2", fc="#FFEBEE", ec="#D32F2F", lw=1))
|
| 148 |
+
|
| 149 |
+
ax2.text(3.4, 1.15, "Distress Threshold (1.1)", fontsize=8, color='#C62828', fontweight='bold', ha='right')
|
| 150 |
+
ax2.text(3.4, 2.65, "Safe Threshold (2.6)", fontsize=8, color='#2E7D32', fontweight='bold', ha='right')
|
| 151 |
+
|
| 152 |
+
ax2.legend(loc='upper right', frameon=True, facecolor='white', framealpha=0.9, fontsize=8.5)
|
| 153 |
+
|
| 154 |
+
plt.tight_layout(rect=[0, 0.03, 1, 0.94])
|
| 155 |
+
output_path = os.path.join(OUTPUT_DIR, "altman_vs_accounting_surplus.png")
|
| 156 |
+
plt.savefig(output_path, dpi=300)
|
| 157 |
+
plt.close()
|
| 158 |
+
print(f" Successfully saved: {output_path}")
|
| 159 |
+
|
| 160 |
+
|
| 161 |
+
def generate_option_value_vega_gain():
|
| 162 |
+
"""
|
| 163 |
+
Figure 2: option_value_vega_gain.png
|
| 164 |
+
Visualizes Black-Scholes-Merton option pricing dynamics under dividend protection
|
| 165 |
+
and leverage-induced volatility expansion. Highlights the agency risk-shifting payoff.
|
| 166 |
+
"""
|
| 167 |
+
dataset = get_company_data()
|
| 168 |
+
|
| 169 |
+
# Extract case studies
|
| 170 |
+
delek_d0 = dataset["Delek_Group"]["dividends"][0]
|
| 171 |
+
delek_opt = dataset["Delek_Group"]["executive_options"][0]
|
| 172 |
+
|
| 173 |
+
afr_d0 = dataset["Africa_Israel"]["dividends"][0]
|
| 174 |
+
afr_opt = dataset["Africa_Israel"]["executive_options"][0]
|
| 175 |
+
|
| 176 |
+
# Simulation 1: Delek Real Estate 2007 Event
|
| 177 |
+
sim_delek = simulate_dividend_impact(
|
| 178 |
+
S_0=delek_d0["stock_price_pre"],
|
| 179 |
+
K_0=delek_opt["strike_k0"],
|
| 180 |
+
T=delek_opt["maturity_years"],
|
| 181 |
+
r=delek_d0["risk_free_rate"],
|
| 182 |
+
sigma_0=delek_d0["pre_div_volatility"],
|
| 183 |
+
dividend=delek_d0["dividend_per_share"],
|
| 184 |
+
sigma_increase=delek_d0["post_div_volatility"] - delek_d0["pre_div_volatility"]
|
| 185 |
+
)
|
| 186 |
+
|
| 187 |
+
# Simulation 2: Africa Israel 2007 Event
|
| 188 |
+
sim_afr = simulate_dividend_impact(
|
| 189 |
+
S_0=afr_d0["stock_price_pre"],
|
| 190 |
+
K_0=afr_opt["strike_k0"],
|
| 191 |
+
T=afr_opt["maturity_years"],
|
| 192 |
+
r=afr_d0["risk_free_rate"],
|
| 193 |
+
sigma_0=afr_d0["pre_div_volatility"],
|
| 194 |
+
dividend=afr_d0["dividend_per_share"],
|
| 195 |
+
sigma_increase=afr_d0["post_div_volatility"] - afr_d0["pre_div_volatility"]
|
| 196 |
+
)
|
| 197 |
+
|
| 198 |
+
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(15, 6.8), gridspec_kw={'width_ratios': [1.1, 1.2]})
|
| 199 |
+
fig.suptitle("Executive Compensation Asymmetry: Dividend Protection & Vega Expansion\nBSM Option Value Shift under Leverage-Induced Volatility", fontsize=14, y=0.98)
|
| 200 |
+
|
| 201 |
+
# --- Subplot 1: 4-Stage State Comparison per Share (Delek Real Estate & Africa Israel) ---
|
| 202 |
+
stages = [
|
| 203 |
+
"1. Pre-Dividend\nBaseline (T0)",
|
| 204 |
+
"2. Post-Dividend\nUnprotected\n(S - D, K)",
|
| 205 |
+
"3. Post-Dividend\nProtected\n(S - D, K - D)",
|
| 206 |
+
"4. Protected +\nVol Expansion\n(Vega Gain)"
|
| 207 |
+
]
|
| 208 |
+
|
| 209 |
+
delek_vals = [
|
| 210 |
+
sim_delek["Value_Pre_Div"],
|
| 211 |
+
sim_delek["Value_Unprotected"],
|
| 212 |
+
sim_delek["Value_Protected_Same_Vol"],
|
| 213 |
+
sim_delek["Value_Protected_Higher_Vol"]
|
| 214 |
+
]
|
| 215 |
+
|
| 216 |
+
afr_vals_norm = [
|
| 217 |
+
(v / sim_afr["Value_Pre_Div"]) * 100 for v in [
|
| 218 |
+
sim_afr["Value_Pre_Div"],
|
| 219 |
+
sim_afr["Value_Unprotected"],
|
| 220 |
+
sim_afr["Value_Protected_Same_Vol"],
|
| 221 |
+
sim_afr["Value_Protected_Higher_Vol"]
|
| 222 |
+
]
|
| 223 |
+
]
|
| 224 |
+
|
| 225 |
+
delek_vals_norm = [(v / sim_delek["Value_Pre_Div"]) * 100 for v in delek_vals]
|
| 226 |
+
|
| 227 |
+
x = np.arange(len(stages))
|
| 228 |
+
width = 0.35
|
| 229 |
+
|
| 230 |
+
b1 = ax1.bar(x - width/2, delek_vals_norm, width, label='Delek Real Estate (Indexed 100)', color='#1E88E5', edgecolor='#1565C0', alpha=0.9)
|
| 231 |
+
b2 = ax1.bar(x + width/2, afr_vals_norm, width, label='Africa Israel (Indexed 100)', color='#FB8C00', edgecolor='#E65100', alpha=0.9)
|
| 232 |
+
|
| 233 |
+
ax1.axhline(100, color='#555555', linestyle=':', linewidth=1.2)
|
| 234 |
+
ax1.set_title("A. Option Value Evolution Across Distribution States\n(Indexed to Pre-Dividend Value = 100)", fontsize=11, pad=10)
|
| 235 |
+
ax1.set_ylabel("Option Value Index (% of Baseline T0)")
|
| 236 |
+
ax1.set_xticks(x)
|
| 237 |
+
ax1.set_xticklabels(stages, fontsize=8.5)
|
| 238 |
+
ax1.set_ylim(60, 135)
|
| 239 |
+
ax1.grid(axis='y', linestyle='--', alpha=0.6)
|
| 240 |
+
ax1.legend(loc='upper left', frameon=True, facecolor='white', framealpha=0.9)
|
| 241 |
+
|
| 242 |
+
# Annotate percent changes
|
| 243 |
+
for bar, val, abs_v in zip(b1, delek_vals_norm, delek_vals):
|
| 244 |
+
ax1.text(bar.get_x() + bar.get_width()/2., val + 1.5, f"{val:.1f}%\n({abs_v:.2f}₪)", ha='center', va='bottom', fontsize=7.8, fontweight='bold', color='#0D47A1')
|
| 245 |
+
|
| 246 |
+
for bar, val, abs_v in zip(b2, afr_vals_norm, [sim_afr["Value_Pre_Div"], sim_afr["Value_Unprotected"], sim_afr["Value_Protected_Same_Vol"], sim_afr["Value_Protected_Higher_Vol"]]):
|
| 247 |
+
ax1.text(bar.get_x() + bar.get_width()/2., val + 1.5, f"{val:.1f}%\n({abs_v:.1f}₪)", ha='center', va='bottom', fontsize=7.8, fontweight='bold', color='#E65100')
|
| 248 |
+
|
| 249 |
+
# --- Subplot 2: Vega Gain Curve - Option Value vs Post-Dividend Volatility ---
|
| 250 |
+
vol_range = np.linspace(0.20, 0.70, 100)
|
| 251 |
+
|
| 252 |
+
# Continuous BSM curves for Delek Real Estate
|
| 253 |
+
S_post_delek = delek_d0["stock_price_pre"] - delek_d0["dividend_per_share"]
|
| 254 |
+
K_post_delek = delek_opt["strike_k0"] - delek_d0["dividend_per_share"]
|
| 255 |
+
K_unprot_delek = delek_opt["strike_k0"]
|
| 256 |
+
|
| 257 |
+
c_protected = [black_scholes_call(S_post_delek, K_post_delek, delek_opt["maturity_years"], delek_d0["risk_free_rate"], v)[0] for v in vol_range]
|
| 258 |
+
c_unprotected = [black_scholes_call(S_post_delek, K_unprot_delek, delek_opt["maturity_years"], delek_d0["risk_free_rate"], v)[0] for v in vol_range]
|
| 259 |
+
|
| 260 |
+
ax2.plot(vol_range * 100, c_protected, color='#2E7D32', linewidth=2.8, label='Protected Option ($K \\to K - D$)')
|
| 261 |
+
ax2.plot(vol_range * 100, c_unprotected, color='#D32F2F', linewidth=2.2, linestyle='--', label='Unprotected Option ($K$ Unchanged)')
|
| 262 |
+
|
| 263 |
+
# Highlight specific volatility points
|
| 264 |
+
sigma_pre = delek_d0["pre_div_volatility"] * 100
|
| 265 |
+
sigma_post = delek_d0["post_div_volatility"] * 100
|
| 266 |
+
|
| 267 |
+
v_unprot_at_pre = sim_delek["Value_Unprotected"]
|
| 268 |
+
v_prot_at_post = sim_delek["Value_Protected_Higher_Vol"]
|
| 269 |
+
|
| 270 |
+
ax2.scatter([sigma_pre], [v_unprot_at_pre], color='#D32F2F', s=90, zorder=5, edgecolors='black')
|
| 271 |
+
ax2.scatter([sigma_post], [v_prot_at_post], color='#2E7D32', s=110, zorder=5, edgecolors='black')
|
| 272 |
+
|
| 273 |
+
# Annotation arrows showing Protection gain and Vega gain
|
| 274 |
+
ax2.annotate(
|
| 275 |
+
f"Unprotected at Pre-Vol ({sigma_pre:.0f}%):\n₪{v_unprot_at_pre:.2f}/opt",
|
| 276 |
+
xy=(sigma_pre, v_unprot_at_pre), xytext=(sigma_pre - 8, v_unprot_at_pre + 4),
|
| 277 |
+
arrowprops=dict(arrowstyle="->", color="#D32F2F", lw=1.5),
|
| 278 |
+
fontsize=8.5, fontweight='bold', color='#B71C1C',
|
| 279 |
+
bbox=dict(boxstyle="round,pad=0.3", fc="#FFEBEE", ec="#D32F2F")
|
| 280 |
+
)
|
| 281 |
+
|
| 282 |
+
ax2.annotate(
|
| 283 |
+
f"Protected + Vol Expansion ({sigma_post:.0f}%):\n₪{v_prot_at_post:.2f}/opt (+29.6% Net Gain)",
|
| 284 |
+
xy=(sigma_post, v_prot_at_post), xytext=(sigma_post - 12, v_prot_at_post + 4.5),
|
| 285 |
+
arrowprops=dict(arrowstyle="->", color="#2E7D32", lw=1.5),
|
| 286 |
+
fontsize=8.5, fontweight='bold', color='#1B5E20',
|
| 287 |
+
bbox=dict(boxstyle="round,pad=0.3", fc="#E8F5E9", ec="#2E7D32")
|
| 288 |
+
)
|
| 289 |
+
|
| 290 |
+
# Arrow showing net executive wealth transfer
|
| 291 |
+
ax2.annotate(
|
| 292 |
+
"", xy=(sigma_post, v_prot_at_post), xytext=(sigma_pre, v_unprot_at_pre),
|
| 293 |
+
arrowprops=dict(arrowstyle="fancy,tail_width=0.4,head_width=0.8", color="#FF8F00", alpha=0.7)
|
| 294 |
+
)
|
| 295 |
+
ax2.text(37, 25.5, "+₪13.06M Total Wealth Transfer\n(2.0M Options Pool)", fontsize=9, fontweight='bold', color='#E65100',
|
| 296 |
+
bbox=dict(boxstyle="round,pad=0.3", fc="#FFF3E0", ec="#FFB74D"))
|
| 297 |
+
|
| 298 |
+
ax2.set_title("B. Vega Slope & Wealth Transfer (Delek Real Estate)\nOption Value Curve: $C(S-D, K-D, \\sigma)$ vs $\\sigma$", fontsize=11, pad=10)
|
| 299 |
+
ax2.set_xlabel("Annualized Asset Volatility $\\sigma$ (%)")
|
| 300 |
+
ax2.set_ylabel("Option Price per Share (NIS / Option)")
|
| 301 |
+
ax2.set_xlim(20, 70)
|
| 302 |
+
ax2.set_ylim(14, 38)
|
| 303 |
+
ax2.grid(True, linestyle='--', alpha=0.6)
|
| 304 |
+
ax2.legend(loc='lower right', frameon=True, facecolor='white', framealpha=0.9)
|
| 305 |
+
|
| 306 |
+
plt.tight_layout(rect=[0, 0.03, 1, 0.94])
|
| 307 |
+
output_path = os.path.join(OUTPUT_DIR, "option_value_vega_gain.png")
|
| 308 |
+
plt.savefig(output_path, dpi=300)
|
| 309 |
+
plt.close()
|
| 310 |
+
print(f" Successfully saved: {output_path}")
|
| 311 |
+
|
| 312 |
+
|
| 313 |
+
def generate_sensitivity_heatmap():
|
| 314 |
+
"""
|
| 315 |
+
Figure 3: sensitivity_heatmap.png
|
| 316 |
+
Generates a high-resolution dual-heatmap matrix showing Executive Option Net Gain (NIS)
|
| 317 |
+
and Percentage Value Gain (%) across Moneyness (K/S) and Volatility Expansion Shocks (Δσ).
|
| 318 |
+
"""
|
| 319 |
+
# Base simulation baseline: S0 = 100 NIS, Dividend = 15 NIS (15%), T = 3.0 yrs, r = 4.0%, base_vol = 30%
|
| 320 |
+
S_0 = 100.0
|
| 321 |
+
dividend = 15.0
|
| 322 |
+
T = 3.0
|
| 323 |
+
r = 0.04
|
| 324 |
+
sigma_0 = 0.30
|
| 325 |
+
|
| 326 |
+
moneyness_ratios = [0.80, 0.90, 1.00, 1.10, 1.20]
|
| 327 |
+
moneyness_labels = ["ITM (0.80)", "ITM (0.90)", "ATM (1.00)", "OTM (1.10)", "OTM (1.20)"]
|
| 328 |
+
vol_shocks = [0.02, 0.05, 0.08, 0.10, 0.12, 0.15]
|
| 329 |
+
vol_shock_labels = ["+2% (32%)", "+5% (35%)", "+8% (38%)", "+10% (40%)", "+12% (42%)", "+15% (45%)"]
|
| 330 |
+
|
| 331 |
+
net_gain_matrix = np.zeros((len(moneyness_ratios), len(vol_shocks)))
|
| 332 |
+
pct_gain_matrix = np.zeros((len(moneyness_ratios), len(vol_shocks)))
|
| 333 |
+
|
| 334 |
+
for i, m in enumerate(moneyness_ratios):
|
| 335 |
+
K_0 = S_0 * m
|
| 336 |
+
for j, v_shock in enumerate(vol_shocks):
|
| 337 |
+
sim = simulate_dividend_impact(S_0, K_0, T, r, sigma_0, dividend, sigma_increase=v_shock)
|
| 338 |
+
net_gain_matrix[i, j] = sim["Net_Benefit_To_Executive"]
|
| 339 |
+
pct_gain_matrix[i, j] = (sim["Value_Protected_Higher_Vol"] / sim["Value_Unprotected"] - 1.0) * 100.0
|
| 340 |
+
|
| 341 |
+
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(15, 6.5))
|
| 342 |
+
fig.suptitle("Executive Wealth Sensitivity Matrix: Strike Moneyness ($K/S$) vs Volatility Jump ($\\Delta\\sigma$)\nImpact of Dividend Protection + Risk Shifting Leverage Expansion", fontsize=13.5, y=0.98)
|
| 343 |
+
|
| 344 |
+
# --- Heatmap 1: Net Benefit in NIS per Option ---
|
| 345 |
+
im1 = ax1.imshow(net_gain_matrix, cmap='YlOrRd', aspect='auto', interpolation='nearest')
|
| 346 |
+
ax1.set_title("A. Absolute Option Gain (NIS / Option)\n$\\Delta C = C_{\\text{Protected}}(\\sigma_0 + \\Delta\\sigma) - C_{\\text{Unprotected}}(\\sigma_0)$", fontsize=10.5, pad=10)
|
| 347 |
+
ax1.set_xticks(np.arange(len(vol_shock_labels)))
|
| 348 |
+
ax1.set_yticks(np.arange(len(moneyness_labels)))
|
| 349 |
+
ax1.set_xticklabels(vol_shock_labels, rotation=25, ha='right', fontsize=9)
|
| 350 |
+
ax1.set_yticklabels(moneyness_labels, fontsize=9.5)
|
| 351 |
+
ax1.set_xlabel("Volatility Shock Expansion $\\Delta\\sigma$ (Post-Div $\\sigma$)", fontweight='bold')
|
| 352 |
+
ax1.set_ylabel("Option Moneyness $(K_0 / S_0)$", fontweight='bold')
|
| 353 |
+
|
| 354 |
+
# Annotate values inside cells
|
| 355 |
+
for i in range(len(moneyness_ratios)):
|
| 356 |
+
for j in range(len(vol_shocks)):
|
| 357 |
+
val = net_gain_matrix[i, j]
|
| 358 |
+
text_color = "white" if val > (net_gain_matrix.max() * 0.65) else "black"
|
| 359 |
+
ax1.text(j, i, f"+₪{val:.2f}", ha="center", va="center", color=text_color, fontweight='bold', fontsize=9.5)
|
| 360 |
+
|
| 361 |
+
cbar1 = fig.colorbar(im1, ax=ax1, fraction=0.046, pad=0.04)
|
| 362 |
+
cbar1.set_label("NIS / Option Gain", fontsize=9.5, fontweight='bold')
|
| 363 |
+
|
| 364 |
+
# --- Heatmap 2: Percentage Benefit over Unprotected (%) ---
|
| 365 |
+
im2 = ax2.imshow(pct_gain_matrix, cmap='viridis', aspect='auto', interpolation='nearest')
|
| 366 |
+
ax2.set_title("B. Relative Wealth Gain (% Over Unprotected Baseline)\n$[C_{\\text{Protected}}(\\sigma_0 + \\Delta\\sigma) / C_{\\text{Unprotected}}(\\sigma_0) - 1] \\times 100\\%$", fontsize=10.5, pad=10)
|
| 367 |
+
ax2.set_xticks(np.arange(len(vol_shock_labels)))
|
| 368 |
+
ax2.set_yticks(np.arange(len(moneyness_labels)))
|
| 369 |
+
ax2.set_xticklabels(vol_shock_labels, rotation=25, ha='right', fontsize=9)
|
| 370 |
+
ax2.set_yticklabels(moneyness_labels, fontsize=9.5)
|
| 371 |
+
ax2.set_xlabel("Volatility Shock Expansion $\\Delta\\sigma$ (Post-Div $\\sigma$)", fontweight='bold')
|
| 372 |
+
ax2.set_ylabel("Option Moneyness $(K_0 / S_0)$", fontweight='bold')
|
| 373 |
+
|
| 374 |
+
# Annotate values inside cells
|
| 375 |
+
for i in range(len(moneyness_ratios)):
|
| 376 |
+
for j in range(len(vol_shocks)):
|
| 377 |
+
val = pct_gain_matrix[i, j]
|
| 378 |
+
text_color = "black" if val > (pct_gain_matrix.max() * 0.7) else "white"
|
| 379 |
+
ax2.text(j, i, f"+{val:.1f}%", ha="center", va="center", color=text_color, fontweight='bold', fontsize=9.5)
|
| 380 |
+
|
| 381 |
+
cbar2 = fig.colorbar(im2, ax=ax2, fraction=0.046, pad=0.04)
|
| 382 |
+
cbar2.set_label("Percentage Gain (%)", fontsize=9.5, fontweight='bold')
|
| 383 |
+
|
| 384 |
+
plt.tight_layout(rect=[0, 0.03, 1, 0.94])
|
| 385 |
+
output_path = os.path.join(OUTPUT_DIR, "sensitivity_heatmap.png")
|
| 386 |
+
plt.savefig(output_path, dpi=300)
|
| 387 |
+
plt.close()
|
| 388 |
+
print(f" Successfully saved: {output_path}")
|
| 389 |
+
|
| 390 |
+
|
| 391 |
+
def main():
|
| 392 |
+
print("================================================================")
|
| 393 |
+
print("Plot Generator: Generating Academic-Grade Publication Figures")
|
| 394 |
+
print("================================================================")
|
| 395 |
+
|
| 396 |
+
generate_altman_vs_accounting_surplus()
|
| 397 |
+
generate_option_value_vega_gain()
|
| 398 |
+
generate_sensitivity_heatmap()
|
| 399 |
+
|
| 400 |
+
print("================================================================")
|
| 401 |
+
print("All 3 high-resolution figures successfully generated in /home/dcor/omerazoulay/nini:")
|
| 402 |
+
print("1. altman_vs_accounting_surplus.png")
|
| 403 |
+
print("2. option_value_vega_gain.png")
|
| 404 |
+
print("3. sensitivity_heatmap.png")
|
| 405 |
+
print("================================================================")
|
| 406 |
+
|
| 407 |
+
|
| 408 |
+
if __name__ == "__main__":
|
| 409 |
+
main()
|