mystycrym commited on
Commit
5fcda4c
·
verified ·
1 Parent(s): 36a9c04

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -4
app.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import streamlit as st
2
  import yfinance as yf
3
  from statsmodels.tsa.arima.model import ARIMA
@@ -6,7 +7,10 @@ import matplotlib.pyplot as plt
6
 
7
  # Title and description
8
  st.title("Algorithmic Trading Bot with ARIMA")
9
- st.write("This app simulates an algorithmic trading bot using the ARIMA model for price prediction.")
 
 
 
10
 
11
  # Sidebar for user inputs
12
  st.sidebar.title("Settings")
@@ -35,7 +39,7 @@ except Exception as e:
35
  # Trading Bot Simulation
36
  if st.button("Run Trading Bot"):
37
  st.write("### Trading Bot Simulation")
38
-
39
  if len(data) < 30:
40
  st.error("Not enough data to train the model. Please select a longer date range.")
41
  else:
@@ -47,7 +51,8 @@ if st.button("Run Trading Bot"):
47
  # Predict future prices
48
  future_index = pd.date_range(start=data.index[-1], periods=n_days + 1, freq="B")[1:]
49
  forecast = fitted_model.forecast(steps=n_days)
50
- forecast_df = pd.DataFrame({"Date": future_index, "Predicted Price": forecast}).set_index("Date")
 
51
 
52
  # Simulate trading
53
  balance = initial_balance
@@ -80,7 +85,7 @@ if st.button("Run Trading Bot"):
80
  # Plot results
81
  plt.figure(figsize=(10, 6))
82
  plt.plot(data, label="Historical Data (USD/share)")
83
- plt.plot(forecast_df, label="Predicted Data (USD/share)", linestyle="--")
84
  for trade in trades:
85
  plt.scatter(trade[0], trade[2], label=trade[1], color="green" if trade[1] == "BUY" else "red")
86
  plt.legend()
 
1
+ # Import libraries
2
  import streamlit as st
3
  import yfinance as yf
4
  from statsmodels.tsa.arima.model import ARIMA
 
7
 
8
  # Title and description
9
  st.title("Algorithmic Trading Bot with ARIMA")
10
+ st.write(
11
+ "This app simulates an algorithmic trading bot using the ARIMA model for price prediction. "
12
+ "The bot predicts future stock prices and simulates trades based on the predicted trends."
13
+ )
14
 
15
  # Sidebar for user inputs
16
  st.sidebar.title("Settings")
 
39
  # Trading Bot Simulation
40
  if st.button("Run Trading Bot"):
41
  st.write("### Trading Bot Simulation")
42
+
43
  if len(data) < 30:
44
  st.error("Not enough data to train the model. Please select a longer date range.")
45
  else:
 
51
  # Predict future prices
52
  future_index = pd.date_range(start=data.index[-1], periods=n_days + 1, freq="B")[1:]
53
  forecast = fitted_model.forecast(steps=n_days)
54
+ st.write("### Debug: Forecasted Prices")
55
+ st.write(pd.DataFrame({"Date": future_index, "Predicted Price": forecast}))
56
 
57
  # Simulate trading
58
  balance = initial_balance
 
85
  # Plot results
86
  plt.figure(figsize=(10, 6))
87
  plt.plot(data, label="Historical Data (USD/share)")
88
+ plt.plot(future_index, forecast, label="Predicted Data (USD/share)", linestyle="--")
89
  for trade in trades:
90
  plt.scatter(trade[0], trade[2], label=trade[1], color="green" if trade[1] == "BUY" else "red")
91
  plt.legend()