Greedy allocation
PortfolioOptimisers.GreedyAllocationResult Type
struct GreedyAllocationResult{__T_oe, __T_retcode, __T_shares, __T_cost, __T_w, __T_cash, __T_fb} <: FiniteAllocationOptimisationResultResult type for Greedy Allocation portfolio optimisation.
Fields
oe: Type of the optimisation estimator that produced this result.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.
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.
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 Function
optimise(ga::GreedyAllocation{<:Any, <:Any, <:Any, Nothing}, w::VecNum, p::VecNum,
cash::Number = 1e6, T::Option{<:Number} = nothing,
fees::Option{<:Fees} = nothing; kwargs...) -> GreedyAllocationResultRun the Greedy Allocation portfolio optimisation.
Arguments
ga: The greedy 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.kwargs: Additional keyword arguments passed to the optimisation function.
Related
source