Panel collapse

PortfolioOptimisers.calc_net_returns — Function
calc_net_returns(res::OptimisationResult, X::MatNum, fees = nothing, wd = nothing, obs = nothing)
calc_net_returns(res::OptimisationResult, pr::Pr_RR, fees = nothing, wd = nothing, obs = nothing)

Computes the net returns of the weights of an OptimisationResult.

The weights, the returns and the fee meet on the investable universe of res, through result_investable_view. res.w is on the universe of the caller, and res.fees is on the universe that the fit solved. So the function views the weights and a matrix X of the caller at the Investable Mask of the result. A fees of the caller goes through investable_fees_view, as a fee does at the fit. A fees of the caller has priority over res.fees.

The method that takes pr gives the whole of pr to the view, and reads its X after the view.

The argument wd is the Weight Drift of the window. With nothing, the window is read at the constant weights res.w. A SelfFinancingDrift reads it as the wealth ratio of the drifted holdings, and obs names the observations in the message of a wealth that is not positive.

Algorithm

  1. View the weights, the returns data and the fee on the investable universe of res with result_investable_view.
  2. Return calc_net_returns(w, X, fees, wd, obs) of the viewed values.

Related

source
PortfolioOptimisers.AbstractPanelCollapseAlgorithm — Type
abstract type AbstractPanelCollapseAlgorithm <: AbstractAlgorithm

Abstract supertype for the rules that state how the panel collapse of a meta-optimiser weighs a member at an observation where the member is outside the universe.

A sub-portfolio of a meta-optimiser holds each member with one weight for the whole history, and a time-varying Asset Panel lists and delists the members. At an observation where a member is inactive, the panel stores a finite value with no meaning. So the collapse reads only the members that are active there, and the rule states what the weight of an inactive member becomes. The rule is the pcol field of NestedClustered and of Stacking, and collapse_asset_panel states the mathematics. A static panel has no inactive member. A static field with no placeholder therefore takes the collapse of all the members under every rule, but a static field with a placeholder reads the members that hold data, and the rules differ there.

Interfaces

To add a rule, subtype AbstractPanelCollapseAlgorithm and implement the method below. The collapse sets the value of each inactive member to zero before it contracts, so a rule states only the divisor of each collapsed value.

active_weight_divisor

  • active_weight_divisor(alg::MyRule, m::AbstractMatrix{Bool}, W::MatNum) -> Option{<:MatNum}: The divisor of each sub-portfolio at each observation, or nothing for no division.

Arguments

  • alg: The concrete subtype instance.
  • m: The mask of the cells that the collapse reads, observations × members: a member is read where it is active and its cell holds data. A member is an asset, and a pair of assets for a tensor field whose labels are the asset names.
  • W: The normalised inner weights, members × sub-portfolios, or kron(W, W) for the pairs.

Returns

  • The divisors, observations × sub-portfolios, or nothing. A divisor must not be zero.

Related

source
PortfolioOptimisers.active_weight_divisor — Function
active_weight_divisor(alg::AbstractPanelCollapseAlgorithm, m::Nothing, W::MatNum) -> nothing
active_weight_divisor(alg::InactiveAsCash, m::AbstractMatrix{Bool}, W::MatNum) -> nothing
active_weight_divisor(alg::RenormaliseActive, m::AbstractMatrix{Bool}, W::MatNum) -> Matrix

Returns the divisor of each collapsed value of a time-varying Asset Panel under a rule of the panel collapse, or nothing for no division.

RenormaliseActive divides by the weight of the active members. The divisor is one where a sub-portfolio has no active member, because its active values are all zero, and where it has no inactive member with weight, because its weights already sum to one. So the second case keeps the collapse of all the members bit for bit, where a division by a sum that rounds to one would change the last bit. InactiveAsCash divides by nothing. A mask of nothing marks no member unread, and no rule divides. A static field with a placeholder passes its data mask as m, so the rule divides there as on a time-varying panel.

Mathematical definition

\[\begin{align} d_{tk} &= \begin{cases} \sum_{i=1}^{N} \tilde{W}_{ik} m_{ti} & \sum_{i=1}^{N} \tilde{W}_{ik} m_{ti} > 0 \text{ and } \sum_{i=1}^{N} \tilde{W}_{ik} (1 - m_{ti}) > 0\,,\\ 1 & \text{otherwise}\,. \end{cases} \end{align}\]

Where:

  • $d_{tk}$: Divisor of sub-portfolio $k$ at observation $t$.
  • $m_{ti}$: Active mask of the Asset Panel, $1$ when asset $i$ is in the universe at observation $t$ and $0$ otherwise.
  • $\tilde{\mathbf{W}}$: Normalised inner weight matrix, $\tilde{W}_{ik} = |W_{ik}| / \sum_{j=1}^{N} |W_{jk}|$. A column of zeros stays a column of zeros.
  • $N$: Number of assets.

Arguments

  • alg: The rule of the panel collapse.
  • m: The active mask of the panel, observations × assets, or nothing for a static panel.
  • W: The normalised inner weights, assets × sub-portfolios.

Returns

  • The divisors, observations × sub-portfolios, or nothing.

Related

source
PortfolioOptimisers.RenormaliseActive — Type
struct RenormaliseActive <: AbstractPanelCollapseAlgorithm

Collapses an Asset Panel over the members that are active at each observation, and divides by their weight. It is the default rule of the panel collapse of NestedClustered and of Stacking.

The collapse already divides out the gross exposure of a sub-portfolio: its leverage, its short positions and the cash that a budget leaves. The weight of an inactive member is one more part of the portfolio outside the universe, and this rule divides it out in the same way. So each collapsed value stays a convex combination of the values of the active members. A sub-portfolio whose weighted members are all active divides by one, so its collapse does not change.

Related

source
PortfolioOptimisers.InactiveAsCash — Type
struct InactiveAsCash <: AbstractPanelCollapseAlgorithm

Collapses an Asset Panel over the members that are active at each observation, and reads the weight of an inactive member as cash with a zero feature.

The outer returns of a meta-optimiser are read off the returns of the prior, which hold a zero at an inactive cell of an admitted asset. So the weight of that asset sits in cash. For an additive feature, such as a loading, this rule gives the feature of the outer returns column. For a characteristic, such as a ratio or the fraction of an industry, a zero is not a value of cash, and the collapsed value moves toward zero as the active weight falls.

Related

source