Factory: private API
Utility functions
PortfolioOptimisers._wprop — Function
_wprop(
field,
args...;
kwargs...
) -> Union{DynamicAbstractWeights, AbstractWeights}
New value of an observation-weights field with a @wprop tag, in a call of factory.
When factory passes an ObsWeights argument, those weights replace the field. Otherwise, the field keeps its value. factory, which @fprop uses, is different. It recurses into sub-estimators, and it returns nothing and every value that is not an estimator with no change. A weights field that holds nothing and an optional sub-estimator that is nothing need different rules, so they use different functions.
Algorithm
The method that Julia selects is the algorithm, and the selection reads args..., never the field.
- The first threaded positional argument is an
ObsWeights: return that value, whatever the field held. - The first threaded positional argument is not an
ObsWeights, or no argument is threaded: returnfieldwith no change.
The value of the field never selects the branch. An incoming ObsWeights replaces a field that holds nothing and a field that holds weights in the same way. Without an incoming ObsWeights, both fields keep their values.
Related
PortfolioOptimisers.resolve_deferred_quantities — Function
resolve_deferred_quantities(x, pr::AbstractPriorResult, slv = nothing)Resolve every Deferred Quantity that x holds against a prior result. The result is a struct of the same type whose deferred slots hold plain values.
The function resolves the deferred state and nothing else. A slot that the caller did not state stays nothing, so the fallback of each consumer works as before. On the factory path, that fallback is sel. On the JuMP path, it is chol_sigma_selector and its siblings. The two paths are separate. A JuMP model builder reads the slots of the risk measure directly and never calls factory, so both entry points resolve.
With a prior result, the rule has two parts. The recursion into a container comes from deferred_slots, so a type that only holds children needs no method. A type that resolves a quantity of its own defines a method, which overrides the derived method. That method is per type and not per field, so it resolves together the slots that go together. For example, a deferred sigma gives chol from the same fit, so the pair never comes from two different sources.
The third argument, slv, is the effective solver, and a Calibration Rule in the same struct reads it. It holds the solver that the optimisation selected, so a rule resolves against one solver on both routes. On the factory route, the @cprop selection already put that solver on the struct, so the argument keeps its default. On the JuMP route, no selection runs, so set_risk_constraints! reads the solver from the estimator and passes it here. A type that holds a solver of its own selects it locally as sel(x.slv, slv), as it does for its observation weights. A type that holds no solver gives its rules no solver on either route.
Algorithm
The method that Julia selects is the algorithm. It is the method that deferred_slots derives for a container, or the hand-written method of a type that resolves a quantity of its own. Each method takes a prior result as its second argument. A second argument that is not a prior result raises a MethodError, because without a prior the function cannot fit anything, and no caller asks it to.
Related
PortfolioOptimisers.sel — Function
sel(risk_variable, source_variable)Select the value of a risk-measure slot, for the @pprop and @cprop tags that emit this call. The value of the measure, risk_variable, wins when it is present. Otherwise the call falls back to source_variable, which is a moment of the prior for @pprop and a value that the optimiser threads for @cprop. The types of the operands select the selector:
- A solver,
Slv_VecSlv, is selected here. The solver of the measure wins, and a measure with no solver takes the solver of the optimiser. - An uncertainty set,
UcSE_UcS, goes toucs_selector. - A Deferred Quantity or a Calibration Rule is kept, because a slot that the caller filled with the method that computes the value is a stated slot.
- Every other value, such as a moment, goes to
nothing_scalar_array_selector.
The Deferred-Quantity method exists because @propagatable runs the selection before resolve_deferred_quantities, so a @pprop slot that admits a Deferred Quantity still holds one here. The prior must not fill such a slot. The caller stated the method, and the resolution that follows replaces it with the value that the method gives. The same holds for a Calibration Rule.
A call with two nothing operands goes to nothing_scalar_array_selector and returns nothing. A JuMPOptimiser always carries a solver, so the pipeline never meets a slot of a solver with two nothing operands.
Related