Budget Constraints

PortfolioOptimisers.BudgetRange — Type
struct BudgetRange{__T_lb, __T_ub} <: BudgetEstimator

Bounds the sum of the portfolio weights inside a closed interval, rather than pinning it to one value.

At least one of lb or ub must be given; the absent side is left unbounded. The same type serves the net budget bgt, the short budget sbgt and the gross budget gbgt.

Fields

  • lb: Lower bound.
  • ub: Upper bound.

Constructors

BudgetRange(; lb::Option{<:Number} = 1.0, ub::Option{<:Number} = 1.0) -> BudgetRange

Keywords correspond to the struct's fields.

Validation

  • At least one of lb, ub must not be nothing.
  • lb and ub must be finite.
  • lb <= ub when both are provided.

Related

source
PortfolioOptimisers.BudgetCosts — Type
struct BudgetCosts{__T_bgt, __T_w, __T_vp, __T_vn, __T_up, __T_un, __T_fixed, __T_xbgt} <: BudgetCostEstimator

Charges the portfolio budget for transaction costs that grow linearly with the traded volume.

Models the cost of the bid-ask spread, of slippage, of a borrowing charge, or of a management fee. The cost is charged against the budget: the weights and their costs together must not exceed bgt, so a portfolio that trades more may hold less. The part of the budget that the weights and their costs do not use is cash.

The rows are Equations 1 to 3 of [186] with one linear segment on each side of the trade. Exhibit 3 of that work charges the cost against the cash of the revised portfolio, as the first row charges it against the budget.

The budget row is a ceiling, not an equality. Equation 2.6 of [237] states the self-financing condition as an equality, and Section 4.7 of that work relaxes it to an inequality, because the equality is not convex. Equation 9.15 of [12] and Equation 6.2 of [238] keep the equality on the two parts of the trade, and Section 6.1 of [238] states that the equality keeps one of the two parts at zero. It does not: nothing makes $\boldsymbol{w}_p$ and $\boldsymbol{w}_n$ complementary, so the equality charges a cost for a buy and a sale of one asset together, and so holds cash that it reports as cost. The ceiling admits exactly the weights whose cost fits the budget, at every solution of a convex programme. A floor on the weights and their costs is not convex either, so the floor of a BudgetRange bounds the invested weights alone.

xbgt = true pins the budget exactly, as the xbgt of JuMPOptimiser pins the long and short parts. One binary for each asset keeps the buy or the sale of the asset at zero, so the charge is the cost of the trade, and a floor that holds the cost is exact. A scalar bgt then pins sum(w) plus the cost, and the floor of a BudgetRange holds the cost. set_cost_budget_mip_constraints! writes these rows, and the problem needs a mixed-integer solver. BudgetMarketImpact has no such option.

Mathematical definition

\[\begin{align} \boldsymbol{1}^\intercal \boldsymbol{w} + \boldsymbol{v}_p^\intercal \boldsymbol{w}_p + \boldsymbol{v}_n^\intercal \boldsymbol{w}_n &\leq k\,\mathrm{ub}\,, \\ \boldsymbol{1}^\intercal \boldsymbol{w} &\geq k\,\mathrm{lb}\,, \\ \boldsymbol{w} - k\,\boldsymbol{w}_0 &= \boldsymbol{w}_p - \boldsymbol{w}_n\,, \\ \boldsymbol{w}_p &\leq k\,\boldsymbol{u}_p\,, \\ \boldsymbol{w}_n &\leq k\,\boldsymbol{u}_n\,, \\ \boldsymbol{w}_p,\; \boldsymbol{w}_n &\geq \boldsymbol{0}\,. \end{align}\]

Where:

  • $\boldsymbol{w}$: Portfolio weights vector $N \times 1$.
  • $k$: Variable that scales the budget in the homogenised problem.
  • $\boldsymbol{w}_0$: Reference portfolio the trade starts from (w). factory replaces it with the weights of the previous fold or step, unless fixed is true.
  • $\boldsymbol{w}_p$, $\boldsymbol{w}_n$: Positive and negative weight increments.
  • $\boldsymbol{v}_p$, $\boldsymbol{v}_n$: Cost coefficient vectors for positive and negative changes.
  • $\boldsymbol{u}_p$, $\boldsymbol{u}_n$: Upper limits on the positive and negative increments.
  • $\mathrm{ub}$: Ceiling of the weights and their costs. A scalar bgt gives it, and a BudgetRange gives its ub. A ub of nothing writes no ceiling.
  • $\mathrm{lb}$: Floor of the invested weights, the lb of a BudgetRange. A scalar bgt, and a lb of nothing, write no floor.

