Greedy allocation
PortfolioOptimisers.GreedyAllocationResult Type
struct GreedyAllocationResult{__T_retcode, __T_shares, __T_cost, __T_w, __T_cash, __T_fb} <: FiniteAllocationOptimisationResultResult type for Greedy Allocation portfolio optimisation.
Fields
retcode: Optimisation return code.shares: Number of shares allocated per asset.cost: Cost of the allocation.w: Realised portfolio weights.cash: Remaining uninvested cash after 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.
factory and port_opt_view are the two propagation mechanisms in this library. They are duals: factory threads runtime values (prior moments, observation weights, previous portfolio weights) down through a composed struct tree; port_opt_view threads an index selection (a subset of assets or observations) down through the same tree.
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.GreedyAllocation Type
struct GreedyAllocation{__T_unit, __T_args, __T_kwargs, __T_fb} <: FiniteAllocationOptimisationEstimatorGreedy Allocation portfolio optimiser.
GreedyAllocation converts continuous portfolio weights to discrete share quantities using a greedy two-pass allocation: first round shares to the nearest unit multiple, then iteratively buy remaining shares with leftover cash in order of largest weight.
Mathematical definition
Then iteratively while
Where:
: Initial share allocation for asset . : Residual cash after initial allocation. : Target weight vector. : Available cash. : Asset price vector. : Minimum share purchase unit. : Asset with largest weight among those affordable with remaining cash . : Initial share allocation vector.
Fields
unit: Minimum purchase unit (e.g., price per share or lot size).args: Additional positional arguments forwarded toround.kwargs: Additional keyword arguments.fb: Fallback result or estimator.
Constructors
GreedyAllocation(;
unit::Number = 1,
args::Tuple = (),
kwargs::NamedTuple = (;),
fb::Option{<:FOptE_FOpt} = nothing
) -> GreedyAllocationKeywords correspond to the struct's fields.
Validation
unit > 0.
Examples
julia> GreedyAllocation()
GreedyAllocation
unit ┼ Int64: 1
args ┼ Tuple{}: ()
kwargs ┼ @NamedTuple{}: NamedTuple()
fb ┴ nothingRelated
sourcePortfolioOptimisers.roundmult Function
roundmult(val, prec, args...; kwargs...)Round a value to the nearest multiple of prec.
Arguments
val: Value to round.prec: Precision (multiple to round to).args...: Additional arguments passed toBase.round.kwargs...: Additional keyword arguments passed toBase.round.
Returns
- Rounded value.
Related
sourcePortfolioOptimisers.finite_sub_allocation! Function
finite_sub_allocation!(w, p, cash, bgt, ...)In-place finite allocation for one side (long or short) of the portfolio using the greedy algorithm.
Modifies the allocation in-place, greedily assigning shares to assets to minimise allocation error.
Arguments
w: Target portfolio weights (in-place modified).p: Asset prices.cash: Cash available.bgt: Budget target.Additional parameters.
Returns
- Modified allocation vector.
Related
sourcePortfolioOptimisers.optimise Method
optimise(ga::GreedyAllocation{<:Any, <:Any, <:Any, Nothing},
fai::FiniteAllocationInput; kwargs...) -> GreedyAllocationResultRun the Greedy Allocation portfolio optimisation.
Arguments
ga: The greedy allocation optimiser to use.fai: TheFiniteAllocationInputcarrying the target weights, prices, cash budget, and optional horizon and fees.kwargs: Additional keyword arguments passed to the optimisation function.
Related
source