File size: 814 Bytes
89de1c7
 
 
 
7fb41fd
 
 
 
 
 
 
 
 
89de1c7
 
 
7fb41fd
 
89de1c7
7fb41fd
89de1c7
7fb41fd
 
 
 
 
89de1c7
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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