Nested Clustered: private API

PortfolioOptimisers.nested_clustered_td_defaults — Function
nested_clustered_td_defaults(

) -> @NamedTuple{pe::EmpiricalPrior{PortfolioOptimisersCovariance{Covariance{SimpleExpectedReturns{Nothing, Nothing, Nothing}, GeneralCovariance{SimpleCovariance, Nothing, Nothing}, FullMoment, Nothing, Nothing, Nothing}, MatrixProcessing{Posdef{UnionAll, @NamedTuple{}}, Nothing, Nothing, Nothing, NTuple{4, Symbol}}, Nothing}, SimpleExpectedReturns{Nothing, Nothing, Nothing}, Nothing, Nothing, Nothing, Nothing, Nothing}, cle::ClustersEstimator{PortfolioOptimisersCovariance{Covariance{SimpleExpectedReturns{Nothing, Nothing, Nothing}, GeneralCovariance{SimpleCovariance, Nothing, Nothing}, FullMoment, Nothing, Nothing, Nothing}, MatrixProcessing{Posdef{UnionAll, @NamedTuple{}}, Nothing, Nothing, Nothing, NTuple{4, Symbol}}, Nothing}, Distance{Nothing, CanonicalDistance}, HClustAlgorithm{Symbol}, OptimalNumberClusters{Nothing, SecondOrderDifference{StandardisedValue{MeanValue{Nothing}, StdValue{Nothing, Bool}}}}, Nothing}, opti::NoDefault, opto::NoDefault, wf::IterativeWeightFinaliser{Int64}}

Return the static defaults of the NestedClustered fields that can hold a TimeDependent schedule.

The substitution pass of the constructor and time_dependent_field_defaults both read it. opti and opto have no keyword default, so they map to NoDefault, and a schedule in them needs its own default to run outside a fold loop. pe, cle and wf map to their keyword defaults. The tuple omits wb, fees, sets and fb, whose keyword default is nothing.

Related

source
PortfolioOptimisers.reset_time_dependent_estimator — Method
reset_time_dependent_estimator(
    opt::NestedClustered
) -> NestedClustered

Replace the TimeDependent schedules in the fields of opt with their static defaults.

The method does not recurse into opti, opto or fb. A solve of opt outside a fold loop gives the schedules inside opti to its inner cross-validation, and each solve of a wrapped optimiser outside the folds resets its own schedules. A schedule that binds :nearest in a field that the inner fold loop reads stays too, see inner_fold_fields. A reset of that schedule puts its default in place before the inner cross-validation reads it.

source
PortfolioOptimisers.assert_rc_pl — Method
assert_rc_pl(opt)

Assert that a FactorRiskContribution holds no precomputed phylogeny constraint in frc_ple.

A precomputed phylogeny constraint states its matrix over one fixed universe, and a nested optimiser views that universe. The method for any other value does nothing.

Arguments

  • opt: An optimiser.

Validation

  • opt.frc_ple holds no AbstractPhylogenyConstraintResult, directly, in a vector or in a TimeDependent schedule. The method throws an ArgumentError otherwise.

Returns

  • nothing.

Related

source
PortfolioOptimisers.stated_constraint_space_basis — Function
stated_constraint_space_basis(space::FactorSpace) -> Bool
stated_constraint_space_basis(ece::ExposureConstraintEstimator) -> Bool
stated_constraint_space_basis(lcse::AbstractVector) -> Bool
stated_constraint_space_basis(td::TimeDependent) -> Bool
stated_constraint_space_basis(::Any) -> Bool

Report whether an lcse slot holds a precomputed basis, so that an outer optimiser can refuse it.

A stated basis holds loadings indexed by the assets of one fixed universe. An inner solve takes a slice of the universe, and port_opt_view takes the same slice of the basis, so an inner optimiser can hold a stated basis. An outer solve replaces the universe with the names of the clusters, and no slice of the asset loadings follows that change. So an outer optimiser refuses a stated basis, as it refuses a precomputed opt.re and opt.rba.re.

The predicate is false for every other value, and for a space whose re is an estimator. An estimator fits again against the universe it receives, so the error message names it as the remedy. A vector and the entries and default of a TimeDependent schedule are read entry by entry.

Related

source
PortfolioOptimisers.assert_external_lcse — Function
assert_external_lcse(opt) -> Nothing

Assert that the lcse slot of an outer optimiser holds no precomputed basis.

The JuMP optimiser, the RiskBudgetingOptimiser and the FactorRiskContribution methods of assert_external_optimiser apply it. stated_constraint_space_basis states why an outer solve refuses a basis that an inner solve views.

Validation

  • stated_constraint_space_basis(opt.opt.lcse) is false. The function throws an ArgumentError otherwise.

Related

source
PortfolioOptimisers.assert_estimated_prior — Function
assert_estimated_prior(pe, name::AbstractString) -> Nothing

Assert that a pe slot holds a prior estimator, and no precomputed prior, directly or through a TimeDependent schedule.

A prior result is a fit over the rows that it saw. A fold loop that reads one gives every fold the same moments, so the test rows of each fold enter its fit. The outer solve of a nested optimiser cannot fit it again over the synthetic assets either. holds_precomputed reads the slot, and each vector entry and the default of a schedule. A callable schedule passes, because its values exist only when it runs.

