-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdashboard_phase7.py
More file actions
138 lines (120 loc) · 6.06 KB
/
Copy pathdashboard_phase7.py
File metadata and controls
138 lines (120 loc) · 6.06 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
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
"""
dashboard_phase7.py (Phase 7e)
===============================
Interactive ESG-tilted optimiser dashboard.
Run: streamlit run dashboard_phase7.py
(Pulls live SX5E data via the BL data layer on first load; needs network.)
Standalone by design -- keeps the Phases 1-6 dashboard.py untouched.
Controls:
- Reporting year -> moves the 1.5C pathway target (-7% p.a.)
- Carbon target -> the binding decarbonisation constraint
- Per-name cap -> UCITS-style concentration limit
"""
import numpy as np
import pandas as pd
import streamlit as st
from phase7.esg_data import build_universe
from phase7.esg_optimiser import (min_tracking_error, run_scenarios,
cost_of_green_frontier, benchmark_waci)
from sfdr2.alignment import pathway_target
from sfdr2.exclusions import screen_portfolio
st.set_page_config(page_title="SFDR 2.0 ESG-Tilted Optimiser", layout="wide")
st.title("ESG-Tilted Minimum-Tracking-Error Optimiser")
st.caption("Phase 7 - closes the SFDR engine's decarbonisation residual by "
"tilting the SX5E benchmark to the 1.5C pathway under a tracking-"
"error budget. Returns and covariance from the Black-Litterman "
"data layer (real, Ledoit-Wolf shrunk).")
@st.cache_data(show_spinner="Pulling SX5E data via the BL data layer...")
def load_bundle(years: int):
b = build_universe(years=years)
# cache-friendly: return plain objects
return {
"tickers": b["tickers"], "names": b["names"],
"Sigma": b["Sigma"], "w_bench": b["w_bench"],
"holdings": b["holdings"], "r_f": b["r_f"],
}
bundle = load_bundle(3)
tickers, holdings = bundle["tickers"], bundle["holdings"]
parent_waci = benchmark_waci(holdings, tickers, bundle["w_bench"].values)
# --- sidebar ---------------------------------------------------------------
st.sidebar.header("Mandate parameters")
year = st.sidebar.slider("Reporting year", 2024, 2035, 2026, 1)
tgt_default = pathway_target(parent_waci, year)
cap = st.sidebar.slider("Per-name cap (UCITS-style)", 0.05, 1.0, 0.12, 0.01,
help="Concentration limit. Lower caps force the tilt "
"across more names and raise tracking error.")
carbon_target = st.sidebar.slider(
"Carbon-intensity target (tCO2e/EURm)",
min_value=float(round(0.5 * tgt_default, 1)),
max_value=float(round(parent_waci, 1)),
value=float(round(tgt_default, 1)), step=0.5,
help=f"1.5C pathway target this year = {tgt_default:.1f}. "
"Lower = deeper decarbonisation = higher tracking error.")
st.sidebar.markdown("---")
st.sidebar.caption("ESG attributes are sector-archetype proxies (see README), "
"not audited issuer figures. Market data is real.")
# --- headline optimisation -------------------------------------------------
r = min_tracking_error(bundle["Sigma"], bundle["w_bench"].values, holdings,
tickers, carbon_target=carbon_target, floor=None,
max_weight=cap, year=year)
c1, c2, c3, c4 = st.columns(4)
c1.metric("Tracking error", f"{r['te_bps']:.0f} bps",
help="Annualised active risk vs the SX5E benchmark")
c2.metric("Achieved WACI", f"{r['waci']:.1f}",
delta=f"{r['waci'] - parent_waci:+.1f} vs parent",
delta_color="inverse")
c3.metric("1.5C pathway target", f"{tgt_default:.1f}",
delta="aligned" if r["waci"] <= tgt_default + 1e-6 else "above",
delta_color="off")
c4.metric("Active share", f"{r['active_share']*100:.0f}%")
if not r["success"]:
st.error("Optimisation infeasible at this carbon target and name cap. "
"Raise the target or the cap.")
st.divider()
# --- cost-of-green frontier ------------------------------------------------
left, right = st.columns([1.4, 1])
with left:
st.subheader("The cost of green")
st.caption("Active risk vs decarbonisation. Convexity means each extra "
"tonne removed costs more than the last.")
df = cost_of_green_frontier(bundle, year=year, n_points=25, floor=None,
max_weight=cap)
feas = df[df.feasible].copy()
chart_df = feas.set_index("intensity_cut_pct")[["tracking_error_bps"]]
chart_df.columns = ["Tracking error (bps)"]
st.line_chart(chart_df, height=360)
pathway_cut = 100.0 * (parent_waci - tgt_default) / parent_waci
st.caption(f"1.5C pathway = {pathway_cut:.0f}% intensity cut vs parent "
f"benchmark (WACI {parent_waci:.1f} -> {tgt_default:.1f}).")
with right:
st.subheader("Compliance-path cost")
st.caption("Tracking-error cost of each SFDR 2.0 qualifying route, at the "
"1.5C pathway target.")
sc = run_scenarios(bundle, year=year, max_weight=cap)
rows = [{"Path": v["label"], "TE (bps)": round(v["te_bps"], 0),
"WACI": round(v["waci"], 1),
"Qual wt %": round(v["qualifying_weight"] * 100, 0),
"Feasible": "Yes" if v["success"] else "No"}
for v in sc["results"].values()]
st.dataframe(pd.DataFrame(rows), hide_index=True, use_container_width=True)
scr = screen_portfolio(holdings)["summary"]
st.caption(f"On this benchmark, {scr['n_excluded']} names are PAB-excluded "
f"({scr['weight_excluded_pct']:.0f}% of weight); qualifying "
"weight stays above 70%, so the three paths coincide here.")
st.divider()
# --- resulting weights -----------------------------------------------------
st.subheader("Resulting tilt vs benchmark")
wb = bundle["w_bench"].values
active = r["weights"] - wb
wt_df = pd.DataFrame({
"Name": bundle["names"],
"Benchmark %": (wb * 100).round(2),
"Optimised %": (r["weights"] * 100).round(2),
"Active %": (active * 100).round(2),
"Carbon intensity": [h["scope12_intensity_tco2_per_eur_m"] or np.nan
for h in holdings],
}).sort_values("Active %")
st.dataframe(wt_df, hide_index=True, use_container_width=True)
st.caption("The optimiser cuts high-carbon names (negative active weight) and "
"overweights low-carbon ones, minimising active risk subject to the "
"carbon constraint.")