Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -36,16 +36,22 @@ def plot_efficient_frontier(dataframes, names):
|
|
| 36 |
max_sharpe_return = ret_arr[max_sharpe_idx]
|
| 37 |
max_sharpe_volatility = vol_arr[max_sharpe_idx]
|
| 38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
st.write("Optimal Portfolio Weights:")
|
| 40 |
optimal_weights = all_weights[max_sharpe_idx]
|
| 41 |
for i, name in enumerate(names):
|
| 42 |
st.write(f"{name}: {optimal_weights[i]:.4f}")
|
| 43 |
|
| 44 |
fig, ax = plt.subplots()
|
| 45 |
-
scatter = ax.scatter(vol_arr, ret_arr, c=sharpe_arr, cmap='
|
| 46 |
colorbar = plt.colorbar(scatter, ax=ax)
|
| 47 |
colorbar.set_label('Sharpe Ratio')
|
| 48 |
-
ax.scatter(max_sharpe_volatility, max_sharpe_return, c='red', s=
|
|
|
|
| 49 |
ax.set_xlabel('Volatility')
|
| 50 |
ax.set_ylabel('Return')
|
| 51 |
ax.set_title('Efficient Frontier')
|
|
|
|
| 36 |
max_sharpe_return = ret_arr[max_sharpe_idx]
|
| 37 |
max_sharpe_volatility = vol_arr[max_sharpe_idx]
|
| 38 |
|
| 39 |
+
# Find the portfolio with the minimum volatility
|
| 40 |
+
min_vol_idx = np.argmin(vol_arr)
|
| 41 |
+
min_vol_return = ret_arr[min_vol_idx]
|
| 42 |
+
min_vol_volatility = vol_arr[min_vol_idx]
|
| 43 |
+
|
| 44 |
st.write("Optimal Portfolio Weights:")
|
| 45 |
optimal_weights = all_weights[max_sharpe_idx]
|
| 46 |
for i, name in enumerate(names):
|
| 47 |
st.write(f"{name}: {optimal_weights[i]:.4f}")
|
| 48 |
|
| 49 |
fig, ax = plt.subplots()
|
| 50 |
+
scatter = ax.scatter(vol_arr, ret_arr, c=sharpe_arr, cmap='Blues')
|
| 51 |
colorbar = plt.colorbar(scatter, ax=ax)
|
| 52 |
colorbar.set_label('Sharpe Ratio')
|
| 53 |
+
ax.scatter(max_sharpe_volatility, max_sharpe_return, c='red', s=200, marker='*', label='Optimal Portfolio - Max Sharpe Ratio')
|
| 54 |
+
ax.scatter(min_vol_volatility, min_vol_return, c='purple', s=150, edgecolors='black', marker='o', label='Minimum Volatility Portfolio')
|
| 55 |
ax.set_xlabel('Volatility')
|
| 56 |
ax.set_ylabel('Return')
|
| 57 |
ax.set_title('Efficient Frontier')
|