Spaces:
Runtime error
Runtime error
Commit
·
b8766f9
1
Parent(s):
b5e9b5a
stock prediction 1
Browse files
ADHI.h5
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:8668c127c3076c5e09bc0f96b8d1f2bfd6ddfaf599ab6d0481bf8e776ef46aea
|
| 3 |
+
size 2919964
|
ANTM.h5
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:24452cd37ef00a81077db77b9afb9b499c6809576451280c95c5010336f73edb
|
| 3 |
+
size 2919964
|
Procfile
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
web: sh setup.sh && streamlit run app.py
|
TLKM.h5
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:f26e8cd59924d569473f3c658942f20e01a8020359427df932e88ce39f7721f0
|
| 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',('ADHI', 'ANTM', 'TLKM'))
|
| 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,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
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
|