Advertisement
angelorcc

Untitled

Mar 8th, 2020
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.50 KB | None | 0 0
  1. import pandas_datareader.data as web
  2. import datetime
  3. import dash
  4. import dash_core_components as dcc
  5. import dash_html_components as html
  6. from dash.dependencies import Input, Output
  7. import pandas as pd
  8. import datetime
  9.  
  10.  
  11.  
  12.  
  13. TAB_STYLE = {
  14.     'width': 'inherit',
  15.     'border': 'none',
  16.     'boxShadow': 'inset 0px -1px 0px 0px lightgrey',
  17.     'background': 'white',
  18.     'paddingTop': 0,
  19.     'paddingBottom': 0,
  20.     'height': '42px',
  21. }
  22.  
  23. SELECTED_STYLE = {
  24.     'width': 'inherit',
  25.     'boxShadow': 'none',
  26.     'borderLeft': 'none',
  27.     'borderRight': 'none',
  28.     'borderTop': 'none',
  29.     'borderBottom': '2px #004A96 solid',
  30.     'background': 'white',
  31.     'paddingTop': 0,
  32.     'paddingBottom': 0,
  33.     'height': '42px',
  34. }
  35.  
  36.  
  37. colors={
  38.     'background':'D3B592',
  39.     'text':'#7FDBFF'
  40.     }
  41.  
  42. external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
  43.  
  44.  
  45.  
  46.  
  47. app = dash.Dash()
  48.  
  49.  
  50.  
  51.  
  52.  
  53. app.layout = html.Div(style={'backgroundColor': colors['background']},children=[
  54.     html.H1(children='STOCK DASHBOARD',
  55.             style={'textAlign': 'left', 'colour': colors['text']}),
  56.    
  57.     dcc.Interval(id='refresh', interval=200,),
  58.     dcc.Input(id='input', value='', type='text', placeholder="stock code"),
  59.    
  60.  
  61.     dcc.Tabs(id="tabs", value='tab-1', children=[
  62.         dcc.Tab(label='SNAPSHOT', value='tab-2', style=TAB_STYLE,selected_style=SELECTED_STYLE,),
  63.        
  64.                  
  65.         dcc.Tab(label='KEY STATS', value='tab-3',style=TAB_STYLE,selected_style=SELECTED_STYLE,),
  66.        
  67.         dcc.Tab(label='FINANCIALS', value='tab-4',style=TAB_STYLE,selected_style=SELECTED_STYLE,children=[
  68.             dcc.Dropdown(id='subtab3', options=[{'label': 'Balance Sheet', 'value': 'A'},
  69.                                                {'label': 'Income Statement', 'value': 'B'},
  70.                                                {'label': 'Cash Flow', 'value': 'C'}],
  71.                          )]),
  72.        
  73.         dcc.Tab(label='PERFORMANCE', value='tab-5',style=TAB_STYLE,selected_style=SELECTED_STYLE,),
  74.         dcc.Tab(label='VALUE ANALYSIS', value='tab-6',style=TAB_STYLE,selected_style=SELECTED_STYLE,),
  75.         dcc.Tab(label='FUNDUMANTAL ANALYSIS', value='tab-7',style=TAB_STYLE,selected_style=SELECTED_STYLE,),
  76.         dcc.Tab(label='SENTIMENT ANALYSIS', value='tab-8',style=TAB_STYLE,selected_style=SELECTED_STYLE,),
  77.         dcc.Tab(label='MOMENTUM ANALYSIS', value='tab-9',style=TAB_STYLE,selected_style=SELECTED_STYLE,),
  78.         dcc.Tab(label='SCORE', value='tab-10', style=TAB_STYLE,selected_style=SELECTED_STYLE,),
  79.         dcc.Tab(label='DATA', value='tab-11', style=TAB_STYLE,selected_style=SELECTED_STYLE,),
  80.  
  81.        
  82.        
  83.        
  84.     ]),
  85.         html.Div(id='tabs-content')])
  86.  
  87.  
  88.    
  89.  
  90.  
  91.  
  92.  
  93.  
  94. @app.callback(
  95.     Output('tabs-content','children'),
  96.     [Input('input','value')]
  97. )
  98.    
  99.    
  100. def update_value(input_data):
  101.    
  102.    
  103.     start = datetime.datetime(2015, 1, 1)
  104.     end = datetime.datetime.now()
  105.     df = web.DataReader(input_data, 'yahoo', start, end)
  106.     df.reset_index(inplace=True)
  107.     df.set_index("Date", inplace=True)
  108.  
  109.  
  110.    
  111.                              
  112.    
  113.  
  114.     return html.Div([html.H3('PRICE CHART'),
  115.                      dcc.Graph(id='example-graph',   figure={'data': [{'x': df.index, 'y': df.Close, 'type': 'line', 'name': input_data},],'layout': {'title': input_data}})])
  116.                          
  117.                      
  118.  
  119.  
  120.  
  121.  
  122.            
  123.    
  124.  
  125.                    
  126.  
  127. if __name__ == '__main__':
  128.     app.run_server(debug=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement