Spaces:
Runtime error
Runtime error
Upload 9 files
Browse files- BBRI.h5 +3 -0
- HMSP.h5 +3 -0
- JSMR.h5 +3 -0
- PGAS.h5 +3 -0
- Procfile.txt +1 -0
- WSKT.h5 +3 -0
- app.py +83 -0
- requirements.txt +7 -0
- setup.sh +13 -0
BBRI.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:e0361196e71c11258c8c5e8514369ad99d779c7a5319945650bd52225aef7c76
|
3 |
+
size 2919964
|
HMSP.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:b8824250763e540e72f8510fefe2e408d5f48d64a8344b7fe2788bc6af455f1e
|
3 |
+
size 2919964
|
JSMR.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:772c7e0bcea6c29e9b92e8f4dcd0bc38084c6547f08636fc16149c188555086a
|
3 |
+
size 2919964
|
PGAS.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:03b4348a6864f7bc763220084e7c644738e666d8e374c38ab6f75285c862ced6
|
3 |
+
size 2919964
|
Procfile.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
web: sh setup.sh && streamlit run app.py
|
WSKT.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:2d94d6e52735a9371c291653c5ef9f6251480121804e5b666443e5d646b299ea
|
3 |
+
size 2919964
|
app.py
ADDED
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import yfinance as yf
|
2 |
+
import streamlit as st
|
3 |
+
import pandas as pd
|
4 |
+
import datetime
|
5 |
+
|
6 |
+
import numpy as np
|
7 |
+
import matplotlib.pyplot as plt
|
8 |
+
from keras.models import Sequential
|
9 |
+
from keras.layers import LSTM
|
10 |
+
from keras.layers import Dense
|
11 |
+
from keras.layers import Bidirectional
|
12 |
+
|
13 |
+
|
14 |
+
st.write("""
|
15 |
+
# Simple Stock Price App
|
16 |
+
|
17 |
+
Shown are the stock **closing price** and **volume**.
|
18 |
+
""")
|
19 |
+
|
20 |
+
def user_input_features() :
|
21 |
+
stock_symbol = st.sidebar.selectbox('Symbol',('BBRI', 'HMSP', 'WSKT', 'JSMR', 'PGAS'))
|
22 |
+
date_start = st.sidebar.date_input("Start Date", datetime.date(2015, 5, 31))
|
23 |
+
date_end = st.sidebar.date_input("End Date", datetime.date.today())
|
24 |
+
|
25 |
+
tickerData = yf.Ticker(stock_symbol+'.JK')
|
26 |
+
tickerDf = tickerData.history(period='1d', start=date_start, end=date_end)
|
27 |
+
return tickerDf, stock_symbol
|
28 |
+
|
29 |
+
input_df, stock_symbol = user_input_features()
|
30 |
+
|
31 |
+
st.line_chart(input_df.Close)
|
32 |
+
st.line_chart(input_df.Volume)
|
33 |
+
|
34 |
+
st.write("""
|
35 |
+
# Stock Price Prediction
|
36 |
+
|
37 |
+
Shown are the stock prediction for next 20 days.
|
38 |
+
""")
|
39 |
+
|
40 |
+
n_steps = 100
|
41 |
+
n_features = 1
|
42 |
+
|
43 |
+
model = Sequential()
|
44 |
+
model.add(Bidirectional(LSTM(300, activation='relu'), input_shape=(n_steps, n_features)))
|
45 |
+
model.add(Dense(1))
|
46 |
+
model.compile(optimizer='adam', loss='mse')
|
47 |
+
|
48 |
+
model.load_weights(stock_symbol + ".h5")
|
49 |
+
df = input_df.dropna(axis=0, how='any', thresh=None, subset=None, inplace=False)
|
50 |
+
df = df[df.Volume > 0]
|
51 |
+
|
52 |
+
close = df['Close'][-n_steps:].to_list()
|
53 |
+
min_in = min(close)
|
54 |
+
max_in = max(close)
|
55 |
+
in_seq = []
|
56 |
+
for i in close :
|
57 |
+
in_seq.append((i - min_in) / (max_in - min_in))
|
58 |
+
|
59 |
+
for i in range(20) :
|
60 |
+
x_input = np.array(in_seq[-100:])
|
61 |
+
x_input = x_input.reshape((1, n_steps, n_features))
|
62 |
+
yhat = model.predict(x_input, verbose=0)
|
63 |
+
in_seq.append(yhat[0][0])
|
64 |
+
|
65 |
+
norm_res = in_seq[-20:]
|
66 |
+
res = []
|
67 |
+
for i in norm_res :
|
68 |
+
res.append(i * (max_in - min_in) + min_in)
|
69 |
+
|
70 |
+
closepred = close[-80:]
|
71 |
+
for x in res :
|
72 |
+
closepred.append(x)
|
73 |
+
|
74 |
+
plt.figure(figsize = (20,10))
|
75 |
+
plt.plot(closepred, label="Prediction")
|
76 |
+
plt.plot(close[-80:], label="Previous")
|
77 |
+
plt.ylabel('Price (Rp)', fontsize = 15 )
|
78 |
+
plt.xlabel('Days', fontsize = 15 )
|
79 |
+
plt.title(stock_symbol + " Stock Prediction", fontsize = 20)
|
80 |
+
plt.legend()
|
81 |
+
plt.grid()
|
82 |
+
|
83 |
+
st.pyplot(plt)
|
requirements.txt
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
keras==2.9.0
|
2 |
+
matplotlib==3.5.2
|
3 |
+
numpy==1.23.1
|
4 |
+
pandas==1.4.3
|
5 |
+
streamlit==1.12.0
|
6 |
+
yfinance==0.1.74
|
7 |
+
tensorflow
|
setup.sh
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
mkdir -p ~/.streamlit/
|
2 |
+
|
3 |
+
echo "\
|
4 |
+
[general]\n\
|
5 |
+
email = \"[email protected]\"\n\
|
6 |
+
" > ~/.streamlit/credentials.toml
|
7 |
+
|
8 |
+
echo "\
|
9 |
+
[server]\n\
|
10 |
+
headless = true\n\
|
11 |
+
enableCORS=false\n\
|
12 |
+
port = $PORT\n\
|
13 |
+
" > ~/.streamlit/config.toml
|