Skip to content
13

Discrete allocation

PortfolioOptimisers.DiscreteAllocationResult Type
julia
struct DiscreteAllocationResult{__T_oe, __T_retcode, __T_s_retcode, __T_l_retcode, __T_shares, __T_cost, __T_w, __T_cash, __T_s_model, __T_l_model, __T_fb} <: FiniteAllocationOptimisationResult

Result type for Discrete Allocation portfolio optimisation.

Fields

  • oe: Type of the optimisation estimator that produced this result.

  • retcode: Optimisation return code.

  • s_retcode: Return code for the short allocation sub-problem.

  • l_retcode: Return code for the long allocation sub-problem.

  • shares: Number of shares allocated per asset.

  • cost: Cost of the allocation.

  • w: Realised portfolio weights.

  • cash: Remaining uninvested cash after allocation.

  • s_model: JuMP model for the short allocation.

  • l_model: JuMP model for the long allocation.

  • fb: Fallback result or estimator.

Related

source
PortfolioOptimisers.factory Method
julia
factory(a::Union{Nothing, <:AbstractEstimator, <:AbstractAlgorithm,
                 <:AbstractResult}, args...; kwargs...) -> a

No-op factory function for constructing objects with a uniform interface.

Defining methods which dispatch on the first argument allows for a consistent factory interface across different types.

Arguments

  • a: Indicates no object should be constructed.

  • args...: Arbitrary positional arguments (ignored).

  • kwargs...: Arbitrary keyword arguments (ignored).

Returns

  • a: The input unchanged.

Examples

julia
julia> factory(nothing, 1, 2; x = 3)

julia> factory(MeanValue())
MeanValue
  w ┴ nothing

Related

source
julia
factory(res::FiniteAllocationOptimisationResult, fb::Option{<:FOptE_FOpt})

Rebuild a finite allocation result with an updated fallback optimiser fb.

Like the continuous-result generic, every finite allocation result carries fb as its last field, so the rebuild copies all fields unchanged except the trailing fb. Concrete result types may override this method when rebuilding requires more than swapping fb.

Related

source
PortfolioOptimisers.DiscreteAllocation Type
julia
struct DiscreteAllocation{__T_slv, __T_sc, __T_so, __T_wf, __T_fb} <: FiniteAllocationOptimisationEstimator

Discrete Allocation portfolio optimiser.

DiscreteAllocation allocates a portfolio by solving a Mixed-Integer Programming (MIP) problem to find the optimal number of shares for each asset, minimising the deviation between the target continuous weights and the realised discrete allocation.

Mathematical definition

Default (absolute error) MIP formulation:

minxZ0Nu+r,s.t.uwCxp1,r=Cxp0.

Where:

  • x: Integer share vector.

  • u: L1 tracking error auxiliary variable.

  • r: Residual cash.

  • w: Target weight vector.

  • C: Available cash.

  • p: Asset price vector.

  • : Element-wise (Hadamard) product.

  • N: Number of assets.

The weight finaliser wf controls which norm/error is used.

  • slv: Solver or vector of solvers.

  • sc: Constraint scale factor.

  • so: Objective scale factor.

  • wf: Weight finaliser.

  • fb: Fallback result or estimator.

Constructors

julia
DiscreteAllocation(;
    slv::Slv_VecSlv,
    sc::Number = 1,
    so::Number = 1,
    wf::JuMPWeightFinaliserFormulation = AbsoluteErrorWeightFinaliser(),
    fb::Option{<:FOptE_FOpt} = GreedyAllocation()
) -> DiscreteAllocation

Keywords correspond to the struct's fields.

Validation

  • If slv is a vector: !isempty(slv).

  • sc > 0, so > 0.

Examples

julia
julia> DiscreteAllocation(; slv = Solver())
DiscreteAllocation
  slv ┼ Solver
      │          name ┼ String: ""
      │        solver ┼ nothing
      │      settings ┼ nothing
      │     check_sol ┼ @NamedTuple{}: NamedTuple()
      │   add_bridges ┴ Bool: true
   sc ┼ Int64: 1
   so ┼ Int64: 1
   wf ┼ AbsoluteErrorWeightFinaliser()
   fb ┼ GreedyAllocation
      │     unit ┼ Int64: 1
      │     args ┼ Tuple{}: ()
      │   kwargs ┼ @NamedTuple{}: NamedTuple()
      │       fb ┴ nothing

Related

source
PortfolioOptimisers.finite_sub_allocation Function
julia
finite_sub_allocation(w, p, cash, bgt, ...)

Compute the finite (integer) allocation for one side (long or short) of the portfolio.

Solves a discrete allocation sub-problem using the given weights, prices, and cash budget.

Arguments

  • w: Target portfolio weights.

  • p: Asset prices.

  • cash: Cash available for this side.

  • bgt: Budget target.

  • Additional parameters for solver configuration.

Returns

  • Allocation vector (number of units per asset) or similar.

Related

source
PortfolioOptimisers.optimise Function
julia
optimise(da::DiscreteAllocation{<:Any, <:Any, <:Any, Nothing}, w::VecNum,
         p::VecNum, cash::Number = 1e6, T::Option{<:Number} = nothing,
         fees::Option{<:Fees} = nothing; str_names::Bool = false,
         save::Bool = true, kwargs...) -> DiscreteAllocationResult

Run the Discrete Allocation portfolio optimisation.

Arguments

  • da: The discrete allocation optimiser to use.

  • w: Portfolio weights vector assets × 1.

  • p: The prices of the assets in the same order as w.

  • cash: The initial cash balance.

  • T: The time horizon for the optimisation. Used to adjust the initial cash balance according to the fees charged on the portfolio for the time horizon.

  • fees: The fees to apply to the portfolio.

  • str_names: Whether to use string names for the assets in the optimisation.

  • save: Whether to save the JuMP model in the optimisation result.

  • kwargs: Additional keyword arguments passed to the optimisation function.

Related

source
PortfolioOptimisers.set_discrete_error! Function
julia
set_discrete_error!(model, w, p, cash, ...)

Add discrete allocation error constraints to the JuMP model.

Sets up the tracking error objective between target weights and the discrete allocation, subject to available cash and price constraints.

Arguments

  • model: JuMP model.

  • w: Target portfolio weights.

  • p: Asset prices.

  • cash: Cash budget.

  • Additional parameters.

Returns

  • nothing.

Related

source