Spaces:
Sleeping
Sleeping
AJAY KASU commited on
Commit ·
816b15c
1
Parent(s): e176953
Feat: Update EDA Pie Chart to show individual companies (tickers)
Browse files- streamlit_app.py +16 -7
streamlit_app.py
CHANGED
|
@@ -215,19 +215,28 @@ if run_btn and user_input:
|
|
| 215 |
|
| 216 |
all_sectors = sorted(list(set(list(port_sector_weights.keys()) + list(bench_sector_weights.keys()))))
|
| 217 |
|
| 218 |
-
# 3.
|
| 219 |
-
|
| 220 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 221 |
|
| 222 |
fig_pie = go.Figure(data=[go.Pie(
|
| 223 |
labels=labels,
|
| 224 |
values=values,
|
| 225 |
hole=.4,
|
| 226 |
-
|
|
|
|
| 227 |
)])
|
| 228 |
|
| 229 |
fig_pie.update_layout(
|
| 230 |
-
title="
|
| 231 |
template="plotly_dark",
|
| 232 |
paper_bgcolor='rgba(0,0,0,0)',
|
| 233 |
plot_bgcolor='rgba(0,0,0,0)',
|
|
@@ -236,14 +245,14 @@ if run_btn and user_input:
|
|
| 236 |
)
|
| 237 |
st.plotly_chart(fig_pie, use_container_width=True)
|
| 238 |
|
| 239 |
-
# Bar chart
|
| 240 |
fig_sector = go.Figure(data=[
|
| 241 |
go.Bar(name='Bench', x=all_sectors, y=[bench_sector_weights.get(s, 0)*100 for s in all_sectors], marker_color="#94a3b8"),
|
| 242 |
go.Bar(name='Port', x=all_sectors, y=[port_sector_weights.get(s, 0)*100 for s in all_sectors], marker_color="#34d399")
|
| 243 |
])
|
| 244 |
|
| 245 |
fig_sector.update_layout(
|
| 246 |
-
title="Sector Match (%)",
|
| 247 |
template="plotly_dark",
|
| 248 |
barmode='group',
|
| 249 |
height=250,
|
|
|
|
| 215 |
|
| 216 |
all_sectors = sorted(list(set(list(port_sector_weights.keys()) + list(bench_sector_weights.keys()))))
|
| 217 |
|
| 218 |
+
# 3. Portfolio Composition Pie Chart (Holding Level)
|
| 219 |
+
# Using top 15 holdings for better readability in the pie
|
| 220 |
+
sorted_weights = sorted(opt.weights.items(), key=lambda x: x[1], reverse=True)
|
| 221 |
+
top_holdings = sorted_weights[:15]
|
| 222 |
+
other_weight = sum(w for t, w in sorted_weights[15:])
|
| 223 |
+
|
| 224 |
+
labels = [t for t, w in top_holdings]
|
| 225 |
+
values = [w for t, w in top_holdings]
|
| 226 |
+
if other_weight > 0:
|
| 227 |
+
labels.append("Others")
|
| 228 |
+
values.append(other_weight)
|
| 229 |
|
| 230 |
fig_pie = go.Figure(data=[go.Pie(
|
| 231 |
labels=labels,
|
| 232 |
values=values,
|
| 233 |
hole=.4,
|
| 234 |
+
textinfo='label',
|
| 235 |
+
marker=dict(colors=px.colors.qualitative.Prism)
|
| 236 |
)])
|
| 237 |
|
| 238 |
fig_pie.update_layout(
|
| 239 |
+
title="Top Holdings Allocation",
|
| 240 |
template="plotly_dark",
|
| 241 |
paper_bgcolor='rgba(0,0,0,0)',
|
| 242 |
plot_bgcolor='rgba(0,0,0,0)',
|
|
|
|
| 245 |
)
|
| 246 |
st.plotly_chart(fig_pie, use_container_width=True)
|
| 247 |
|
| 248 |
+
# Bar chart for sector comparison
|
| 249 |
fig_sector = go.Figure(data=[
|
| 250 |
go.Bar(name='Bench', x=all_sectors, y=[bench_sector_weights.get(s, 0)*100 for s in all_sectors], marker_color="#94a3b8"),
|
| 251 |
go.Bar(name='Port', x=all_sectors, y=[port_sector_weights.get(s, 0)*100 for s in all_sectors], marker_color="#34d399")
|
| 252 |
])
|
| 253 |
|
| 254 |
fig_sector.update_layout(
|
| 255 |
+
title="Sector Exposure Match (%)",
|
| 256 |
template="plotly_dark",
|
| 257 |
barmode='group',
|
| 258 |
height=250,
|