Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -97,24 +97,24 @@ if st.button("Analisis Portofolio"):
|
|
| 97 |
portfolio_weights = {stock: weight for stock, weight in zip(stock_data.columns, optimal_weights)}
|
| 98 |
st.write(portfolio_weights)
|
| 99 |
|
| 100 |
-
# Pie Chart dengan
|
| 101 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
fig, ax = plt.subplots()
|
| 103 |
-
ax.pie(
|
| 104 |
-
filtered_weights.values(),
|
| 105 |
-
labels=filtered_weights.keys(),
|
| 106 |
-
autopct=lambda p: f'{p:.1f}%' if p > 1 else '', # Hanya tampilkan jika > 1%
|
| 107 |
-
startangle=140,
|
| 108 |
-
pctdistance=0.85 # Mengatur jarak label agar lebih terlihat
|
| 109 |
-
)
|
| 110 |
ax.axis('equal')
|
| 111 |
st.pyplot(fig)
|
| 112 |
|
| 113 |
st.markdown("""
|
| 114 |
**Interpretasi Pie Chart:**
|
| 115 |
- Pie chart ini menunjukkan distribusi bobot optimal dari setiap saham dalam portofolio.
|
| 116 |
-
-
|
| 117 |
-
- Saham dengan bobot
|
| 118 |
- Portofolio optimal didasarkan pada perhitungan rasio Sharpe, yang mencari keseimbangan terbaik antara return dan risiko.
|
| 119 |
""")
|
| 120 |
|
|
@@ -132,7 +132,7 @@ if st.button("Analisis Portofolio"):
|
|
| 132 |
|
| 133 |
st.markdown("""
|
| 134 |
**Interpretasi:**
|
| 135 |
-
- **Bobot Portofolio Optimal**: Menunjukkan alokasi dana ke setiap saham.
|
| 136 |
- **Grafik Efficient Frontier**:
|
| 137 |
- Sumbu **X**: Risiko (diukur dengan standar deviasi return portofolio).
|
| 138 |
- Sumbu **Y**: Return tahunan dari berbagai kombinasi portofolio.
|
|
|
|
| 97 |
portfolio_weights = {stock: weight for stock, weight in zip(stock_data.columns, optimal_weights)}
|
| 98 |
st.write(portfolio_weights)
|
| 99 |
|
| 100 |
+
# Pie Chart dengan pengelompokan saham kecil ke "Others"
|
| 101 |
+
threshold = 0.05 # Saham dengan bobot <5% digabung ke "Others"
|
| 102 |
+
large_weights = {k: v for k, v in portfolio_weights.items() if v >= threshold}
|
| 103 |
+
small_weights = {k: v for k, v in portfolio_weights.items() if v < threshold}
|
| 104 |
+
|
| 105 |
+
if small_weights:
|
| 106 |
+
large_weights["Others"] = sum(small_weights.values())
|
| 107 |
+
|
| 108 |
fig, ax = plt.subplots()
|
| 109 |
+
ax.pie(large_weights.values(), labels=large_weights.keys(), autopct='%1.1f%%', startangle=140)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
ax.axis('equal')
|
| 111 |
st.pyplot(fig)
|
| 112 |
|
| 113 |
st.markdown("""
|
| 114 |
**Interpretasi Pie Chart:**
|
| 115 |
- Pie chart ini menunjukkan distribusi bobot optimal dari setiap saham dalam portofolio.
|
| 116 |
+
- Saham dengan bobot signifikan ditampilkan dengan persentase masing-masing.
|
| 117 |
+
- Saham dengan bobot kecil (<5%) digabung ke dalam kategori "Others".
|
| 118 |
- Portofolio optimal didasarkan pada perhitungan rasio Sharpe, yang mencari keseimbangan terbaik antara return dan risiko.
|
| 119 |
""")
|
| 120 |
|
|
|
|
| 132 |
|
| 133 |
st.markdown("""
|
| 134 |
**Interpretasi:**
|
| 135 |
+
- **Bobot Portofolio Optimal**: Menunjukkan alokasi dana ke setiap saham.
|
| 136 |
- **Grafik Efficient Frontier**:
|
| 137 |
- Sumbu **X**: Risiko (diukur dengan standar deviasi return portofolio).
|
| 138 |
- Sumbu **Y**: Return tahunan dari berbagai kombinasi portofolio.
|