Stochastic Dominance API
Main functions
StochasticDominance.optimize_max_return_SD
— Functionoptimize_max_return_SD(ξ, ξ_0,SDorder;p_ξ, p_ξ_0,plot=false,verbose=false, ε=1e-5, max_ipot=50, max_iter=50, n_particles=50)
Solve a portfolio optimization problem under stochastic dominance constraints to maximize the expected return.
Arguments
ξ::AbstractMatrix{<:Number}
: Portfolio return scenarios.ξ_0::AbstractVector{<:Number}
: Benchmark return scenarios.SDorder::Number}
: Order of stochastic dominance.p_ξ::AbstractVector{<:Number}
: Probability distribution over portfolio scenarios.p_ξ_0::AbstractVector{<:Number}
: Probability distribution over benchmark scenarios.plot::Bool
(optional, default =false
): Plot the optimal asset allocation.verbose::Bool
(optional, default =false
): Print convergence details.ε::Float64
(optional, default =1e-7
): Convergence tolerance.max_ipot::Integer
(optional, default =50
): Maximum number of attempts to push the objective towards maximization. (Interior point optimization)max_iter::Integer
(optional, default =50
): Maximum iterations for optimization.n_particles::Integer
(optional, default =200
): Number of particles for PSO.
Returns
- A tuple
(x_opt, t_opt)
, where:x_opt
: Optimized portfolio weights.t_opt
: Auxiliary optimization variable.
Examples
# Define portfolio return scenarios (rows: assets, columns: scenarios)
ξ = [0.02 0.05 -0.01; # Asset 1 returns under different scenarios
0.03 0.06 0.02] # Asset 2 returns under different scenarios
# Define benchmark return scenarios (column vector)
ξ_0 = [0.01, 0.04, 0.00] # Benchmark returns in the same scenarios
# Define probability distributions for portfolio and benchmark scenarios
p_ξ = [0.3, 0.4, 0.3] # Probabilities for each scenario
p_ξ_0 = [0.4, 0.4, 0.2] # Probabilities for benchmark scenarios
# Set the order of stochastic dominance
SDorder = 2.0 # Second-order stochastic dominance
x_opt, t_opt = optimize_max_return_SD(ξ, ξ_0,SDorder;p_ξ, p_ξ_0,ε=1e-6,verbose=true)
Solves the portfolio optimization problem under stochastic dominance constraints.
StochasticDominance.optimize_min_riskreturn_SD
— Functionoptimize_min_riskreturn_SD(ξ, ξ_0,SDorder; β=0.5,r=2.0,p_ξ, p_ξ_0, ε=1e-5, plot=false, verbose=false, max_ipot=50, max_iter=50, n_particles=50)
Solve a portfolio optimization problem under stochastic dominance risk constraints
Arguments
ξ::AbstractMatrix{<:Number}
: Portfolio return scenarios.ξ_0::AbstractVector{<:Number}
: Benchmark return scenarios.SDorder::S
: Order of stochastic dominance.r::Number
(optional, default =2.0
): norm of risk measure.β::Number
(optional, default =0.5
): Confidence level for risk measure.p_ξ::AbstractVector{<:Number}
: Probability distribution over portfolio scenarios.p_ξ_0::AbstractVector{<:Number}
: Probability distribution over benchmark scenarios.ε::Float64
(optional, default =1e-7
): Convergence tolerance.plot::Bool
(optional, default =false
): Plot the optimal asset allocation.verbose::Bool
(optional, default =false
): Print convergence details.max_ipot::Integer
(optional, default =50
): Maximum number of attempts to push the objective towards maximization. (Interior point optimization)max_iter::Integer
(optional, default =50
): Maximum iterations for optimization.n_particles::Integer
(optional, default =200
): Number of particles for PSO.
Returns
- A tuple
(x_opt, q_opt, t_opt)
, where:x_opt
: Optimized portfolio weights.q_opt
: Optimized risk threshold parameter.t_opt
: Auxiliary optimization variable.
Examples
# Define portfolio return scenarios (rows: assets, columns: scenarios)
ξ = [0.02 0.05 -0.01; # Asset 1 returns under different scenarios
0.03 0.06 0.02] # Asset 2 returns under different scenarios
# Define benchmark return scenarios (column vector)
ξ_0 = [0.01, 0.04, 0.00] # Benchmark returns in the same scenarios
# Define probability distributions for portfolio and benchmark scenarios
p_ξ = [0.3, 0.4, 0.3] # Probabilities for each scenario
p_ξ_0 = [0.4, 0.4, 0.2] # Probabilities for benchmark scenarios
# Set the order of stochastic dominance
SDorder = 2 # Second-order stochastic dominance
# Set the risk parameter
β=0.5
# Set the norm of the risk measure
r=2.0
x_opt, q_opt,t_opt= optimize_min_riskreturn_SD(ξ, ξ_0,SDorder;p_ξ, p_ξ_0,β,r,ε=1e-6,verbose=true,plot=true)
Solves the portfolio optimization problem under stochastic dominance constraints.
StochasticDominance.verify_dominance
— Functionverify_dominance(Y, X,SDorder; p_X, p_Y,ε=1e-5,verbose=false)
Verify if Y
stochastically dominates X
at a given stochastic oder
Arguments
Y::AbstractVector{<:Number}
: Portfolio outcomes (returns).X::AbstractVector{<:Number}
: Benchmark outcomes.p_X::AbstractVector{<:Number}
: Probabilities associated withX
.p_Y::AbstractVector{<:Number}
: Probabilities associated withY
.SDorder::Integer
: Order of stochastic dominance (SD).
Keyword Arguments
ε::Float64=1e-5
: Convergence tolerance for the dominance check.verbose::Bool=false
: Iftrue
, print detailed accuracy or residuals.
Returns
- A message indicating whether
Y
stochastically dominatesX
at orderSDorder
. true
ifY
stochastically dominatesX
at the given order.false
otherwise.
Examples
Y = [3, 5, 7]
X = [2, 4, 6]
p_Y = [0.3, 0.4, 0.3]
p_X = [0.2, 0.5, 0.3]
SDorder = 2
verify_dominance(Y, X, SDorder; p_X, p_Y, ε=1e-8,verbose=true)
StochasticDominance.optimize_min_risk
— Functionoptimize_min_risk(ξ_0::AbstractVector{T}, p_ξ_0::AbstractVector{T};
β::T=0.5, r::T=2, ε::Float64=1e-7, max_iter::Integer=50,
n_particles::Integer=100, max_ipot::Integer=50) where {T<:Number}
Performs risk minimization using Particle Swarm Optimization (PSO) to find the optimal risk threshold parameter q
.
Arguments
ξ_0::AbstractVector{<:Number}
: Benchmark return scenarios.p_ξ_0::AbstractVector{<:Number}
: Probability distribution over benchmark scenarios.
Keyword Arguments
β::Number = 0.5
: Confidence level for risk measure.r::Number = 2.0
: Norm of the risk measure.ε::Float64 = 1e-7
: Convergence tolerance.max_iter::Integer = 50
: Maximum number of iterations for optimization.n_particles::Integer = 100
: Number of particles for PSO.max_ipot::Integer = 50
: Maximum number of attempts for interior point optimization.
Returns
q_opt_best::Float64
: The optimized risk threshold parameter.
Example
# Define benchmark return scenarios
ξ_0 = [0.01, 0.04, 0.00] # Benchmark returns in different scenarios
# Define probability distribution for benchmark scenarios
p_ξ_0 = [0.4, 0.4, 0.2] # Probabilities for benchmark scenarios
# Set risk parameters
β = 0.5
r = 2.0
# Solve the risk minimization problem
q_opt_best = optimize_min_risk(ξ_0, p_ξ_0; β=β, r=r, ε=1e-6, max_iter=100)
Auxiliary functions
StochasticDominance.AuxiliaryFunc.g_bar
— Functiong_bar(x, ξ, ξ_0, p, p_ξ, p_ξ_0)
Compute the verification of the higher-order stochastic dominance constraint by evaluating g_p
over sorted benchmark values.
Arguments
x::AbstractVector{<:Number}
: Portfolio weights (simplex).ξ::AbstractVector{<:Number}
: Portfolio returns.ξ_0::AbstractVector{<:Number}
: Benchmark returns.p::Number
: The order-1 of stochastic dominance.p_ξ::AbstractVector{<:Number}
: Probability of portfolioξ
.p_ξ_0::AbstractVector{<:Number}
: Probability of benchmarkξ_0
.
Returns
- A numeric value computed as
max(max_value, 0.0)
, where:max_value
is the maximum ofg_p(t, x, ξ, ξ_0, p, p_ξ, p_ξ_0)
over sortedξ_0
.- If
max_value
is negative, the function returns0.0
. - If
max_value
is positive, the selected portfolio or the portfolio with assigned weights does not satisfy the dominance condition."
Examples
g_bar([0.7, 0.3], [2 3; 5 6], [2,3,4], 3, [0.5,0.5], [0.2,0.3,0.5])
StochasticDominance.AuxiliaryFunc.boundary_moments
— Functionboundarymoments(x, ξ, pξ, pξ0, ξ_0, p)
Compute the boundary moments for higher-order stochastic dominance constraints by comparing the moments of the portfolio and benchmark distributions.
Arguments
x::AbstractVector{<:Number}
: Portfolio weights (simplex constraint).ξ::AbstractMatrix{<:Number}
: Portfolio returns.p_ξ::AbstractVector{<:Number}
: Probability distribution of the portfolio returnsξ
.p_ξ_0::AbstractVector{<:Number}
: Probability distribution of the benchmark returnsξ_0
.ξ_0::AbstractVector{<:Number}
: Benchmark returns.p::Real
: The highest moment order. Ifp
is an integer,boundary_moments_integer
is used. Ifp
is non-integer,boundary_moments_noninteger
is used.
Returns
- A vector containing computed moment constraints:
- For
k = 1
: Compares the mean of the portfolio and benchmark. - For
k ≥ 2
: Computes and compares the central moments. - If the portfolio moment does not exceed the benchmark moment, the value is set to zero.
- Otherwise, the result stores the norm of the difference.
Methodology
- Integer Case (
p
is an integer): - Computes moments from order 1 order
p
. - Uses the function
boundary_moments_integer
. - Non-Integer Case (
p
is a non-integer): - Computes moments from order (0,1) order
p
- Uses the function
boundary_moments_noninteger
.
Examples
# Example 1: Integer order moments
boundary_moments([0.7, 0.3], [2 3; 5 6], [0.5, 0.5], [0.2, 0.3, 0.5], [2, 3, 4], 3)
# Example 2: Non-integer order moments
boundary_moments([0.7, 0.3], [2 3; 5 6], [0.5, 0.5], [0.2, 0.3, 0.5], [2, 3, 4], 2.7)
StochasticDominance.AuxiliaryFunc.expected_portfolio_return
— Functionexpected_portfolio_return(x, ξ, p_ξ)
Compute the expected return of a portfolio given asset returns and probabilities.
Arguments
x::AbstractVector{<:Number}
: Portfolio weights (simplex).ξ::AbstractMatrix{<:Number}
: Matrix of asset returns (each column represents a scenario).p_ξ::AbstractVector{<:Number}
: Probability distribution over the scenarios.
Returns
- A numeric value representing the expected portfolio return
Examples
expected_portfolio_return([0.7, 0.3], [2 3; 5 6], [0.5,0.5])
# Computes the expected portfolio return.
StochasticDominance.AuxiliaryFunc.riskfunction_asset_allocation
— Functionriskfunction_asset_allocation(x, q, ξ, r, p_ξ, β)
Calculates the risk-adjusted portfolio return based on quantile-based risk measures.
Arguments
x
: Portfolio weights (decision variables to optimize).q
: Quantile threshold for the risk measure.ξ
: Portfolio scenarios (matrix of asset returns).r
: Norm parameter.p_ξ
: Probability weights for the scenarios inξ
.β
: Risk aversion parameter (closer to 1 indicates higher aversion).
Returns
- The risk-adjusted return, which accounts for portfolio performance and risk under extreme loss scenarios.