Concentration limit generation
PortfolioOptimisers.ConcentrationLimitEstimator — Type
struct ConcentrationLimitEstimator{__T_t, __T_c, __T_s, __T_set, __T_pos, __T_alg} <: AbstractConstraintEstimatorConfigures a concentration rule, whose positions can be written as issuer names that resolve against a universe.
A concentration rule caps each position at c, and limits the sum of the positions over the threshold t to s. The UCITS rule, the "5/10/40 rule" of Art. 52(2) of Directive 2009/65/EC, is the default: a fund holds at most 10 % of its assets in one issuer, and the issuers over 5 % sum to at most 40 %. The weight bounds give the cap alone. The limit of the sum depends on which positions are over t, so no linear constraint gives it.
concentration_limit_constraints resolves the estimator to a ConcentrationLimit. It reads the positions from set. With set = nothing, each asset is its own position. An AssetSetsMatrixEstimator groups the assets by a key of sets.dict, such as the issuer of each asset. Then the cap is on the issuer, which is what the directive states, and two share classes of one issuer are one position.
The exceptions of Art. 52(3) to 52(5) of the directive are more rules, not more fields of one rule. The field on of AssetSetsMatrixEstimator gives each rule its issuers. A vector of rules goes in the slot conc of ConstraintBlock, and the group constraints give the limit of a government issuer.
sets = UniverseSets(; dict = Dict("nx" => ["C1", "C2", "K1", "G1"], "nx_issuer" => ["Acme", "Acme", "BankX", "DE"], "ucits_standard" => ["C1", "C2"], "ucits_covered" => ["K1"]))conc = [ConcentrationLimitEstimator(; set = AssetSetsMatrixEstimator(; val = "nx_issuer", on = "ucits_standard")), ConcentrationLimitEstimator(; c = 0.25, s = 0.8, set = AssetSetsMatrixEstimator(; val = "nx_issuer", on = "ucits_covered"))]lcse = LinearConstraintEstimator(; val = "G1 <= 0.35")The clustering and the naive optimisers take the rule through the block of a JuMPWeightFinaliser. concentration_margins checks the weights of any optimiser against the rule.
Fields
t: Threshold of a large position. A position overtcounts towards the sum limits. The UCITS value is0.05.
c: Cap on each position. The UCITS value is0.10. It is a cap on the issuer whensetgroups the assets by issuer.
s: Limit of the sum of the positions overt. The UCITS value is0.40.
set: The positions that the rule reads.nothingmakes each asset its own position. AnAssetSetsMatrixEstimatoror a membership matrix makes each row of the matrix one position, such as one issuer, so two share classes of one issuer are one position.
pos: Reading of a position with a short side:GrossPosition(),NetPosition()orLongPosition(). On a long-only book the three readings are the weights.
alg: Form of the rule:ExactConcentration(), the mixed-integer rule itself, orSumLargestConcentration(), a linear form that is stricter than the rule.
Constructors
ConcentrationLimitEstimator(; t::Number = 0.05, c::Number = 0.1, s::Number = 0.4, set::Option{<:MatNum_ASetMatE} = nothing, pos::AbstractPositionReading = GrossPosition(), alg::AbstractConcentrationAlgorithm = ExactConcentration()) -> ConcentrationLimitEstimatorKeywords correspond to the struct's fields.
Validation
- The rules of
assert_concentration_limitfort,cands.
View parameters
port_opt_view takes the view of these @vprop fields at the selected indices:
set: A membership matrix keeps the columns of the selected assets. AnAssetSetsMatrixEstimatorstays unchanged, and it resolves against the universe of the view.
Examples
julia> ConcentrationLimitEstimator(; set = AssetSetsMatrixEstimator(; val = "nx_issuer"))ConcentrationLimitEstimator t ┼ Float64: 0.05 c ┼ Float64: 0.1 s ┼ Float64: 0.4 set ┼ AssetSetsMatrixEstimator │ val ┼ String: "nx_issuer" │ on ┴ nothing pos ┼ GrossPosition() alg ┴ ExactConcentration()Related
PortfolioOptimisers.ConcentrationLimit — Type
struct ConcentrationLimit{__T_t, __T_c, __T_s, __T_set, __T_pos, __T_alg} <: AbstractConstraintResultCaps each position at c, and limits the sum of the positions over the threshold t to s.
This is the resolved form of ConcentrationLimitEstimator, whose docstring states the rule and the directive that it comes from. The positions are the rows of set, or the assets when set is nothing. The slot conc of ConstraintBlock takes one rule or a vector of rules, and set_concentration_constraints! adds each rule to the model.
Mathematical definition
The form ExactConcentration states the rule with one binary for each position:
\[\begin{align} x_j &\leq t + (c - t)\, z_j\,, \\ y_j &\geq x_j - c\,(1 - z_j)\,,\quad y_j \geq 0\,, \\ \sum_{j=1}^{M} y_j &\leq s\,,\quad \boldsymbol{z} \in \{0, 1\}^{M}\,. \end{align}\]
Where:
- $x_j$: Position $j$, row $j$ of
settimes the reading of the weights thatposgives. - $z_j$: Binary that says that position $j$ is over $t$.
- $y_j$: The part of position $j$ that counts towards the sum.
- $t$, $c$, $s$: The threshold, the cap and the limit of the sum.
- $M$: The number of positions.
When $z_j = 0$, the position is at most $t$, and $y_j$ can be zero. When $z_j = 1$, the position is at most $c$, and $y_j \geq x_j$. So the feasible set is the rule itself. A solver has no reason to set $z_j = 1$ for a small position, because that only adds to the sum. The binary is not the held bit of HeldIndicators or LongShortIndicators, because "held" and "over $t$" are two different facts.
The form SumLargestConcentration states a stricter rule with no binary.
Fields
t: Threshold of a large position. A position overtcounts towards the sum limits. The UCITS value is0.05.
c: Cap on each position. The UCITS value is0.10. It is a cap on the issuer whensetgroups the assets by issuer.
s: Limit of the sum of the positions overt. The UCITS value is0.40.
set: Membership matrix whose rows are the positions that the rule reads, ornothingto make each asset its own position.
pos: Reading of a position with a short side:GrossPosition(),NetPosition()orLongPosition(). On a long-only book the three readings are the weights.
alg: Form of the rule:ExactConcentration(), the mixed-integer rule itself, orSumLargestConcentration(), a linear form that is stricter than the rule.
Constructors
ConcentrationLimit(; t::Number = 0.05, c::Number = 0.1, s::Number = 0.4, set::Option{<:MatNum} = nothing, pos::AbstractPositionReading = GrossPosition(), alg::AbstractConcentrationAlgorithm = ExactConcentration()) -> ConcentrationLimitKeywords correspond to the struct's fields.
Validation
- The rules of
assert_concentration_limitfort,cands.
View parameters
port_opt_view takes the view of these @vprop fields at the selected indices:
set: The membership matrix keeps the columns of the selected assets.
Examples
julia> ConcentrationLimit(; set = [1 1 0; 0 0 1])ConcentrationLimit t ┼ Float64: 0.05 c ┼ Float64: 0.1 s ┼ Float64: 0.4 set ┼ 2×3 Matrix{Int64} pos ┼ GrossPosition() alg ┴ ExactConcentration()Related
PortfolioOptimisers.AbstractPositionReading — Type
abstract type AbstractPositionReading <: AbstractAlgorithm endAbstract supertype of the readings of a position of a ConcentrationLimit.
A reading tells the rule how a short position counts. A long-only book has no short position, so every reading gives the weights there. The name avoids the word "exposure", because the factor exposures use it.
| reading | gated expression | a short of -30 % of X | A1 +8 %, A2 -8 % of one issuer |
|---|---|---|---|
GrossPosition | lw + sw | counts as 30 % | 16 % |
NetPosition | w | not seen by the rule | 0 % |
LongPosition | lw | not seen by the rule | 8 % |
Interfaces
To make a new reading, subtype AbstractPositionReading and implement the method below.
Reading of the weights
PortfolioOptimisers.position_reading(pos::AbstractPositionReading, w::AbstractVector, lw::AbstractVector, sw::AbstractVector) -> AbstractVector: The reading of each asset, from the weightswand their long and short partslwandsw.
One method serves both callers. The model gives the variables of its parts. concentration_margins gives the parts of a weight vector, max.(w, 0) and max.(-w, 0). There is no fallback.
Related
PortfolioOptimisers.GrossPosition — Type
struct GrossPosition <: AbstractPositionReading endReads a position as the sum of its long and its short part, so a short position counts at its size.
This is the default reading of a ConcentrationLimit, and the safe one: a short position cannot hide a long position of the same issuer. The model reads the parts lw and sw of the weights. They give lw + sw >= |w|, so the reading is never below the gross position. When the short budget sbgt pins the sum of the parts and xbgt is off, the parts can be larger than |w|, and then the rule is stricter than the gross position.
A RiskBudgeting head declares its own parts of the weights, and the reading uses them.
Related
PortfolioOptimisers.NetPosition — Type
struct NetPosition <: AbstractPositionReading endReads a position as its net weight, so a short position lowers the position of its issuer.
A short position is below every threshold, so the rule does not see it. Two share classes of one issuer at +8 % and -8 % give a position of zero.
Related
PortfolioOptimisers.LongPosition — Type
struct LongPosition <: AbstractPositionReading endReads a position as its long part, so the rule does not see a short position.
The model reads the long part lw of the weights. It gives lw >= max(w, 0), so the reading is never below the long position. When the budgets pin the sum of the long part and xbgt is off, lw can be larger than max(w, 0), and then the rule is stricter than the long position.
Related
PortfolioOptimisers.AbstractConcentrationAlgorithm — Type
abstract type AbstractConcentrationAlgorithm <: AbstractAlgorithm endAbstract supertype of the forms of a ConcentrationLimit in the model.
Interfaces
To make a new form, subtype AbstractConcentrationAlgorithm and implement the method below.
Rows of the rule
PortfolioOptimisers.set_concentration_rows!(model::JuMP.Model, alg::AbstractConcentrationAlgorithm, sp::ConcentrationMIPSpace, x::AbstractVector, wb::WeightBounds, ss::Option{<:Number}) -> Nothing: Add the rows of the rulesp.clon the positionsx. Register each entry withstate_set!(model, Symbol(""), mip_key(sp, name), val), so that two rules do not collide. A form with a binary declares it and its gate withdeclare_mip_gate!, so that its rows hold under a ratio objective too.
There is no fallback. concentration_margins reads the rule itself whatever the form, so a new form needs no method there.
Related
PortfolioOptimisers.ExactConcentration — Type
struct ExactConcentration <: AbstractConcentrationAlgorithm endStates a ConcentrationLimit exactly, with one binary for each position.
The binary says that the position is over the threshold t. The feasible set is the rule itself, see the mathematical definition of ConcentrationLimit. It is the default form. It needs a solver that takes integer variables.
The rule holds to the tolerance of the solver. A solver takes a binary at $\epsilon$ as zero when $\epsilon$ is under its integrality tolerance. Under a constant budget, a position with such a binary can be at $t + (c - t) \epsilon$. Under a ratio objective or a RiskBudgeting head, the gate multiplies $\epsilon$ by the big-M constant ss of the block, see declare_mip_gate!. So the position can be at $t + (c - t) M_s \epsilon / k$. With $M_s = 1000$, $\epsilon = 10^{-6}$ and $k = 1$, the excess is 0.005 % of the book under 5/10/40. The sum of the rule is a step, so a check with no tolerance then counts the whole position. Use one of these remedies:
- A smaller constant, such as
ss = 10in the block. It must stay above thekof the solution. - A smaller integrality tolerance in the settings of the solver.
- A threshold
ta little under the limit of the mandate. - A
tolat the size of the excess inconcentration_margins, for a check that accepts the excess.
Related
PortfolioOptimisers.SumLargestConcentration — Type
struct SumLargestConcentration <: AbstractConcentrationAlgorithm endStates a ConcentrationLimit as a linear form with no integer variable: the sum of the k largest positions is at most s, with k = ceil(s / t), and each position is at most c.
The form is safe: a book that meets it meets the rule. A book with more than k positions over t has a sum of its k largest positions over k t >= s. So at most k positions are over t. They are among the k largest positions, so their sum is at most s. The form reads the positive part of each position, so a negative net position adds nothing.
The form is stricter than the rule. With 5/10/40, k = 8. A book of four positions at 10 % and six at 5 % meets the rule, because only the four positions at 10 % are over 5 %, and their sum is 40 %. Its eight largest positions sum to 50 %, so the form refuses it.
| book | the rule | this form | the sum of the 4 largest |
|---|---|---|---|
| 8 x 9 % | fails | fails | passes (not safe) |
| 4 x 10 % + 6 x 5 % | passes | fails (stricter) | passes |
| 20 x 5 % | passes | passes | passes |
The form "the sum of the 4 largest positions is at most 40 %" is not safe. A book of eight positions at 9 % meets it, but the sum of its positions over 5 % is 72 %.
Use the form for a solver with no integer variables, for a large universe, or for a loop of folds with many solves.
Related
PortfolioOptimisers.concentration_limit_constraints — Function
concentration_limit_constraints(cl::Option{<:ConcentrationLimit}, args...; kwargs...)
concentration_limit_constraints(cl::ConcentrationLimitEstimator,
sets::Option{<:UniverseSets}; strict::Bool = false,
kwargs...)
concentration_limit_constraints(cl::VecCnlE_Cnl, sets::Option{<:UniverseSets};
kwargs...)Resolve a concentration rule, or a vector of rules, against a universe.
The method for a ConcentrationLimit or nothing returns its input unchanged. The method for a ConcentrationLimitEstimator resolves its set with asset_sets_matrix, and keeps the other fields. The method for a vector resolves each entry and keeps the order.
The block resolves the rule at stage 1, resolve_constraint_block_names, before the reduction to the Investable Mask. So the matrix has one column for each asset of the caller, and the view at the mask keeps the columns of the investable assets, as it does for smtx.
Algorithm
- Resolve
cl.setwithasset_sets_matrix(cl.set, sets; strict = strict).nothingand a matrix stay unchanged. - Return a
ConcentrationLimitwith the resolved matrix and the other fields ofcl.
Arguments
cl: The rule, or a vector of rules.sets: AUniverseSetsthat holds the asset universe and the groups. A rule whosesetholds no estimator does not read it, so it can benothing.strict: Whether to throw an error ifsetsdoes not contain the desired value insets.dict[key].args...,kwargs...: More arguments, which the method for a resolved rule ignores, and which the method for a vector gives to the method of each entry.
Validation
setsis notnothingwhencl.setis anAssetSetsMatrixEstimator. AnIsNothingErroris thrown otherwise.- The rules of
asset_sets_matrixfor anAssetSetsMatrixEstimatorincl.set.
Returns
cl::Option{<:Cnl_VecCnl}: The resolved rule, or one resolved rule for each entry of a vector.
Examples
julia> sets = UniverseSets(; dict = Dict("nx" => ["A1", "A2", "B"], "nx_issuer" => ["A", "A", "B"]));julia> cl = ConcentrationLimitEstimator(; set = AssetSetsMatrixEstimator(; val = "nx_issuer"));julia> concentration_limit_constraints(cl, sets).set2×3 transpose(::BitMatrix) with eltype Bool: 1 1 0 0 0 1Related
PortfolioOptimisers.position_reading — Function
position_reading(pos::AbstractPositionReading, w::AbstractVector, lw::AbstractVector,
sw::AbstractVector)Return the reading of each asset that pos gives, from the weights and their long and short parts.
The builder mip_wx! gives the variables of the parts of the model. concentration_margins gives the smallest parts of a weight vector, max.(w, 0) and max.(-w, 0). Then the gross reading is |w|, and the long reading is the positive part of w.
Algorithm
The method that Julia selects is the algorithm:
GrossPosition:lw + sw.NetPosition:w.LongPosition:lw.
Arguments
pos: The reading.w: The weights.lw,sw: The long and the short parts of the weights.
Returns
v::AbstractVector: The reading of each asset.
Related
PortfolioOptimisers.concentration_margins — Function
concentration_margins(cl::ConcentrationLimit, w::VecNum;
tol::Number = weights_bound_tolerance(eltype(w)), kwargs...)
concentration_margins(cl::ConcentrationLimitEstimator, w::VecNum;
sets::Option{<:UniverseSets} = nothing, strict::Bool = false,
kwargs...)
concentration_margins(cl::VecCnlE_Cnl, w::VecNum; kwargs...)Check a weight vector against a concentration rule, and return its margins.
The check serves the mandate check of a book from any optimiser. The clustering and the naive optimisers have no slot for the rule, so their weights can break it. A rule holds when every margin is <= 0. The precedent of a check on weights is weights_meet_bounds.
Mathematical definition
\[\begin{align} \mathrm{cap}_j &= x_j - c\,, \\ \mathrm{total} &= \sum_{j\,:\,x_j > t + \tau} x_j - s\,. \end{align}\]
Where:
- $x_j$: Position $j$, row $j$ of
settimes the reading of the weights thatposition_readinggives forpos. - $t$, $c$, $s$: The threshold, the cap and the limit of the sum.
- $\tau$: The tolerance
tol.
The sum is a step: a position that passes $t + \tau$ adds its whole size, and not its excess over $t$. So the check of a book of a solver needs a tol at the size of the tolerance of the solver. ExactConcentration states the excess that a mixed-integer solver can give, and how to lower it. tol does not move the margins of the cap and of the sum, so compare them with a tolerance too.
Algorithm
- Resolve an estimator with
concentration_limit_constraintsagainstsets. - Read the weights with
position_reading, with the partsmax.(w, 0)andmax.(-w, 0), and make the positions withconcentration_positions. - Return the margins of the formulas above. The method for a vector returns one
ConcentrationMarginsfor each rule, in order.
Arguments
cl: The rule, or a vector of rules.w: The weights, one for each asset of the universe of the rule.tol: The excess overtup to which a position does not count towards the sum. The default is the tolerance ofweights_bound_tolerance.sets: AUniverseSetsagainst which an estimator resolves, ornothing.strict: Whether to throw an error ifsetsdoes not contain the desired value insets.dict[key].kwargs...: The method for a resolved rule ignores them. The method for an estimator gives them to the method for its resolved rule, and the method for a vector gives them to each entry.
Validation
- The rules of
concentration_limit_constraintsfor an estimator. - The width of
cl.setislength(w). ADimensionMismatchis thrown otherwise.
Returns
cm::ConcentrationMargins: The margins of one rule, or one for each rule of a vector.
Examples
Six positions at 10 % sum to 60 %, so the book is 20 % over the limit of the sum, and no position is over the cap.
julia> w = [fill(0.1, 6); fill(0.04, 10)];julia> cm = concentration_margins(ConcentrationLimit(), w);julia> maximum(cm.cap) <= 0, round(cm.total; digits = 10)(true, 0.2)Related
PortfolioOptimisers.ConcentrationMargins — Type
struct ConcentrationMargins{__T_x, __T_cap, __T_total} <: AbstractResultHolds the margins of a weight vector against one concentration rule.
concentration_margins makes it. A margin <= 0 passes, so a book meets the rule when every entry of cap is <= 0 and total <= 0. A positive margin is the excess over the rule. A position counts towards the sum only when it is over the threshold by more than the keyword tol of that function. The check reads the rule itself, the form of ExactConcentration, whatever the field alg of the rule holds.
Fields
x: The position of each row of the rule, asposandsetread the weights.
cap: The cap margin of each position,x - c. A margin<= 0passes.
total: The sum margin, the sum of the positions overtminuss. A margin<= 0passes.
Constructors
ConcentrationMargins(; x::VecNum, cap::VecNum, total::Number) -> ConcentrationMarginsKeywords correspond to the struct's fields.
Validation
length(x) == length(cap).
Related