The rows above are those of xbgt = false. With xbgt = true, the floor holds the cost, $\boldsymbol{1}^\intercal \boldsymbol{w} + \boldsymbol{v}_p^\intercal \boldsymbol{w}_p + \boldsymbol{v}_n^\intercal \boldsymbol{w}_n \geq k\,\mathrm{lb}$, a scalar bgt is also its $\mathrm{lb}$, and set_cost_budget_mip_constraints! states the complementarity rows.

Every row is homogeneous in $(\boldsymbol{w}, k)$. Under MaximumRatio, the start portfolio $\boldsymbol{w}_0$, the caps and the budget therefore scale with $k$, and the weights do not depend on ohf while the ceiling binds. Where it does not bind, ohf sets the share of cash, see the warning below. Every other objective fixes $k = 1$.

A bgt = 1.0 and a MaximumReturn objective meet the ceiling to 1.5e-8 on a five-asset sample with a positive mean: sum(w) + 0.01 * sum(abs.(w - w0)) lands on 0.9999999851855913.

Warning

The programme holds cash wherever cash serves the objective better than an asset, and the ceiling alone does not stop it. Under MinimumRisk, a scalar bgt sells the book to cash: on the sample above, minimising the variance gives sum(w) = 0.0045. Give a floor on the invested weights to bound the cash: bgt = BudgetRange(; lb = 0.95, ub = 1.0) gives sum(w) = 0.95 on the same sample. Or write xbgt = true to hold no cash, under a mixed-integer solver. Under MaximumRatio with rf = 0, cash does not change the ratio, so the share of cash is not unique and ohf sets it: on the same sample the ratio agrees to 1e-6 from ohf = 1e-3 to ohf = 0.3, and sum(w) plus the cost is 0.70 at ohf = 1e-3, 0.71 at the default and 0.95 at ohf = 0.3. A positive rf makes cash lower the ratio, so the ceiling binds.

Note

Where the ceiling does not bind, $\boldsymbol{w}_p$ and $\boldsymbol{w}_n$ can both be positive. The weights stay exact, but the value of cost_bgt_expr can then exceed the cost of the trade. Compute the cost from the weights.

Fields

  • bgt: Ceiling that the weights and their trading costs together must not exceed, or a BudgetRange whose ub is that ceiling and whose lb is a floor of the invested weights alone. The unused part of the budget is cash.
  • w: Portfolio weights vector assets × 1.
  • vp: Cost coefficients for positive weight changes. Non-negative.
  • vn: Cost coefficients for negative weight changes. Non-negative.
  • up: Upper limit on positive weight changes. Non-negative.
  • un: Upper limit on negative weight changes. Non-negative.
  • fixed: If true, factory keeps the reference weights w and ignores the new weights. If false, factory replaces w with the new weights.
  • xbgt: Whether to pin the budget exactly. When false (the default), the budget is a ceiling of the weights and their costs, and a BudgetRange floor bounds the invested weights alone, so the programme stays convex and the unused budget is cash. When true, one binary for each asset keeps the buy or the sale of the asset at zero, so a scalar bgt pins the weights and their costs, and a BudgetRange floor holds the costs too. The problem is then mixed-integer.

Constructors

BudgetCosts(;    bgt::Num_BgtRg = 1.0,    w::VecNum,    vp::Num_VecNum = 1.0,    vn::Num_VecNum = 1.0,    up::Num_VecNum = 1.0,    un::Num_VecNum = 1.0,    fixed::Bool = false,    xbgt::Bool = false) -> BudgetCosts

Keywords correspond to the struct's fields.

Validation

  • !isempty(w).
  • If vp is a vector: !isempty(vp) and all elements >= 0. If scalar: >= 0.
  • If vn is a vector: !isempty(vn) and all elements >= 0. If scalar: >= 0.
  • If up is a vector: !isempty(up) and all elements >= 0. If scalar: >= 0.
  • If un is a vector: !isempty(un) and all elements >= 0. If scalar: >= 0.

View parameters

port_opt_view takes the view of these @vprop fields at the selected indices:

Related

