Navya-Sree commited on
Commit
7fb41fd
·
verified ·
1 Parent(s): aa74cd7

Update portfolio.py

Browse files
Files changed (1) hide show
  1. 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
- 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
 
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