Spaces:
Sleeping
Sleeping
ameya123ch
commited on
Commit
•
2e09097
1
Parent(s):
94dbafb
Upload 2 files
Browse files- app.py +91 -0
- requirements.txt +4 -0
app.py
ADDED
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
7 |
+
|
8 |
+
start_date = "2016-01-01"
|
9 |
+
today_date = date.today().strftime("%Y-%m-%d")
|
10 |
+
|
11 |
+
st.title("Stock Price Forcasting App")
|
12 |
+
|
13 |
+
stocks = ("GS","MS","JPM","C")
|
14 |
+
selected_stocks = st.selectbox("Select the stock for prediction",stocks)
|
15 |
+
n_years = st.slider("Years of Prediction",1, 4)
|
16 |
+
period = n_years * 365
|
17 |
+
|
18 |
+
@st.cache
|
19 |
+
def load_data(ticker):
|
20 |
+
data = yf.download(ticker,start_date,today_date)
|
21 |
+
data.reset_index(inplace=True)
|
22 |
+
return data
|
23 |
+
|
24 |
+
data_load_state = st.text("Loading the data....")
|
25 |
+
data = load_data(selected_stocks)
|
26 |
+
data_load_state.text("Data is Loaded!!")
|
27 |
+
|
28 |
+
st.subheader("Raw Data")
|
29 |
+
st.write(data.tail())
|
30 |
+
|
31 |
+
def plot_raw_data():
|
32 |
+
fig = go.Figure()
|
33 |
+
fig.add_trace(go.Scatter(x = data['Date'],y=data['Open'], name = 'Open Price'))
|
34 |
+
fig.add_trace(go.Scatter(x=data['Date'], y=data['Close'], name = 'Close Price'))
|
35 |
+
fig.layout.update(title_text = "Time Series Data", xaxis_rangeslider_visible=True)
|
36 |
+
st.plotly_chart(fig)
|
37 |
+
|
38 |
+
plot_raw_data()
|
39 |
+
|
40 |
+
|
41 |
+
# forecasting
|
42 |
+
df_train = data[['Date','Close']]
|
43 |
+
df_train = df_train.rename(columns={"Date":"ds", "Close":"y"})
|
44 |
+
|
45 |
+
model = Prophet()
|
46 |
+
|
47 |
+
|
48 |
+
model.fit(df_train)
|
49 |
+
future = model.make_future_dataframe(periods= period)
|
50 |
+
forecast = model.predict(future)
|
51 |
+
|
52 |
+
st.subheader('Forecast Data')
|
53 |
+
st.write(forecast.tail())
|
54 |
+
|
55 |
+
st.write("Forecast Data")
|
56 |
+
fig_1 = plot_plotly(model, forecast)
|
57 |
+
st.plotly_chart(fig_1)
|
58 |
+
|
59 |
+
st.write("Forecast Components")
|
60 |
+
fig_2 = model.plot_components(forecast)
|
61 |
+
st.write(fig_2)
|
62 |
+
|
63 |
+
|
64 |
+
|
65 |
+
|
66 |
+
|
67 |
+
|
68 |
+
|
69 |
+
|
70 |
+
|
71 |
+
|
72 |
+
|
73 |
+
|
74 |
+
|
75 |
+
|
76 |
+
|
77 |
+
|
78 |
+
|
79 |
+
|
80 |
+
|
81 |
+
|
82 |
+
|
83 |
+
|
84 |
+
|
85 |
+
|
86 |
+
|
87 |
+
|
88 |
+
|
89 |
+
|
90 |
+
|
91 |
+
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
streamlit==1.15.1
|
2 |
+
prophet==1.1.1
|
3 |
+
plotly==5.11.0
|
4 |
+
yfinance==0.1.87
|