shaheerawan3 commited on
Commit
2162ce8
·
verified ·
1 Parent(s): a3a681d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -7
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import streamlit as st
2
  from datetime import date
3
  import yfinance as yf
 
4
  from prophet import Prophet
5
  from prophet.plot import plot_plotly
6
  from plotly import graph_objs as go
@@ -33,7 +34,7 @@ data = load_data(selected_asset)
33
  data_load_state.text('Loading data... done!')
34
 
35
  # Display raw data
36
- st.subheader('Raw data')
37
  st.write(data.tail())
38
 
39
  # Ensure 'Close' prices are numeric and handle any missing values
@@ -43,8 +44,8 @@ data.dropna(subset=['Close'], inplace=True)
43
  # Plot raw data function
44
  def plot_raw_data():
45
  fig = go.Figure()
46
- fig.add_trace(go.Scatter(x=data['Date'], y=data['Open'], name="Open Price"))
47
- fig.add_trace(go.Scatter(x=data['Date'], y=data['Close'], name="Close Price"))
48
  fig.layout.update(title_text='Time Series Data with Rangeslider', xaxis_rangeslider_visible=True)
49
  st.plotly_chart(fig)
50
 
@@ -64,14 +65,30 @@ future = m.make_future_dataframe(periods=period)
64
  forecast = m.predict(future)
65
 
66
  # Show forecast data and plot forecast
67
- st.subheader('Forecast data')
68
  st.write(forecast[['ds', 'yhat', 'yhat_lower', 'yhat_upper']].tail())
69
- st.write(f'Forecast plot for {n_years} years')
70
 
71
  fig1 = plot_plotly(m, forecast)
72
  st.plotly_chart(fig1)
73
 
74
  # Show forecast components
75
- st.write("Forecast components")
76
  fig2 = m.plot_components(forecast)
77
- st.write(fig2)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
  from datetime import date
3
  import yfinance as yf
4
+ import pandas as pd # Importing pandas to avoid NameError
5
  from prophet import Prophet
6
  from prophet.plot import plot_plotly
7
  from plotly import graph_objs as go
 
34
  data_load_state.text('Loading data... done!')
35
 
36
  # Display raw data
37
+ st.subheader('Raw Data')
38
  st.write(data.tail())
39
 
40
  # Ensure 'Close' prices are numeric and handle any missing values
 
44
  # Plot raw data function
45
  def plot_raw_data():
46
  fig = go.Figure()
47
+ fig.add_trace(go.Scatter(x=data['Date'], y=data['Open'], name="Open Price", line=dict(color='blue')))
48
+ fig.add_trace(go.Scatter(x=data['Date'], y=data['Close'], name="Close Price", line=dict(color='orange')))
49
  fig.layout.update(title_text='Time Series Data with Rangeslider', xaxis_rangeslider_visible=True)
50
  st.plotly_chart(fig)
51
 
 
65
  forecast = m.predict(future)
66
 
67
  # Show forecast data and plot forecast
68
+ st.subheader('Forecast Data')
69
  st.write(forecast[['ds', 'yhat', 'yhat_lower', 'yhat_upper']].tail())
70
+ st.write(f'Forecast plot for the next {n_years} years')
71
 
72
  fig1 = plot_plotly(m, forecast)
73
  st.plotly_chart(fig1)
74
 
75
  # Show forecast components
76
+ st.subheader("Forecast Components")
77
  fig2 = m.plot_components(forecast)
78
+ st.plotly_chart(fig2)
79
+
80
+ # Additional Insights: Displaying key metrics
81
+ st.subheader("Key Metrics")
82
+ latest_data = forecast.iloc[-1]
83
+ st.write(f"Predicted Price: ${latest_data['yhat']:.2f}")
84
+ st.write(f"Lower Bound: ${latest_data['yhat_lower']:.2f}")
85
+ st.write(f"Upper Bound: ${latest_data['yhat_upper']:.2f}")
86
+
87
+ # User Guidance Section
88
+ st.sidebar.header("User Guidance")
89
+ st.sidebar.write("""
90
+ This application allows you to predict stock prices or cryptocurrency values based on historical data.
91
+ - Select a stock or cryptocurrency from the dropdown menu.
92
+ - Use the slider to choose how many years into the future you want to predict.
93
+ - View the forecasted prices along with confidence intervals.
94
+ """)