Arguments

  • pe: The value of the pe slot.
  • name: The path of the slot, as the error message names it.

Validation

  • Neither pe, nor a vector entry of a schedule in pe, nor the default of that schedule, is an AbstractPriorResult. The function throws an ArgumentError that names name otherwise.

Returns

  • nothing.

Related

source
PortfolioOptimisers.holds_precomputed — Function
holds_precomputed(x, ::Type{T}) -> Bool

Report whether a slot of an estimator holds a value of type T.

The predicate reads the value in the slot and each entry of a vector in the slot. For a TimeDependent schedule in the slot, it reads each vector entry and the default, through time_dependent_entries. A callable schedule has no value until it runs, so the predicate reads its default alone. The refusals of a nested optimiser pass a result type as T, so one predicate finds a precomputed result in each shape that a slot accepts. FactorRiskContribution passes the two semidefinite kinds of a phylogeny, so it finds one in each shape that opt.ple accepts.

Arguments

  • x: The value of the slot.
  • T: The type to find.

Returns

  • true when x, an entry of a vector in x, or an entry of a schedule in x is a T. false otherwise.

Related

source
PortfolioOptimisers.assert_external_optimiser — Method
assert_external_optimiser(opt::ClusteringOptimisationEstimator)
assert_external_optimiser(opt::JuMPOptimisationEstimator)
assert_external_optimiser(opt::RiskBudgetingOptimiser)
assert_external_optimiser(opt::FactorRiskContribution)
assert_external_optimiser(opt::VecOptE_Opt_TD)
assert_external_optimiser(opt::NestedClustered)

Assert that an optimiser can solve the inter-cluster problem of a NestedClustered, or fit again in each fold of its cross-validation.

The outer problem replaces the assets with one synthetic asset for each cluster. So the outer optimiser estimates its prior from the synthetic returns, and no input can be a result over the original assets. Each method also applies the refusals of assert_internal_optimiser. NestedClustered applies this function to opti when cv is present, because each fold fits opti again, and a result fitted over every row puts the test rows of each fold into its fit.

Arguments

  • opt: The outer optimiser, or the inner optimiser of a cross-validated NestedClustered.

Validation

  • Each method except the vector method: the pe slot passes assert_estimated_prior. The slot is opt.opt.pe, or opt.pe for a NestedClustered.
  • A JuMP optimiser, a RiskBudgetingOptimiser and a FactorRiskContribution: opt passes assert_external_lcse.
  • A RiskBudgetingOptimiser: no FactorRiskBudgeting in opt.rba, or in an entry or the default of a schedule in opt.rba, holds an AbstractLoadingsRegressionResult in re.
  • A FactorRiskContribution: opt.re holds no AbstractLoadingsRegressionResult.
  • A NestedClustered: opt.cle holds no AbstractClusteringResult, and opt.opto passes this function. When opt.opti is not opt.opto, it passes assert_internal_optimiser. When opt.cv is present, opt.opti passes this function.
  • A vector of optimisers: each entry passes.

The methods throw an ArgumentError otherwise.

Returns

  • nothing.

Related

source
PortfolioOptimisers.assert_rc_variance — Function
assert_rc_variance(opt)

Assert that no Variance of a JuMP optimiser holds a LinearConstraint in its rc field.

A precomputed risk contribution constraint states its rows over the full asset universe. A nested optimiser views that universe onto a cluster, or replaces it with the synthetic assets of the clusters, and no view of such a row keeps the assets of one group alone. The constraint also breaks a factor risk contribution, which reads the same rows. The method for any other value does nothing.

Arguments

  • opt: An optimiser. The method for a risk-based JuMP optimiser reads opt.r, as one risk measure or as a vector of risk measures.

Validation

  • No Variance in opt.r holds a LinearConstraint in rc. The method throws an ArgumentError otherwise.

Returns

  • nothing.

Related

source
PortfolioOptimisers._update_asset_sets — Function
_update_asset_sets(
    nco::NestedClustered,
    rdo::ReturnsResult
) -> NestedClustered

Rebuild the asset sets of the outer optimiser over the names of the synthetic assets.

The outer optimiser of a NestedClustered sees one synthetic asset for each cluster, and the outer returns result rdo carries their names, _1, _2, …. The method writes these names into the xkey entry of the UniverseSets of the outer optimiser. A constraint or a bound of the outer optimiser then names a cluster by the name of its synthetic asset, for example _1 >= 0.3.

Algorithm

  1. When nco.opto has an opt field whose sets is present, and the xkey entry of those sets is not the vector rdo.nx itself, copy the dictionary of the sets to ndict and set ndict[xkey] = rdo.nx. Return nco with ndict in nco.opto.opt.sets.
  2. Otherwise, when nco.opto has a sets field that meets the same condition, do step 1 on nco.opto.sets.
  3. Otherwise, return nco unchanged.

The method copies the dictionary, so the UniverseSets of the caller does not change.

Arguments

  • nco::NestedClustered: The nested clustered optimiser.
  • rdo::ReturnsResult: Outer returns result, whose nx holds the names of the synthetic assets.

Returns

  • nco::NestedClustered: The optimiser, with the asset sets of nco.opto rebuilt over rdo.nx, or nco unchanged by step 3.

Related

source