Nested Clustered: private API
PortfolioOptimisers.RiskBudgetingOptimiser — Type
const RiskBudgetingOptimiser = Union{RiskBudgeting, RelaxedRiskBudgeting}Group the two JuMP optimisers that carry a risk budget algorithm in rba.
assert_external_optimiser dispatches on the group, because a FactorRiskBudgeting in rba holds a regression, and an outer optimiser must estimate that regression over the synthetic assets.
Related
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
PortfolioOptimisers.is_time_dependent — Method
is_time_dependent(opt::NestedClustered) -> Any
Return true when a field of opt holds a TimeDependent schedule, or when opti, opto or fb holds one at any depth.
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.
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_pleholds noAbstractPhylogenyConstraintResult, directly, in a vector or in aTimeDependentschedule. The method throws anArgumentErrorotherwise.
Returns
nothing.
Related
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) -> BoolReport 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
PortfolioOptimisers.assert_external_lcse — Function
assert_external_lcse(opt) -> NothingAssert 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)isfalse. The function throws anArgumentErrorotherwise.
Related
PortfolioOptimisers.assert_estimated_prior — Function
assert_estimated_prior(pe, name::AbstractString) -> NothingAssert 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 thepeslot.name: The path of the slot, as the error message names it.
Validation
- Neither
pe, nor a vector entry of a schedule inpe, nor thedefaultof that schedule, is anAbstractPriorResult. The function throws anArgumentErrorthat namesnameotherwise.
Returns
nothing.
Related
PortfolioOptimisers.holds_precomputed — Function
holds_precomputed(x, ::Type{T}) -> BoolReport 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
truewhenx, an entry of a vector inx, or an entry of a schedule inxis aT.falseotherwise.
Related
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-validatedNestedClustered.
Validation
- Each method except the vector method: the
peslot passesassert_estimated_prior. The slot isopt.opt.pe, oropt.pefor aNestedClustered. - A JuMP optimiser, a
RiskBudgetingOptimiserand aFactorRiskContribution:optpassesassert_external_lcse. - A
RiskBudgetingOptimiser: noFactorRiskBudgetinginopt.rba, or in an entry or thedefaultof a schedule inopt.rba, holds anAbstractLoadingsRegressionResultinre. - A
FactorRiskContribution:opt.reholds noAbstractLoadingsRegressionResult. - A
NestedClustered:opt.cleholds noAbstractClusteringResult, andopt.optopasses this function. Whenopt.optiis notopt.opto, it passesassert_internal_optimiser. Whenopt.cvis present,opt.optipasses this function. - A vector of optimisers: each entry passes.
The methods throw an ArgumentError otherwise.
Returns
nothing.
Related
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 readsopt.r, as one risk measure or as a vector of risk measures.
Validation
- No
Varianceinopt.rholds aLinearConstraintinrc. The method throws anArgumentErrorotherwise.
Returns
nothing.
Related
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
- When
nco.optohas anoptfield whosesetsis present, and thexkeyentry of those sets is not the vectorrdo.nxitself, copy the dictionary of the sets tondictand setndict[xkey] = rdo.nx. Returnncowithndictinnco.opto.opt.sets. - Otherwise, when
nco.optohas asetsfield that meets the same condition, do step 1 onnco.opto.sets. - Otherwise, return
ncounchanged.
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, whosenxholds the names of the synthetic assets.
Returns
nco::NestedClustered: The optimiser, with the asset sets ofnco.optorebuilt overrdo.nx, orncounchanged by step 3.
Related