Harsh23Kashyap commited on
Commit
03332e8
1 Parent(s): 7b91c5c

Upload 4 files

Browse files
Files changed (4) hide show
  1. LSTM.ipynb +0 -0
  2. app.py +174 -0
  3. requirements.txt +240 -0
  4. stock_prediction.h5 +3 -0
LSTM.ipynb ADDED
The diff for this file is too large to render. See raw diff
 
app.py ADDED
@@ -0,0 +1,174 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ import numpy as np
3
+ import matplotlib.pyplot as plt
4
+ import pandas_datareader as data
5
+ import plotly.express as px
6
+ import streamlit as st
7
+ import requests
8
+ from streamlit_lottie import st_lottie
9
+ from keras.models import load_model
10
+
11
+ st.set_page_config(
12
+ page_title=" Stonks Trends Prediction", #The page title, shown in the browser tab.(should be Placement Details)
13
+ initial_sidebar_state="auto", #The way sidebar should start out. Auto shows it in desktop.
14
+ page_icon=":computer:", #The page favicon. Use the computer emoji
15
+ layout="wide", #The way page content should be laid out. "wide" uses the entire screen.
16
+ menu_items={ #Configure the menu that appears on the top-right side of this app.
17
+ 'About': 'https://www.linkedin.com/in/harsh-kashyap-79b87b193/', #A markdown string to show in the About dialog. Used my linkedIn id
18
+ }
19
+ )
20
+
21
+ from datetime import date
22
+ from datetime import timedelta
23
+ today = date.today()
24
+ # Yesterday date
25
+ yesterday = today - timedelta(days = 1)
26
+ start='2008-01-01'
27
+ end=yesterday;
28
+
29
+ st.title(":computer: Stock Market Predictor") #Title heading of the page
30
+ st.markdown("##")
31
+
32
+
33
+
34
+ st.subheader("Enter Stock Ticker")
35
+ user_input=st.text_input('','AAPL')
36
+ df=data.DataReader(user_input,'yahoo',start,end)
37
+ date=df.index
38
+
39
+ #Checks if which parameters in hsc_s which is named as branch in sidebar is checked or not and display results accordingly
40
+ def load_lottieurl(url: str):
41
+ r = requests.get(url) #Make a request to a web page, and return the status code:
42
+ if r.status_code != 200: #200 is the HTTP status code for "OK", a successful response.
43
+ return None
44
+ return r.json() #return the animated gif
45
+
46
+ left_column, right_column = st.columns(2) #Columns divided into two parts
47
+ with left_column:
48
+ dashboard1 = load_lottieurl("https://assets10.lottiefiles.com/packages/lf20_kuhijlvx.json") #get the animated gif from file
49
+ st_lottie(dashboard1, key="Dashboard1", height=400) #change the size to height 400
50
+ with right_column:
51
+ dashboard2 = load_lottieurl("https://assets10.lottiefiles.com/packages/lf20_i2eyukor.json") #get the animated gif from file
52
+ st_lottie(dashboard2, key="Dashboard2", height=400) #change the size to height 400
53
+
54
+
55
+ st.markdown("""---""")
56
+ #Describing data
57
+ st.subheader('Data from 2008 to '+str(end.year))
58
+ st.write(df.describe())
59
+
60
+ st.markdown("""---""")
61
+ #Visualisations
62
+ st.subheader("Closing Price vs Time Chart of "+str(user_input)) #Header
63
+ #plot a line graph
64
+ fig_line = px.line(
65
+ df,
66
+ x = df.index,
67
+ y = "Close",
68
+ width=1400, #width of the chart
69
+ height=750, #height of the chart
70
+ )
71
+ #remove the background of the back label
72
+ fig_line.update_layout(
73
+ plot_bgcolor="rgba(0,0,0,0)", #rgba means transparent
74
+ xaxis=(dict(showgrid=False)) #dont show the grid
75
+ )
76
+ #plot the chart
77
+ st.plotly_chart(fig_line, use_container_width=True)
78
+ st.markdown("""---""")
79
+
80
+
81
+ st.subheader("Closing Price vs Time with 100MA of "+str(user_input)) #Header
82
+ ma100=df.Close.rolling(100).mean()
83
+ #plot a line graph
84
+ fig_line = px.line(
85
+ ma100,
86
+ x = df.index,
87
+ y = ma100,
88
+ width=1400, #width of the chart
89
+ height=750, #height of the chart
90
+ )
91
+ #remove the background of the back label
92
+ fig_line.update_layout(
93
+ plot_bgcolor="rgba(0,0,0,0)", #rgba means transparent
94
+ xaxis=(dict(showgrid=False)) #dont show the grid
95
+ )
96
+ #plot the chart
97
+ st.plotly_chart(fig_line, use_container_width=True)
98
+ st.markdown("""---""")
99
+
100
+
101
+ st.subheader("Closing Price vs Time with 1 year moving average of "+str(user_input)) #Header
102
+ ma365=df.Close.rolling(365).mean()
103
+ #plot a line graph
104
+ fig_line = px.line(
105
+ ma365,
106
+ x = df.index,
107
+ y = ma365,
108
+ width=1400, #width of the chart
109
+ height=750, #height of the chart
110
+ )
111
+ #remove the background of the back label
112
+ fig_line.update_layout(
113
+ plot_bgcolor="rgba(0,0,0,0)", #rgba means transparent
114
+ xaxis=(dict(showgrid=False)) #dont show the grid
115
+ )
116
+ #plot the chart
117
+ st.plotly_chart(fig_line, use_container_width=True)
118
+ st.markdown("""---""")
119
+
120
+
121
+
122
+ #Splitting data into training and testing
123
+
124
+ data_training= pd.DataFrame(df['Close'][0:int(len(df)*0.7)])
125
+ data_testing= pd.DataFrame(df['Close'][int(len(df)*0.7):int(len(df))])
126
+ ydate= date[int(len(df)*0.7):int(len(df))]
127
+ print(data_training.shape)
128
+ print(data_testing.shape)
129
+
130
+ #normalising data
131
+ from sklearn.preprocessing import MinMaxScaler
132
+ scaler=MinMaxScaler(feature_range=(0,1))
133
+
134
+ dataset_train = scaler.fit_transform(data_training)
135
+ dataset_test = scaler.transform(data_testing)
136
+
137
+ def create_dataset(df):
138
+ x = []
139
+ y = []
140
+ for i in range(50, df.shape[0]):
141
+ x.append(df[i-50:i, 0])
142
+ y.append(df[i, 0])
143
+ x = np.array(x)
144
+ y = np.array(y)
145
+ return x,y
146
+
147
+ #Creating dataset
148
+ x_train, y_train = create_dataset(dataset_train)
149
+ x_test, y_test = create_dataset(dataset_test)
150
+
151
+ x_train = np.reshape(x_train, (x_train.shape[0], x_train.shape[1], 1))
152
+ x_test = np.reshape(x_test, (x_test.shape[0], x_test.shape[1], 1))
153
+
154
+ #Load my model
155
+ model=load_model('stock_prediction.h5')
156
+
157
+ predictions = model.predict(x_test)
158
+ predictions = scaler.inverse_transform(predictions)
159
+ y_test_scaled = scaler.inverse_transform(y_test.reshape(-1, 1))
160
+
161
+ cydate=ydate[50:]
162
+ st.markdown("""---""")
163
+ st.subheader("Actual Vs Predicted Price Graph for "+user_input)
164
+ fig, ax = plt.subplots(figsize=(16,8))
165
+ ax.set_facecolor('#000041')
166
+ ax.plot(cydate,y_test_scaled, color='red', label='Original price')
167
+ plt.plot(cydate,predictions, color='cyan', label='Predicted price')
168
+ plt.xlabel("Date")
169
+ plt.ylabel("Price")
170
+ plt.title("Stocks for the company "+str(user_input))
171
+ plt.legend()
172
+ st.pyplot(fig)
173
+
174
+ st.markdown("""---""")
requirements.txt ADDED
@@ -0,0 +1,240 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ absl-py==1.2.0
2
+ aiofiles==22.1.0
3
+ altair==4.2.0
4
+ anyio==3.6.1
5
+ appnope==0.1.3
6
+ argon2-cffi==21.3.0
7
+ argon2-cffi-bindings==21.2.0
8
+ astroid==2.11.7
9
+ asttokens==2.0.5
10
+ astunparse==1.6.3
11
+ attrs==22.1.0
12
+ Babel==2.10.3
13
+ backcall==0.2.0
14
+ beautifulsoup4==4.11.1
15
+ bert-extractive-summarizer==0.4.2
16
+ bleach==5.0.1
17
+ blinker==1.5
18
+ blis==0.7.9
19
+ boto3==1.26.18
20
+ botocore==1.29.18
21
+ cached-property==1.5.2
22
+ cachetools==5.2.0
23
+ catalogue==2.0.8
24
+ certifi==2022.6.15
25
+ cffi==1.15.1
26
+ charset-normalizer==2.1.0
27
+ ci-info==0.3.0
28
+ click==8.1.3
29
+ commonmark==0.9.1
30
+ confection==0.0.3
31
+ configobj==5.0.6
32
+ configparser==5.3.0
33
+ cycler==0.11.0
34
+ cymem==2.0.7
35
+ debugpy==1.6.2
36
+ decorator==5.1.1
37
+ defusedxml==0.7.1
38
+ dill==0.3.5.1
39
+ docopt==0.6.2
40
+ docx==0.2.4
41
+ entrypoints==0.4
42
+ etelemetry==0.3.0
43
+ executing==0.8.3
44
+ fastjsonschema==2.16.1
45
+ filelock==3.8.0
46
+ fitz==0.0.1.dev2
47
+ Flask==2.2.2
48
+ Flask-SQLAlchemy==3.0.2
49
+ flatbuffers==1.12
50
+ fonttools==4.34.4
51
+ frontend==0.0.3
52
+ future==0.18.2
53
+ gast==0.4.0
54
+ gitdb==4.0.9
55
+ GitPython==3.1.27
56
+ google-auth==2.9.1
57
+ google-auth-oauthlib==0.4.6
58
+ google-pasta==0.2.0
59
+ greenlet==2.0.1
60
+ grpcio==1.47.0
61
+ gTTS==2.2.4
62
+ h11==0.14.0
63
+ h5py==3.7.0
64
+ httplib2==0.21.0
65
+ huggingface-hub==0.11.1
66
+ idna==3.3
67
+ importlib-metadata==4.12.0
68
+ inflection==0.5.1
69
+ ipykernel==6.15.1
70
+ ipython==8.4.0
71
+ ipython-genutils==0.2.0
72
+ ipywidgets==7.7.1
73
+ isodate==0.6.1
74
+ isort==5.10.1
75
+ itsdangerous==2.1.2
76
+ jedi==0.18.1
77
+ Jinja2==3.1.2
78
+ jmespath==1.0.1
79
+ joblib==1.1.0
80
+ json5==0.9.10
81
+ jsonschema==4.9.1
82
+ jupyter-client==7.3.4
83
+ jupyter-core==4.11.1
84
+ jupyter-server==1.18.1
85
+ jupyterlab==3.4.5
86
+ jupyterlab-pygments==0.2.2
87
+ jupyterlab-widgets==1.1.1
88
+ jupyterlab_server==2.15.1
89
+ keras==2.9.0
90
+ Keras-Preprocessing==1.1.2
91
+ kiwisolver==1.4.3
92
+ langcodes==3.3.0
93
+ lazy-object-proxy==1.7.1
94
+ libclang==14.0.6
95
+ looseversion==1.0.2
96
+ lxml==4.9.1
97
+ Markdown==3.4.1
98
+ MarkupSafe==2.1.1
99
+ matplotlib==3.5.2
100
+ matplotlib-inline==0.1.3
101
+ mccabe==0.7.0
102
+ mistune==0.8.4
103
+ murmurhash==1.0.9
104
+ mypy-extensions==0.4.3
105
+ mysql-connector==2.2.9
106
+ mysql-connector-python-rf==2.2.2
107
+ nbclassic==0.4.3
108
+ nbclient==0.6.6
109
+ nbconvert==6.5.0
110
+ nbformat==5.4.0
111
+ nest-asyncio==1.5.5
112
+ networkx==2.8.8
113
+ nibabel==4.0.2
114
+ nipype==1.8.5
115
+ nltk==3.7
116
+ notebook==6.4.12
117
+ notebook-shim==0.1.0
118
+ numpy==1.23.1
119
+ oauthlib==3.2.0
120
+ opencv-python==4.6.0.66
121
+ opt-einsum==3.3.0
122
+ packaging==21.3
123
+ pandas==1.4.3
124
+ pandas-datareader==0.10.0
125
+ pandocfilters==1.5.0
126
+ parso==0.8.3
127
+ passlib==1.7.4
128
+ pathlib==1.0.1
129
+ pathy==0.10.0
130
+ pexpect==4.8.0
131
+ pickleshare==0.7.5
132
+ Pillow==9.2.0
133
+ pipreqs==0.4.11
134
+ platformdirs==2.5.2
135
+ plotly==5.9.0
136
+ preshed==3.0.8
137
+ prometheus-client==0.14.1
138
+ prompt-toolkit==3.0.30
139
+ protobuf==3.19.4
140
+ prov==2.0.0
141
+ psutil==5.9.1
142
+ ptyprocess==0.7.0
143
+ pure-eval==0.2.2
144
+ py4j==0.10.9.5
145
+ pyarrow==9.0.0
146
+ pyasn1==0.4.8
147
+ pyasn1-modules==0.2.8
148
+ pycparser==2.21
149
+ pydantic==1.10.2
150
+ pydeck==0.7.1
151
+ pydot==1.4.2
152
+ Pygments==2.12.0
153
+ pylint==2.14.4
154
+ Pympler==1.0.1
155
+ PyMuPDF==1.21.0
156
+ pyparsing==3.0.9
157
+ pyrsistent==0.18.1
158
+ pyspark==3.3.0
159
+ pytesseract==0.3.10
160
+ python-dateutil==2.8.2
161
+ python-docx==0.8.11
162
+ pytils==0.4.1
163
+ pytz==2022.1
164
+ pytz-deprecation-shim==0.1.0.post0
165
+ pyxnat==1.5
166
+ PyYAML==6.0
167
+ pyzmq==23.2.0
168
+ qrcode==7.3.1
169
+ rdflib==6.2.0
170
+ regex==2022.10.31
171
+ requests==2.28.1
172
+ requests-oauthlib==1.3.1
173
+ rich==12.5.1
174
+ rsa==4.9
175
+ s3transfer==0.6.0
176
+ scikit-learn==1.1.1
177
+ scipy==1.9.0
178
+ seaborn==0.11.2
179
+ semver==2.13.0
180
+ Send2Trash==1.8.0
181
+ sentence-transformers==2.2.2
182
+ sentencepiece==0.1.97
183
+ simplejson==3.18.0
184
+ six==1.16.0
185
+ smart-open==5.2.1
186
+ smmap==5.0.0
187
+ sniffio==1.2.0
188
+ soupsieve==2.3.2.post1
189
+ spacy==3.4.3
190
+ spacy-legacy==3.0.10
191
+ spacy-loggers==1.0.3
192
+ SQLAlchemy==1.4.44
193
+ sqlalchemy-orm==1.2.3
194
+ srsly==2.4.5
195
+ stack-data==0.3.0
196
+ starlette==0.23.0
197
+ streamlit==1.11.1
198
+ streamlit-lottie==0.0.3
199
+ tenacity==8.0.1
200
+ tensorboard==2.9.1
201
+ tensorboard-data-server==0.6.1
202
+ tensorboard-plugin-wit==1.8.1
203
+ tensorflow==2.9.1
204
+ tensorflow-estimator==2.9.0
205
+ tensorflow-io-gcs-filesystem==0.26.0
206
+ termcolor==1.1.0
207
+ terminado==0.15.0
208
+ thinc==8.1.5
209
+ threadpoolctl==3.1.0
210
+ tinycss2==1.1.1
211
+ tokenizers==0.13.2
212
+ toml==0.10.2
213
+ tomli==2.0.1
214
+ tomlkit==0.11.1
215
+ tools==0.1.9
216
+ toolz==0.12.0
217
+ torch==1.13.0
218
+ torchvision==0.14.0
219
+ tornado==6.2
220
+ tqdm==4.64.1
221
+ traitlets==5.3.0
222
+ traits==6.3.2
223
+ transformers==4.24.0
224
+ typer==0.7.0
225
+ typing-inspect==0.8.0
226
+ typing_extensions==4.3.0
227
+ tzdata==2022.1
228
+ tzlocal==4.2
229
+ urllib3==1.26.11
230
+ uvicorn==0.20.0
231
+ validators==0.20.0
232
+ wasabi==0.10.1
233
+ wcwidth==0.2.5
234
+ webencodings==0.5.1
235
+ websocket-client==1.4.0
236
+ Werkzeug==2.2.2
237
+ widgetsnbextension==3.6.1
238
+ wrapt==1.14.1
239
+ yarg==0.1.9
240
+ zipp==3.8.1
stock_prediction.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:230bec19c7ac3b71d78e29f788fa7155b55e6c5836872c26c1c809de4c14f463
3
+ size 3195144