Base Prior
PortfolioOptimisers.AbstractPriorEstimator — Type
abstract type AbstractPriorEstimator <: AbstractEstimatorAbstract supertype for all prior estimators.
A prior estimator computes a prior result from asset returns, from factor returns, or from both. Every concrete prior estimator subtypes one of the families below.
Interfaces
To implement a new prior estimator, subtype the family that names the returns it reads, and hold every parameter in a field of the struct. The families are AbstractLowOrderPriorEstimator_A, AbstractLowOrderPriorEstimator_F and AbstractLowOrderPriorEstimator_AF for a low order estimator. They are AbstractHighOrderPriorEstimator_F and AbstractHighOrderPriorEstimator for a high order estimator. Then implement this method:
prior(pe::AbstractPriorEstimator, X::MatNum, F::Option{<:MatNum} = nothing, pnl::Option{<:AssetPanel} = nothing; dims::Int = 1, kwargs...) -> AbstractPriorResult: Estimate the prior from the returns matrices and the Asset Panel.
The family sets the signature. A member of the _A family declares F as args... and does not read it. A member of a _F family declares F::MatNum and requires it. A member of the _AF family, or of the high order root, declares F::Option{<:MatNum} = nothing and reads F when the caller gives it.
pnl is the Asset Panel of the ReturnsResult, and the ReturnsResult method gives it to every estimator. An estimator takes it and ignores it, unless the estimator fits on a panel, as CrossSectionalFactorPrior does. An estimator that wraps another over the assets passes pnl to it unchanged, so that the wrapped estimator can also fit on the panel. An estimator that wraps a prior over the factors does not pass it, because no panel describes a factor axis. An estimator that declares args... takes pnl there, and needs no other declaration.
The method returns the prior result of its own order. A low order estimator returns a LowOrderPrior, and a high order estimator returns a HighOrderPrior. An estimator that wraps another rebuilds the wrapped result with forward_prior, not with a hand-written constructor call. Every field that the wrapper does not name then keeps its value.
This file defines the ReturnsResult method of prior, so a new estimator does not implement it.
Arguments
pe: Prior estimator.X: Data matrixobservations × assetsif thedimskeyword does not exist ordims = 1,assets × observationswhendims = 2.F: Factor returns matrix, ornothing.pnl: OptionalAssetPanel, the panel that the returns data held. A wrapping prior forwards it unchanged, so that it can compose an estimator that is fitted on a panel. An estimator that reads no panel ignores it.dims: Dimension along which the computation runs.kwargs...: Additional keyword arguments passed to the nested estimators.
Returns
pr::AbstractPriorResult: Result object containing the estimated prior.
carry_folds (optional)
carry_folds(pe::MyPriorEstimator) -> Bool: Returnstruewhen the carry fold of aCrossSectionalFactorPriorfolds the prior as its factor prior, one row at a time.
A prior that returns true also implements two methods. partial_fit!(pe, f::MatNum) -> pe folds factor returns into a state that the prior holds, and prior(pe; strict::Bool = false) -> LowOrderPrior reads that state. The fallback returns false, which is correct for every prior. The cost of false is on the carry fold. FoldOrRefit fits the factor prior again over every carried factor return at each step, and FoldOnly refuses the prior.
returns_source (optional)
returns_source(pe::MyPriorEstimator) -> Option{<:AbstractReturnsSource}: Returns the source of the returns that the prior fits on. This is usually a fieldx_src::Option{<:AbstractReturnsSource}, which the inner constructor checks withPortfolioOptimisers.assert_returns_source(x_src, PortfolioOptimisers.DATA_RETURNS_SOURCES, :MyPriorEstimator).
The ReturnsResult method of prior reads the source through this method, and the frame walk of an optimiser also reads it. The fallback returns nothing, so a prior with no method reads the raw returns rd.X. A prior that holds another reader in a field refuses a source on that reader, with PortfolioOptimisers.assert_inner_reader in its keyword constructor. The outer prior picks the returns.
keeps_observations (optional)
keeps_observations(pe::MyPriorEstimator) -> Bool: Returnstruewhen the result carries one scenario for each observation that the prior receives, for every configuration and all data.
A prior that reweights observations, such as EntropyPoolingPrior, reads this method on the prior that it wraps. It reads the count of the scenarios of the wrapped prior before it fits that prior under the prior probabilities of a caller. When the wrapped prior returns true, the count needs no fit. Otherwise the count runs only the steps that drop rows. The wrapped prior fits once more only when no method of PortfolioOptimisers.scenario_count gives the count. The fallback returns false, which is correct for every prior and costs at most that one fit. A prior that drops rows, such as one that holds a Scenario Cap, keeps the fallback. A prior that wraps another returns the answer of the prior that it wraps.
Examples
This example makes a minimal prior estimator:
julia> struct MyPriorEstimator <: PortfolioOptimisers.AbstractLowOrderPriorEstimator_A endjulia> function PortfolioOptimisers.prior(pe::MyPriorEstimator, X::PortfolioOptimisers.MatNum, args...; dims::Int = 1, kwargs...) mu = vec(sum(X; dims = 1)) / size(X, 1) sigma = Matrix(LinearAlgebra.I * 1.0, size(X, 2), size(X, 2)) return LowOrderPrior(; X = X, mu = mu, sigma = sigma) endjulia> prior(MyPriorEstimator(), [0.01 0.02; 0.03 0.04])LowOrderPrior X ┼ 2×2 Matrix{Float64} o_X ┼ nothing mu ┼ Vector{Float64}: [0.02, 0.03] sigma ┼ 2×2 Matrix{Float64} chol ┼ nothing w ┼ nothing ens ┼ nothing eoc ┼ Tuple{Nothing, Nothing}: (nothing, nothing) kld ┼ nothing ow ┼ nothing rr ┼ nothing fpr ┼ nothing x_src ┼ nothing ss_gaps ┼ nothing pc ┴ nothingRelated
PortfolioOptimisers.AbstractPriorResult — Type
abstract type AbstractPriorResult <: AbstractResultAbstract supertype for all prior result types.
A prior estimator returns a prior result. The result holds the moments, the asset returns and the factor returns that the estimator computed.
The library has two prior result types. LowOrderPrior holds the returns, the mean and the covariance. HighOrderPrior holds the co-moments, and wraps a LowOrderPrior.
Interfaces
To implement a new prior result type, subtype AbstractPriorResult, hold every value in a field of the struct, and implement these methods:
reconstruct_prior(pr::AbstractPriorResult, patch::NamedTuple) -> AbstractPriorResult: Rebuildprthrough its own constructor withpatchapplied.forward_priorcalls it. Each result type writes its own method, because the method names the constructor and does not find it by reflection.port_opt_view(pr::AbstractPriorResult, i, args...) -> AbstractPriorResult: Restrictprto the assets at indexi, for hierarchical and subset optimisation.
prior_field_values reads the field list from the type, so a result type that gains a field needs no other method. An @pprop field can name only a field of LowOrderPrior or of HighOrderPrior, because prior_result_property_pool writes those two types by name. check_propagatable_contracts refuses a name that only a new result type has.
Arguments
pr: Prior result.patch: Named tuple of field overrides.i: Asset indices the view keeps.args...: Additional arguments the view reads.
Returns
pr::AbstractPriorResult: A prior result of the same type as the input.
Examples
This example makes a minimal prior result type:
julia> struct MyPriorResult <: PortfolioOptimisers.AbstractPriorResult X::Matrix{Float64} mu::Vector{Float64} endjulia> function PortfolioOptimisers.reconstruct_prior(pr::MyPriorResult, patch::NamedTuple) vals = merge(PortfolioOptimisers.prior_field_values(pr), patch) return MyPriorResult(vals.X, vals.mu) endjulia> function PortfolioOptimisers.port_opt_view(pr::MyPriorResult, i, args...) return MyPriorResult(pr.X[:, i], pr.mu[i]) endjulia> pr = MyPriorResult([0.01 0.02; 0.03 0.04], [0.02, 0.03]);julia> PortfolioOptimisers.forward_prior(pr; mu = [0.05, 0.06]).mu2-element Vector{Float64}: 0.05 0.06julia> PortfolioOptimisers.port_opt_view(pr, [1]).mu1-element Vector{Float64}: 0.02Related
PortfolioOptimisers.AbstractLowOrderPriorEstimator_A — Type
abstract type AbstractLowOrderPriorEstimator_A <: AbstractLowOrderPriorEstimatorLow order prior estimator using only asset returns.
A member of this family computes the mean and the covariance from asset returns alone.
This is the first of the three source shapes. A member admits asset returns only. Its prior method declares the factor argument as args... and does not read it, so the method ignores factor returns and does not refuse them.
Interfaces
prior(pe::AbstractLowOrderPriorEstimator_A, X::MatNum, args...; dims::Int = 1, kwargs...) -> LowOrderPrior: Estimate the prior from asset returns alone.args...takes the factor returns, and the method ignores them.
Related
PortfolioOptimisers.AbstractLowOrderPriorEstimator_F — Type
abstract type AbstractLowOrderPriorEstimator_F <: AbstractLowOrderPriorEstimatorLow order prior estimator using factor returns.
A member of this family computes the mean and the covariance from asset returns and factor returns, and it requires both.
This is the second of the three source shapes. A member admits asset returns and requires factor returns. Its prior method declares the factor argument as F::MatNum with no default, so a call with no factor returns raises a MethodError. When a ReturnsResult with F === nothing reaches such an estimator, prior raises a named error before that call.
Interfaces
prior(pe::AbstractLowOrderPriorEstimator_F, X::MatNum, F::MatNum, args...; dims::Int = 1, kwargs...) -> LowOrderPrior: Estimate the prior from asset and factor returns. A call with noFraises aMethodError.
Related
PortfolioOptimisers.AbstractLowOrderPriorEstimator_AF — Type
abstract type AbstractLowOrderPriorEstimator_AF <: AbstractLowOrderPriorEstimatorLow order prior estimator using both asset and factor returns.
A member of this family computes the mean and the covariance from asset returns, and it reads factor returns when the caller gives them.
This is the third of the three source shapes. A member admits asset returns, and admits factor returns as an option. Its prior method declares the factor argument as F::Option{<:MatNum} = nothing, and reads F when the caller gives it. The shape does not tell whether the result carries a regression. Use assert_prior_regression to find that.
The shape also does not tell whether the fit reads factor returns. needs_factor_returns gives one of three answers. A member that requires them answers true, and a member that does not read them answers false. This shape answers nothing by default, which means that the type does not decide and the fold takes the data it receives. The batch verb does the same. Every member of this shape in the library holds another prior and gives F to it, so each member defines the recursion and answers with the value of the innermost prior.
A new subtype that holds a prior must define the same recursion. A new subtype that reads F itself can keep the default.
Interfaces
prior(pe::AbstractLowOrderPriorEstimator_AF, X::MatNum, F::Option{<:MatNum} = nothing, args...; dims::Int = 1, kwargs...) -> LowOrderPrior: Estimate the prior from asset returns, and readFwhen the caller gives it.
Related
PortfolioOptimisers.AbstractHighOrderPriorEstimator — Type
abstract type AbstractHighOrderPriorEstimator <: AbstractPriorEstimatorAbstract supertype for high order prior estimators.
A high order prior estimator computes the coskewness and the cokurtosis from asset returns, from factor returns, or from both. A member of this family returns a HighOrderPrior. That result wraps the LowOrderPrior of the nested low order estimator of the member. A high order estimator adds an order and does not replace one, and the wrapper answers every low order name.
A member that requires factor returns subtypes AbstractHighOrderPriorEstimator_F. A member that reads factor returns only when the caller gives them subtypes this type directly, as HighOrderPriorEstimator does.
Interfaces
prior(pe::AbstractHighOrderPriorEstimator, X::MatNum, F::Option{<:MatNum} = nothing, args...; dims::Int = 1, kwargs...) -> HighOrderPrior: Estimate the prior from asset returns, and readFwhen the caller gives it.
Related
PortfolioOptimisers.AbstractHighOrderPriorEstimator_F — Type
abstract type AbstractHighOrderPriorEstimator_F <: AbstractHighOrderPriorEstimatorHigh order prior estimator using factor returns.
A member of this family computes the coskewness and the cokurtosis from asset returns and factor returns, and it requires both.
A member admits asset returns and requires factor returns, as a member of AbstractLowOrderPriorEstimator_F does at the low order. Its prior method declares the factor argument as F::MatNum with no default. The two families are the members of AbstractHiLoOrderPriorEstimator_F. That union lets prior find a factor prior of either order.
Interfaces
prior(pe::AbstractHighOrderPriorEstimator_F, X::MatNum, F::MatNum, args...; dims::Int = 1, kwargs...) -> HighOrderPrior: Estimate the prior from asset and factor returns. A call with noFraises aMethodError.
Related
PortfolioOptimisers.LowOrderPrior — Type
struct LowOrderPrior{__T_X, __T_o_X, __T_mu, __T_sigma, __T_chol, __T_w, __T_ens, __T_kld, __T_ow, __T_rr, __T_fpr, __T_x_src, __T_ss_gaps, __T_pc} <: AbstractPriorResultCarries the returns, mean and covariance a low order prior estimator produced.
Every low order prior estimator returns a LowOrderPrior. It holds the asset returns, the mean vector and the covariance matrix. It can also hold a Cholesky factor, the observation weights and three diagnostics of them, a factor block, and the original returns. The last fields record the source of the returns, the marks of a Shared Series cut, and the cache of an opinion pool. The constructor checks every field.
Fields
X: Data matrixobservations × assetsif thedimskeyword does not exist ordims = 1,assets × observationswhendims = 2.
o_X: The returns matrix of the caller when theXof the prior result is a different matrix, andnothingotherwise. The estimators that lift a factor-axis prior onto the asset axis overwriteX, with the reconstructionF * transpose(M) .+ transpose(b)or with scenarios of the factor model.o_Xholds the asset returns that they received, over the same observations and the same assets. Read it asoriginal_X, which is always a matrix, and not as this field.
mu: Expected returns vectorassets × 1.
sigma: Covariance matrixassets × assets.
chol: Cholesky factorisation of the covariance matrix.
w: Observation weights of the fit of the prior,observations × 1, seeObsWeights, ornothingwhen the fit used no weights. It bindsens,eoc,kldandow, which are diagnostics of it and counts of the moments that it weights, seeforward_prior.
ens: Effective number of scenarios of the weightsw, ornothing. An entropy pooling prior and an opinion pooling prior writeexp(entropy(w)). It is a diagnostic ofw, andwbinds it, seeforward_prior. It is not the count of the moments, whicheocstates.
eoc: Effective number of observations of the moments, a tuple(T_mu, T_sigma)with one count formuand one forsigma. An entry ofnothingmeanssize(X, 1).EmpiricalPriorwrites the count of itsmeand of itscefromeffective_observation_count. That is the Kish count of a weighted estimator, and the number of observations of the fit when a Scenario Capmax_scenarioskeeps fewer rows inX. A pooling prior refits its prior under its weightswand keeps the counts of the refit. An estimator that readswstates the Kish count ofw.wbinds the field, seeforward_prior. A wrapper forwards it. A consumer that needs a sample size reads it, and not the number of rows inX: the denoiser of a matrix that a prior assembles, a normal uncertainty set and a calibration rule.
kld: Kullback-Leibler divergence ofwfrom the weights from which it came. It is a scalar against the prior observation weights for one reweighting, or one entry per opinion when an opinion pool madew.
ow: The penalised opinion probabilities of the opinion pool that made the result, one entry per opinion, ornothingwhen no pool made it.
rr: Regression result.
fpr: Prior result over the factor axis, ornothing. ItsXis the factor returns matrix, so its moments describe factors and not assets. It has the same observations as the asset block.
x_src: The source of the returns on which the prior fitted,nothingor anAbstractReturnsSource.priorrecords the source that the prior estimator states. It does this when it fits on the returns data, and when it reads out the state of an online fold.nothingmeans that the fit stated no source, or that the caller gave a returns matrix, so a reader of the Result readsXas raw returns. The outer problem of a meta-optimiser reads it, seeouter_returns_source.
ss_gaps: One mark for each observation of the returns data that the prior read,trueat an observation that the prior dropped for a Shared Series gap, ornothingwhen it dropped none. The rows ofXare the lastsize(X, 1)observations that the marks keep, so a reader that holds the returns data finds the observation of each row, seeshared_series_record.priorwrites it when it fits on the returns data, and when it reads out the state of an online fold. An optimiser writes it on the prior that it fits after its own cut. A returns-matrix method ofpriordrops no observation, so it leavesnothing.
pc: The cache of the opinion pool that made the result,(; X, w, pe2), ornothing.Xholds the rows ofpe1that the opinions read, ornothingwhen the pool reads the returns.wholds the pooled weights, andpe2holds the cache of the result ofpe2. A pool fitted withcache_reg = truestores it. An entropy pooling prior that wraps the pool reads it when it fits again, so no opinion runs again. Every other fit leaves itnothing.
Constructors
LowOrderPrior(; X::MatNum, o_X::Option{<:MatNum} = nothing, mu::VecNum, sigma::MatNum, chol::Option{<:MatNum} = nothing, w::Option{<:ObsWeights} = nothing, ens::Option{<:Number} = nothing, eoc::Tuple{Option{<:Real}, Option{<:Real}} = (nothing, nothing), kld::Option{<:Num_VecNum} = nothing, ow::Option{<:VecNum} = nothing, rr::Option{<:AbstractLoadingsRegressionResult} = nothing, fpr::Option{<:LowOrderPrior} = nothing, x_src::Option{<:AbstractReturnsSource} = nothing, ss_gaps::Option{<:AbstractVector{Bool}} = nothing, pc::Option{<:NamedTuple} = nothing) -> LowOrderPriorKeywords correspond to the struct's fields.
The factor block
A prior that a factor model fits carries two distributions. The fields of the LowOrderPrior hold the distribution over the assets. The field fpr holds the distribution over the factors, as a nested LowOrderPrior. A nested result, and not a set of flat fields with an f_ prefix, gives the factor distribution every field of a LowOrderPrior. These are w, ens, eoc, kld and ow as well as mu and sigma. A field added later also applies to it with no second edit. Its X is the factor returns matrix, over the same observations as the asset X.
fpr and rr are the factor block, and the constructor requires them together or not at all. rr projects the block onto the assets, mu ≈ rr.M * fpr.mu + rr.b. A factor distribution with no loadings has no relation to this asset axis.
The bound of rr is AbstractLoadingsRegressionResult. A member of that root carries the loadings matrix M, so the field admits a Regression and a CrossSectionalFactorModel. The bound selects by the loadings, and not by the method of the fit. Every check of the constructor on the block reads rr.M alone, and fpr is on the axis that the columns of M name. Every consumer of the field reads M, or reads L, which returns M when L is not set.
The field does not tell one property of the block, so a consumer that needs it must ask. A member fitted in a re-based Factor Family answers true to has_family_rebasis. Its fpr.sigma is then singular, because the raw factor axis is a linear image of the re-based axis. A projection through M stays correct, and HighOrderFactorPriorEstimator does such a projection. An inverse or a factorisation of fpr.sigma has no answer. The inverse raises no error, and returns a result whose scale looks usual. For this reason, BayesianBlackLittermanPrior refuses such a prior result.
The flat names read the nested block, so code written for the old shape still works. pr.f_mu, pr.f_sigma and pr.f_w return fpr.mu, fpr.sigma and fpr.w, or nothing when there is no factor block. pr.f_ens, pr.f_kld and pr.f_ow work in the same way. They are properties, not fields, so forward_prior and prior_field_values see only fpr.
Which read to use
Read the factor block as pr.fpr.mu. The flat names with the f_ prefix stay so that code written for the old shape still works. They also help where a read must return a value or nothing with no branch.
The flat names do not cover the block, and the set does not grow. There are six flat names for fifteen fields. fpr.X, the factor returns matrix, has no flat name, and neither have fpr.chol, fpr.eoc and fpr.rr. The set has six names here, and seven on HighOrderPrior. A field added to LowOrderPrior later is available as pr.fpr.<name>, and gets no flat name, so no field needs an edit in two places.
The two reads are different when there is no factor block. pr.f_mu returns nothing, but pr.fpr.mu raises an error, because fpr is nothing. First check the block with assert_prior_regression, and then read through fpr. The check reads rr only, which is enough, because rr and fpr are present together or not at all.
Composition: what a wrapping estimator forwards
Most prior estimators wrap another, and build their prior result from the result that they receive. forward_prior enforces one rule for the fields that the wrapper keeps. A wrapper forwards a field when the value stays correct. It drops a field only when the forwarded value would state something false. The docstring of the estimator names every field that it drops.
The returned result must be consistent. A wrapper must not remove a value that the caller computed to get that consistency. The default is to forward, and the docstring of each estimator lists the fields that it drops and the reasons. Three bindings tie a field to another, so a wrapper never forwards the bound fields alone:
sigmabindschol. Whencholis present, every consumer reads it in place ofsigma, and a stalecholreplaces the changed covariance with no error.wbindsens,eoc,kldandow. These are diagnostics and counts of the weights.rrbindso_X.rrrecords the projection that madeXfromo_X.
forward_prior refuses a forward that breaks a binding.
The original returns matrix
Four estimators overwrite X, and o_X exists for them. FactorPrior, FactorBlackLittermanPrior and AugmentedBlackLittermanPrior write a reconstruction from the factors. CrossSectionalFactorPrior writes scenarios from the factor returns, the loadings and the standardised idiosyncratic returns. On their results, X is the asset distribution that the prior states, and not the returns of the caller. o_X holds the returns of the caller. It is nothing on every other result, where X is the returns of the caller.
The two matrices are different. The reconstruction of the first three estimators spans only the factors. It has rank size(F, 2), and it has no residual. A consumer that fits a moment on the sample again must read the original. Otherwise it gets a singular matrix when there are more assets than factors.
Read the original returns as original_X, not as o_X. The property is always a matrix. It is the field when the field holds one, and X when it does not. A consumer needs no fallback. The field is storage, and it answers a different question. isnothing(pr.o_X) tells whether this prior result changed X. The field holds this state, and the property does not. forward_prior rebuilds through the keyword constructor with every field named. A nothing has no effect there, but a matrix in every result would become stale after a change to X.
o_X requires rr. Every estimator that overwrites X now builds it from a factor prior and loadings, and carries the loadings in rr. A prior result that has an o_X and no rr is a defect. This is a rule of the present library, and not of the domain. A new estimator that changes X with no regression must change this rule on purpose.
The source of the returns
x_src records the frame of X. prior writes in it the source that the prior estimator states, through stamp_returns_source. It does this when it fits on a ReturnsResult, and when it reads out the state of an online fold. A returns-matrix method of prior cannot know the frame of the matrix that it receives, so it leaves nothing. A consumer that receives the Result in place of the estimator reads the frame from this field. The outer problem of a meta-optimiser adds the benchmark back to X when the field is ExcessSource, see outer_returns_source. A HighOrderPrior holds no such field, and answers x_src from the LowOrderPrior that it wraps.
The observations of the rows
ss_gaps records the observations of the returns data that the fit dropped for a Shared Series gap. A fit also drops rows at the start. A Scenario Cap keeps the last rows, and a CrossSectionalFactorPrior drops the rows of its warm-up and of its exposure lag. So the rows of X are the last size(X, 1) observations that ss_gaps keeps. When ss_gaps is nothing, they are the last size(X, 1) observations of the returns data.
A reader that holds the returns data that the prior read pairs its rows with the rows of X through the marks, see shared_series_kept_rows. A reader that holds the returns data after the same cut has fewer observations than the marks, and pairs the last rows. That was the rule before the record existed. prior writes the marks after it fits on the returns data, and after it reads out an online fold. A returns-matrix method of prior drops no observation, so it leaves nothing. A HighOrderPrior answers ss_gaps from the LowOrderPrior that it wraps.
Validation
X,mu, andsigmamust be non-empty.size(sigma, 1) == size(sigma, 2).size(X, 2) == length(mu) == size(sigma, 1).- Every entry of
sigmabetween two investable assets is finite. An investable asset has a finitemuand a finite variance. Raises anIsNonFiniteError. - If
wis notnothing,!isempty(w)andlength(w) == size(X, 1). - Each entry of
eocthat is notnothingis finite and positive, throughassert_moment_counts. - If
kldis anAbstractVector,!isempty(kld). - If
owis notnothing,!isempty(ow). rrandfprmust be provided together or not at all.- If the factor block is present,
size(rr.M, 2) == length(fpr.mu) == size(fpr.sigma, 1),size(rr.M, 1) == length(mu), andsize(fpr.X, 1) == size(X, 1). The two blocks describe the same observations. The constructor of the factor block checks the inside of the block, such as its ownwagainst its ownX. - If
o_Xis notnothing,o_X !== X,size(o_X) == size(X), andrris notnothing.o_X !== Xtests identity, not equality. Soo_X = copy(X)passes, ando_X = Xraises an error. The two calls look the same, but only the first holds a matrix that a later change toXdoes not change. The check refuses a prior result whose original is the same object as itsX. It does not refuse a matrix with equal values. - If
cholis notnothing,!isempty(chol)andlength(mu) == size(chol, 2). - The rules of
assert_shared_series_gapsonss_gaps. - If
pcis notnothing,length(pc.w) == size(X, 1), andsize(pc.X, 1) == size(X, 1)whenpc.Xis a matrix, throughassert_pool_cache.
View parameters
LowOrderPrior defines its own port_opt_view method, and does not make one from field tags.
- It reads no argument after
i. It takes and ignores more positional arguments. rrrecurses throughport_opt_viewwithi, which cuts the loadings on their asset axis.X,o_X,mu,sigmaandcholare cut toion the asset axis.o_Xtakes the same cut asX, so the original returns of a subproblem are the returns of the caller for the assets of that subproblem.w,ens,eoc,kldandowpass through unchanged. They are on the observation axis, andiindexes assets.fprpasses through unchanged, because it is a distribution over factors and not over assets. The view thus keepsrrandfprtogether, as the rule of the factor block requires.ss_gapspasses through unchanged. It is on the observation axis.pcis dropped. Its rows hold every asset, and a fit of the subset of assets has no cache of its own.
Examples
julia> LowOrderPrior(; X = [0.01 0.02; 0.03 0.04], mu = [0.02, 0.03], sigma = [0.0001 0.0002; 0.0002 0.0003])LowOrderPrior X ┼ 2×2 Matrix{Float64} o_X ┼ nothing mu ┼ Vector{Float64}: [0.02, 0.03] sigma ┼ 2×2 Matrix{Float64} chol ┼ nothing w ┼ nothing ens ┼ nothing eoc ┼ Tuple{Nothing, Nothing}: (nothing, nothing) kld ┼ nothing ow ┼ nothing rr ┼ nothing fpr ┼ nothing x_src ┼ nothing ss_gaps ┼ nothing pc ┴ nothingRelated
PortfolioOptimisers.HighOrderPrior — Type
struct HighOrderPrior{__T_pr, __T_kt, __T_D2, __T_L2, __T_S2, __T_sk, __T_V, __T_skmp, __T_fpr} <: AbstractPriorResultCarries the coskewness and cokurtosis a high order prior estimator produced, over the low order prior it wraps.
Every high order prior estimator returns a HighOrderPrior. It wraps a low order prior result, and holds the cokurtosis matrix, the duplication, elimination and summation matrices, the coskewness matrix, and the negative spectral coskewness. It also holds the matrix processing estimator of the coskewness, and the factor co-moments. The constructor checks every field.
Fields
pr: Prior result.
kt: Cokurtosis matrixassets^2 × assets^2.
D2: Duplication matrix.
L2: Elimination matrix.
S2: Summation matrix.
sk: Coskewness matrixassets × assets^2.
V: Sum of the negative spectral slices of the coskewness matrixassets × assets.
skmp: Coskewness matrix processing estimator.
eoc: Effective number of observations of the higher moments, a tuple(T_sk, T_kt)with one count for the coskewness and one for the cokurtosis. An entry ofnothingmeanssize(X, 1). The propertypr.eocof the result reads the four counts(T_mu, T_sigma, T_sk, T_kt), with the two counts of the low order result first.
fpr: Prior result over the factor axis, ornothing. ItsXis the factor returns matrix, so its moments describe factors and not assets. It has the same observations as the asset block.
Constructors
HighOrderPrior(; pr::AbstractPriorResult, kt::Option{<:MatNum} = nothing, D2::Option{<:MatNum} = nothing, L2::Option{<:MatNum} = nothing, S2::Option{<:MatNum} = nothing, sk::Option{<:MatNum} = nothing, V::Option{<:MatNum} = nothing, skmp::Option{<:AbstractMatrixProcessingEstimator} = nothing, eoc::Tuple{Option{<:Real}, Option{<:Real}} = (nothing, nothing), fpr::Option{<:HighOrderPrior} = nothing) -> HighOrderPriorKeywords correspond to the struct's fields.
The counts of the moments
The field eoc holds the effective number of observations of the coskewness and of the cokurtosis. The property pr.eoc reads four counts. The first two are the eoc of pr, the counts of mu and sigma. So pr.eoc[k] is the count of moment k on both result types, and moment_observation_count reads it. A read of the field itself, with getfield, gives the pair. reconstruct_prior reads the fields so, and keeps the pair.
The factor block
A high order prior that a factor model fits carries factor co-moments as well as asset co-moments. The field fpr holds them as a nested HighOrderPrior, and not as the flat fields f_kt, f_sk and f_V. The factor block thus has every field of a HighOrderPrior. These are D2, L2, S2 and skmp as well as kt, sk and V. A field added later also applies to it with no second edit. The flat names still read the nested block. pr.f_kt, pr.f_sk and pr.f_V return fpr.kt, fpr.sk and fpr.V, or nothing when there is no factor block. pr.f_D2, pr.f_L2, pr.f_S2 and pr.f_skmp work in the same way.
fpr.pr is the factor block at the low order, the LowOrderPrior over the factors. pr.pr.fpr, the factor block of the low order result, is the same distribution. The constructor requires that the two are the same object, see the validation below.
fpr is a field of the HighOrderPrior, so a read of fpr finds the field before the forward(pr) block. It names the high order factor block. Before the nested block existed, it named the low order factor block. Reads through it give the same values. The nested HighOrderPrior forwards to its own pr, which the constructor requires to be pr.fpr. So hop.fpr.mu is the factor mean in both cases, and hop.fpr is the factor prior at this order.
Which read to use
Read the factor block as pr.fpr.kt, for the reasons that LowOrderPrior gives. The seven flat names here are f_kt, f_sk, f_V, f_D2, f_L2, f_S2 and f_skmp, and the set does not grow. A field added to HighOrderPrior later is available as pr.fpr.<name>, and gets no flat name.
The two reads are different when there is no factor block. pr.f_kt returns nothing, and pr.fpr.kt raises an error. Check the block first, and then read through fpr.
Validation
Let N = length(pr.mu).
- If one of
kt,L2orS2is given, all three must be given and not empty, withsize(kt) == (N^2, N^2)andsize(L2) == size(S2) == (div(N * (N + 1), 2), N^2). - If
skorVis given, both must be given and not empty, withsize(sk) == (N, N^2)andsize(V) == (N, N). - If the three matrices of the first rule and
skare given,D2must be given and not empty, withsize(D2) == size(transpose(L2)).D2has no other rule. It is the one moment field that the constructor admits alone, and aHighOrderPriorthat holds onlyD2is valid. - If
fpris given,pr.fprmust be given, andfpr.pr === pr.fpr. The factor co-moments are computed against the factor block of the low order result, not against a copy of it. The opposite rule does not apply. A low order factor block with no factor co-moments is usual, sofpr === nothingalways passes. The constructor of the factor block checks the inside of the block, such as its own shapes against its ownN.
View parameters
HighOrderPrior defines its own port_opt_view method, and does not make one from field tags.
- It reads no argument after
i. It takes and ignores more positional arguments. prrecurses throughport_opt_viewwithi, which cuts every low order field.- A fourth-moment index derived from
iindexeskt, andidoes not.ktis $N^2 \times N^2$ over ordered pairs of assets, so the asset index does not address it. skis cut byion its asset axis, and by the same fourth-moment index on its pair axis.Vis computed again from the cutsk, and is not cut. It is a spectral quantity of the coskewness matrix, so the submatrix ofVis not theVof the submatrix.D2,L2andS2are built again for the number of assets of the subproblem, and are not cut. They depend only on that number, and hold no data of a specific asset.skmppasses through unchanged. It is the matrix processing estimator that the new computation ofVreads.eocpasses through unchanged. It is on the observation axis, andiindexes assets.fprpasses through unchanged, because it holds co-moments over factors and not over assets. The view forwards the same object, sofpr.pr === pr.fprstays true. The low order view forwards its own factor block in the same way.
Examples
julia> HighOrderPrior(; pr = LowOrderPrior(; X = [0.01 0.02; 0.03 0.04], mu = [0.02, 0.03], sigma = [0.0001 0.0002; 0.0002 0.0003]), kt = rand(4, 4), D2 = PortfolioOptimisers.duplication_matrix(2), L2 = PortfolioOptimisers.elimination_matrix(2), S2 = PortfolioOptimisers.summation_matrix(2), sk = rand(2, 4), V = rand(2, 2))HighOrderPrior pr ┼ LowOrderPrior │ X ┼ 2×2 Matrix{Float64} │ o_X ┼ nothing │ mu ┼ Vector{Float64}: [0.02, 0.03] │ sigma ┼ 2×2 Matrix{Float64} │ chol ┼ nothing │ w ┼ nothing │ ens ┼ nothing │ eoc ┼ Tuple{Nothing, Nothing}: (nothing, nothing) │ kld ┼ nothing │ ow ┼ nothing │ rr ┼ nothing │ fpr ┼ nothing │ x_src ┼ nothing │ ss_gaps ┼ nothing │ pc ┴ nothing kt ┼ 4×4 Matrix{Float64} D2 ┼ 4×3 SparseArrays.SparseMatrixCSC{Int64, Int64} L2 ┼ 3×4 SparseArrays.SparseMatrixCSC{Int64, Int64} S2 ┼ 3×4 SparseArrays.SparseMatrixCSC{Int64, Int64} sk ┼ 2×4 Matrix{Float64} V ┼ 2×2 Matrix{Float64} skmp ┼ nothing eoc ┼ NTuple{4, Nothing}: (nothing, nothing, nothing, nothing) fpr ┴ nothingRelated
PortfolioOptimisers.prior — Method
prior(pe::AbstractPriorEstimator, rd::ReturnsResult; strict::Bool = false,
dims::Int = 1, cache_reg::Bool = false)Compute a prior result from the returns data with a prior estimator.
prior reads the asset returns and the factor returns from rd, and gives them to pe with the other data that rd holds. Every caller uses this method, and this file defines it once. Each estimator implements the returns-matrix method that this method calls. AbstractPriorEstimator states that contract.
Algorithm
- Check that
rdcarries asset returns, so that the estimator does not receivenothingforX. - When
needs_factor_returnsanswerstrue, check thatrdcarries factor returns. The predicate reads the whole tree, so it finds a factor estimator inside an outer estimator whose factor argument is optional. The check runs here, so the caller gets a named error aboutrd.F. Without it, the caller gets aMethodErrorfrom the inner estimator one call later. - Check that every
UniverseSetson the asset axis of the tree ofpenames the columns ofrd, in order, withassert_universe_axis_order. The returns-matrix method resolves a name to a column by its position alone, so a universe in another order binds each view to the wrong asset. - Read the source that
pestates withreturns_source. Call itx_src. - Drop the observations of a Shared Series gap with
shared_series_view. These are a gap of a vector benchmark underx_src = ExcessSource(), and a gap of the factor returns whenneeds_factor_returnsanswerstrue. Every field ofrdloses the same observations, and every fixed observation weight in the tree ofpeloses them too, throughshared_series_estimator. - Read the asset returns
Xwithbenchmark_relative_returnsunderx_src.Xisrd.X, orrd.X - rd.BunderExcessSource(). - Call the returns-matrix method of the estimator with
X,rd.Fandrd.pnl. Passrd.iv,rd.ivpa,rd.ne,rd.E,strictandcache_regas keyword arguments. A wrapper prior passes its keyword arguments to the estimator that it holds. The Exogenous Series gets to aCrossSectionalFactorPriorwhose observed factors read it, and every other estimator ignores it. The call passesdims = 1, because aReturnsResultholds its observations along the rows. The keyworddimshas no effect. - Record the observations that step 5 dropped with
shared_series_record. A reader that holdsrdthen pairs the rows ofXwith the correct observations. - Record
x_srcin the prior result withstamp_returns_source.
The Asset Panel is the third positional argument for the same reason that rd.F is the second. A wrapper prior holds no ReturnsResult. It can hold an estimator that fits on a panel only if the panel gets to the returns-matrix method of that estimator. Every returns-matrix method takes the argument. Every wrapper prior passes it unchanged to the estimator that it holds over the assets. An estimator that reads no panel ignores it.
Arguments
pe: Prior estimator.rd: Returns data that holds the asset returns, and the factor returns when the estimator reads them.strict: Passed to the returns-matrix method of the prior, where it decides if a scenario fill or a coverage peel raises in place of a warning.dims: Accepted and ignored. AReturnsResultholds its observations along the rows, so the call passesdims = 1. The method takes no other keyword that it does not list: an unknown keyword raises theMethodErrorof the language, and no estimator swallows it.cache_reg: Iftrue, a prior stores on its result the cache that its refit under new scenario weights reads: aCrossSectionalFactorPriorthe active mask and the Return Forecast history on its block, and anOpinionPoolingPriorthe rows ofpe1, its pooled weights and the cache ofpe2inpc. The refit of an entropy pooling prior around it then runs no regression and no opinion. Every other prior forwards it to the prior that it wraps. Default isfalse.
Validation
!isnothing(rd.X).- The rules of
benchmark_relative_returns. !isnothing(rd.F), whenneeds_factor_returns(pe) === true.- The rules of
assert_universe_axis_order. - The rules of
shared_series_rows.
Returns
pr::AbstractPriorResult: The prior result that the estimator computed.
Related
PortfolioOptimisers.prior — Method
prior(pr::AbstractPriorResult, args...; kwargs...)Return a prior result unchanged.
This method is the result half of PrE_Pr. A field with that bound calls prior once. Because of this method, a field that holds a fitted result needs no branch of its own. The method takes and ignores every other argument, so the call site is the same for an estimator and for a result.
Arguments
pr: Prior result.args...: Additional positional arguments (ignored).kwargs...: Additional keyword arguments (ignored).
Returns
pr::AbstractPriorResult: The input prior result, unchanged.
Related
PortfolioOptimisers.forward_prior — Function
forward_prior(
pr::AbstractPriorResult;
overrides...
) -> AbstractPriorResult
Forward a wrapped prior result, and name only the fields that the wrapper estimator changes or drops.
This function applies the composition rule of the prior results. A wrapper forwards a field when the value stays correct. It drops a field only when the forwarded value would state something false. The docstring of the estimator names every field that it drops.
The default is to forward, and the caller writes nothing for it. A wrapper cannot return fewer fields than the result that it wraps by mistake. The call site names every change. A new value is field = value, and a drop is field = nothing. A search of the source finds every drop. A hand-written call to the constructor names all fifteen fields of a LowOrderPrior, and does not show which of them it changes.
The rebuild goes through the keyword constructor of pr, see reconstruct_prior. Every @argcheck runs, and a forward that leaves the result inconsistent raises the same error as a hand-written constructor call. A caller can name only a field of pr. A forwarded or computed property is a view of a nested value, so a value for it can mean only a value for the field that holds it.
The three enforced bindings
Three fields are bound to the value of another field. To forward one of them past a change to its field states something false. The function enforces each binding. When the caller names the field on the left, the caller must also name the fields on the right, with a rebuilt value or with nothing.
sigmabindschol. Whencholis present, every consumer reads it in place ofsigma. A stalecholmakes the optimisation ignore the posterior covariance with no error.wbindsens,eoc,kldandow. These are diagnostics ofwand the counts of the moments thatwweights, so they are false for a differentw.rrbindso_X.o_Xsays thatXis a reconstruction, andrrrecords the projection that made it, so the constructor refuses one without the other. A drop of the factor block also drops the original returns.
A binding has no effect when the bound field is nothing, or when pr has no such field. No stale value is then present.
The constructor checks the rest. rr and fpr must be given together or not at all. The constructor checks w, chol, o_X, ss_gaps and pc against the shape of X and mu again.
What does not fit
FactorPrior and FactorBlackLittermanPrior lift a factor-axis prior into an asset-axis result. AugmentedBlackLittermanPrior merges two priors. None of the three forwards one wrapped result along its own axis. Each calls the constructor of its prior result directly, and does not use this function. Each still uses forward_prior on the factor block that it builds, because that is a usual forward of the factor prior.
Algorithm
- Collect the keyword overrides into the named tuple
patch. Whenpatchis empty, returnpritself, because a forward that changes nothing rebuilds nothing. - Compare the names of
patchwith the fields oftypeof(pr). Call the names that are not fieldsextra. Whenextrais not empty, raise anArgumentErrorthat names the fields ofpr. - Enforce the binding of
choltosigma. Whenpatchnamessigmaand notchol, andbound_field_is_stalesays thatprholds achol, raise aConflictingArgumentError. - Enforce the binding of
o_Xtorrwith the same three tests. A failure raises the secondConflictingArgumentError. - Enforce the binding of
ens,eoc,kldandowtow. Whenpatchnamesw, collect intostaleeach of the four thatpatchdoes not name and thatprholds. Raise whenstaleis not empty. - Rebuild
prthroughreconstruct_prior. It mergespatchoverprior_field_valuesand calls the keyword constructor, so every@argcheckoftypeof(pr)runs on the result.
Arguments
pr: Prior result that the wrapped estimator returned.overrides...: Field overrides. Each is a value to replace, ornothingto drop.
Validation
- When
overridesnamessigma, it also nameschol, unlesspr.cholisnothing. - When
overridesnamesw, it also names each ofens,eoc,kldandowthatprstates. - When
overridesnamesrr, it also nameso_X, unlesspr.o_Xisnothing. - Every name in
overridesis a field oftypeof(pr). - Every
@argcheckof the constructor oftypeof(pr).
Returns
pr::AbstractPriorResult: The wrapped result withoverridesapplied, orpritself whenoverridesis empty.
Examples
julia> pr = LowOrderPrior(; X = [0.01 0.02; 0.03 0.04], mu = [0.02, 0.03], sigma = [0.0004 0.0002; 0.0002 0.0003], chol = [0.02 0.01; 0.0 0.01415]);julia> PortfolioOptimisers.forward_prior(pr) === prtruejulia> pr2 = PortfolioOptimisers.forward_prior(pr; mu = [0.05, 0.06], chol = nothing);julia> (pr2.mu, pr2.chol, pr2.sigma === pr.sigma)([0.05, 0.06], nothing, true)julia> PortfolioOptimisers.forward_prior(pr; sigma = [0.0009 0.0001; 0.0001 0.0004])ERROR: ConflictingArgumentError: forwarding `chol` past a change to `sigma` would state something false: `chol` takes precedence over `sigma` at every consumer, so a stale factor makes the optimisation silently ignore the updated covariance. Pass `chol = nothing` to drop it, or a factor rebuilt from the new `sigma`.[...]Related
PortfolioOptimisers.reconstruct_prior — Function
reconstruct_prior(
pr::LowOrderPrior,
patch::NamedTuple
) -> LowOrderPrior
Rebuild a prior result through its keyword constructor, with the fields that patch names replaced.
Each prior result type has one method, because the method names the constructor of the type and does not find it by reflection. A generic method needs Base.typename(T).wrapper or a dependency on ConstructionBase, and neither gives more. prior_field_values already reads the field list from the type, so a result type that gains a field needs no change here. Only a new prior result type needs a method. Until it has one, a call raises a MethodError that names this function, and no generic code rebuilds a type that it does not know.
The rebuild runs all the checks of the type, which is the purpose of the call to the constructor. A patch that leaves the result inconsistent raises the same error as a hand-written constructor call. Keyword arguments have no order, so patch can name fields in any order.
This file defines these methods after both prior result types, because they dispatch on the concrete types.
Algorithm
Both methods do the same three steps. Only the constructor of step 3 is different.
- Read the fields of
printo a named tuple withprior_field_values, keyed in declaration order. - Merge
patchover that tuple. A field thatpatchnames takes the value of the patch, and every other field keeps the value ofpr. - Splat the merged tuple into the keyword constructor of the type,
LowOrderPriorin the first method andHighOrderPriorin the second. Return the prior result that it builds. Every@argcheckof that constructor runs on the merged values.
Arguments
pr: Prior result to rebuild.patch: Named tuple of field overrides. Every name must be a field oftypeof(pr).forward_priorchecks the names before the call, so its error names the rule, and not an unknown keyword.
Returns
pr::AbstractPriorResult: Reconstructed result of the same type.
Related
PortfolioOptimisers.port_opt_view — Method
port_opt_view(pr::Option{<:AbstractPriorEstimator}, ::Any, args...; kwargs...)
port_opt_view(pr::AbstractVector{<:Union{AbstractPriorResult, AbstractPriorEstimator}},
i, args...; kwargs...)Pass a prior estimator through a view unchanged, or view each member of a vector of priors.
The first method cuts nothing. It catches an estimator that has no view method of its own. Such an estimator holds a configuration and no data on an asset axis, so the view has nothing to cut. The subproblem fits the estimator again on its own universe. A @propagatable estimator, such as an EntropyPoolingPrior, has a more specific method, which cuts each field with a @vprop tag.
The second method views each member of the vector at i. A vector of priors is a field of one estimator, such as the opinions pes of an OpinionPoolingPrior, and each member reads the same asset axis as its parent. So the index goes to each member and never to the vector. A vector that returns unchanged keeps the sets of each member on every asset, and a fit of the view on the selected assets then fails. The method narrows the element type of the result with concrete_typed_array_if_abstract, so a vector of members of different types still meets the bound of its field.
The prior result types that hold data on the asset axis have their own methods. See port_opt_view on LowOrderPrior and on HighOrderPrior.
Algorithm
The method that Julia selects is the algorithm.
- A prior estimator, or
nothing: returnprunchanged. - A vector of priors: call
port_opt_viewon each member ati, withargs...andkwargs..., in the order ofpr. Narrow the element type of the result withconcrete_typed_array_if_abstract, and return it.
Arguments
pr: Prior estimator or result.i: The asset index. The first method does not read it, so that argument has no name.args...: Additional arguments. The first method ignores them, and the second method forwards them to each member.kwargs...: Additional keyword arguments. The first method ignores them, and the second method forwards them to each member.
Returns
pr: The input, unchanged, from the first method.v::AbstractVector: The views of the members, from the second method. It has the length ofpr.
Related
PortfolioOptimisers.port_opt_view — Method
port_opt_view(
pr::LowOrderPrior,
i,
args...
) -> Union{LowOrderPrior{T, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, Nothing, Nothing, Nothing} where {T, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10}, LowOrderPrior{T, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, <:AbstractReturnsSource, Nothing, Nothing} where {T, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10}, LowOrderPrior{T, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, Nothing, <:AbstractVector{Bool}, Nothing} where {T, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10}, LowOrderPrior{T, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, <:AbstractReturnsSource, <:AbstractVector{Bool}, Nothing} where {T, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10}}
Return a view of a LowOrderPrior restricted to assets at index i.
The view keeps every observation (Colon), because a fold cuts the observations before the prior fits.
The view forwards the factor block with no cut, because i indexes assets and fpr is a distribution over factors. Only rr is cut, on its asset axis.
Algorithm
- Cut the Cholesky factor to
ion its column axis. Call itchol. A prior result that holds none keepsnothing. - Cut the original returns matrix to
ion its asset axis. Call ito_X. A prior result that holds none keepsnothing.o_Xtakes the same cut asXin the next step, because the two have the same observations and the same assets. - Rebuild the prior result through its keyword constructor. Cut
Xandmutoi, andsigmatoion both axes. Takecholando_Xfrom the two steps above. Recurserrthroughport_opt_viewwithi. Forwardw,ens,eoc,kld,ow,fpr,x_srcandss_gapsunchanged, and droppc. Every@argcheckof the constructor thus runs on the view.
Arguments
pr: Prior result.i: Asset indices the view keeps.args...: Additional arguments (ignored).
Returns
pr::LowOrderPrior: The prior result restricted to the assets ati. It holds views, not copies.
Related
PortfolioOptimisers.port_opt_view — Method
port_opt_view(
pr::HighOrderPrior,
i,
args...
) -> HighOrderPrior
Return a view of a HighOrderPrior restricted to the assets at index i, with every moment matrix cut to match.
The view forwards the factor block with no cut, as on LowOrderPrior, because i indexes assets and fpr holds co-moments over factors. The view forwards the same object, so fpr.pr === pr.fpr stays true. The low order view forwards its own factor block in the same way.
Algorithm
- Make
idxwithfourth_moment_index_generatoragainst the full number of assets ofpr.idxis the fourth-moment index that addresses the co-moment matrices of the assets ati. - Cut the coskewness matrix to
ion its asset axis and toidxon its pair axis, withnothing_scalar_array_view_odd_order. Call itsk. A prior result that holds none keepsnothing. - Compute
Vagain from theskof step 2 and the cut returns matrix, withnegative_spectral_coskewness, theskmpofprand the count of the coskewness frommoment_observation_count.Vis a spectral quantity of the coskewness matrix, so the step builds it again and does not cut it. When step 2 gavenothing,Visnothing. - Build
D2,L2andS2again for the number of assets of the subproblem withdup_elim_sum_view, and do not cut them. WhenprholdsD2, take all three. When it holdsS2and noD2, takeL2andS2, and keepD2asnothing. When it holds neither, take none. - Rebuild the prior result through its keyword constructor. Recurse
prthroughport_opt_viewwithi, indexktbyidx, take the values of steps 2 to 4, and forwardskmp, the fieldeocandfprunchanged. Every@argcheckof the constructor thus runs on the view.
Arguments
pr: Prior result.i: Asset indices the view keeps.args...: Additional arguments (ignored).
Returns
pr::HighOrderPrior: The prior result restricted to the assets ati.
Related