AJAY KASU commited on
Commit
e176953
·
1 Parent(s): aa9ef27

Feat: Add Pie Chart to EDA dashboard for sector allocation

Browse files
Files changed (1) hide show
  1. streamlit_app.py +28 -5
streamlit_app.py CHANGED
@@ -200,7 +200,7 @@ if run_btn and user_input:
200
  st.plotly_chart(fig_perf, use_container_width=True)
201
 
202
  with eda_col2:
203
- # 2. Sector Weight Comparison
204
  # Aggregating sector weights
205
  port_sector_weights = {}
206
  bench_sector_weights = {}
@@ -215,18 +215,41 @@ 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
  fig_sector = go.Figure(data=[
219
- go.Bar(name='Benchmark', x=all_sectors, y=[bench_sector_weights.get(s, 0)*100 for s in all_sectors], marker_color="#94a3b8"),
220
- go.Bar(name='Portfolio', x=all_sectors, y=[port_sector_weights.get(s, 0)*100 for s in all_sectors], marker_color="#34d399")
221
  ])
222
 
223
  fig_sector.update_layout(
224
- title="Sector Allocation (%)",
225
  template="plotly_dark",
226
  barmode='group',
 
227
  paper_bgcolor='rgba(0,0,0,0)',
228
  plot_bgcolor='rgba(0,0,0,0)',
229
- margin=dict(l=20, r=20, t=40, b=20),
230
  showlegend=False
231
  )
232
  st.plotly_chart(fig_sector, use_container_width=True)
 
200
  st.plotly_chart(fig_perf, use_container_width=True)
201
 
202
  with eda_col2:
203
+ # 2. Sector Weight Comparison (Bar)
204
  # Aggregating sector weights
205
  port_sector_weights = {}
206
  bench_sector_weights = {}
 
215
 
216
  all_sectors = sorted(list(set(list(port_sector_weights.keys()) + list(bench_sector_weights.keys()))))
217
 
218
+ # 3. Sector Allocation Pie Chart (New)
219
+ labels = list(port_sector_weights.keys())
220
+ values = list(port_sector_weights.values())
221
+
222
+ fig_pie = go.Figure(data=[go.Pie(
223
+ labels=labels,
224
+ values=values,
225
+ hole=.4,
226
+ marker=dict(colors=px.colors.qualitative.Pastel)
227
+ )])
228
+
229
+ fig_pie.update_layout(
230
+ title="Portfolio Composition",
231
+ template="plotly_dark",
232
+ paper_bgcolor='rgba(0,0,0,0)',
233
+ plot_bgcolor='rgba(0,0,0,0)',
234
+ margin=dict(l=10, r=10, t=40, b=10),
235
+ showlegend=False
236
+ )
237
+ st.plotly_chart(fig_pie, use_container_width=True)
238
+
239
+ # Bar chart below pie for detailed comparison
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,
250
  paper_bgcolor='rgba(0,0,0,0)',
251
  plot_bgcolor='rgba(0,0,0,0)',
252
+ margin=dict(l=10, r=10, t=30, b=10),
253
  showlegend=False
254
  )
255
  st.plotly_chart(fig_sector, use_container_width=True)