Skip to content

Instantly share code, notes, and snippets.

app = JupyterDash(__name__, external_stylesheets=[dbc.themes.LUX])
# app = JupyterDash(__name__, external_stylesheets=[dbc.themes.CYBORG]) ## switch to a dark theme!
app.layout = html.Div(id='page-content', children=firstpage, className='p-3')
@app.callback(
[
Output("revenuechart", "figure"), Output("netprofitmargchart", "figure"), Output("shareschart", "figure"),
Output("ebitdachart", "figure"), Output("debtchart", "figure"), Output("freecashchart", "figure"),
Output("pricechart", "figure"), Output("sec", "children"), Output("ind", "children"),
firstpage = [
dbc.Row([
dbc.Col([
html.H3('FINANCIAL ASSISTANT DASHBOARD', className='text-center mb-3 p-3'),
html.Hr(),
],
width={'size': 12, 'offset': 0, 'order': 0}),
]),
dbc.Row([
dbc.Col([
#### READ THE DATA
stocks = ['AMZN','NFLX', 'SBUX', 'DIS', 'MSFT', 'TSLA']
dict_income = {}
dict_balsheet = {}
dict_financials = {}
dict_q_income = {}
dict_q_balsheet = {}
dict_q_financials = {}
dict_price = {}
dict_overview = {}
fig_pricehist = px.line(dict_price['O'],
y='Close',
title='2Y Price History')
fig_pricehist.update_layout(template=THEME, margin = dict(t=50, b=30, l=25, r=25))
fig_pricehist.update_traces(line_color='royalblue', line_width=3, hovertemplate='Close @ %{x}: $%{y}')
fig_pricehist.show()
##################
fig_rev = px.bar(dict_income['AMZN']['Revenue'],
firstpage_ = [
dbc.Row([
dbc.Col([
],
width={'size': 12, 'offset': 0, 'order': 0}),
]),
dbc.Row([
dbc.Col([
],
width={'size': 4, 'offset': 0, 'order': 0}),
app = JupyterDash(__name__, external_stylesheets=[dbc.themes.FLATLY])
app.layout = dbc.Container(
[
dbc.Row(dbc.Col(html.H2('PORTFOLIO OVERVIEW', className='text-center text-primary, mb-3'))), # header row
dbc.Row([ # start of second row
dbc.Col([ # first column on second row
html.H5('Total Portfolio Value ($USD)', className='text-center'),
dcc.Graph(id='chrt-portfolio-main',
# getting the accumulated positions for our tickers
last_positions = final_filtered.groupby(['ticker']).agg({'cml_units': 'last', 'cml_cost': 'last',
'gain_loss': 'sum', 'cashflow': 'sum'}).reset_index()
curr_prices = []
# not the most elegant way of getting prices but will do for now
for tick in last_positions['ticker']:
stonk = yf.Ticker(tick)
price = stonk.info['regularMarketPrice']
curr_prices.append(price)
print(f'Done for {tick}')
indicators_ptf = go.Figure()
indicators_ptf.layout.template = CHART_THEME
indicators_ptf.add_trace(go.Indicator(
mode = "number+delta",
value = kpi_portfolio7d_pct,
number = {'suffix': " %"},
title = {"text": "<br><span style='font-size:0.7em;color:gray'>7 Days</span>"},
delta = {'position': "bottom", 'reference': kpi_sp500_7d_pct, 'relative': False},
domain = {'row': 0, 'column': 0}))
df = plotlydf_portfval[['date', 'ptf_growth', 'sp500_growth']].copy().round(3)
df['month'] = df.date.dt.month_name() # date column should be formatted as datetime
df['weekday'] = df.date.dt.day_name() # could be interesting to analyze weekday returns later
df['year'] = df.date.dt.year
df['weeknumber'] = df.date.dt.week # could be interesting to try instead of timeperiod
df['timeperiod'] = df.year.astype(str) + ' - ' + df.date.dt.month.astype(str).str.zfill(2)
# getting the percentage change for each period. the first period will be NaN
sp = df.reset_index().groupby('timeperiod').last()['sp500_growth'].pct_change()*100
ptf = df.reset_index().groupby('timeperiod').last()['ptf_growth'].pct_change()*100
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Output, Input
import plotly.express as px
import dash_bootstrap_components as dbc
import plotly.graph_objects as go
import dash_table
from jupyter_dash import JupyterDash