Finance_toolkit / portfolio.py
Navya-Sree's picture
Update portfolio.py
7fb41fd verified
raw
history blame contribute delete
814 Bytes
import pandas as pd
import matplotlib.pyplot as plt
def analyze_portfolio(file, risk_profile):
if isinstance(file, str):
# Example file path
df = pd.read_csv(file)
else:
# Uploaded file
df = pd.read_csv(file.name)
# Generate pie chart
fig, ax = plt.subplots(figsize=(6, 6))
df.groupby('Asset')['Value'].sum().plot.pie(
autopct='%1.1f%%',
ax=ax,
ylabel='',
startangle=90
)
plt.title('Current Allocation')
# Generate recommendations
recs = f"✅ {risk_profile} Portfolio Recommendations:\n"
recs += "- Consider adding international stocks (15-20%)\n"
recs += "- Reduce tech sector exposure by 5-10%\n"
recs += "- Increase bond allocation to 20% for better stability"
return fig, recs