-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
74 lines (54 loc) · 2.42 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
import os
import streamlit as st
from typing import List
from src.process import process
def main():
st.title('Backtesting Trading Strategy Using Bollinger Bands')
tickers = [
"SELECT ALL","AAPL", "MSFT", "AMZN", "NVDA", "GOOGL", "META", "TSLA", "BRK.B", "JPM", "V",
"JNJ", "PG", "UNH", "MA", "PFE", "XOM", "CVX", "KO", "PEP", "MRK",
"DIS", "ADBE", "INTC", "CRM", "AVGO", "COST", "NFLX", "AMD", "PYPL", "QCOM",
"T", "VZ", "TXN", "CSCO", "MMM", "HON", "ABBV", "BMY", "AMGN", "LLY",
"TMO", "ISRG", "DHR", "LMT", "RTX", "BA", "SBUX", "MCD", "NKE", "LULU"
]
# initialized session state and it components
if "result" not in st.session_state:
st.session_state["result"] = None
if 'display' not in st.session_state:
st.session_state['display'] = False
with st.sidebar:
# Select Ticker
selection_box = st.multiselect(
label='Select Stock(s)',
options=tickers,
default=['AAPL'])
if 'SELECT ALL' in selection_box:
selection_box = tickers[1:]
# start_date input
start_date = st.date_input('Select Start Date', format='DD/MM/YYYY')
# End date Input
end_date = st.date_input('Select End Date', format='DD/MM/YYYY')
# Interval
interval = st.slider(label='Select Interval(Days)', min_value=1, max_value=31)
interval = f'{interval}d'
submit = st.button('Submit')
if submit:
with st.spinner('Processing...'):
st.session_state['result'] = process(selection_box, start_date, end_date, interval)
st.session_state['display'] = True
if st.session_state['display']:
trades = st.session_state['result'][0]
graphs = st.session_state['result'][1]
if len(selection_box) > 2:
select_figure = st.slider('Select Stock Index', 0, len(selection_box)-1)
st.subheader('Trades:\n')
st.dataframe(trades[select_figure])
st.subheader('Visuals for each selected stocks:\n')
st.plotly_chart(graphs[select_figure])
else:
st.subheader('Trades:\n')
st.dataframe(trades[0])
st.subheader('Visuals for each selected stocks:\n')
st.plotly_chart(graphs[0])
if __name__ == '__main__':
main()