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: true when the slot holds such an estimator.

Related

source
name_keyed(wb::ScoreWeightBounds) -> Bool

Tell 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: true when val is not a number or a vector of numbers, or when wb.wb is keyed by name.

Related

source
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: true when the slot holds an exposure estimator.

Related

source
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: true when the bounds read the rows.

Related

source
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). A DomainError is thrown otherwise.

Returns

  • nothing.

Related

source
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

  1. Check that Σ lb ≤ 1 ≤ Σ ub with assert_feasible_bounds.
  2. When the floors sum to one, return lb.
  3. Collect the finite entries of b in finite, and refuse an empty finite.
  4. Write the clipped budget f(mu). An asset whose base b_i + mu is at or below zero takes ub_i, and every other asset takes clamp(phi(b_i + mu), lb_i, ub_i).
  5. Set the lower end lo = -maximum(finite), at which every finite entry is at its cap. Refuse f(lo) < 1.
  6. Find the upper end hi with barrier_upper_bracket.
  7. Bisect [lo, hi] for mu with bounded_root.
  8. Return the clipped allocation at mu.

Arguments

  • b: The mirror image of the raw step, Inf at a zero entry.
  • phi: The inverse mirror map of a positive base.
  • wb: The resolved bounds.

Validation

  • Σ lb ≤ 1 ≤ Σ ub. An ArgumentError is thrown otherwise.
  • At least one raw entry is positive. A DomainError is thrown otherwise.
  • The caps of the positive entries and the floors of the zero entries reach the budget. A DomainError is thrown otherwise, because a zero entry stays at its floor under a barrier.

Returns

  • w'::Vector: The projected allocation, a new vector.

Related

source
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

  1. Start from hi = max(lo, 0) + 1.
  2. Double hi while f(hi) > 1.
  3. 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

source
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 q is finite and non-negative. A DomainError is thrown otherwise.
  • all(>= 0, wb.lb). A DomainError is thrown otherwise.

Returns

  • nothing.

Related

source
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

Returns

  • nothing.

Related

source
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

Returns

  • nothing.

Related

source
PortfolioOptimisers.reader_frames — Method
reader_frames(set::ProgrammeAllocationSet, path::AbstractString, refit::Bool) -> ReturnsFrames

Walk 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: true when a regression reader at x_src = nothing in the group fits its regression on the raw returns data. refits_regression finds 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

source