Base Prior

PortfolioOptimisers.AbstractPriorEstimator — Type
abstract type AbstractPriorEstimator <: AbstractEstimator

Abstract 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 matrix observations × assets if the dims keyword does not exist or dims = 1, assets × observations when dims = 2.
  • F: Factor returns matrix, or nothing.
  • pnl: Optional AssetPanel, 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: Returns true when the carry fold of a CrossSectionalFactorPrior folds 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 field x_src::Option{<:AbstractReturnsSource}, which the inner constructor checks with PortfolioOptimisers.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: Returns true when 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 ┴ nothing

Related

source
PortfolioOptimisers.AbstractPriorResult — Type
abstract type AbstractPriorResult <: AbstractResult

Abstract 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: Rebuild pr through its own constructor with patch applied. forward_prior calls 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: Restrict pr to the assets at index i, 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.02

Related

source
PortfolioOptimisers.AbstractLowOrderPriorEstimator_A — Type
abstract type AbstractLowOrderPriorEstimator_A <: AbstractLowOrderPriorEstimator

Low 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

source
PortfolioOptimisers.AbstractLowOrderPriorEstimator_F — Type
abstract type AbstractLowOrderPriorEstimator_F <: AbstractLowOrderPriorEstimator

Low 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 no F raises a MethodError.

Related

source
PortfolioOptimisers.AbstractLowOrderPriorEstimator_AF — Type
abstract type AbstractLowOrderPriorEstimator_AF <: AbstractLowOrderPriorEstimator

Low 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 read F when the caller gives it.

Related

source
PortfolioOptimisers.AbstractHighOrderPriorEstimator — Type
abstract type AbstractHighOrderPriorEstimator <: AbstractPriorEstimator

Abstract 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 read F when the caller gives it.

Related

source
PortfolioOptimisers.AbstractHighOrderPriorEstimator_F — Type
abstract type AbstractHighOrderPriorEstimator_F <: AbstractHighOrderPriorEstimator

High 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 no F raises a MethodError.

Related

source
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} <: AbstractPriorResult

Carries 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 matrix observations × assets if the dims keyword does not exist or dims = 1, assets × observations when dims = 2.
  • o_X: The returns matrix of the caller when the X of the prior result is a different matrix, and nothing otherwise. The estimators that lift a factor-axis prior onto the asset axis overwrite X, with the reconstruction F * transpose(M) .+ transpose(b) or with scenarios of the factor model. o_X holds the asset returns that they received, over the same observations and the same assets. Read it as original_X, which is always a matrix, and not as this field.
  • mu: Expected returns vector assets × 1.
  • sigma: Covariance matrix assets × assets.
  • chol: Cholesky factorisation of the covariance matrix.
  • w: Observation weights of the fit of the prior, observations × 1, see ObsWeights, or nothing when the fit used no weights. It binds ens, eoc, kld and ow, which are diagnostics of it and counts of the moments that it weights, see forward_prior.
  • ens: Effective number of scenarios of the weights w, or nothing. An entropy pooling prior and an opinion pooling prior write exp(entropy(w)). It is a diagnostic of w, and w binds it, see forward_prior. It is not the count of the moments, which eoc states.
  • eoc: Effective number of observations of the moments, a tuple (T_mu, T_sigma) with one count for mu and one for sigma. An entry of nothing means size(X, 1). EmpiricalPrior writes the count of its me and of its ce from effective_observation_count. That is the Kish count of a weighted estimator, and the number of observations of the fit when a Scenario Cap max_scenarios keeps fewer rows in X. A pooling prior refits its prior under its weights w and keeps the counts of the refit. An estimator that reads w states the Kish count of w. w binds the field, see forward_prior. A wrapper forwards it. A consumer that needs a sample size reads it, and not the number of rows in X: the denoiser of a matrix that a prior assembles, a normal uncertainty set and a calibration rule.
  • kld: Kullback-Leibler divergence of w from 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 made w.
  • ow: The penalised opinion probabilities of the opinion pool that made the result, one entry per opinion, or nothing when no pool made it.
  • rr: Regression result.
  • fpr: Prior result over the factor axis, or nothing. Its X is 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, nothing or an AbstractReturnsSource. prior records 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. nothing means that the fit stated no source, or that the caller gave a returns matrix, so a reader of the Result reads X as raw returns. The outer problem of a meta-optimiser reads it, see outer_returns_source.
  • ss_gaps: One mark for each observation of the returns data that the prior read, true at an observation that the prior dropped for a Shared Series gap, or nothing when it dropped none. The rows of X are the last size(X, 1) observations that the marks keep, so a reader that holds the returns data finds the observation of each row, see shared_series_record. prior writes 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 of prior drops no observation, so it leaves nothing.
  • pc: The cache of the opinion pool that made the result, (; X, w, pe2), or nothing. X holds the rows of pe1 that the opinions read, or nothing when the pool reads the returns. w holds the pooled weights, and pe2 holds the cache of the result of pe2. A pool fitted with cache_reg = true stores it. An entropy pooling prior that wraps the pool reads it when it fits again, so no opinion runs again. Every other fit leaves it nothing.

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) -> LowOrderPrior

