Programme Allocation Set: private API
PortfolioOptimisers.name_keyed — Function
name_keyed(x)
name_keyed(x::AbstractVector)Tells whether a constraint slot holds an estimator that resolves its names over sets.
The owner of such a slot must carry sets. The estimators are every AbstractWeightBoundsEstimator, LinearConstraintEstimator, ExposureConstraintEstimator, ThresholdEstimator, AssetSetsMatrixEstimator and TurnoverEstimator. A ScoreWeightBounds is the exception: it is keyed by name only when its val or its static bounds name assets. A vector is keyed by name when one of its entries is.
Returns
::Bool:truewhen the slot holds such an estimator.
Related
name_keyed(wb::ScoreWeightBounds) -> BoolTell whether a ScoreWeightBounds resolves a name over sets.
A number or a vector of numbers in val names no asset, so it resolves without sets. A pair, a dictionary, a vector of pairs or a value algorithm in val reads the universe of sets. The estimator also needs sets when its static bounds wb do.
Returns
::Bool:truewhenvalis not a number or a vector of numbers, or whenwb.wbis keyed by name.
Related
PortfolioOptimisers.exposure_keyed — Function
exposure_keyed(x)
exposure_keyed(x::AbstractVector)Tells whether a linear-constraint slot holds an ExposureConstraintEstimator.
An exposure estimator writes its rows in the basis of the factors, and the loadings of a factor prior take them to the assets. So such a slot resolves on the head's rows at every step, and not once per fold. A vector is keyed by exposure when one of its entries is.
Returns
::Bool:truewhen the slot holds an exposure estimator.
Related
PortfolioOptimisers.fitted_on_rows — Function
fitted_on_rows(x)
fitted_on_rows(x::AbstractVector)Tells whether a centrality or phylogeny slot holds an estimator that the set fits on the head's rows at every step.
A precomputed LinearConstraint, IntegerPhylogeny or SemiDefinitePhylogeny reads no rows. A vector reads the rows when one of its entries does.
Returns
::Bool:truewhen the slot holds a centrality or phylogeny estimator.
Related
PortfolioOptimisers.bounds_read_rows — Function
bounds_read_rows(wb)
bounds_read_rows(wb::AbstractWeightBoundsEstimator)
bounds_read_rows(wb::WeightBoundsEstimator)Tells whether the weight bounds of a programme set read the head's rows.
A WeightBounds, a WeightBoundsEstimator and nothing read no rows, so resolve_allocation_set resolves them once per fold. Every other AbstractWeightBoundsEstimator, such as a ScoreWeightBounds, can read the returns of the fit. Stage 2, resolve_constraint_block, resolves it at each step on the head's rows, so it reads no row after the step.
Returns
::Bool:truewhen the bounds read the rows.
Related
PortfolioOptimisers.assert_mirror_base — Function
assert_mirror_base(base::AbstractVector, s::AbstractVector)
Refuses a barrier mirror step that has a base at or below zero.
The error names the scaled gradient s that gave the base.
Validation
all(> 0, base). ADomainErroris thrown otherwise.
Returns
nothing.
Related
PortfolioOptimisers.barrier_projection — Function
barrier_projection(
b::AbstractVector,
phi,
wb::WeightBounds
) -> Any
Projects a raw step onto a bounded set in a barrier geometry, through the scalar root of the budget.
The root is the budget multiplier mu at which Σ_i clip(phi(b_i + mu), lb_i, ub_i) is one. Here b is the mirror image of the raw step and phi is the inverse mirror map. A base at or below zero puts its asset at its cap. phi decreases on positive bases and has no bound as the base falls to zero, so the clipped budget does not increase in mu and has no jump. A zero raw entry has the base Inf, and it stays at its floor. TsallisProjection and LogBarrierProjection state the root as $\boldsymbol{w}(\theta)$.
Algorithm
- Check that
Σ lb ≤ 1 ≤ Σ ubwithassert_feasible_bounds. - When the floors sum to one, return
lb. - Collect the finite entries of
binfinite, and refuse an emptyfinite. - Write the clipped budget
f(mu). An asset whose baseb_i + muis at or below zero takesub_i, and every other asset takesclamp(phi(b_i + mu), lb_i, ub_i). - Set the lower end
lo = -maximum(finite), at which every finite entry is at its cap. Refusef(lo) < 1. - Find the upper end
hiwithbarrier_upper_bracket. - Bisect
[lo, hi]formuwithbounded_root. - Return the clipped allocation at
mu.
Arguments
b: The mirror image of the raw step,Infat a zero entry.phi: The inverse mirror map of a positive base.wb: The resolved bounds.
Validation
Σ lb ≤ 1 ≤ Σ ub. AnArgumentErroris thrown otherwise.- At least one raw entry is positive. A
DomainErroris thrown otherwise. - The caps of the positive entries and the floors of the zero entries reach the budget. A
DomainErroris thrown otherwise, because a zero entry stays at its floor under a barrier.
Returns
w'::Vector: The projected allocation, a new vector.
Related
PortfolioOptimisers.barrier_upper_bracket — Function
barrier_upper_bracket(f, lo) -> Any
Finds the upper end of the bracket of a barrier root, a positive multiplier above lo at which the clipped budget is at most one.
The loop stops, because the clipped budget tends to Σ lb < 1 as the multiplier grows. barrier_projection returns lb before it calls this function when Σ lb = 1.
Algorithm
- Start from
hi = max(lo, 0) + 1. - Double
hiwhilef(hi) > 1. - Return
hi.
Arguments
f: The clipped budget as a function of the multiplier, non-increasing.lo: The lower end of the bracket.
Returns
hi: The upper end of the bracket.
Related
PortfolioOptimisers.assert_barrier_raw_step — Function
assert_barrier_raw_step(q::AbstractVector, wb::WeightBounds)
Refuses, for a barrier geometry, a raw step with a negative or non-finite entry, and a bound with a negative floor.
The potential of a barrier geometry is undefined below zero.
Validation
- Every entry of
qis finite and non-negative. ADomainErroris thrown otherwise. all(>= 0, wb.lb). ADomainErroris thrown otherwise.
Returns
nothing.
Related
PortfolioOptimisers.assert_geometry_admits_set — Function
assert_geometry_admits_set(proj::AbstractProjectionGeometry, set::AbstractAllocationSet)Refuses a negative lower bound under a geometry whose potential is undefined below zero.
The head calls this function at its construction, with the geometry of its rule and its set. The entropic, Tsallis and log-barrier geometries refuse a negative bound. This function refuses a bound that is a value, through assert_geometry_admits_bounds. The projection refuses a bound that an estimator resolves. The Euclidean, Gram and diagonal geometries admit a negative bound, so a long-short rule needs no other set.
Validation
- With a
WeightBoundsinset.wb: the rules ofassert_geometry_admits_bounds.
Returns
nothing.
Related
PortfolioOptimisers.assert_geometry_admits_bounds — Function
assert_geometry_admits_bounds(proj::AbstractProjectionGeometry, wb::WeightBounds)Refuses a resolved bound with a negative floor under a geometry whose potential is undefined below zero.
assert_geometry_admits_set calls it at the construction of the head, on a bound that is a value. The projection programme of project calls it at each step, on the bound that the step resolves, before the solve. The entropic, Tsallis and log-barrier geometries refuse a negative floor, and every other geometry admits it.
Validation
- Under
EntropicProjection,TsallisProjectionorLogBarrierProjectionwith anlbthat is a number or a vector:all(>= 0, lb). ADomainErroris thrown otherwise.
Returns
nothing.
Related
PortfolioOptimisers.reader_frames — Method
reader_frames(set::ProgrammeAllocationSet, path::AbstractString, refit::Bool) -> ReturnsFramesWalk the readers of a ProgrammeAllocationSet for the group of the head that holds it.
The set holds no source of its own. Its prior pe, each graph slot in cte and ple, the regression of each exposure slot in lcse, and the readers inside its measures are the outermost readers of the head's rows, so the walk counts each one. field_frames walks every field, and it enters the ConstraintBlock in cbe through reader_frames(cbe::ConstraintBlock, path, refit). So the path of a slot passes through the block, as "set.cbe.ple". The walk reads the refit rule of the set's own prior, because a regression reader of the set reads the loadings of that prior, see refits_regression.
Arguments
set: The programme set.path: The path of the value from the head, for example"pe","cle"or"r[2].pe". A warning names a reader by its path.refit:truewhen a regression reader atx_src = nothingin the group fits its regression on the raw returns data.refits_regressionfinds the value. The set ignores it and reads the rule of its own prior.
Returns
fr::ReturnsFrames: The frames that the set adds to the group.
Related