-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
62 lines (48 loc) · 1.68 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
import streamlit as st
import sys
from streamlit import cli as stcli
from matplotlib.backends.backend_agg import RendererAgg
import plotly.express as px
import pandas as pd
from get_data import get_info
_lock = RendererAgg.lock
apptitle = 'Time series forecasting via topological data analysis'
st.set_page_config(page_title=apptitle, page_icon=":eyeglasses:", layout='wide')
st.title(apptitle)
col1, col2 = st.columns(2)
@st.cache
def load_data(dates):
real_data = pd.read_csv('data/raw/data.csv', index_col='symbol')
real_data.columns = [item.split()[0] for item in real_data.columns.to_list()]
real_data = real_data[dates]
return real_data
@st.cache
def load_prediction():
prediction_data = pd.read_csv('data/prediction.csv', index_col='shortName')
prediction_data.drop(
['2021-09-18', '2021-09-25', '2021-10-02', '2021-10-09', '2021-10-16', '2021-10-23', '2021-10-30', '2021-11-05'],
axis=1,
inplace=True
)
return prediction_data
preds = load_prediction()
real = load_data(preds.columns.to_list())
with st.spinner('Loading Forecasting...'):
for i, item in enumerate(real.index):
ticker_info = get_info(item, '1d', ['shortName'])
data = pd.DataFrame({'Real values': real.loc[item], 'Predicted': preds.loc[item]})
fig = px.line(
data,
labels={
"index": "Date",
"Value": "Close price"
},
title=f"{ticker_info['shortName']}"
)
if i % 2 == 0:
col1.plotly_chart(fig)
else:
col2.plotly_chart(fig)
if __name__ == '__main__':
sys.argv = ["streamlit", "run", "app.py"]
sys.exit(stcli.main())