Keywords 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:

  • sigma binds chol. When chol is present, every consumer reads it in place of sigma, and a stale chol replaces the changed covariance with no error.
  • w binds ens, eoc, kld and ow. These are diagnostics and counts of the weights.
  • rr binds o_X. rr records the projection that made X from o_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, and sigma must be non-empty.
  • size(sigma, 1) == size(sigma, 2).
  • size(X, 2) == length(mu) == size(sigma, 1).
  • Every entry of sigma between two investable assets is finite. An investable asset has a finite mu and a finite variance. Raises an IsNonFiniteError.
  • If w is not nothing, !isempty(w) and length(w) == size(X, 1).
  • Each entry of eoc that is not nothing is finite and positive, through assert_moment_counts.
  • If kld is an AbstractVector, !isempty(kld).
  • If ow is not nothing, !isempty(ow).
  • rr and fpr must 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), and size(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 own w against its own X.
  • If o_X is not nothing, o_X !== X, size(o_X) == size(X), and rr is not nothing. o_X !== X tests identity, not equality. So o_X = copy(X) passes, and o_X = X raises an error. The two calls look the same, but only the first holds a matrix that a later change to X does not change. The check refuses a prior result whose original is the same object as its X. It does not refuse a matrix with equal values.
  • If chol is not nothing, !isempty(chol) and length(mu) == size(chol, 2).
  • The rules of assert_shared_series_gaps on ss_gaps.
  • If pc is not nothing, length(pc.w) == size(X, 1), and size(pc.X, 1) == size(X, 1) when pc.X is a matrix, through assert_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.
  • rr recurses through port_opt_view with i, which cuts the loadings on their asset axis.
  • X, o_X, mu, sigma and chol are cut to i on the asset axis. o_X takes the same cut as X, so the original returns of a subproblem are the returns of the caller for the assets of that subproblem.
  • w, ens, eoc, kld and ow pass through unchanged. They are on the observation axis, and i indexes assets.
  • fpr passes through unchanged, because it is a distribution over factors and not over assets. The view thus keeps rr and fpr together, as the rule of the factor block requires.
  • ss_gaps passes through unchanged. It is on the observation axis.
  • pc is 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 ┴ nothing

Related

source
PortfolioOptimisers.HighOrderPrior — Type
struct HighOrderPrior{__T_pr, __T_kt, __T_D2, __T_L2, __T_S2, __T_sk, __T_V, __T_skmp, __T_fpr} <: AbstractPriorResult

Carries 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 matrix assets^2 × assets^2.
  • D2: Duplication matrix.
  • L2: Elimination matrix.
  • S2: Summation matrix.
  • sk: Coskewness matrix assets × assets^2.
  • V: Sum of the negative spectral slices of the coskewness matrix assets × 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 of nothing means size(X, 1). The property pr.eoc of 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, or nothing. Its X is 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) -> HighOrderPrior

