Skip to content

Instantly share code, notes, and snippets.

@fnneves
Created May 11, 2021 16:33
Show Gist options
  • Save fnneves/f2249e52ad04d8533da4b3ea783b8e77 to your computer and use it in GitHub Desktop.
Save fnneves/f2249e52ad04d8533da4b3ea783b8e77 to your computer and use it in GitHub Desktop.
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
initial_date = '2020-05-30' # do not use anything earlier than your first trade
plotlydf_portfval = portf_allvalues[portf_allvalues.index > initial_date]
plotlydf_portfval = plotlydf_portfval[['portf_value', 'sp500_mktvalue', 'ptf_value_pctch',
'sp500_pctch', 'ptf_value_diff', 'sp500_diff']].reset_index().round(2)
# calculating cumulative growth since initial date
plotlydf_portfval['ptf_growth'] = plotlydf_portfval.portf_value/plotlydf_portfval['portf_value'].iloc[0]
plotlydf_portfval['sp500_growth'] = plotlydf_portfval.sp500_mktvalue/plotlydf_portfval['sp500_mktvalue'].iloc[0]
plotlydf_portfval.rename(columns={'index': 'date'}, inplace=True) # needed for later
# Plotly part
CHART_THEME = 'plotly_white' # others examples: seaborn, ggplot2, plotly_dark
chart_ptfvalue = go.Figure() # generating a figure that will be updated in the following lines
chart_ptfvalue.add_trace(go.Scatter(x=plotlydf_portfval.date, y=plotlydf_portfval.portf_value,
mode='lines', # you can also use "lines+markers", or just "markers"
name='Global Value'))
chart_ptfvalue.layout.template = CHART_THEME
chart_ptfvalue.layout.height=500
chart_ptfvalue.update_layout(margin = dict(t=50, b=50, l=25, r=25)) # this will help you optimize the chart space
chart_ptfvalue.update_layout(
# title='Global Portfolio Value (USD $)',
xaxis_tickfont_size=12,
yaxis=dict(
title='Value: $ USD',
titlefont_size=14,
tickfont_size=12,
))
# chart_ptfvalue.update_xaxes(rangeslider_visible=False)
# chart_ptfvalue.update_layout(showlegend=False)
chart_ptfvalue.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment