market cap

This commit is contained in:
Alagris 2021-06-22 12:30:42 +02:00
parent f9ddbd77d2
commit f74c686be0

View File

@ -10,6 +10,7 @@ import numpy as np
import pandas as pd
import datetime
import time
from pandas_datareader import data
# Load data
stock_list = ['MMM', 'ABT', 'ABBV', 'ABMD', 'ACN', 'ATVI', 'ADBE', 'AMD', 'AAP', 'AES', 'AFL', 'A', 'APD', 'AKAM',
@ -50,6 +51,7 @@ stock_list = ['MMM', 'ABT', 'ABBV', 'ABMD', 'ACN', 'ATVI', 'ADBE', 'AMD', 'AAP',
stock_list = ['WHR', 'WMB', 'WLTW', 'WYNN', 'XEL', 'XLNX', 'XYL', 'YUM', 'ZBRA', 'ZBH', 'ZION', 'ZTS']
tickerData = yf.Tickers(stock_list)
market_cap = data.get_quote_yahoo(stock_list)['marketCap']
fullTableDf = tickerData.history(period='1d', start='2019-1-1', end='2020-1-25')
closePrices = fullTableDf['Close']
selected_stocks_in_graph = [stock_list[0]]
@ -63,6 +65,10 @@ app = dash.Dash(__name__)
app.config.suppress_callback_exceptions = True
stock_info_in_time_period_df = pd.DataFrame(columns=stock_list, index=["średnia", "cena", "dywidenda", "wolatylność"])
mean_prices_and_dividends = fullTableDf[['Close', 'Dividends']].mean(axis=0).unstack(level=0)
mean_prices_and_dividends_and_market_cap = pd.concat([mean_prices_and_dividends, market_cap], axis=1)
mean_prices_and_dividends_figure = px.scatter(mean_prices_and_dividends_and_market_cap.reset_index(), size="marketCap", x='Dividends', y='Close', text="index", template='plotly_dark')
def make_gauge(title, min_v, value, max_v):
gauge_size = 180
@ -145,7 +151,7 @@ app.layout = html.Div(
dcc.Graph(id='timeseries', config={'displayModeBar': False}, animate=True),
]),
dcc.Tab(id='tab-2', label='Chart 2', value='tab-2',children=[
dcc.Graph(id='price-dividends', config={'displayModeBar': False}, animate=True),
dcc.Graph(id='price-dividends', figure=mean_prices_and_dividends_figure, config={'displayModeBar': False}, animate=True),
]),
]),
dash_table.DataTable(
@ -251,12 +257,7 @@ def change_time_period(selectedData):
volatility_gauge = make_gauge('wolatylność', 0, std['Close'], 400)
return average_gauge, volatility_gauge, stock_info_in_time_period_df.T.to_dict('records')
@app.callback(Output('price-dividends', 'figure'),
[Input('table_selector', 'value')])
def update_point_chart(selected_dropdown_value):
selected_stock_in_table_df = fullTableDf.xs(selected_dropdown_value, axis=1, level=1)
figure = px.scatter(selected_stock_in_table_df, x='Dividends', y='Close', template='plotly_dark')
return figure
if __name__ == '__main__':
app.run_server(debug=True)