kshitij10000 commited on
Commit
35cecda
·
1 Parent(s): 6b333ad

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +87 -0
  2. requirements.txt +10 -0
app.py ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import numpy as np
3
+ import pandas as pd
4
+ import matplotlib.pyplot as plt
5
+ import pandas_datareader as data
6
+ import yfinance as yf
7
+ from keras.models import load_model
8
+
9
+
10
+ st.title('Stock Trend predictor')
11
+
12
+ user_input = st.text_input('Enter Stock Ticker','AAPL' )
13
+ script = yf.download(tickers=user_input,period='15y',interval='1d')
14
+
15
+ #describing data
16
+ st.subheader('Data of last 15 years')
17
+ st.write(script.describe())
18
+
19
+ #visualization
20
+ st.subheader('closing price vs time chart')
21
+ fig = plt.figure(figsize=(17,7))
22
+ plt.plot(script.Close, 'b')
23
+ st.pyplot(fig)
24
+
25
+ st.subheader('Closing price vs time chart with 100MA')#100 ma
26
+ ma100 = script.Close.rolling(100).mean()
27
+ fig = plt.figure(figsize=(17,7))
28
+ plt.plot(ma100, 'g')
29
+ plt.plot(script.Close, 'b')
30
+ st.pyplot(fig)
31
+
32
+ st.subheader('Closing price vs time chart with 100MA and 200MA')#200&100 ma
33
+ ma200 = script.Close.rolling(200).mean()
34
+ #ma100 = script.Close.rolling(100).mean()
35
+ fig = plt.figure(figsize=(17,7))
36
+ plt.plot(ma200, 'r')
37
+ plt.plot(ma100, 'g')
38
+ plt.plot(script.Close, 'b')
39
+ st.pyplot(fig)
40
+
41
+ # splitting data into training and testing
42
+
43
+ data_training = pd.DataFrame(script['Close'][0:int(len(script)*0.70)])
44
+ data_testing = pd.DataFrame(script['Close'][int(len(script)*0.70): int(len(script))])
45
+
46
+ from sklearn.preprocessing import MinMaxScaler
47
+ scaler = MinMaxScaler(feature_range=(0,1))
48
+
49
+ data_training_array = scaler.fit_transform(data_training)
50
+
51
+ #load my model
52
+ model = load_model('stock_model.h5')
53
+
54
+
55
+
56
+ #testing part
57
+ past_100_days = data_training.tail(100)
58
+ final_script = pd.concat([past_100_days, data_testing], ignore_index=True)
59
+ input_data = scaler.fit_transform(final_script)
60
+
61
+ x_test = []
62
+ y_test = []
63
+
64
+ for i in range(100, input_data.shape[0]):
65
+ x_test.append(input_data[i-100: i])
66
+ y_test.append(input_data[i, 0])
67
+
68
+ x_test, y_test = np.array(x_test), np.array(y_test)
69
+
70
+ # making prediction
71
+
72
+ y_predicted = model.predict(x_test)
73
+ #scaler.scale_
74
+
75
+ scale_factor = 1/scaler.scale_
76
+ y_predicted = y_predicted * scale_factor
77
+ y_test = y_test * scale_factor
78
+ #final graph
79
+
80
+ st.subheader('Prediction vs original')
81
+ fig2 = plt.figure(figsize=(17,7))
82
+ plt.plot(y_test, 'b', label = 'Original Price')
83
+ plt.plot(y_predicted, 'r', label = 'Predicted Price')
84
+ plt.xlabel('Time')
85
+ plt.ylabel('Price')
86
+ plt.legend()
87
+ st.pyplot(fig2)
requirements.txt ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ streamlit
2
+ numpy
3
+ pandas
4
+ matplotlib
5
+ pandas_datareader
6
+ yfinance
7
+ keras.models
8
+ tensorflow
9
+ sklearn
10
+ MinMaxScaler