q.plot.tree_plot shows portfolio performance in two synchronized views. Accumulated is the default: it shows held-period performance for every asset that has appeared in the portfolio. Point in time uses the same accumulated held-period returns through the selected date, but includes only assets held at that date and sizes them by current absolute weight. The date slider controls both views and starts at the terminal date.
Tile color is centered at zero: blue is positive and red is negative. The input is a wide DataFrame with timestamps on the index and assets in the columns. A finite return means that the asset was held during that period; NaN means that no return accrues for the asset.
In accumulated mode, an asset remains in every frame after it first appears. When it exits, its cumulative return is frozen at the terminal value until a later holding period adds another return.
Build a changing portfolio
This deterministic example has five assets. AAPL and MSFT are present from the start, NVDA enters later, and JPM leaves before the final observation.
Without weights, every asset held on or before the selected date gets equal area. Return magnitude controls color, not size, so the chart does not imply portfolio weights that were never supplied. The initial view is the terminal date and includes all historical holdings, including JPM after exit.
fig = q.plot.tree_plot(asset_returns)fig.show()
Size tiles by historical portfolio exposure
Pass a matching weight DataFrame when holdings are available. A finite return and nonzero finite weight mark a held period. Tile area is the cumulative average absolute weight through the selected date, so exited assets remain visible in proportion to their historical exposure. Color remains the asset’s compounded held-period return. Negative weights are treated by absolute exposure, and a static Series indexed by asset can be used when weights do not vary through time.
q.bt.report automatically reads conventional Asset Returns and Asset Weights charts when a LEAN algorithm records them. The bundled SMA demo does this for every invested symbol, so its report includes accumulated performance without additional arguments:
For other backtest engines, or older LEAN artifacts without those charts, pass the same explicit asset_returns and optional asset_weights inputs. The resulting BacktestReport exposes the figure as report.performance_treemap.