Naive optimisation
PortfolioOptimisers.NaiveOptimisationEstimator Type
abstract type NaiveOptimisationEstimator <: NonFiniteAllocationOptimisationEstimatorAbstract supertype for naive (heuristic) portfolio optimisation estimators.
Naive optimisers compute portfolio weights directly from statistical properties of asset returns (e.g., volatility or equal weights) without solving an optimisation problem.
Related
sourcePortfolioOptimisers.needs_previous_weights Method
needs_previous_weights(
opt::NaiveOptimisationEstimator
) -> AnyReturn whether the naive optimiser's fallback estimator requires previous portfolio weights.
Related
sourcePortfolioOptimisers.assert_internal_optimiser Method
assert_internal_optimiser(_::NaiveOptimisationEstimator)Assert internal validity for a naive optimisation estimator. No-op default.
Related
sourcePortfolioOptimisers.assert_external_optimiser Method
assert_external_optimiser(_::NaiveOptimisationEstimator)Assert external validity for a naive optimisation estimator. No-op default.
Related
sourcePortfolioOptimisers.NaiveOptimisationResult Type
struct NaiveOptimisationResult{__T_oe, __T_pr, __T_wb, __T_retcode, __T_w, __T_fb} <: NonJuMPOptimisationResultResult type for naive portfolio optimisation estimators.
Fields
oe: Type of the optimisation estimator that produced this result.pr: Prior result.wb: Weight bounds.retcode: Optimisation return code.w: Portfolio weights vectorassets × 1.fb: Fallback result or estimator.
Constructors
NaiveOptimisationResult(oe, pr, wb, retcode, w, fb) -> NaiveOptimisationResultPositional arguments correspond to the struct's fields.
Examples
julia> NaiveOptimisationResult(InverseVolatility, nothing, nothing, OptimisationSuccess(),
[0.5, 0.5], nothing)
NaiveOptimisationResult
oe ┼ UnionAll: InverseVolatility
pr ┼ nothing
wb ┼ nothing
retcode ┼ OptimisationSuccess
│ res ┴ nothing
w ┼ Vector{Float64}: [0.5, 0.5]
fb ┴ nothingRelated
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.InverseVolatility Type
struct InverseVolatility{__T_pe, __T_wb, __T_sets, __T_wf, __T_fb, __T_sq, __T_brt, __T_strict} <: NaiveOptimisationEstimatorInverse Volatility portfolio optimiser.
InverseVolatility allocates portfolio weights inversely proportional to each asset's volatility (standard deviation). Optionally, sq = true uses variance instead.
Mathematical definition
Where:
: Portfolio weight of asset . : Standard deviation of asset (variance when sq = true).: Number of assets.
Fields
pe: Prior estimator.wb: Weight bounds.sets: Sets used to map estimator values to features.wf: Weight finaliser.fb: Fallback result or estimator.sq: Whether to use variance instead of volatility in the inverse weighting.brt: Whether to use bootstrap returns.strict: Whether to strictly enforce weight bounds.
Constructors
InverseVolatility(;
pe::PrE_Pr = EmpiricalPrior(),
wb::Option{<:WbE_Wb} = WeightBounds(),
sets::Option{<:AssetSets} = nothing,
wf::WeightFinaliser = IterativeWeightFinaliser(),
fb::Option{<:OptE_Opt} = nothing,
sq::Bool = false,
brt::Bool = false,
strict::Bool = false
) -> InverseVolatilityKeywords correspond to the struct's fields.
Propagated parameters
When factory is called on this type, the following @fprop-tagged fields are automatically propagated:
fb: Recursively updated viafactory.
View parameters
When port_opt_view is called on this type, the following @vprop-tagged fields are automatically subset to the selected indices:
pe: Recursively viewed viaport_opt_view.wb: Recursively viewed viaport_opt_view.sets: Sliced to the selected indices viaport_opt_view.
Examples
julia> InverseVolatility()
InverseVolatility
pe ┼ EmpiricalPrior
│ ce ┼ PortfolioOptimisersCovariance
│ │ ce ┼ Covariance
│ │ │ me ┼ SimpleExpectedReturns
│ │ │ │ w ┴ nothing
│ │ │ ce ┼ GeneralCovariance
│ │ │ │ ce ┼ StatsBase.SimpleCovariance: StatsBase.SimpleCovariance(true)
│ │ │ │ w ┴ nothing
│ │ │ alg ┴ Full()
│ │ mp ┼ MatrixProcessing
│ │ │ pdm ┼ Posdef
│ │ │ │ alg ┼ UnionAll: NearestCorrelationMatrix.Newton
│ │ │ │ kwargs ┴ @NamedTuple{}: NamedTuple()
│ │ │ dn ┼ nothing
│ │ │ dt ┼ nothing
│ │ │ alg ┼ nothing
│ │ │ order ┴ NTuple{4, Symbol}: (:pdm, :dn, :dt, :alg)
│ me ┼ SimpleExpectedReturns
│ │ w ┴ nothing
│ horizon ┴ nothing
wb ┼ WeightBounds
│ lb ┼ Float64: 0.0
│ ub ┴ Float64: 1.0
sets ┼ nothing
wf ┼ IterativeWeightFinaliser
│ iter ┴ Int64: 100
fb ┼ nothing
sq ┼ Bool: false
brt ┼ Bool: false
strict ┴ Bool: falseRelated
sourcePortfolioOptimisers.assert_external_optimiser Method
assert_external_optimiser(opt::InverseVolatility)Assert that InverseVolatility is valid for external use.
Requires that opt.pe is not an AbstractPriorResult.
Related
sourcePortfolioOptimisers._optimise Method
_optimise(
iv::InverseVolatility;
...
) -> Union{NaiveOptimisationResult{__T_oe, __T_pr, _A, OptimisationSuccess{Nothing}, _B, Nothing} where {__T_oe<:(Type{InverseVolatility{__T_pe, __T_wb, __T_sets, __T_wf, __T_fb, __T_sq, __T_brt, __T_strict}} where {__T_pe, __T_wb, __T_sets, __T_wf, __T_fb, __T_sq, __T_brt, __T_strict}), __T_pr<:AbstractPriorResult, _A, _B}, NaiveOptimisationResult{__T_oe, __T_pr, _A, OptimisationFailure{String}, _B, Nothing} where {__T_oe<:(Type{InverseVolatility{__T_pe, __T_wb, __T_sets, __T_wf, __T_fb, __T_sq, __T_brt, __T_strict}} where {__T_pe, __T_wb, __T_sets, __T_wf, __T_fb, __T_sq, __T_brt, __T_strict}), __T_pr<:AbstractPriorResult, _A, _B}}
_optimise(
iv::InverseVolatility,
rd::ReturnsResult;
dims,
kwargs...
) -> Union{NaiveOptimisationResult{__T_oe, _A, _B, OptimisationSuccess{Nothing}, _C, Nothing} where {__T_oe<:(Type{InverseVolatility{__T_pe, __T_wb, __T_sets, __T_wf, __T_fb, __T_sq, __T_brt, __T_strict}} where {__T_pe, __T_wb, __T_sets, __T_wf, __T_fb, __T_sq, __T_brt, __T_strict}), _A, _B, _C}, NaiveOptimisationResult{__T_oe, _A, _B, OptimisationFailure{String}, _C, Nothing} where {__T_oe<:(Type{InverseVolatility{__T_pe, __T_wb, __T_sets, __T_wf, __T_fb, __T_sq, __T_brt, __T_strict}} where {__T_pe, __T_wb, __T_sets, __T_wf, __T_fb, __T_sq, __T_brt, __T_strict}), _A, _B, _C}}Run the inverse volatility portfolio optimisation.
Internal dispatch called by optimise. Computes covariance via the prior estimator, assigns weights inversely proportional to volatility (or variance when iv.sq = true), then applies weight bounds.
Related
sourcePortfolioOptimisers.optimise Function
optimise(iv::InverseVolatility{<:Any, <:Any, <:Any, <:Any, Nothing},
rd::ReturnsResult = ReturnsResult(); dims::Int = 1, kwargs...) -> NaiveOptimisationResultRun the inverse volatility portfolio optimisation.
Arguments
iv: The inverse volatility optimiser to use.rd: The returns result to use. Ifisa(iv.pe, AbstractPriorResult),rdis not necessary.dims: The dimension along which observations advance in time.kwargs: Additional keyword arguments passed to the optimisation function.
PortfolioOptimisers.EqualWeighted Type
struct EqualWeighted{__T_wb, __T_sets, __T_wf, __T_fb, __T_strict} <: NaiveOptimisationEstimatorEqual-weighted portfolio optimiser.
EqualWeighted allocates equal weight to all
Mathematical definition
Where:
: Portfolio weight of asset . : Number of assets.
Fields
wb: Weight bounds.sets: Sets used to map estimator values to features.wf: Weight finaliser.fb: Fallback result or estimator.strict: Whether to strictly enforce weight bounds.
Constructors
EqualWeighted(;
wb::Option{<:WbE_Wb} = WeightBounds(),
sets::Option{<:AssetSets} = nothing,
wf::WeightFinaliser = IterativeWeightFinaliser(),
fb::Option{<:OptE_Opt} = nothing,
strict::Bool = false
) -> EqualWeightedKeywords correspond to the struct's fields.
Propagated parameters
When factory is called on this type, the following @fprop-tagged fields are automatically propagated:
fb: Recursively updated viafactory.
View parameters
When port_opt_view is called on this type, the following @vprop-tagged fields are automatically subset to the selected indices:
wb: Recursively viewed viaport_opt_view.sets: Sliced to the selected indices viaport_opt_view.
Examples
julia> EqualWeighted()
EqualWeighted
wb ┼ WeightBounds
│ lb ┼ Float64: 0.0
│ ub ┴ Float64: 1.0
sets ┼ nothing
wf ┼ IterativeWeightFinaliser
│ iter ┴ Int64: 100
fb ┼ nothing
strict ┴ Bool: falseRelated
sourcePortfolioOptimisers._optimise Method
_optimise(
ew::EqualWeighted,
rd::ReturnsResult;
dims,
kwargs...
) -> Union{NaiveOptimisationResult{__T_oe, Nothing, _A, OptimisationSuccess{Nothing}, _B, Nothing} where {__T_oe<:(Type{EqualWeighted{__T_wb, __T_sets, __T_wf, __T_fb, __T_strict}} where {__T_wb, __T_sets, __T_wf, __T_fb, __T_strict}), _A, _B}, NaiveOptimisationResult{__T_oe, Nothing, _A, OptimisationFailure{String}, _B, Nothing} where {__T_oe<:(Type{EqualWeighted{__T_wb, __T_sets, __T_wf, __T_fb, __T_strict}} where {__T_wb, __T_sets, __T_wf, __T_fb, __T_strict}), _A, _B}}Run the equal-weighted portfolio optimisation.
Internal dispatch called by optimise. Assigns equal weights to all assets, then applies weight bounds.
Related
sourcePortfolioOptimisers.optimise Method
optimise(ew::EqualWeighted{<:Any, <:Any, <:Any, Nothing},
rd::ReturnsResult; dims::Int = 1, kwargs...) -> NaiveOptimisationResultRun the equal-weighted portfolio optimisation.
Arguments
ew: The equal-weighted optimiser to use.rd: The returns result to use. Used to know how many assets there are.dims: The dimension along which observations advance in time.kwargs: Additional keyword arguments passed to the optimisation function.
PortfolioOptimisers.RandomWeighted Type
struct RandomWeighted{__T_alpha, __T_rng, __T_seed, __T_wb, __T_sets, __T_wf, __T_fb, __T_strict} <: NaiveOptimisationEstimatorRandom-weighted portfolio optimiser.
RandomWeighted draws portfolio weights at random from a Dirichlet distribution with concentration parameter alpha. This can be used for simulation, benchmarking, or stress-testing.
Mathematical definition
Where:
: Portfolio weight vector. : Scalar or vector concentration parameter. Larger values concentrate the distribution near equal weights.
Fields
alpha: Dirichlet concentration parameter.rng: Random number generator.seed: Seed for the random number generator.wb: Weight bounds.sets: Sets used to map estimator values to features.wf: Weight finaliser.fb: Fallback result or estimator.strict: Whether to strictly enforce weight bounds.
Constructors
RandomWeighted(;
alpha::Num_VecNum = 1,
rng::Random.AbstractRNG = Random.default_rng(),
seed::Option{<:Integer} = nothing,
wb::Option{<:WbE_Wb} = nothing,
sets::Option{<:AssetSets} = nothing,
wf::WeightFinaliser = IterativeWeightFinaliser(),
fb::Option{<:OptE_Opt} = nothing,
strict::Bool = false
) -> RandomWeightedKeywords correspond to the struct's fields.
Validation
- If
alphais provided: all elements positive and finite.
Propagated parameters
When factory is called on this type, the following @fprop-tagged fields are automatically propagated:
fb: Recursively updated viafactory.
View parameters
When port_opt_view is called on this type, the following @vprop-tagged fields are automatically subset to the selected indices:
alpha: Sliced to the selected indices viaport_opt_view.wb: Recursively viewed viaport_opt_view.sets: Sliced to the selected indices viaport_opt_view.
Examples
julia> RandomWeighted()
RandomWeighted
alpha ┼ Int64: 1
rng ┼ Random.TaskLocalRNG: Random.TaskLocalRNG()
seed ┼ nothing
wb ┼ nothing
sets ┼ nothing
wf ┼ IterativeWeightFinaliser
│ iter ┴ Int64: 100
fb ┼ nothing
strict ┴ Bool: falseRelated
sourcePortfolioOptimisers._optimise Method
_optimise(
rw::RandomWeighted,
rd::ReturnsResult;
dims,
kwargs...
) -> Union{NaiveOptimisationResult{__T_oe, Nothing, _A, OptimisationSuccess{Nothing}, _B, Nothing} where {__T_oe<:(Type{RandomWeighted{__T_alpha, __T_rng, __T_seed, __T_wb, __T_sets, __T_wf, __T_fb, __T_strict}} where {__T_alpha, __T_rng, __T_seed, __T_wb, __T_sets, __T_wf, __T_fb, __T_strict}), _A, _B}, NaiveOptimisationResult{__T_oe, Nothing, _A, OptimisationFailure{String}, _B, Nothing} where {__T_oe<:(Type{RandomWeighted{__T_alpha, __T_rng, __T_seed, __T_wb, __T_sets, __T_wf, __T_fb, __T_strict}} where {__T_alpha, __T_rng, __T_seed, __T_wb, __T_sets, __T_wf, __T_fb, __T_strict}), _A, _B}}Run the random-weighted portfolio optimisation.
Internal dispatch called by optimise. Draws weights from a Dirichlet distribution parameterised by rw.alpha, then applies weight bounds.
Related
sourcePortfolioOptimisers.optimise Method
optimise(rw::RandomWeighted{<:Any, <:Any, <:Any, <:Any, <:Any, <:Any, Nothing},
rd::ReturnsResult; dims::Int = 1, kwargs...) -> NaiveOptimisationResultRun the random-weighted portfolio optimisation.
Arguments
rw: The random-weighted optimiser to use.rd: The returns result to use. Used to know how many assets there are.dims: The dimension along which observations advance in time.kwargs: Additional keyword arguments passed to the optimisation function.