Keywords 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, L2 or S2 is given, all three must be given and not empty, with size(kt) == (N^2, N^2) and size(L2) == size(S2) == (div(N * (N + 1), 2), N^2).
  • If sk or V is given, both must be given and not empty, with size(sk) == (N, N^2) and size(V) == (N, N).
  • If the three matrices of the first rule and sk are given, D2 must be given and not empty, with size(D2) == size(transpose(L2)). D2 has no other rule. It is the one moment field that the constructor admits alone, and a HighOrderPrior that holds only D2 is valid.
  • If fpr is given, pr.fpr must be given, and fpr.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, so fpr === nothing always passes. The constructor of the factor block checks the inside of the block, such as its own shapes against its own N.

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.
  • pr recurses through port_opt_view with i, which cuts every low order field.
  • A fourth-moment index derived from i indexes kt, and i does not. kt is $N^2 \times N^2$ over ordered pairs of assets, so the asset index does not address it.
  • sk is cut by i on its asset axis, and by the same fourth-moment index on its pair axis.
  • V is computed again from the cut sk, and is not cut. It is a spectral quantity of the coskewness matrix, so the submatrix of V is not the V of the submatrix.
  • D2, L2 and S2 are 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.
  • skmp passes through unchanged. It is the matrix processing estimator that the new computation of V reads.
  • eoc passes through unchanged. It is on the observation axis, and i indexes assets.
  • fpr passes through unchanged, because it holds co-moments over factors and not over assets. 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.

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 ┴ nothing

Related

source
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

  1. Check that rd carries asset returns, so that the estimator does not receive nothing for X.
  2. When needs_factor_returns answers true, check that rd carries 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 about rd.F. Without it, the caller gets a MethodError from the inner estimator one call later.
  3. Check that every UniverseSets on the asset axis of the tree of pe names the columns of rd, in order, with assert_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.
  4. Read the source that pe states with returns_source. Call it x_src.
  5. Drop the observations of a Shared Series gap with shared_series_view. These are a gap of a vector benchmark under x_src = ExcessSource(), and a gap of the factor returns when needs_factor_returns answers true. Every field of rd loses the same observations, and every fixed observation weight in the tree of pe loses them too, through shared_series_estimator.
  6. Read the asset returns X with benchmark_relative_returns under x_src. X is rd.X, or rd.X - rd.B under ExcessSource().
  7. Call the returns-matrix method of the estimator with X, rd.F and rd.pnl. Pass rd.iv, rd.ivpa, rd.ne, rd.E, strict and cache_reg as keyword arguments. A wrapper prior passes its keyword arguments to the estimator that it holds. The Exogenous Series gets to a CrossSectionalFactorPrior whose observed factors read it, and every other estimator ignores it. The call passes dims = 1, because a ReturnsResult holds its observations along the rows. The keyword dims has no effect.
  8. Record the observations that step 5 dropped with shared_series_record. A reader that holds rd then pairs the rows of X with the correct observations.
  9. Record x_src in the prior result with stamp_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. A ReturnsResult holds its observations along the rows, so the call passes dims = 1. The method takes no other keyword that it does not list: an unknown keyword raises the MethodError of the language, and no estimator swallows it.
  • cache_reg: If true, a prior stores on its result the cache that its refit under new scenario weights reads: a CrossSectionalFactorPrior the active mask and the Return Forecast history on its block, and an OpinionPoolingPrior the rows of pe1, its pooled weights and the cache of pe2 in pc. 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 is false.

Validation

Returns

  • pr::AbstractPriorResult: The prior result that the estimator computed.

Related

source
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

source
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.

  • sigma binds chol. When chol is present, every consumer reads it in place of sigma. A stale chol makes the optimisation ignore the posterior covariance with no error.
  • w binds ens, eoc, kld and ow. These are diagnostics of w and the counts of the moments that w weights, so they are false for a different w.
  • rr binds o_X. o_X says that X is a reconstruction, and rr records 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

  1. Collect the keyword overrides into the named tuple patch. When patch is empty, return pr itself, because a forward that changes nothing rebuilds nothing.
  2. Compare the names of patch with the fields of typeof(pr). Call the names that are not fields extra. When extra is not empty, raise an ArgumentError that names the fields of pr.
  3. Enforce the binding of chol to sigma. When patch names sigma and not chol, and bound_field_is_stale says that pr holds a chol, raise a ConflictingArgumentError.
  4. Enforce the binding of o_X to rr with the same three tests. A failure raises the second ConflictingArgumentError.
  5. Enforce the binding of ens, eoc, kld and ow to w. When patch names w, collect into stale each of the four that patch does not name and that pr holds. Raise when stale is not empty.
  6. Rebuild pr through reconstruct_prior. It merges patch over prior_field_values and calls the keyword constructor, so every @argcheck of typeof(pr) runs on the result.

Arguments

  • pr: Prior result that the wrapped estimator returned.
  • overrides...: Field overrides. Each is a value to replace, or nothing to drop.

Validation

  • When overrides names sigma, it also names chol, unless pr.chol is nothing.
  • When overrides names w, it also names each of ens, eoc, kld and ow that pr states.
  • When overrides names rr, it also names o_X, unless pr.o_X is nothing.
  • Every name in overrides is a field of typeof(pr).
  • Every @argcheck of the constructor of typeof(pr).

Returns

  • pr::AbstractPriorResult: The wrapped result with overrides applied, or pr itself when overrides is 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

source
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.

  1. Read the fields of pr into a named tuple with prior_field_values, keyed in declaration order.
  2. Merge patch over that tuple. A field that patch names takes the value of the patch, and every other field keeps the value of pr.
  3. Splat the merged tuple into the keyword constructor of the type, LowOrderPrior in the first method and HighOrderPrior in the second. Return the prior result that it builds. Every @argcheck of 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 of typeof(pr). forward_prior checks 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

source
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.

  1. A prior estimator, or nothing: return pr unchanged.
  2. A vector of priors: call port_opt_view on each member at i, with args... and kwargs..., in the order of pr. Narrow the element type of the result with concrete_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 of pr.

Related

source
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

  1. Cut the Cholesky factor to i on its column axis. Call it chol. A prior result that holds none keeps nothing.
  2. Cut the original returns matrix to i on its asset axis. Call it o_X. A prior result that holds none keeps nothing. o_X takes the same cut as X in the next step, because the two have the same observations and the same assets.
  3. Rebuild the prior result through its keyword constructor. Cut X and mu to i, and sigma to i on both axes. Take chol and o_X from the two steps above. Recurse rr through port_opt_view with i. Forward w, ens, eoc, kld, ow, fpr, x_src and ss_gaps unchanged, and drop pc. Every @argcheck of 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 at i. It holds views, not copies.

Related

source
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

  1. Make idx with fourth_moment_index_generator against the full number of assets of pr. idx is the fourth-moment index that addresses the co-moment matrices of the assets at i.
  2. Cut the coskewness matrix to i on its asset axis and to idx on its pair axis, with nothing_scalar_array_view_odd_order. Call it sk. A prior result that holds none keeps nothing.
  3. Compute V again from the sk of step 2 and the cut returns matrix, with negative_spectral_coskewness, the skmp of pr and the count of the coskewness from moment_observation_count. V is a spectral quantity of the coskewness matrix, so the step builds it again and does not cut it. When step 2 gave nothing, V is nothing.
  4. Build D2, L2 and S2 again for the number of assets of the subproblem with dup_elim_sum_view, and do not cut them. When pr holds D2, take all three. When it holds S2 and no D2, take L2 and S2, and keep D2 as nothing. When it holds neither, take none.
  5. Rebuild the prior result through its keyword constructor. Recurse pr through port_opt_view with i, index kt by idx, take the values of steps 2 to 4, and forward skmp, the field eoc and fpr unchanged. Every @argcheck of 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 at i.

Related

source