-
Notifications
You must be signed in to change notification settings - Fork 0
/
bband.py
70 lines (53 loc) · 2.3 KB
/
bband.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
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
import plotly.graph_objs as go
from datetime import date
#Uncomment two lines below if: ImportError: cannot import name 'is_list_like
#import pandas as pd
#pd.core.common.is_list_like = pd.api.types.is_list_like
from pandas_datareader import data, wb
tick = 'TSLA'
start = '2017-01-01'
end = date.today()
tick = tick.upper()
df = data.DataReader(tick, 'iex', start, end)
app = dash.Dash()
app.title=f'BBands: {tick}'
app.layout = html.Div([
dcc.Graph(id='bb_graph',className='big_graph'),
html.Div([
html.H4('Bollinger Bands MA'),
dcc.Slider(id='slider_bband_ma',className='sliders',
min=5,
max=60,
step=1,
marks={i: f'{i}' for i in range(5,65,5)},
value=20),
html.H4('Bollinger Bands STD'),
dcc.Slider(id='slider_bband_std',className='sliders',
min=0.2,
max=10,
step=0.2,
marks={i: f'{i}' for i in range(0,10,1)},
value=2)
],id='slider_ma_div',className='slid_divs'),
],id='moad')
app.css.append_css({'external_url': 'http://memakewebsite.com/css/newstyle.css'})
# Main Graphs
@app.callback(Output('bb_graph','figure'),
[Input('slider_bband_ma','value'),
Input('slider_bband_std','value')])
def update_bands(bbma,bbstd):
df['BBand MA'] = df['close'].rolling(window=bbma).mean()
df['Upper'] = df['BBand MA'] + bbstd * df['close'].rolling(window=bbma).std()
df['Lower'] = df['BBand MA'] - bbstd * df['close'].rolling(window=bbma).std()
data = [go.Scatter(x=df.index,y=df['close'],name=tick),
go.Scatter(x=df.index,y=df['BBand MA'],name=f'{bbma} MA(BB)'),
go.Scatter(x=df.index,y=df['Upper'],name='Upper BBand'),
go.Scatter(x=df.index,y=df['Lower'],name='Lower BBand')]
layout = go.Layout(title=f'{tick} BOLLINGER BANDS')
return {'data':data,'layout':layout}
if __name__ == '__main__':
app.run_server()