julkarnaeen commited on
Commit
fed6be4
·
verified ·
1 Parent(s): 16641f9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -6
app.py CHANGED
@@ -78,12 +78,17 @@ def analyze_stock(symbol):
78
  }
79
  performance_df = pd.DataFrame(performance_data)
80
 
81
- # Extract values properly
82
- current_price = float(data['Close'].iloc[-1])
83
- start_price = float(data['Close'].iloc[0])
84
- high_price = float(data['Close'].max())
85
- low_price = float(data['Close'].min())
86
- volatility = float(returns.std() * 100)
 
 
 
 
 
87
 
88
  total_return = ((current_price / start_price) - 1) * 100
89
  price_change = current_price - start_price
 
78
  }
79
  performance_df = pd.DataFrame(performance_data)
80
 
81
+ # Extract values properly - handle both Series and scalar values
82
+ current_price = float(data['Close'].iloc[-1]) if hasattr(data['Close'].iloc[-1], 'item') else data['Close'].iloc[-1]
83
+ start_price = float(data['Close'].iloc[0]) if hasattr(data['Close'].iloc[0], 'item') else data['Close'].iloc[0]
84
+ high_price = float(data['Close'].max()) if hasattr(data['Close'].max(), 'item') else data['Close'].max()
85
+ low_price = float(data['Close'].min()) if hasattr(data['Close'].min(), 'item') else data['Close'].min()
86
+
87
+ # Calculate volatility safely
88
+ if len(returns) > 0:
89
+ volatility = float(returns.std()) * 100
90
+ else:
91
+ volatility = 0.0
92
 
93
  total_return = ((current_price / start_price) - 1) * 100
94
  price_change = current_price - start_price