rasa0704 commited on
Commit
2dd599b
·
1 Parent(s): ec332ab

adding files to stock dashboard

Browse files
Files changed (3) hide show
  1. app.py +95 -0
  2. keras_model.h5 +3 -0
  3. requirements.txt +9 -0
app.py ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ import numpy as np
3
+ from matplotlib import pyplot as plt
4
+ import pandas_datareader.data as web
5
+ import sklearn as sk
6
+ import datetime as dt
7
+ import yfinance as yf
8
+ yf.pdr_override()
9
+ from keras.models import load_model
10
+ import streamlit as st
11
+
12
+ # defining the dates here
13
+ st_dt1 = dt.datetime(2010,1,1)
14
+ end_dt1 = dt.datetime(2019,12,31)
15
+ st_dt2 = dt.datetime(2021,1,1)
16
+ end_dt2 = dt.datetime(2023,12,31)
17
+
18
+ st.title('Stock Trend Prediction')
19
+ user_input = st.text_input('Enter Stock Tiker','AAPL')
20
+
21
+ df_stocks1 = web.get_data_yahoo( user_input, st_dt1, end_dt1 )
22
+ df_stocks2 = web.get_data_yahoo(user_input, st_dt2, end_dt2 )
23
+ df_stocks = pd.concat([df_stocks1,df_stocks2])
24
+
25
+ df = df_stocks.reset_index()
26
+
27
+ # Desribing the data
28
+ st.subheader('Data from 2010 to 2023 exluding the Covid Year')
29
+ st.write(df.describe())
30
+
31
+ # visualization
32
+ st.subheader('The Closing price vs Time Chart')
33
+ fig = plt.figure(figsize=(12,6))
34
+ plt.plot(df.close)
35
+ st.pyplot(fig)
36
+
37
+ # with Moving Averages
38
+ st.subheader('The Closing price vs Time Chart with MA')
39
+ ma100 = df.Close.rolling(100).mean()
40
+ ma200 = df.Close.rolling(200).mean()
41
+ fig = plt.figure(figsize=(12,6))
42
+ plt.plot(df.close,'b')
43
+ plt.plot(ma100,'r')
44
+ plt.plot(ma200,'g')
45
+ st.pyplot(fig)
46
+
47
+ # train-test split
48
+ df_train = pd.DataFrame(df['Close'][0:int(df.shape[0]*0.7)])
49
+ df_test = pd.DataFrame(df['Close'][int(df.shape[0]*0.7):int(df.shape[0])])
50
+
51
+ from sklearn.preprocessing import MinMaxScaler
52
+ scaler = MinMaxScaler(feature_range=(0,1))
53
+ df_train_array = scaler.fit_transform(df_train)
54
+
55
+ # need to fix the step size of 100
56
+ x_train = []
57
+ y_train = []
58
+
59
+ for i in range(100,df_train_array.shape[0]):
60
+ x_train.append(df_train_array[i-100:i])
61
+ y_train.append(df_train_array[i,0])
62
+
63
+ x_train,y_train = np.array(x_train), np.array(y_train)
64
+
65
+ model = load_model("keras_model.h5")
66
+
67
+ past_100_days = df_train.tail(100)
68
+ df_final = past_100_days.append(df_test,ignore_index=True)
69
+
70
+ df_final = scaler.fit_transform(df_final)
71
+ x_test = []
72
+ y_test = []
73
+
74
+ for i in range(100,df_final.shape[0]):
75
+ x_test.append(df_final[i-100:i])
76
+ y_test.append(df_final[i,0])
77
+ x_test, y_test = np.array(x_test), np.array(y_test)
78
+
79
+ y_pred = model.predict(x_test)
80
+
81
+ scaler_val = scaler.scale_
82
+ scale_factor = 1/0.00615148
83
+ y_pred = y_pred*scale_factor
84
+ y_test = y_test*scale_factor
85
+
86
+ #plotting
87
+ st.subheader("Trends vs Original Prie")
88
+ fig2 = plt.figure(figsize=(12,6))
89
+ plt.plot(y_test,'b',label='Original Price')
90
+ plt.plot(y_pred,'r',label='Predicted Price')
91
+ plt.xlabel('Time')
92
+ plt.ylabel('Price')
93
+ plt.legend()
94
+ st.pyplot(fig2)
95
+
keras_model.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:745734736901b9186c5f50e2b1b79a7fbbd2084b81a3b32a38737420e00d3b2b
3
+ size 1679912
requirements.txt ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ pandas
2
+ streamlit
3
+ keras
4
+ matplotlib
5
+ numpy
6
+ sklearn
7
+ datetime
8
+ yfinane
9
+ tensorflow