Stacking
PortfolioOptimisers.BaseStackingOptimisationEstimator Type
abstract type BaseStackingOptimisationEstimator <: NonFiniteAllocationOptimisationEstimatorAbstract supertype for stacking-based portfolio optimisation estimators.
Related Types
sourcePortfolioOptimisers.StackingResult Type
struct StackingResult{__T_oe, __T_pr, __T_wb, __T_fees, __T_resi, __T_reso, __T_cv, __T_retcode, __T_w, __T_fb} <: NonJuMPOptimisationResultResult type for Stacking portfolio optimisation.
Fields
oe: Type of the optimisation estimator that produced this result.pr: Prior result.wb: Weight bounds.fees: Fees estimator or result.resi: Inner optimisation results.reso: Outer optimisation results.cv: Cross-validation estimator.retcode: Optimisation return code.w: Final aggregated portfolio weights.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::NonFiniteAllocationOptimisationResult, fb::Option{<:OptE_Opt})Rebuild a continuous optimisation result with an updated fallback optimiser fb.
Every optimisation result carries fb as its last field, so the generic rebuild copies all fields unchanged except the trailing fb. Concrete result types may override this method when rebuilding requires more than swapping fb.
Related
sourcefactory(
opt::Union{NonFiniteAllocationOptimisationEstimator, NonFiniteAllocationOptimisationResult},
_
) -> RandomWeighted{_A, var"#s179", _B, _C, _D, var"#s1791", _E, Bool} where {_A, var"#s179"<:AbstractRNG, _B, _C, _D, var"#s1791"<:WeightFinaliser, _E}Return opt unchanged.
Default pass-through factory for optimisation estimators and results. Overridden for estimators that carry parameters requiring update at each optimisation step.
Related
sourcePortfolioOptimisers.Stacking Type
struct Stacking{__T_pe, __T_wb, __T_fees, __T_sets, __T_scale, __T_opti, __T_opto, __T_cv, __T_wf, __T_ex, __T_fb, __T_brt, __T_strict} <: BaseStackingOptimisationEstimatorStacking portfolio optimiser.
Stacking implements a stacking (model combination) approach to portfolio optimisation. It applies multiple inner optimisers (opti) to the data, then combines their outputs with a single outer optimiser (opto) to produce a final portfolio. Optionally, cross-validation can be used to weight the inner optimisers' contributions.
Fields
pe: Prior estimator.wb: Weight bounds estimator or weight bounds.fees: Fees estimator.sets: Sets used to map estimator values to features.scale: Optional scaling vector for inner optimiser weights (length must matchopti).opti: Inner optimiser.opto: Outer optimiser.cv: Cross-validation estimator.wf: Weight finaliser.ex: Parallel execution strategy.fb: Fallback result or estimator.brt: Whether to use bootstrap returns.strict: Whether to strictly enforce weight bounds.
Constructors
Stacking(;
pe::PrE_Pr = EmpiricalPrior(),
wb::Option{<:WbE_Wb} = nothing,
fees::Option{<:FeesE_Fees} = nothing,
sets::Option{<:AssetSets} = nothing,
scale::Option{<:VecNum} = nothing,
opti::VecOptE_Opt,
opto::NonFiniteAllocationOptimisationEstimator,
cv::Option{<:OptimisationCrossValidation} = nothing,
wf::WeightFinaliser = IterativeWeightFinaliser(),
ex::FLoops.Transducers.Executor = FLoops.ThreadedEx(),
fb::Option{<:OptE_Opt} = nothing,
brt::Bool = false,
strict::Bool = false
) -> StackingKeywords correspond to the struct's fields.
Validation
!isempty(opti).If
scaleis provided:length(scale) == length(opti)and all elements are finite.
Mathematical definition
Let
Where:
: Final stacked portfolio weights. : Number of inner optimisers. : Optional scale factor for inner optimiser . : Returns proxy matrix weighted by inner-optimiser weights . : Outer optimiser applied to the aggregated returns proxy.
Related
sourcePortfolioOptimisers.needs_previous_weights Method
needs_previous_weights(opt::Stacking) -> AnyReturn true if any sub-estimator of opt requires previous portfolio weights (fees, inner optimiser, outer optimiser, or fallback).
PortfolioOptimisers.factory Method
factory(
st::Stacking,
w::AbstractVector
) -> Stacking{_A, _B, _C, _D, _E, var"#s179", var"#s1791", _F, var"#s1792", var"#s1793", _G, Bool, Bool} where {_A, _B, _C, _D, _E, var"#s2432"<:(Union{var"#s2432", var"#s2431"} where {var"#s2432"<:NonFiniteAllocationOptimisationEstimator, var"#s2431"<:NonFiniteAllocationOptimisationResult}), var"#s179"<:AbstractVector{var"#s2432"}, var"#s1791"<:NonFiniteAllocationOptimisationEstimator, _F, var"#s1792"<:WeightFinaliser, var"#s1793"<:Transducers.Executor, _G}Build an updated Stacking with all estimators that track previous weights updated via factory using w.
PortfolioOptimisers.port_opt_view Method
port_opt_view(
st::Stacking,
i,
X::AbstractMatrix{<:Union{var"#s20", var"#s19"} where {var"#s20"<:Number, var"#s19"<:AbstractJuMPScalar}},
args...
) -> Stacking{_A, _B, _C, _D, _E, var"#s179", var"#s1791", _F, var"#s1792", var"#s1793", _G, Bool, Bool} where {_A, _B, _C, _D, _E, var"#s2432"<:(Union{var"#s2432", var"#s2431"} where {var"#s2432"<:NonFiniteAllocationOptimisationEstimator, var"#s2431"<:NonFiniteAllocationOptimisationResult}), var"#s179"<:AbstractVector{var"#s2432"}, var"#s1791"<:NonFiniteAllocationOptimisationEstimator, _F, var"#s1792"<:WeightFinaliser, var"#s1793"<:Transducers.Executor, _G}Return a cluster-sliced copy of Stacking for asset index set i and returns matrix X.
PortfolioOptimisers.predict_outer_st_estimator_returns Function
predict_outer_st_estimator_returns(
st::Option{<:Stacking},
rd::ReturnsResult,
pr::AbstractPriorResult,
fees::Option{<:Fees},
wi::MatNum,
resi::VecOpt
)Predict outer portfolio returns for Stacking optimisation. Overload this using st.cv for custom cross-validation prediction.
PortfolioOptimisers.assert_special_nco_requirements Method
assert_special_nco_requirements(opt)Assert that the optimiser meets special requirements for Nested Clustered Optimisation (NCO).
The default implementation does nothing. Overridden for estimators (e.g. Stacking) that have requirements which must be validated before NCO can proceed.
Arguments
opt: Optimisation estimator, result, or vector thereof.
Returns
nothing.
Related
sourcePortfolioOptimisers.optimise Method
optimise(st::Stacking{<:Any, <:Any, <:Any, <:Any, <:Any, <:Any, <:Any, <:Any,
<:Any, <:Any, Nothing
}, rd::ReturnsResult;
dims::Int = 1, branchorder::Symbol = :optimal, str_names::Bool = false,
save::Bool = true, kwargs...) -> StackingResultRun the Stacking portfolio optimisation.
Arguments
st: The stacking optimiser to use.rd: The returns result to use.dims: The dimension along which observations advance in time.branchorder: Passed to the inner and outer optimisers. The branch order to use for the clusterisation.str_names: Passed to the inner and outer optimisers. Whether to use string names for the assets in the optimisation.save: Passed to the inner and outer optimisers. Whether to save the JuMP model in the optimisation result.kwargs: Additional keyword arguments passed to the optimisation function.
Related
source