QuantumLearner commited on
Commit
50d6ab2
·
verified ·
1 Parent(s): 3c5b0f0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -5
app.py CHANGED
@@ -55,19 +55,18 @@ with st.expander("Click here to read more about the methodology", expanded=False
55
  """)
56
 
57
  if st.sidebar.button('Run Analysis'):
 
58
  stock_data = yf.download(ticker, start=start_date, end=end_date)
59
-
60
  if not stock_data.empty:
61
- # Use "Close" column; adjusted close no longer exists. Squeeze to ensure a 1D Series.
62
  stock_data = stock_data['Close'].squeeze()
63
- stock_data = pd.Series(stock_data) # Ensure it's a Pandas Series
64
- stock_data['Returns'] = stock_data.pct_change()
65
  current_price = stock_data.iloc[-1]
66
 
67
  # Method 1: Volatility over dynamic periods
68
  fig1 = go.Figure()
69
  plot_data = stock_data[-rolling_window:]
70
- # Convert last index to Timestamp to add DateOffset
71
  last_date = pd.to_datetime(plot_data.index[-1])
72
  date_range = pd.date_range(last_date + pd.DateOffset(1), periods=time_horizon, freq='D')
73
 
 
55
  """)
56
 
57
  if st.sidebar.button('Run Analysis'):
58
+ # Download data; use "Close" and squeeze to ensure a 1D Series.
59
  stock_data = yf.download(ticker, start=start_date, end=end_date)
 
60
  if not stock_data.empty:
 
61
  stock_data = stock_data['Close'].squeeze()
62
+ # Compute returns separately (do not add to stock_data to avoid modifying the index)
63
+ returns = stock_data.pct_change()
64
  current_price = stock_data.iloc[-1]
65
 
66
  # Method 1: Volatility over dynamic periods
67
  fig1 = go.Figure()
68
  plot_data = stock_data[-rolling_window:]
69
+ # Ensure the last index is a Timestamp (avoid concatenation error)
70
  last_date = pd.to_datetime(plot_data.index[-1])
71
  date_range = pd.date_range(last_date + pd.DateOffset(1), periods=time_horizon, freq='D')
72