References

  • [186] G. A. Pogue. An extension of the Markowitz portfolio selection model to include variable transactions' costs, short sales, leverage policies and taxes. Working paper 388-69B, Sloan School of Management, Massachusetts Institute of Technology (1969). Pages 11 and 12, Equations 1 to 3, and page 29, Exhibit 3.
  • [237] S. Boyd, E. Busseti, S. Diamond, R. N. Kahn, K. Koh, P. Nystrup and J. Speth. Multi-Period Trading via Convex Optimization. Foundations and Trends in Optimization 3, 1–76 (2017). Section 2.5, Equation 2.6, and Section 4.7.
  • [12] D. Cajas. Advanced Portfolio Optimization: A Cutting-edge Quantitative Approach (Springer Nature Switzerland, 2025). Section 9.1, Equations 9.14 and 9.15, and Listing 9.8.
  • [238] MOSEK ApS. MOSEK Portfolio Optimization Cookbook (2023). Section 6.1, Equation 6.2.
source
PortfolioOptimisers.BudgetMarketImpact — Type
struct BudgetMarketImpact{__T_bgt, __T_w, __T_vp, __T_vn, __T_up, __T_un, __T_beta, __T_fixed} <: BudgetCostEstimator

Charges the portfolio budget and the return for market impact costs that follow an empirical power law.

Extends BudgetCosts with a power cone, so the charge grows as the traded volume raised to $1/\mathrm{beta}$. Unlike a linear cost, the charge is also subtracted from the return expression of every term whose settings.mic is true.

Section 6.3 of [238] states this cost, charges it against the budget, and writes it as a power cone. That work names page 452 of [85] as the source of the power law. No copy of that work was found. [12] splits the trade into its two signs, as the rows below do.

The budget row is a ceiling, as for BudgetCosts. Section 6.3 of [238] states that its equality lets the solver treat the charge as a riskless asset and throw money away, and it adds a risk-free security to stop that. A ceiling is that security at a zero rate: the part of the budget that the weights and their costs do not use is cash. Section 4.7 of [237] relaxes the self-financing equality to the same inequality. The floor of a BudgetRange bounds the invested weights alone.

Mathematical definition

\[\begin{align} \boldsymbol{1}^\intercal \boldsymbol{w} + \boldsymbol{v}_p^\intercal \boldsymbol{\iota}_p + \boldsymbol{v}_n^\intercal \boldsymbol{\iota}_n &\leq k\,\mathrm{ub}\,, \\ \boldsymbol{1}^\intercal \boldsymbol{w} &\geq k\,\mathrm{lb}\,, \\ (\iota_{p,i},\; k,\; w_{p,i}) &\in \mathcal{K}_{\mathrm{pow}}^\beta \quad \forall i = 1,\dots,N\,, \\ (\iota_{n,i},\; k,\; w_{n,i}) &\in \mathcal{K}_{\mathrm{pow}}^\beta \quad \forall i = 1,\dots,N\,, \\ \boldsymbol{w} - k\,\boldsymbol{w}_0 &= \boldsymbol{w}_p - \boldsymbol{w}_n\,, \\ \boldsymbol{w}_p &\leq k\,\boldsymbol{u}_p\,, \\ \boldsymbol{w}_n &\leq k\,\boldsymbol{u}_n\,, \\ \boldsymbol{w}_p,\; \boldsymbol{w}_n &\geq \boldsymbol{0}\,. \end{align}\]

Where:

  • $\boldsymbol{w}$: Portfolio weights vector $N \times 1$.
  • $k$: Variable that scales the budget in the homogenised problem.
  • $N$: Number of assets.
  • $\boldsymbol{w}_0$: Reference portfolio the trade starts from (w). factory replaces it with the weights of the previous fold or step, unless fixed is true.
  • $\boldsymbol{w}_p$, $\boldsymbol{w}_n$: Positive and negative weight increments.
  • $\boldsymbol{\iota}_p$, $\boldsymbol{\iota}_n$: Auxiliary variables the power cone bounds below by $w_p^{1/\beta}$ and $w_n^{1/\beta}$.
  • $\boldsymbol{v}_p$, $\boldsymbol{v}_n$: Market impact cost coefficients for positive and negative trades.
  • $\boldsymbol{u}_p$, $\boldsymbol{u}_n$: Upper limits on the positive and negative increments.
  • $\mathcal{K}_{\mathrm{pow}}^\beta$: Three-dimensional power cone of exponent $\beta$.
  • $\mathrm{ub}$: Ceiling of the weights and their costs. A scalar bgt gives it, and a BudgetRange gives its ub. A ub of nothing writes no ceiling.
  • $\mathrm{lb}$: Floor of the invested weights, the lb of a BudgetRange. A scalar bgt, and a lb of nothing, write no floor.

Every row is homogeneous in $(\boldsymbol{w}, k)$. Under MaximumRatio, the start portfolio $\boldsymbol{w}_0$, the caps and the budget therefore scale with $k$, and the weights do not depend on ohf. Every other objective fixes $k = 1$.

Note

beta is the reciprocal of the power law's exponent. The cone gives $\iota_i \geq w_i^{1/\beta}$, so the default beta = 2/3 charges the volume raised to 3/2. Equation 1 of [239] is the square-root law of the price impact, and the cost is the impact times the traded volume, so it grows as the volume raised to 3/2. The cone needs 0 < beta < 1; the constructor refuses both endpoints, because a solver reports SLOW_PROGRESS on either.

A bgt = 1.0 and a MaximumReturn objective meet the ceiling to 5.7e-8 on a five-asset sample with a positive mean: sum(w) + 0.01 * sum(abs.(w - w0) .^ 1.5) lands on 0.999999942738817.

Warning

The programme holds cash wherever cash serves the objective better than an asset, and the ceiling alone does not stop it. Under MinimumRisk, a scalar bgt sells the book to cash: on the sample above, minimising the variance gives sum(w) = 0.0047. Give a floor on the invested weights to bound the cash, such as bgt = BudgetRange(; lb = 0.95, ub = 1.0).

Note

The auxiliary variables carry no upper bound, so where the ceiling does not bind they can exceed $w_p^{1/\beta}$ and $w_n^{1/\beta}$. The weights stay exact, but the value of cost_bgt_expr, and the return term that subtracts it, can then charge more than the trade costs. Compute the cost from the weights.

Fields

  • bgt: Ceiling that the weights and their trading costs together must not exceed, or a BudgetRange whose ub is that ceiling and whose lb is a floor of the invested weights alone. The unused part of the budget is cash.
  • w: Portfolio weights vector assets × 1.
  • vp: Cost coefficients for positive weight changes. Non-negative.
  • vn: Cost coefficients for negative weight changes. Non-negative.
  • up: Upper limit on positive weight changes. Non-negative.
  • un: Upper limit on negative weight changes. Non-negative.
  • beta: Reciprocal of the market impact exponent, 0 < beta < 1. The realised exponent is 1/beta.
  • fixed: If true, factory keeps the reference weights w and ignores the new weights. If false, factory replaces w with the new weights.

Constructors

BudgetMarketImpact(;    bgt::Num_BgtRg = 1.0,    w::VecNum,    vp::Num_VecNum = 1.0,    vn::Num_VecNum = 1.0,    up::Num_VecNum = 1.0,    un::Num_VecNum = 1.0,    beta::Number = 2/3,    fixed::Bool = false) -> BudgetMarketImpact

Keywords correspond to the struct's fields.

Validation

  • !isempty(w).
  • If vp is a vector: !isempty(vp) and all elements >= 0. If scalar: >= 0.
  • If vn is a vector: !isempty(vn) and all elements >= 0. If scalar: >= 0.
  • If up is a vector: !isempty(up) and all elements >= 0. If scalar: >= 0.
  • If un is a vector: !isempty(un) and all elements >= 0. If scalar: >= 0.
  • 0 < beta < 1.

View parameters

port_opt_view takes the view of these @vprop fields at the selected indices:

Related

References

  • [238] MOSEK ApS. MOSEK Portfolio Optimization Cookbook (2023). Section 6.3, Equations 6.4 to 6.6. The original source of this formulation was not found. The formulation follows this work and is not checked against the original.
  • [85] R. C. Grinold and R. N. Kahn. Active Portfolio Management: A Quantitative Approach for Producing Superior Returns and Controlling Risk. 2 Edition (McGraw-Hill, New York, 1999).
  • [239] B. Tóth, Y. Lempérière, C. Deremble, J. de Lataillade, J. Kockelkoren and J.-P. Bouchaud. Anomalous price impact and the critical nature of liquidity in financial markets. Physical Review X 1, 021006 (2011). Section 1, Equation 1.
  • [12] D. Cajas. Advanced Portfolio Optimization: A Cutting-edge Quantitative Approach (Springer Nature Switzerland, 2025). Section 9.3, Equations 9.22 and 9.23.
  • [237] S. Boyd, E. Busseti, S. Diamond, R. N. Kahn, K. Koh, P. Nystrup and J. Speth. Multi-Period Trading via Convex Optimization. Foundations and Trends in Optimization 3, 1–76 (2017). Section 4.7.
