How to plot historical portfolio weights?

Dear All,

I have a time series containing different weights in the range of [0, 1] for different assets that sum up to [0, 1] .

I was wondering if anyone has an idea how I could make a plot that shows the history and allows to see how the allocation is variating through time.

An option I have seen online is a Pie chart but it can only show the actual repartition (i.e. the last index of the time series).

Many thanks in advance for your ideas !

Hi,

It depends a lot on what you want to highlight in my opinion.

One way to โ€œunrollโ€ a pie chart over the time dimension is to use a stacked bar chart (which is the default in plotly express). This approach would highlight the proportions over time. Here is a link to the documentation.

1 Like

Many thanks ! I will try that right now !

Hi again,

I am coming back to you with the following simple example:

data = [
    ['01.01.20', 1, 0, 0],
    ['01.02.20', 1, 0, 0],
    ['01.03.20', 0, 0, 0],
    ['01.04.20', 0, 0.1, 0],
    ['01.05.20', 0, 0.1, 0.3],
    ['01.06.20', 0, 0.1, 0.5],
    ['01.07.20', 0, 0.5, 0.5],
    ['01.08.20', 0.5, 0.5, 0],
    ['01.09.20', 0.5, 0.5, 0],
    ['01.10.20', 1, 0, 0],
    ['01.11.20', 0, 1, 0],
    ['01.12.20', 0.3, 0.4, 0.3],
]

df = pd.DataFrame(data, columns=["date","BTC", "ETH", "LTC"])
df['date'] =  pd.to_datetime(df['date'],format='%d.%m.%y')
df.set_index('date',drop=True,inplace=True)

import plotly.express as px

fig = px.bar(df, x=df.index, y=df.BTC)

fig.update_layout(title = 'Weights variations',
                  height = 800,
                  plot_bgcolor="#FFFFFF",
                  hovermode="x",
                  hoverdistance=100,
                  spikedistance=1000,
                  xaxis_rangeslider_visible=False,
                  dragmode='pan',
                  margin=dict(b=20, t=50, l=0, r=40),
                  yaxis1 = {'range': [0, 1]},
                  )
fig.show()

Any idea on how to add the other coins ? That should appear in the remaining blank spot for each bar (if any weights).

With 20 plus assets and a long time series, that will end up building a nice multi-colors โ€œheatmatโ€ !

Thanks again so much for your help !

Fount it (stupid me):

fig = px.bar(df, x=df.index, y=['BTC','ETH','LTC'])

Yes, and you donโ€™t need to specify x if it is the index eitherโ€ฆ

If youโ€™ll have 20 assets, then just make sure to inform the users to click/double-click on the legend to isolate the plots. It makes it easier to compare 2 assets over time.

Best of luck building your portfolio! :smiley: