gauges
This commit is contained in:
parent
6e2677e041
commit
a7b1403487
50
finance.py
50
finance.py
@ -5,7 +5,8 @@ import dash_table
|
||||
import plotly.express as px
|
||||
import yfinance as yf
|
||||
from dash.dependencies import Input, Output
|
||||
|
||||
import plotly.graph_objects as go
|
||||
import pandas as pd
|
||||
# Load data
|
||||
stock_list = ['MMM', 'ABT', 'ABBV', 'ABMD', 'ACN', 'ATVI', 'ADBE', 'AMD', 'AAP', 'AES', 'AFL', 'A', 'APD', 'AKAM',
|
||||
'ALK', 'ALB', 'ARE', 'ALXN', 'ALGN', 'ALLE', 'LNT', 'ALL', 'GOOGL', 'GOOG', 'MO', 'AMZN', 'AMCR', 'AEE',
|
||||
@ -51,11 +52,29 @@ selected_stocks_in_graph = [stock_list[0]]
|
||||
selected_stocks_in_graph_df = closePrices[selected_stocks_in_graph]
|
||||
selected_stock_in_table = stock_list[0]
|
||||
selected_stock_in_table_df = fullTableDf.xs(selected_stock_in_table, axis=1, level=1)
|
||||
from_time = None
|
||||
to_time = None
|
||||
# Initialize the app
|
||||
app = dash.Dash(__name__)
|
||||
app.config.suppress_callback_exceptions = True
|
||||
|
||||
|
||||
def make_gauge(title, min_v, value, max_v):
|
||||
gauge_size = 180
|
||||
fig = go.Figure(go.Indicator(
|
||||
mode="gauge+number",
|
||||
value=value,
|
||||
domain={'x': [0, 1], 'y': [0, 1]},
|
||||
title={'text': title}))
|
||||
fig.layout.height = gauge_size
|
||||
fig.layout.width = gauge_size
|
||||
fig.layout.margin = dict(l=2, r=2, t=10, b=2)
|
||||
fig.layout.paper_bgcolor = "#1E1E1E"
|
||||
fig.layout.font.color = "white"
|
||||
fig.layout.font.family = "Arial"
|
||||
return fig
|
||||
|
||||
|
||||
def get_options(list_stocks):
|
||||
dict_list = []
|
||||
for i in list_stocks:
|
||||
@ -76,7 +95,8 @@ app.layout = html.Div(
|
||||
children=[
|
||||
dcc.Dropdown(id='stockselector',
|
||||
options=get_options(stock_list),
|
||||
multi=True, value=selected_stocks_in_graph,
|
||||
multi=True,
|
||||
value=selected_stocks_in_graph,
|
||||
style={'backgroundColor': '#1E1E1E'},
|
||||
className='stockselector'
|
||||
)
|
||||
@ -93,10 +113,11 @@ app.layout = html.Div(
|
||||
className='stockselector'
|
||||
)
|
||||
],
|
||||
style={'color': '#1E1E1E'})
|
||||
|
||||
]
|
||||
),
|
||||
style={'color': '#1E1E1E'}),
|
||||
html.P('Wybierz przedział czasu by policzyć średnie i wachania'),
|
||||
dcc.Graph(id='average_gauge'),
|
||||
dcc.Graph(id='volatility_gauge')
|
||||
]),
|
||||
html.Div(className='eight columns div-for-charts bg-grey',
|
||||
children=[
|
||||
dcc.Graph(id='timeseries', config={'displayModeBar': False}, animate=True),
|
||||
@ -122,6 +143,7 @@ def update_graph(selected_dropdown_value):
|
||||
selected_stocks_in_graph = selected_dropdown_value
|
||||
selected_stocks_in_graph_df = closePrices[selected_stocks_in_graph]
|
||||
figure = px.line(selected_stocks_in_graph_df, template='plotly_dark', title='Stock Prices')
|
||||
# figure.update_layout(clickmode='event+select')
|
||||
return figure
|
||||
|
||||
|
||||
@ -137,5 +159,21 @@ def update_table(selected_dropdown_value):
|
||||
return data, columns
|
||||
|
||||
|
||||
@app.callback([Output('average_gauge', 'figure'), Output('volatility_gauge', 'figure')],
|
||||
Input('timeseries', 'relayoutData'))
|
||||
def change_time_period(selectedData):
|
||||
global from_time
|
||||
global to_time
|
||||
if selectedData.get('autosize'):
|
||||
from_time = selected_stock_in_table_df.index.min()
|
||||
to_time = selected_stock_in_table_df.index.max()
|
||||
else:
|
||||
from_time = selectedData["xaxis.range[0]"]
|
||||
to_time = selectedData["xaxis.range[1]"]
|
||||
average_gauge = make_gauge('średnia', 0, 290, 400)
|
||||
volatility_gauge = make_gauge('wolatylność', 0, 133, 400)
|
||||
return average_gauge, volatility_gauge
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run_server(debug=True)
|
||||
|
Loading…
Reference in New Issue
Block a user