trackery
This commit is contained in:
parent
a18ae37900
commit
a6fd2339ff
46
finance.py
46
finance.py
@ -65,7 +65,8 @@ to_time = None
|
|||||||
# Initialize the app
|
# Initialize the app
|
||||||
app = dash.Dash(__name__)
|
app = dash.Dash(__name__)
|
||||||
app.config.suppress_callback_exceptions = True
|
app.config.suppress_callback_exceptions = True
|
||||||
stock_info_in_time_period_df = pd.DataFrame(columns=stock_list, index=["średnia", "cena", "dywidenda", "wolatylność"])
|
stock_info_in_time_period_df = pd.DataFrame(index=stock_list, columns=["tracker", "średnia", "cena"])
|
||||||
|
stock_info_in_time_period_df['tracker'] = stock_info_in_time_period_df.index
|
||||||
|
|
||||||
mean_prices_and_dividends = fullTableDf[['Close', 'Dividends']].mean(axis=0).unstack(level=0)
|
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_and_market_cap = pd.concat([mean_prices_and_dividends, market_cap], axis=1)
|
||||||
@ -140,11 +141,30 @@ app.layout = html.Div(
|
|||||||
]),
|
]),
|
||||||
dash_table.DataTable(
|
dash_table.DataTable(
|
||||||
id='info_in_time_period',
|
id='info_in_time_period',
|
||||||
|
columns=[{"name": i, "id": i} for i in stock_info_in_time_period_df.columns],
|
||||||
style_header={'backgroundColor': 'rgb(30, 30, 30)'},
|
style_header={'backgroundColor': 'rgb(30, 30, 30)'},
|
||||||
style_cell={
|
style_cell={
|
||||||
'backgroundColor': 'rgb(50, 50, 50)',
|
'backgroundColor': 'rgb(50, 50, 50)',
|
||||||
'color': 'white'
|
'color': 'white'
|
||||||
},
|
},
|
||||||
|
style_data_conditional=[
|
||||||
|
{
|
||||||
|
'if': {
|
||||||
|
'filter_query': '{cena} > {średnia}',
|
||||||
|
'column_id': 'tracker'
|
||||||
|
},
|
||||||
|
'backgroundColor': 'green',
|
||||||
|
'color': 'black'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'if': {
|
||||||
|
'filter_query': '{cena} <= {średnia}',
|
||||||
|
'column_id': 'tracker'
|
||||||
|
},
|
||||||
|
'backgroundColor': 'red',
|
||||||
|
'color': 'black'
|
||||||
|
},
|
||||||
|
]
|
||||||
)
|
)
|
||||||
]),
|
]),
|
||||||
html.Div(className='eight columns div-for-charts bg-grey',
|
html.Div(className='eight columns div-for-charts bg-grey',
|
||||||
@ -175,7 +195,6 @@ app.layout = html.Div(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Callback for scraping company description
|
# Callback for scraping company description
|
||||||
@app.callback(Output('company-desritpion', 'children'), [Input('table_selector', 'value')])
|
@app.callback(Output('company-desritpion', 'children'), [Input('table_selector', 'value')])
|
||||||
def update_graph(selected_dropdown_value):
|
def update_graph(selected_dropdown_value):
|
||||||
@ -184,15 +203,14 @@ def update_graph(selected_dropdown_value):
|
|||||||
soup = BeautifulSoup(page.content, 'html.parser')
|
soup = BeautifulSoup(page.content, 'html.parser')
|
||||||
comp_name = soup.find(id="Main").h3.text
|
comp_name = soup.find(id="Main").h3.text
|
||||||
description = soup.find_all('section', class_='quote-sub-section')[0].p.text
|
description = soup.find_all('section', class_='quote-sub-section')[0].p.text
|
||||||
|
|
||||||
return dcc.Markdown('''
|
return dcc.Markdown('''
|
||||||
|
|
||||||
# [{comp_name}]({url})
|
# [{comp_name}]({url})
|
||||||
|
|
||||||
{description}
|
{description}
|
||||||
'''.format(comp_name=comp_name,description=description,url=url))
|
'''.format(comp_name=comp_name, description=description, url=url))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Callback for downloading file
|
# Callback for downloading file
|
||||||
@app.callback(
|
@app.callback(
|
||||||
@ -253,21 +271,17 @@ def common_table_callback(callback_data_time_period, callback_data_table_selecto
|
|||||||
from_time = round_to_nearest_weekday(from_time)
|
from_time = round_to_nearest_weekday(from_time)
|
||||||
to_time = round_to_nearest_weekday(to_time)
|
to_time = round_to_nearest_weekday(to_time)
|
||||||
if change_time_period or selected_stock_in_table_changed:
|
if change_time_period or selected_stock_in_table_changed:
|
||||||
full_table_in_time_period = fullTableDf.loc[from_time:to_time]
|
stock_info_in_time_period_df['średnia'] = fullTableDf['Close'].loc[from_time:to_time].mean(axis=0)
|
||||||
mean = full_table_in_time_period.mean(axis=0)
|
stock_info_in_time_period_df['cena'] = fullTableDf['Close'].loc[fullTableDf.index.max()]
|
||||||
mean = mean.xs('Close', level=0)
|
time_period = selected_stock_in_table_df['Close'].loc[from_time:to_time]
|
||||||
std = full_table_in_time_period.std(axis=0)
|
|
||||||
std = std.xs('Close', level=0)
|
|
||||||
time_period = selected_stock_in_table_df.loc[from_time:to_time]
|
|
||||||
mean = time_period.mean(axis=0)
|
mean = time_period.mean(axis=0)
|
||||||
std = time_period.std(axis=0)
|
std = time_period.std(axis=0)
|
||||||
# TODO: oblicz stock_info_in_time_period_df tutuaj !!!
|
average_gauge = make_gauge('średnia', 0, mean, 400)
|
||||||
average_gauge = make_gauge('średnia', 0, mean['Close'], 400)
|
volatility_gauge = make_gauge('wolatylność', 0, std, 400)
|
||||||
volatility_gauge = make_gauge('wolatylność', 0, std['Close'], 400)
|
|
||||||
stock_price_table_data = selected_stock_in_table_df.to_dict('records')
|
stock_price_table_data = selected_stock_in_table_df.to_dict('records')
|
||||||
stock_price_table_columns = [{"name": i, "id": i} for i in selected_stock_in_table_df.columns]
|
stock_price_table_columns = [{"name": i, "id": i} for i in selected_stock_in_table_df.columns]
|
||||||
return stock_price_table_data, stock_price_table_columns, average_gauge, volatility_gauge, stock_info_in_time_period_df.T.to_dict(
|
stock_info_in_time_period_data = stock_info_in_time_period_df.to_dict('records')
|
||||||
'records')
|
return stock_price_table_data, stock_price_table_columns, average_gauge, volatility_gauge, stock_info_in_time_period_data
|
||||||
|
|
||||||
|
|
||||||
average_gauge = make_gauge('średnia', 0, 0, 400)
|
average_gauge = make_gauge('średnia', 0, 0, 400)
|
||||||
|
Loading…
Reference in New Issue
Block a user