Spaces:
Runtime error
Runtime error
Maisarah Nurain
commited on
Commit
•
eb8f9f1
1
Parent(s):
a710a04
Add application file
Browse files
ANTM.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:0d65ffdff792baf02b50cfd8b244fbe8802fef472a71e938124a1ba71bcf0cc0
|
3 |
+
size 2919964
|
ARNA.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:07ce7d79381887ad577959f47b8b53c64d31e38545f0d4352d8275c44a063c49
|
3 |
+
size 2919964
|
DUTI.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:083b5f69e01fd97c9ea79636c7613f1e7ccd630559d6d7b18ef8c7a789730b5e
|
3 |
+
size 2919964
|
ELSA.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:b858d9009d5479439c1a0c5cbf226c17e657e4e18b54c184b2e69e607c0069dc
|
3 |
+
size 2919964
|
MFMI.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:710aa28337cafa689c147042f5d22cc0476eaa4cc591162bf64c6c0fbb56e516
|
3 |
+
size 2919964
|
Procfile
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
web: sh setup.sh && streamlit run app.py
|
app.py
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import yfinance as yf
|
2 |
+
import streamlit as st
|
3 |
+
import pandas as pd
|
4 |
+
import datetime
|
5 |
+
|
6 |
+
st.write("""
|
7 |
+
# Simple Stock Price App
|
8 |
+
|
9 |
+
Shown are the stock **closing price** and **volume**.
|
10 |
+
""")
|
11 |
+
|
12 |
+
def user_input_features() :
|
13 |
+
stock_symbol = st.sidebar.selectbox('Symbol',('ANTM.JK','ARNA.JK', 'DUTI.JK', 'ELSA.JK',
|
14 |
+
'MFMI.JK'))
|
15 |
+
date_start = st.sidebar.date_input("Start Date", datetime.date(2015, 5, 31))
|
16 |
+
date_end = st.sidebar.date_input("End Date", datetime.date.today())
|
17 |
+
|
18 |
+
tickerData = yf.Ticker(stock_symbol)
|
19 |
+
tickerDf = tickerData.history(period='1d', start=date_start, end=date_end)
|
20 |
+
return tickerDf
|
21 |
+
|
22 |
+
input_df = user_input_features()
|
23 |
+
|
24 |
+
st.line_chart(input_df.Close)
|
25 |
+
st.line_chart(input_df.Volume)
|
myapp.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',('ANTM', 'ARNA', 'DUTI', 'ELSA', 'MFMI'))
|
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,2 @@
|
|
|
|
|
|
|
1 |
+
streamlit==1.12.0
|
2 |
+
yfinance
|
setup.sh
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
mkdir -p ~/.streamlit/
|
2 |
+
|
3 |
+
echo "\
|
4 |
+
[general]\n\
|
5 |
+
email = \"your-email@domain.com\"\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
|