mystycrym commited on
Commit
29db047
·
verified ·
1 Parent(s): 5ca1185

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -10
app.py CHANGED
@@ -5,8 +5,8 @@ import pandas as pd
5
  import matplotlib.pyplot as plt
6
 
7
  # Title and description
8
- st.title("S&P 500 Price Prediction with ARIMA")
9
- st.write("This app predicts the price of the S&P 500 index using the ARIMA model.")
10
 
11
  # Sidebar for user inputs
12
  st.sidebar.title("Prediction Settings")
@@ -15,7 +15,7 @@ end_date = st.sidebar.date_input("End Date", value=pd.to_datetime("2023-12-31"))
15
  n_days = st.sidebar.slider("Days to Predict", min_value=1, max_value=30, value=7)
16
 
17
  # Fetch historical data
18
- st.write("### Historical Data")
19
  try:
20
  data = yf.download("^GSPC", start=start_date, end=end_date)
21
  data = data["Close"]
@@ -25,7 +25,7 @@ except Exception as e:
25
 
26
  # Fit ARIMA model
27
  if st.button("Predict"):
28
- st.write("### Predictions")
29
 
30
  # Check for sufficient data
31
  if len(data) < 30:
@@ -39,20 +39,20 @@ if st.button("Predict"):
39
  # Make predictions
40
  future_index = pd.date_range(start=data.index[-1], periods=n_days + 1, freq="B")[1:]
41
  forecast = fitted_model.forecast(steps=n_days)
42
- forecast_df = pd.DataFrame({"Date": future_index, "Predicted Price": forecast}).set_index("Date")
43
 
44
  # Plot results
45
  plt.figure(figsize=(10, 6))
46
- plt.plot(data, label="Historical Data")
47
- plt.plot(forecast_df, label="Predicted Data", linestyle="--")
48
  plt.legend()
49
- plt.title("S&P 500 Price Prediction")
50
  plt.xlabel("Date")
51
- plt.ylabel("Price")
52
  st.pyplot(plt)
53
 
54
  # Show prediction table
55
- st.write("### Predicted Prices")
56
  st.write(forecast_df)
57
  except Exception as e:
58
  st.error(f"Error in prediction: {e}")
 
5
  import matplotlib.pyplot as plt
6
 
7
  # Title and description
8
+ st.title("S&P 500 Price Prediction in USD/Share with ARIMA")
9
+ st.write("This app predicts the price of the S&P 500 index in USD/share using the ARIMA model.")
10
 
11
  # Sidebar for user inputs
12
  st.sidebar.title("Prediction Settings")
 
15
  n_days = st.sidebar.slider("Days to Predict", min_value=1, max_value=30, value=7)
16
 
17
  # Fetch historical data
18
+ st.write("### Historical Data in USD/Share")
19
  try:
20
  data = yf.download("^GSPC", start=start_date, end=end_date)
21
  data = data["Close"]
 
25
 
26
  # Fit ARIMA model
27
  if st.button("Predict"):
28
+ st.write("### Predictions in USD/Share")
29
 
30
  # Check for sufficient data
31
  if len(data) < 30:
 
39
  # Make predictions
40
  future_index = pd.date_range(start=data.index[-1], periods=n_days + 1, freq="B")[1:]
41
  forecast = fitted_model.forecast(steps=n_days)
42
+ forecast_df = pd.DataFrame({"Date": future_index, "Predicted Price (USD/Share)": forecast}).set_index("Date")
43
 
44
  # Plot results
45
  plt.figure(figsize=(10, 6))
46
+ plt.plot(data, label="Historical Data (USD/Share)")
47
+ plt.plot(forecast_df, label="Predicted Data (USD/Share)", linestyle="--")
48
  plt.legend()
49
+ plt.title("S&P 500 Price Prediction in USD/Share")
50
  plt.xlabel("Date")
51
+ plt.ylabel("Price (USD/Share)")
52
  st.pyplot(plt)
53
 
54
  # Show prediction table
55
+ st.write("### Predicted Prices in USD/Share")
56
  st.write(forecast_df)
57
  except Exception as e:
58
  st.error(f"Error in prediction: {e}")