-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_validation.py
More file actions
45 lines (39 loc) · 1.75 KB
/
Copy pathplot_validation.py
File metadata and controls
45 lines (39 loc) · 1.75 KB
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
import csv
import matplotlib.pyplot as plt
scenarios = []
delta_diff, delta_se = [], []
price_diff, price_se = [], []
vega_diff, vega_se = [], []
with open("validation_results.csv") as f:
reader = csv.DictReader(f)
for row in reader:
scenarios.append(row["scenario"])
f_price = float(row["f_price"]); mc_price = float(row["mc_price_mean"])
f_delta = float(row["f_delta"]); mc_delta = float(row["mc_delta_mean"])
f_vega = float(row["f_vega"]); mc_vega = float(row["mc_vega_mean"])
price_diff.append(100 * (mc_price - f_price) / f_price)
price_se.append(100 * 3 * float(row["mc_price_se"]) / f_price)
delta_diff.append(100 * (mc_delta - f_delta) / f_delta)
delta_se.append(100 * 3 * float(row["mc_delta_se"]) / f_delta)
vega_diff.append(100 * (mc_vega - f_vega) / f_vega)
vega_se.append(100 * 3 * float(row["mc_vega_se"]) / f_vega)
x = range(len(scenarios))
fig, axes = plt.subplots(1, 3, figsize=(16, 5.5))
for ax, diffs, ses, title in [
(axes[0], price_diff, price_se, "Price"),
(axes[1], delta_diff, delta_se, "Delta"),
(axes[2], vega_diff, vega_se, "Vega"),
]:
ax.errorbar(x, diffs, yerr=ses, fmt="o", color="#2563eb",
capsize=5, markersize=7, label="MC vs closed-form (mean +/- 3 SE)")
ax.axhline(y=0, color="#111827", linewidth=1)
ax.set_xticks(list(x))
ax.set_xticklabels(scenarios, rotation=25, ha="right", fontsize=8)
ax.set_ylabel("Relative difference (%)")
ax.set_title(title)
ax.grid(alpha=0.3)
ax.legend(fontsize=7)
fig.suptitle("Model Validation: Monte Carlo vs Closed-Form, Relative Error with 3-SE Bands", fontsize=13)
plt.tight_layout()
plt.savefig("validation_plot.png", dpi=150)
print("Saved validation_plot.png")