Spaces:
Sleeping
Sleeping
Update portfolio.py
Browse files- portfolio.py +17 -8
portfolio.py
CHANGED
|
@@ -2,18 +2,27 @@ import pandas as pd
|
|
| 2 |
import matplotlib.pyplot as plt
|
| 3 |
|
| 4 |
def analyze_portfolio(file, risk_profile):
|
| 5 |
-
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
df.groupby('Asset')['Value'].sum().plot.pie(
|
| 8 |
autopct='%1.1f%%',
|
| 9 |
ax=ax,
|
| 10 |
-
ylabel=''
|
|
|
|
| 11 |
)
|
|
|
|
| 12 |
|
| 13 |
-
#
|
| 14 |
-
recs = f"✅ {risk_profile} Portfolio
|
| 15 |
-
recs += "-
|
| 16 |
-
recs += "- Reduce tech sector exposure
|
| 17 |
-
recs += "-
|
| 18 |
|
| 19 |
return fig, recs
|
|
|
|
| 2 |
import matplotlib.pyplot as plt
|
| 3 |
|
| 4 |
def analyze_portfolio(file, risk_profile):
|
| 5 |
+
if isinstance(file, str):
|
| 6 |
+
# Example file path
|
| 7 |
+
df = pd.read_csv(file)
|
| 8 |
+
else:
|
| 9 |
+
# Uploaded file
|
| 10 |
+
df = pd.read_csv(file.name)
|
| 11 |
+
|
| 12 |
+
# Generate pie chart
|
| 13 |
+
fig, ax = plt.subplots(figsize=(6, 6))
|
| 14 |
df.groupby('Asset')['Value'].sum().plot.pie(
|
| 15 |
autopct='%1.1f%%',
|
| 16 |
ax=ax,
|
| 17 |
+
ylabel='',
|
| 18 |
+
startangle=90
|
| 19 |
)
|
| 20 |
+
plt.title('Current Allocation')
|
| 21 |
|
| 22 |
+
# Generate recommendations
|
| 23 |
+
recs = f"✅ {risk_profile} Portfolio Recommendations:\n"
|
| 24 |
+
recs += "- Consider adding international stocks (15-20%)\n"
|
| 25 |
+
recs += "- Reduce tech sector exposure by 5-10%\n"
|
| 26 |
+
recs += "- Increase bond allocation to 20% for better stability"
|
| 27 |
|
| 28 |
return fig, recs
|