Spaces:
Sleeping
Sleeping
Create portfolio.py
Browse files- portfolio.py +19 -0
portfolio.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pandas as pd
|
| 2 |
+
import matplotlib.pyplot as plt
|
| 3 |
+
|
| 4 |
+
def analyze_portfolio(file, risk_profile):
|
| 5 |
+
df = pd.read_csv(file.name)
|
| 6 |
+
fig, ax = plt.subplots()
|
| 7 |
+
df.groupby('Asset')['Value'].sum().plot.pie(
|
| 8 |
+
autopct='%1.1f%%',
|
| 9 |
+
ax=ax,
|
| 10 |
+
ylabel=''
|
| 11 |
+
)
|
| 12 |
+
|
| 13 |
+
# Mock recommendations
|
| 14 |
+
recs = f"✅ {risk_profile} Portfolio Suggestions:\n"
|
| 15 |
+
recs += "- Increase international stocks by 15%\n"
|
| 16 |
+
recs += "- Reduce tech sector exposure\n"
|
| 17 |
+
recs += "- Add 5% treasury bonds"
|
| 18 |
+
|
| 19 |
+
return fig, recs
|