Discrete allocation
PortfolioOptimisers.DiscreteAllocationResult Type
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} <: FiniteAllocationOptimisationResultResult 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:JuMPmodel for the short allocation.l_model:JuMPmodel for the long allocation.fb: Fallback result or estimator.
Related
sourcePortfolioOptimisers.factory Method
factory(a::Union{Nothing, <:AbstractEstimator, <:AbstractAlgorithm,
<:AbstractResult}, args...; kwargs...) -> aNo-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> factory(nothing, 1, 2; x = 3)
julia> factory(MeanValue())
MeanValue
w ┴ nothingRelated
sourcefactory(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
sourcePortfolioOptimisers.DiscreteAllocation Type
struct DiscreteAllocation{__T_slv, __T_sc, __T_so, __T_wf, __T_fb} <: FiniteAllocationOptimisationEstimatorDiscrete 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:
Where:
: Integer share vector. : L1 tracking error auxiliary variable. : Residual cash. : Target weight vector. : Available cash. : Asset price vector. : Element-wise (Hadamard) product. : 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
DiscreteAllocation(;
slv::Slv_VecSlv,
sc::Number = 1,
so::Number = 1,
wf::JuMPWeightFinaliserFormulation = AbsoluteErrorWeightFinaliser(),
fb::Option{<:FOptE_FOpt} = GreedyAllocation()
) -> DiscreteAllocationKeywords correspond to the struct's fields.
Validation
If
slvis a vector:!isempty(slv).sc > 0,so > 0.
Examples
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 ┴ nothingRelated
sourcePortfolioOptimisers.finite_sub_allocation Function
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
sourcePortfolioOptimisers.optimise Function
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...) -> DiscreteAllocationResultRun the Discrete Allocation portfolio optimisation.
Arguments
da: The discrete allocation optimiser to use.w: Portfolio weights vectorassets × 1.p: The prices of the assets in the same order asw.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
sourcePortfolioOptimisers.set_discrete_error! Function
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