-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
92 lines (66 loc) · 2.22 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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
92
import numpy as np
import pandas as pd
import yfinance as yf
from keras.models import load_model
import streamlit as st
import matplotlib.pyplot as plt
model = load_model('Stock Prediction Model.keras')
st.header('Stock Market Predictor')
stock = st.text_input('Enter Stock Symbol', 'GOOG')
start = '2012-01-01'
end = '2022-12-31'
data = yf.download(stock, start, end)
st.subheader('Stock Data')
st.write(data)
data_train = pd.DataFrame(data.Close[0: int(len(data)*0.80)])
data_test = pd.DataFrame(data.Close[int(len(data)*0.80): len(data)])
from sklearn.preprocessing import MinMaxScaler
scaler = MinMaxScaler(feature_range = (0, 1))
pas_100_days = data_train.tail(100)
data_test = pd.concat([pas_100_days, data_test], ignore_index = True)
data_test_scale = scaler.fit_transform(data_test)
st.subheader(' Price vs MA50')
ma_50_days = data.Close.rolling(50).mean()
fig1 = plt.figure(figsize=(8, 6))
plt.plot(ma_50_days, 'r', label = 'ma_50_days')
plt.plot(data.Close, 'g', label = 'Price')
plt.legend()
plt.show()
st.pyplot(fig1)
st.subheader(' Price vs MA50 vs MA100')
ma_100_days = data.Close.rolling(100).mean()
fig2 = plt.figure(figsize=(8, 6))
plt.plot(ma_50_days, 'r', label = 'ma_50_days')
plt.plot(ma_100_days, 'b', label = 'ma_100_days')
plt.plot(data.Close, 'g', label = 'Price')
plt.legend()
plt.show()
st.pyplot(fig2)
st.subheader(' Price vs MA100 vs MA200')
ma_200_days = data.Close.rolling(200).mean()
fig3 = plt.figure(figsize=(8, 6))
plt.plot(ma_100_days, 'r', label = 'ma_100_days')
plt.plot(ma_200_days, 'b', label = 'ma_200_days')
plt.plot(data.Close, 'g', label = 'Price')
plt.legend()
plt.show()
st.pyplot(fig3)
x = []
y = []
for i in range(100, data_test_scale.shape[0]):
x.append(data_test_scale[i - 100: i])
y.append(data_test_scale[i,0])
x, y = np.array(x), np.array(y)
predict = model.predict(x)
scale = 1/scaler.scale_
predict = predict * scale
y = y * scale
st.subheader(' Original Price vs Predicted Price')
fig4 = plt.figure(figsize=(8, 6))
plt.plot(predict, 'r', label = 'Original Price')
plt.plot(y, 'g', label = 'Predicted Price')
plt.xlabel('Time')
plt.ylabel('Price')
plt.legend()
plt.show()
st.pyplot(fig4)