-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
67 lines (53 loc) · 1.67 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
# -*- coding: utf-8 -*-
# Run this app with `python app.py` and
# visit http://127.0.0.1:8050/ in your web browser.
import dash
import dash_core_components as dcc
import dash_html_components as html
import plotly.express as px
import yfinance as yf
import pandas as pd
from dash.dependencies import Input, Output
from controls import PERIODS
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
app.layout = html.Div(children=[
html.H1(children='Financial Analysis Dashboard'),
dcc.Input(
id="tick-input",
placeholder="input ticker symbol",
value='MSFT',
debounce=True,
style={'width': '300px'}
),
dcc.RadioItems(
id="period-interval",
options=[{'label': interval, 'value': interval} for interval in PERIODS],
value='5d',
labelStyle={'display': 'inline-block'}
),
dcc.Graph(
id='close-price-graph'
)
])
# Helper function
def create_df(ticker, interval):
return df
@app.callback(
Output('close-price-graph', 'figure'),
[Input('tick-input', 'value'),
Input('period-interval', 'value')]
)
def close_price_plot(ticker, interval):
tick = yf.Ticker(ticker)
df = tick.history(period=interval)
df = df.loc[:,'Close']
fig = px.line(df,
x=df.index,
y="Close",
title="<b>{} {}</b> <br> Close Price (USD)".format(tick.info['longName'], tick.info['symbol']),
labels={"Close":"Close Price (USD)"})
fig.update_xaxes(tickformat="%m-%d-%Y")
return fig
if __name__ == '__main__':
app.run_server(debug=True)