source
PortfolioOptimisers.factory — Method
factory(bgt::BudgetCosts, w::VecNum)
factory(bgt::BudgetMarketImpact, w::VecNum)

Replace the reference portfolio of a cost budget with the weights w, unless its fixed field is true.

A BudgetCosts and a BudgetMarketImpact charge the cost of the move from their reference w against the budget. A fold of a walk-forward, or a step of an online rule, trades from the weights that it holds, and factory(opt::JuMPOptimiser, w::AbstractVector) passes these weights to the bgt of the optimiser. So the charged cost is the cost of the trade of the fold, as for a Turnover on tn or on fees. A fixed estimator keeps the reference that it was built with.

A number, a BudgetRange and nothing hold no reference, so they take the leaf method of factory, which returns them unchanged. A TimeDependent schedule applies factory to each entry.

Algorithm

  1. If bgt.fixed is true, return bgt unchanged.
  2. Else rebuild bgt through its keyword constructor with w as the reference portfolio. Every other field keeps its value.

Arguments

  • bgt: The net budget of a JuMPOptimiser.
  • w: The weights that the fold or the step trades from.

Validation

  • Step 2 calls the keyword constructor, so it checks w as the constructor does.

Returns

  • bgt: bgt unchanged in step 1. Else a new estimator of the same type with w as its reference.

Examples

julia> bgt = BudgetCosts(; w = [0.2, 0.3, 0.5], vp = 0.01, vn = 0.01);julia> factory(bgt, [0.1, 0.4, 0.5]).w3-element Vector{Float64}: 0.1 0.4 0.5julia> bgt = BudgetCosts(; w = [0.2, 0.3, 0.5], vp = 0.01, vn = 0.01, fixed = true);julia> factory(bgt, [0.1, 0.4, 0.5]).w3-element Vector{Float64}: 0.2 0.3 0.5

Related

source
PortfolioOptimisers.needs_previous_weights — Method
needs_previous_weights(bgt::BudgetCostEstimator) -> Bool
needs_previous_weights(bgt::Number) -> Bool

Tell whether a net budget reads the weights of the previous fold or step.

A cost budget that is not fixed measures its cost from the weights that factory gives it, so it needs them. A fixed cost budget and a number need none. So a walk-forward that holds a cost budget that is not fixed runs its folds in order, as one that holds a Turnover does.

Algorithm

  1. On a BudgetCostEstimator, return !bgt.fixed.
  2. On a number, return false.

Arguments

Returns

  • Bool: true if bgt needs the previous weights, else false.

Related

source

References

[12]
D. Cajas. Advanced Portfolio Optimization: A Cutting-edge Quantitative Approach (Springer Nature Switzerland, 2025).
[85]
R. C. Grinold and R. N. Kahn. Active Portfolio Management: A Quantitative Approach for Producing Superior Returns and Controlling Risk. 2 Edition (McGraw-Hill, New York, 1999).
[186]
G. A. Pogue. An Extension of the Markowitz Portfolio Selection Model to Include Variable Transactions' Costs, Short Sales, Leverage Policies and Taxes. Working paper 388-69B (Sloan School of Management, Massachusetts Institute of Technology, 1969).
[237]
S. Boyd, E. Busseti, S. Diamond, R. N. Kahn, K. Koh, P. Nystrup and J. Speth. Multi-Period Trading via Convex Optimization. Foundations and Trends in Optimization 3, 1–76 (2017).
[238]
MOSEK ApS. MOSEK Portfolio Optimization Cookbook, https://docs.mosek.com/portfolio-cookbook/index.html (2023).
[239]
B. Tóth, Y. Lémperière, C. Deremble, J. de Lataillade, J. Kockelkoren and J.-P. Bouchaud. Anomalous Price Impact and the Critical Nature of Liquidity in Financial Markets. Physical Review X 1, 021006 (2011).