-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.py
179 lines (161 loc) · 8.21 KB
/
index.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
import dash_core_components as dcc
import dash_html_components as html
import dash
from dash.dependencies import Input, Output, State
from datetime import datetime
import pandas_datareader as wb
import pandas as pd
import dash
from plotly import graph_objects as go
from apps.tab1 import update_graph
from apps.tab2 import moving_average
from apps.tab3 import rsi
# stylesheet of tabs
tab_style = {
'borderTop': '1px solid #f7f7f7',
'padding': '6px',
'fontWeight': 'bold',
'textAlign': 'center',
'font-size': '25px'
}
# stylesheet of tabs selected
tab_selected_style = {
'borderTop': '1px solid #f7f7f7',
'borderBottom': '5px solid #d92027',
'backgroundColor': '#f7f7f7',
'color': 'black',
'padding': '6px',
'textAlign': 'center'
}
# colors of background and text
colors = {
'background': '#111111',
'text': '#7FDBFF'
}
# External stylesheet
external_stylesheet = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
# Reading csv file with tickers
nsdq = pd.read_csv('NASDAQcompanylist.csv')
nsdq.set_index('Symbol', inplace=True)
option = []
for tick in nsdq.index:
mydict = {}
mydict['label'] = nsdq.loc[tick]['Name'] + ' ' + tick
mydict['value'] = tick
option.append(mydict)
app = dash.Dash(external_stylesheets=external_stylesheet)
app.layout = html.Div([html.Div(html.H1('Dashboard', style={'color': 'white', 'textAlign': 'center', }),
style={'inline': 'center',
'background': 'black',
'color': 'white'}),
# Calendar and dropdown list of tickers
html.Div([html.H3('Pick your ticker(-s)'),
dcc.Dropdown(
id='stock-pick',
options=option,
value=['TSLA'],
multi=True,
style={'height': '40px'})], # Dropdown list
style={'display': 'inline-block',
'verticalAlign': 'top',
'width': '50%',
'padding': '5px'}),
html.Div([html.H3('Pick your dates'), dcc.DatePickerRange(
id='date_picker_range',
max_date_allowed=datetime.today(),
start_date=datetime(2020, 4, 30),
end_date=datetime.today(),
style={'display': 'inline-block'}
)], # DatePickerRange
style={'display': 'inline-block', 'padding': '5px'}),
html.Div([html.Button(
id='submit-button',
n_clicks=0,
children='Submit',
style={'fontSize': 18, 'height': '41px'})],
style={'display': 'inline-flex', 'padding': '0px'}), # padding? inlinement? display?
# Tabs selection
# tab 1 calendar and dropdown list of tickers / daily percentage change
# tab 2 / volatility / Bollinger Bands
# tab 3 / Relative strength Index
html.Div([html.H3('Choose your tab!'),
dcc.Tabs(id='finance-tabs', value='common-analysis', children=[
dcc.Tab(label='Common Analysis',
value="common-analysis",
style=tab_style,
selected_style=tab_selected_style), # tab 1
dcc.Tab(label='Bollinger Bands',
value='bollinger',
style=tab_style,
selected_style=tab_selected_style), # tab 2
dcc.Tab(label='Relative Strength Index',
value='rsi',
style=tab_style,
selected_style=tab_selected_style) # tab 3
], style=tab_style),
html.Div(id='finance-tabs-output')])],
style={'margin-right': '0px'})
@app.callback(Output('finance-tabs-output', 'children'),
[Input('finance-tabs', 'value'),
Input('submit-button', 'n_clicks')],
[State('stock-pick', 'value'),
State('date_picker_range', 'start_date'),
State('date_picker_range', 'end_date')])
def graph_content(tab, n_clicks, ticks, start_date, end_date):
if tab == 'common-analysis':
# reading from functions, should return objects
fig_1, fig_2, candle_stick = update_graph(n_clicks, ticks, start_date, end_date)
return html.Div([html.H1('Dynamic chart', style={'color': 'black', 'textAlign': 'center'}),
dcc.Graph(figure=fig_1,
# style=
),
dcc.Graph(figure=fig_2,
# style=
),
dcc.Graph(figure=go.Figure(data=[go.Candlestick(x=candle_stick.index,
open=candle_stick['Open'],
high=candle_stick['High'],
low=candle_stick['Low'],
close=candle_stick['Adj Close'])],
layout={
'title': 'Candle Stick Diagram',
'height': 600,
'font': {
'color': colors['text'],
'size': 12
},
'legend': {'x': 1.04, 'y': 1.04},
'xaxis': {
'title': 'Date',
'side': 'right',
'showspikes': True,
'spikedash': 'dot',
'spikemode': 'across',
'spikesnap': 'cursor',
},
'yaxis': {
'title': 'Price',
'overlaying': 'y',
'side': 'left',
'showspikes': True,
'spikedash': 'dot',
'spikemode': 'across',
'spikesnap': 'cursor',
},
'plot_bgcolor': colors['background'],
'paper_bgcolor': colors['background']
}),
)],
)
elif tab == 'bollinger':
fig_1, fig_2 = moving_average(n_clicks, ticks, start_date, end_date)
return html.Div([html.H3('Moving average chart', style={'color': 'black', 'textAlign': 'center'}),
dcc.Graph(figure=fig_1),
dcc.Graph(figure=fig_2)])
elif tab == 'rsi':
# final graph for RSI
rsi_graph = rsi(n_clicks, ticks, start_date, end_date)
return html.Div([html.H3('Relative Strength Index'),
dcc.Graph(figure=rsi_graph)])
if __name__ == '__main__':
app.run_server(debug=True, port='8999')