Mean Risk
PortfolioOptimisers.MeanRiskResult Type
struct MeanRiskResult{__T_jr, __T_fb} <: RiskJuMPOptimisationResultResult type for Mean-Risk portfolio optimisation.
Fields
jr: Shared JuMP result core, seeJuMPOptimisationResult.fb: Fallback result or estimator.
Property access delegates to the embedded JuMPOptimisationResult: the virtual :w property and unknown properties resolve through jr.
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
sourceBase.getproperty Method
getproperty(
r::RiskJuMPOptimisationResult,
sym::Symbol
) -> AnyDefault property access for RiskJuMPOptimisationResult: unique fields resolve directly; everything else delegates to the embedded JuMPOptimisationResult jr.
PortfolioOptimisers.MeanRisk Type
struct MeanRisk{__T_opt, __T_r, __T_obj, __T_wi, __T_fb} <: RiskJuMPOptimisationEstimatorMean-Risk portfolio optimiser.
MeanRisk formulates and solves a mean-risk portfolio optimisation problem using JuMP. It can optimise a wide variety of objective functions (minimum risk, maximum return, maximum Sharpe ratio, maximum utility) subject to risk, weight, cardinality, and custom constraints.
Fields
opt:JuMPoptimiser configuration.r: Risk measure or vector of risk measures.obj: Portfolio objective function.wi: Initial portfolio weights for warm-starting the solver.fb: Fallback result or estimator.
Constructors
MeanRisk(;
opt::JuMPOptimiser = JuMPOptimiser(),
r::RM_VecRM = Variance(),
obj::ObjectiveFunction = MinimumRisk(),
wi::Option{<:VecNum} = nothing,
fb::Option{<:OptE_Opt} = nothing
) -> MeanRiskKeywords correspond to the struct's fields.
Validation
If
ris a vector:!isempty(r).If
wiis provided:!isempty(wi).
Examples
julia> MeanRisk(; opt = JuMPOptimiser(; slv = Solver()))
MeanRisk
opt ┼ JuMPOptimiser
│ 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
│ slv ┼ Solver
│ │ name ┼ String: ""
│ │ solver ┼ nothing
│ │ settings ┼ nothing
│ │ check_sol ┼ @NamedTuple{}: NamedTuple()
│ │ add_bridges ┴ Bool: true
│ wb ┼ WeightBounds
│ │ lb ┼ Float64: 0.0
│ │ ub ┴ Float64: 1.0
│ bgt ┼ Float64: 1.0
│ sbgt ┼ nothing
│ lt ┼ nothing
│ st ┼ nothing
│ lcse ┼ nothing
│ cte ┼ nothing
│ gcarde ┼ nothing
│ sgcarde ┼ nothing
│ smtx ┼ nothing
│ sgmtx ┼ nothing
│ slt ┼ nothing
│ sst ┼ nothing
│ sglt ┼ nothing
│ sgst ┼ nothing
│ tn ┼ nothing
│ fees ┼ nothing
│ sets ┼ nothing
│ tr ┼ nothing
│ ple ┼ nothing
│ ret ┼ ArithmeticReturn
│ │ ucs ┼ nothing
│ │ lb ┼ nothing
│ │ mu ┴ nothing
│ sca ┼ SumScalariser()
│ ccnt ┼ nothing
│ cobj ┼ nothing
│ sc ┼ Int64: 1
│ so ┼ Int64: 1
│ ss ┼ nothing
│ card ┼ nothing
│ scard ┼ nothing
│ nea ┼ nothing
│ l1 ┼ nothing
│ l2 ┼ nothing
│ linf ┼ nothing
│ lp ┼ nothing
│ brt ┼ Bool: false
│ cle_pr ┼ Bool: true
│ strict ┴ Bool: false
r ┼ Variance
│ settings ┼ RiskMeasureSettings
│ │ scale ┼ Float64: 1.0
│ │ ub ┼ nothing
│ │ rke ┴ Bool: true
│ sigma ┼ nothing
│ chol ┼ nothing
│ rc ┼ nothing
│ alg ┴ SquaredSOCRiskExpr()
obj ┼ MinimumRisk()
wi ┼ nothing
fb ┴ nothingMathematical definition
The general mean-risk optimisation problem is:
Objective ObjectiveFunction:
MaximumRatio(Sharpe):
Where:
: Portfolio weight vector. : Feasible weight set defined by portfolio constraints. : Objective function (depends on ObjectiveFunction).: Portfolio risk measure. : Estimated expected return vector. : Risk aversion parameter. : Risk-free rate.
Related
PortfolioOptimisers.needs_previous_weights Method
needs_previous_weights(opt::MeanRisk) -> AnyReturn true if any sub-estimator of opt requires previous portfolio weights (JuMP optimiser, risk measure, or fallback).
PortfolioOptimisers.factory Method
factory(
mr::MeanRisk,
w::AbstractVector
) -> MeanRisk{JuMPOptimiser{__T_pe, __T_slv, __T_wb, __T_bgt, __T_sbgt, __T_lt, __T_st, __T_lcse, __T_cte, __T_gcarde, __T_sgcarde, __T_smtx, __T_sgmtx, __T_slt, __T_sst, __T_sglt, __T_sgst, __T_tn, __T_fees, __T_sets, __T_tr, __T_ple, __T_ret, __T_sca, __T_ccnt, __T_cobj, __T_sc, __T_so, __T_ss, __T_card, __T_scard, __T_nea, __T_l1, __T_l2, __T_linf, __T_lp, __T_brt, __T_cle_pr, __T_strict}, _A, <:ObjectiveFunction} where {__T_pe, __T_slv, __T_wb, __T_bgt, __T_sbgt, __T_lt, __T_st, __T_lcse, __T_cte, __T_gcarde, __T_sgcarde, __T_smtx, __T_sgmtx, __T_slt, __T_sst, __T_sglt, __T_sgst, __T_tn, __T_fees, __T_sets, __T_tr, __T_ple, __T_ret, __T_sca, __T_ccnt, __T_cobj, __T_sc, __T_so, __T_ss, __T_card, __T_scard, __T_nea, __T_l1, __T_l2, __T_linf, __T_lp, __T_brt, __T_cle_pr, __T_strict, _A}Build an updated MeanRisk with all estimators that track previous weights updated via factory using w.
PortfolioOptimisers.port_opt_view Method
port_opt_view(
mr::MeanRisk,
i,
X::AbstractMatrix{<:Union{var"#s20", var"#s19"} where {var"#s20"<:Number, var"#s19"<:AbstractJuMPScalar}},
args...
) -> MeanRisk{JuMPOptimiser{__T_pe, __T_slv, __T_wb, __T_bgt, __T_sbgt, __T_lt, __T_st, __T_lcse, __T_cte, __T_gcarde, __T_sgcarde, __T_smtx, __T_sgmtx, __T_slt, __T_sst, __T_sglt, __T_sgst, __T_tn, __T_fees, __T_sets, __T_tr, __T_ple, __T_ret, __T_sca, __T_ccnt, __T_cobj, __T_sc, __T_so, __T_ss, __T_card, __T_scard, __T_nea, __T_l1, __T_l2, __T_linf, __T_lp, __T_brt, __T_cle_pr, __T_strict}, _A, <:ObjectiveFunction} where {__T_pe, __T_slv, __T_wb, __T_bgt, __T_sbgt, __T_lt, __T_st, __T_lcse, __T_cte, __T_gcarde, __T_sgcarde, __T_smtx, __T_sgmtx, __T_slt, __T_sst, __T_sglt, __T_sgst, __T_tn, __T_fees, __T_sets, __T_tr, __T_ple, __T_ret, __T_sca, __T_ccnt, __T_cobj, __T_sc, __T_so, __T_ss, __T_card, __T_scard, __T_nea, __T_l1, __T_l2, __T_linf, __T_lp, __T_brt, __T_cle_pr, __T_strict, _A}Return a cluster-sliced copy of MeanRisk for asset index set i and returns matrix X.
PortfolioOptimisers.solve_mean_risk! Function
solve_mean_risk!(model, mr, ret, pr, ::Val{false}, ::Val{false}, args...)
solve_mean_risk!(model, mr, ret, pr, ::Val{true}, ::Val{false}, fees)
solve_mean_risk!(model, mr, ret, pr, ::Val{false}, ::Val{true}, fees)
solve_mean_risk!(model, mr, ret, pr, ::Val{true}, ::Val{true}, fees)Solve the Mean-Risk optimisation problem.
Dispatches based on whether a return frontier and/or risk frontier sweep is requested (controlled by Val arguments). Single-point, return-frontier, risk-frontier, and combined sweeps are all handled.
Arguments
model::JuMP.Model: JuMP optimisation model.mr::MeanRisk: MeanRisk estimator configuration.ret::JuMPReturnsEstimator: Returns estimator.pr::AbstractPriorResult: Prior result with asset moments.::Val{bool}: Whether to do a return frontier sweep.::Val{bool}: Whether to do a risk frontier sweep.fees: Optional fees configuration.
Returns
(retcode, sol)or(retcodes, sols)depending on the sweep mode.
Related
sourcePortfolioOptimisers.compute_ret_lbs Function
compute_ret_lbs(lbs, args...)Compute the return lower bounds for the efficient frontier sweep.
Dispatches based on the type of lbs: if a pre-computed vector of lower bounds is provided, returns it directly. If a Frontier specification is given, solves the minimum and maximum return sub-problems and constructs a range of bounds.
Arguments
lbs: Pre-computed return bounds vector (VecNum) orFrontierconfiguration.args...: Additional arguments (model, optimiser, prior, etc.) needed whenlbsis aFrontier.
Returns
- Vector or range of return lower bounds for frontier sweep.
Related
sourcecompute_ret_lbs(lbs::Frontier, model::JuMP.Model, mr::MeanRisk, ret::JuMPReturnsEstimator, pr::AbstractPriorResult, fees::Option{<:Fees})Compute return lower bounds for a MeanRisk efficient frontier sweep by solving minimum and maximum return sub-problems.
Solves the minimum-risk and maximum-return portfolios, then constructs a uniformly spaced range of lbs.N return targets spanning the two extremes.
Arguments
lbs::Frontier: Frontier configuration specifying the number of points.model::JuMP.Model: JuMP optimisation model.mr::MeanRisk: MeanRisk estimator configuration.ret::JuMPReturnsEstimator: Returns estimator.pr::AbstractPriorResult: Prior result with asset moments.fees::Option{<:Fees}: Optional fees configuration.
Returns
- Range of return lower bounds for the frontier sweep.
Related
sourcecompute_ret_lbs(lbs::Frontier, rt_min::Number, rt_max::Number)Compute return lower bounds for a NearOptimalCentering frontier sweep from pre-computed minimum and maximum return values.
Constructs a uniformly spaced range of lbs.N return targets between rt_min and rt_max.
Arguments
lbs::Frontier: Frontier configuration specifying the number of points.rt_min::Number: Minimum portfolio return (from the minimum-risk portfolio).rt_max::Number: Maximum portfolio return (from the maximum-return portfolio).
Returns
- Range of
lbs.Nequally spaced return lower bounds.
Related
sourcePortfolioOptimisers._rebuild_risk_frontier Function
_rebuild_risk_frontier(pr, fees, ...)Internal helper to rebuild the risk frontier from a prior result.
Recomputes the risk range used for the efficient frontier given updated prior information and fee structures.
Arguments
pr: Prior result with asset moments.fees: Optional fees configuration.Additional parameters.
Returns
- Tuple of risk bound values for the frontier.
Related
sourcePortfolioOptimisers.rebuild_risk_frontier Function
rebuild_risk_frontier(model, mr, ...)Rebuild the efficient frontier risk bounds from a solved JuMP model.
Extracts and recomputes risk bound values from the optimised model for use in subsequent frontier sweeps.
Arguments
model: Solved JuMP model.mr: MeanRisk optimiser configuration.Additional parameters.
Returns
- Updated risk bounds for the frontier.
Related
sourcePortfolioOptimisers.compute_risk_ubs Function
compute_risk_ubs(model, opt, ...)Compute or rebuild risk upper bounds for the efficient frontier sweep.
Extracts the risk frontier from the model and rebuilds any frontier bounds that have not yet been computed as numeric vectors.
Arguments
model::JuMP.Model: JuMP optimisation model containing the risk frontier.opt: Optimiser configuration.Additional arguments (prior, fees, weights, etc.).
Returns
- Updated risk frontier vector of pairs.
Related
sourcecompute_risk_ubs(model::JuMP.Model, noc::NearOptimalCentering{<:Any, <:Any, <:Any, <:Any, <:Any, <:Any, <:Any, <:Any, <:Any, <:Any, <:Any, <:ConstrainedNearOptimalCentering}, pr::AbstractPriorResult, fees::Option{<:Fees}, w_min::VecNum, w_max::VecNum)Compute risk upper bounds for a constrained NearOptimalCentering frontier sweep.
Identifies risk frontier entries that are not yet resolved (i.e. not concrete weight vectors) and rebuilds them using the minimum and maximum portfolio weights.
Arguments
model::JuMP.Model: JuMP optimisation model containingrisk_frontier.noc::NearOptimalCentering{..., <:ConstrainedNearOptimalCentering}: Constrained Near Optimal Centering optimiser.pr::AbstractPriorResult: Prior result with asset moments.fees::Option{<:Fees}: Optional fees configuration.w_min::VecNum: Minimum-risk portfolio weights.w_max::VecNum: Maximum-risk (maximum-return) portfolio weights.
Returns
- Updated risk frontier vector of
(keys, vals)pairs.
Related
sourcePortfolioOptimisers.optimise Function
optimise(mr::MeanRisk{<:Any, <:Any, <:Any, <:Any, Nothing},
rd::ReturnsResult = ReturnsResult(); dims::Int = 1,
str_names::Bool = false, save::Bool = true, kwargs...) -> MeanRiskResultRun the Mean-Risk portfolio optimisation.
Arguments
mr: The mean risk optimiser to use.rd: The returns result to use. Ifisa(mr.opt.pe, AbstractPriorResult),rdis not necessary if doing a standalone optimisation, but may be required/desired by fallbacks and/or clusterisation.dims: The dimension along which observations advance in time.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
source