Variance Skew Kurtosis: private API
PortfolioOptimisers.resolve_deferred_quantities — Method
resolve_deferred_quantities(x, pr::AbstractPriorResult, slv = nothing)Resolve the children that deferred_slots declared and the slots that calibration_slots declared, and return x itself when none of them changed.
This is the derived half of the resolution rule. A container declares its children once and both entry points follow: factory reaches them through @fprop, and the JuMP builders reach them through this method. Neither needs a forwarding method per container.
A type that resolves a quantity of its own overrides this with its own method, which is more specific. So the derivation carries container recursion alone, and never guesses how a matrix, a tensor or the centre a moment was taken about comes out of a fit.
Both channels end in one rebuild: a measure that carries both kinds of slot must not be rebuilt twice. resolve_calibration_slots states the calibration half and returns its resolved slots rather than a rebuilt object, and the two answers merge here. The deferred half merges last, so it wins a key both channels declare. A container names one child in both, and the child the recursion resolved is the one to keep.
slv is the effective solver, and the recursion threads it to every child. A container states no solver of its own, so it changes none: each child settles the one it was handed against the one it carries.
Algorithm
- Read the slots
xdeclares withdeferred_slots, givingslots. - Read the resolved calibration slots with
resolve_calibration_slots, givingcalibrated. - Return
xunchanged when both are empty. A type with neither kind of slot needs no method of its own. - Resolve every entry of
slotswithresolve_deferred_quantities, threadingprandslvto each, givingresolved. A child measure resolves through its own method, a vector of children through the vector method, and any other occupant comes back unchanged through this method, because it declares no slot: a stated value,nothingor a Deferred Quantity that the enclosing type resolves itself. - Refuse a slot the recursion left unresolved with
assert_declared_slot_resolver. - Hand
merge(calibrated, resolved)torebuild_with_slots, which returnsxitself when no entry moved and a rebuilt copy when one did.
Returns
xitself when no slot moved, and a rebuilt copy ofxwhen one did.
Related
resolve_deferred_quantities(
r::Skewness,
pr::AbstractPriorResult
) -> Skewness
resolve_deferred_quantities(
r::Skewness,
pr::AbstractPriorResult,
) -> Skewness
Resolve a Deferred Quantity in the sk slot of Skewness r against prior result pr.
sk is the one slot of the measure that a prior can supply, so the slot holds the estimator itself. The measure reads no V, so it keeps only the sk half of the coskewness pair. NegativeSkewness reads both halves. A coskewness estimator centres the matrix on its own me. A measure whose sk is not a Deferred Quantity returns unchanged.
Related
PortfolioOptimisers.resolve_deferred_quantities — Method
resolve_deferred_quantities(x, pr::AbstractPriorResult, slv = nothing)Resolve the children that deferred_slots declared and the slots that calibration_slots declared, and return x itself when none of them changed.
This is the derived half of the resolution rule. A container declares its children once and both entry points follow: factory reaches them through @fprop, and the JuMP builders reach them through this method. Neither needs a forwarding method per container.
A type that resolves a quantity of its own overrides this with its own method, which is more specific. So the derivation carries container recursion alone, and never guesses how a matrix, a tensor or the centre a moment was taken about comes out of a fit.
Both channels end in one rebuild: a measure that carries both kinds of slot must not be rebuilt twice. resolve_calibration_slots states the calibration half and returns its resolved slots rather than a rebuilt object, and the two answers merge here. The deferred half merges last, so it wins a key both channels declare. A container names one child in both, and the child the recursion resolved is the one to keep.
slv is the effective solver, and the recursion threads it to every child. A container states no solver of its own, so it changes none: each child settles the one it was handed against the one it carries.
Algorithm
- Read the slots
xdeclares withdeferred_slots, givingslots. - Read the resolved calibration slots with
resolve_calibration_slots, givingcalibrated. - Return
xunchanged when both are empty. A type with neither kind of slot needs no method of its own. - Resolve every entry of
slotswithresolve_deferred_quantities, threadingprandslvto each, givingresolved. A child measure resolves through its own method, a vector of children through the vector method, and any other occupant comes back unchanged through this method, because it declares no slot: a stated value,nothingor a Deferred Quantity that the enclosing type resolves itself. - Refuse a slot the recursion left unresolved with
assert_declared_slot_resolver. - Hand
merge(calibrated, resolved)torebuild_with_slots, which returnsxitself when no entry moved and a rebuilt copy when one did.
Returns
xitself when no slot moved, and a rebuilt copy ofxwhen one did.
Related
resolve_deferred_quantities(
r::VarianceSkewKurtosis,
pr::AbstractPriorResult
) -> VarianceSkewKurtosis
resolve_deferred_quantities(
r::VarianceSkewKurtosis,
pr::AbstractPriorResult,
slv
) -> VarianceSkewKurtosis
Resolve every Deferred Quantity held by VarianceSkewKurtosis r against prior result pr.
A child that names its own quantity keeps it, whether it states the quantity or defers it. The composite adds a variance, a skewness and a kurtosis term, so a caller who wants the three to describe one distribution names pe on the container and states nothing on the children.
Algorithm
- Resolve each child with its own method of
resolve_deferred_quantities, givingvr,skandkt. - When
peis notnothing, fit it once againstprwithfan_out_pe, and fill each child slot that is stillnothingfrom that one fit:sigmaand itscholonvr,skonsk, andktonkt. - Return the rebuilt measure with
pe = nothing.
Related
PortfolioOptimisers.variance_skew_kurtosis_terms — Function
variance_skew_kurtosis_terms(
r::VarianceSkewKurtosis,
w::AbstractVector{<:Union{Number, AbstractJuMPScalar}}
) -> Tuple{Any, Any, Any}
Return the three scaled terms of VarianceSkewKurtosis r at the weights w, as the tuple (v, s, k).
The functor of r returns v - s + k. The terms have the degrees of homogeneity 2, 3 and 4, so the sum has no single degree. adjusted_risk divides each term by its own degree, and so risk_contribution decomposes the sum exactly.
Mathematical definition
\[\begin{align} v &= s_{\sigma^2}\, \boldsymbol{w}^\intercal \mathbf{\Sigma} \boldsymbol{w}\,, \\ s &= s_{\mathrm{sk}}\, m_3(\boldsymbol{w})\,, \\ k &= s_{\kappa}\, m_4(\boldsymbol{w})\,. \end{align}\]
Where:
- $\boldsymbol{w}$: Portfolio weights vector $N \times 1$.
- $\mathbf{\Sigma}$: Covariance matrix of the risk measure, $N \times N$. It is the measure's own matrix when the measure states one, and the prior's otherwise.
- $m_3(\boldsymbol{w}) = \boldsymbol{w}^\intercal \mathbf{M}_3 (\boldsymbol{w} \otimes \boldsymbol{w})$: Third central moment of the portfolio returns, with $\otimes$ the Kronecker product.
- $m_4(\boldsymbol{w}) = (\boldsymbol{w} \otimes \boldsymbol{w})^\intercal \mathbf{K} (\boldsymbol{w} \otimes \boldsymbol{w})$: Fourth central moment of the portfolio returns, with $\otimes$ the Kronecker product.
- $s_{\sigma^2}$, $s_{\mathrm{sk}}$, $s_{\kappa}$: The
settings.scaleofvr,skandkt.
Arguments
r::VarianceSkewKurtosis: Measure whose matrices are stated.w::VecNum: Portfolio weights vectorassets × 1.
Returns
(v, s, k)::Tuple: The scaled variance, third moment and fourth moment terms.
Related
PortfolioOptimisers.portfolio_third_moment — Function
portfolio_third_moment(
sk::AbstractMatrix{<:Union{Number, AbstractJuMPScalar}},
w::AbstractVector{<:Union{Number, AbstractJuMPScalar}}
) -> Any
Return the third moment of the portfolio at the weights w, read off the coskewness matrix sk.
This is the term that the model of VarianceSkewKurtosis relaxes, that the lb of a Skewness bounds, and that the functor of Skewness gives.
Where:
- $m_3(\boldsymbol{w}) = \boldsymbol{w}^\intercal \mathbf{M}_3 (\boldsymbol{w} \otimes \boldsymbol{w})$: Third central moment of the portfolio returns, with $\otimes$ the Kronecker product.
- $\mathbf{M}_3$: Coskewness matrix of the risk measure, $N \times N^2$. It is the measure's own
skwhen the measure states one, and the prior's otherwise.
Arguments
sk::MatNum: Coskewness matrixassets × assets^2.w: Portfolio weights vectorassets × 1.
Returns
m3::Number: The third moment of the portfolio.
Related
PortfolioOptimisers.portfolio_fourth_moment — Function
portfolio_fourth_moment(
kt::AbstractMatrix{<:Union{Number, AbstractJuMPScalar}},
w::AbstractVector{<:Union{Number, AbstractJuMPScalar}}
) -> Any
Return the fourth moment of the portfolio at the weights w, read off the cokurtosis matrix kt.
This is the term that the models of Kurtosis and of VarianceSkewKurtosis read. The functor of Kurtosis gives it under the QuadSecondMomentFormulations, and its square root under SOCRiskExpr.
Where:
- $m_4(\boldsymbol{w}) = (\boldsymbol{w} \otimes \boldsymbol{w})^\intercal \mathbf{K} (\boldsymbol{w} \otimes \boldsymbol{w})$: Fourth central moment of the portfolio returns, with $\otimes$ the Kronecker product.
- $\mathbf{K}$: Cokurtosis matrix of the risk measure, $N^2 \times N^2$. It is the measure's own
ktwhen the measure states one, and the prior's otherwise.
Arguments
kt::MatNum: Cokurtosis matrixassets^2 × assets^2.w: Portfolio weights vectorassets × 1.
Returns
m4::Number: The fourth moment of the portfolio.
Related