Api
PortfolioOpt
PortfolioOpt.TestUtils
PortfolioOpt.AmbiguitySet
PortfolioOpt.BudgetSet
PortfolioOpt.CenteredAmbiguitySet
PortfolioOpt.DuWassersteinBall
PortfolioOpt.EllipticalSet
PortfolioOpt.MomentUncertainty
PortfolioOpt.calculate_measure!
PortfolioOpt.calculate_measure!
PortfolioOpt.calculate_measure!
PortfolioOpt.calculate_measure!
PortfolioOpt.calculate_measure!
PortfolioOpt.cidx
PortfolioOpt.convex_hull
PortfolioOpt.market_model
PortfolioOpt.sequential_backtest_market
PortfolioOpt.AmbiguitySet
— TypeAmbiguitySet
Alias for Union{CenteredAmbiguitySet, ContinuousMultivariateSampleable}
PortfolioOpt.BudgetSet
— TypeBudgetSet{T<:Real, D<:ContinuousMultivariateSampleable} <: CenteredAmbiguitySet{T,D}
Bertsimas's uncertainty set:
\[\left\{ \mu \; \middle| \begin{array}{ll} s.t. \quad \mu_i \leq \hat{r}_i + z_i \Delta_i \quad \forall i = 1:\mathcal{N} \\ \quad \quad \mu_i \geq \hat{r}_i - z_i \Delta_i \quad \forall i = 1:\mathcal{N} \\ \quad \quad z_i \geq 0 \quad \forall i = 1:\mathcal{N} \\ \quad \quad z_i \leq 1 \quad \forall i = 1:\mathcal{N} \\ \quad \quad \sum_{i}^{\mathcal{N}} z_i \leq \Gamma \\ \end{array} \right\} \\\]
Attributes:
d::Sampleable{Multivariate, Continous}
: The parent distribution with an uncertain meanΔ::Array{Float64,1}
: Uncertainty around mean. (default: std(d) / 5)Γ::Float64
: Number of assets in worst case. (default: 0.1 * length(d))
References:
- Bertsimas, D. e Sim, M. (2004). The price of robustness. Operations research, 52(1):35–53.
PortfolioOpt.CenteredAmbiguitySet
— TypeCenteredAmbiguitySet
Defines the ambiguity related to the distribution of a random variable, often used in Robust Optimization (RO) and Distributionally Robust Optimization (DRO) problems. It represents a bounded infinite set of distributions.
PortfolioOpt.DuWassersteinBall
— TypeDuWassersteinBall <: CenteredAmbiguitySet
\[\left\{ r \; \middle| \begin{array}{ll} s.t. \quad d_w(P, \hat{P}_N) \leq \epsilon \\ \quad \quad || \xi || \leq \Lambda \\ \quad \quad [\xi; 0] + [0_{m x 1}; \Lambda] \in K \\ \quad \quad K = {[\omega, \pi] \in R^m x R: \pi \geq ||\omega||^*} \\ \end{array} \right\} \\\]
Atributes:
d::DeterministicSamples
: Samples from the parent distributionϵ::Float64
: Wasserstein distance from sampled distribution (has to be greater than 0). (default: 0.01)Λ::Float64
: Uncertainty around sampled values (has to be greater than 0). (default: maximum(d))
References:
- NingNing paper on Wasserstein DRO (Corollary 1-3): https://ieeexplore.ieee.org/abstract/document/9311154
PortfolioOpt.EllipticalSet
— TypeEllipticalSet <: CenteredAmbiguitySet{T,D}
\[\left\{ \mu \; \middle| \begin{array}{ll} s.t. \quad \sqrt{(\hat{r} - \mu) ' \Sigma^{-1} (\hat{r} - \mu)} \leq \delta \\ \end{array} \right\} \\\]
Atributes:
d::Sampleable{Multivariate, Continous}
: The parent distribution with an uncertain meanΔ::Array{Float64,1}
: Uniform uncertainty around mean. (default: 0.025)
References:
- Ben-Tal, A. e Nemirovski, A. (2000). Robust solutions of linear programming problems contaminated with uncertain data. Mathematical programming, 88(3):411–424.
PortfolioOpt.MomentUncertainty
— TypeMomentUncertainty <: CenteredAmbiguitySet
\[\left\{ r \; \middle| \begin{array}{ll} s.t. \quad (\mathbb{E} [r] - \hat{r}) ' \Sigma^{-1} (\mathbb{E} [r] - \hat{r}) \leq \gamma_1 \\ \quad \quad \mathbb{E} [ (r - \hat{r}) ' (r - \hat{r}) ] \leq \gamma_2 \Sigma \\ \end{array} \right\} \\\]
Atributes:
d::Sampleable{Multivariate, Continous}
: The parent distribution with an uncertain meanγ1::Float64
: Uniform uncertainty around the mean (has to be greater than 0).γ2::Float64
: Uncertainty around the covariance (has to be greater than 1).
References:
- Delage paper on moment uncertainty: https://www.researchgate.net/publication/220244490DistributionallyRobustOptimizationUnderMomentUncertaintywithApplicationtoData-Driven_Problems
OptimalBids.change_bids!
— Methodchange_bids!(market::VolumeMarket, model::JuMP.Model, decision_variables)
Solves optimization model and set new bids to optimal values of the decision_variables
.
PortfolioOpt.calculate_measure!
— Methodcalculate_measure!(measure::ExpectedReturn{S}, w) where {S<:DuWassersteinBall}
PortfolioOpt.calculate_measure!
— Methodcalculate_measure!(measure::ExpectedReturn{BudgetSet}, w)
Returns worst case return (WCR) in BudgetSet's uncertainty set (BudgetSet
).
For further reading:
- BudgetSet' paper: BudgetSet, D. e Sim, M. (2004). The price of robustness. Operations research, 52(1):35–53.
- Original implementation from: https://github.com/andrewrosemberg/PortfolioOpt.jl.
WCR is defined by the following primal problem:
\[\begin{aligned} \min_{\mu, z} \quad & \mu ' w \\ s.t. \quad & \mu_i \leq \hat{r}_i + z_i \Delta_i \quad \forall i = 1:\mathcal{N} \quad &: \pi^-_i \\ & \mu_i \geq \hat{r}_i - z_i \Delta_i \quad \forall i = 1:\mathcal{N} \quad &: \pi^+_i \\ & z_i \geq 0 \quad \forall i = 1:\mathcal{N} \\ & z_i \leq 1 \quad \forall i = 1:\mathcal{N} \quad &: \theta_i \\ & \sum_{i}^{\mathcal{N}} z_i \leq \Gamma \quad : \lambda \\ \end{aligned}\]
Which is equivalent to the following dual problem:
\[\begin{aligned} \max_{\lambda, \pi^-, \pi^+, \theta} \quad \sum_{i}^{\mathcal{N}} (\hat{r}_i (\pi^+_i - \pi^-_i) - \theta_i ) - \Gamma \lambda\\ s.t. \quad & w_i = \pi^+_i - \pi^-_i \quad \forall i = 1:\mathcal{N} \\ & \Delta_i (\pi^+_i + \pi^-_i) - \theta_i \leq \lambda \quad \forall i = 1:\mathcal{N} \\ & \lambda \geq 0 , \; \pi^- \geq 0 , \; \pi^+ \geq 0 , \; \theta \geq 0 \\ \end{aligned}\]
To avoid solving an optimization problem we enforece the dual constraints in the upper level problem and return the objective expression (a lower bound of the optimum).
Arguments:
w
: portfolio optimization investment variable ("weights").s::BudgetSet
: Struct containing atributes of BudgetSet's uncertainty set.
PortfolioOpt.calculate_measure!
— Methodcalculate_measure!(measure::ExpectedReturn{EllipticalSet}, w)
Returns worst case return (WCR) in EllipticalSet's uncertainty set (EllipticalSet
).
WCR is defined by the following primal problem:
\[\begin{aligned} \min_{\mu} \quad & \mu ' w \\ s.t. \quad & ||Σ^{-\frac{1}{2}} (\mu - \hat{r}) || \leq \delta \quad &: \theta \\ \end{aligned}\]
Which is equivalent to the following dual problem:
\[\begin{aligned} \max_{\theta} \quad & w ' \hat{r} - \theta \delta \\ s.t. \quad & ||Σ^{\frac{1}{2}} w || \leq \theta \\ \end{aligned}\]
To avoid solving an optimization problem we enforece the dual constraints in the upper level problem and return the objective expression (a lower bound of the optimum).
Arguments:
w
: portfolio optimization investment variable ("weights").s:: EllipticalSet
: Struct containing atributes of EllipticalSet's uncertainty set.
PortfolioOpt.calculate_measure!
— Methodcalculate_measure!(m::ExpectedUtility{U,S}, w) where {U<:PieceWiseUtility,S<:MomentUncertainty}
Returns worst case utility return (WCR) under distribution uncertainty defined by MomentUncertainty ambiguity set (MomentUncertainty
).
Arguments:
w
: portfolio optimization investment variable ("weights").m::ExpectedUtility
: Struct containing information about the utility and ambiguity set.
PortfolioOpt.calculate_measure!
— Methodconditionalexpectation = -cvar = -expectedshortfall
PortfolioOpt.cidx
— Methodcircular index
PortfolioOpt.convex_hull
— Methodcalculate_measure!(measure::ConditionalExpectedReturn{0.0,S}, w)
Returns worst case return in the convex hull uncertainty set, defined by the following dual problem:
\[ \max_{\theta} \quad \theta \\ s.t. \quad \theta \leq r_s ' w \quad \forall s = 1:\mathcal{S} \\\]
Further information:
- Fernandes, B., Street, A., ValladA˜ £o, D., e Fernandes, C. (2016). An adaptive robust portfolio optimization model with loss constraints based on data-driven polyhedral uncertainty sets. European Journal of Operational Research, 255(3):961 – 970. ISSN 0377-2217. URL.
PortfolioOpt.market_model
— Methodmarket_model(market::VolumeMarket{T,N}, optimizer_factory::Function) -> JuMP.Model, Vector{VariableRef}
Creates a JuMP model with appropriate PO variable and constraints: - Investment vector of variables w
(portfolio weights if budget = 1
). - Invested monney should be lower budget.
Returns the model and the reference to the vector of decision variables (length N).
Aditional arguments:
optimizer_factory
: callable with zero arguments and return an emptyMathOptInterface.AbstractOptimizer
`.
PortfolioOpt.sequential_backtest_market
— Methodsequential_backtest_market(strategy_logic::Function, market_history::VolumeMarketHistory) -> Vector{Real}, Vector{Real}
Simple sequential backtest functionality for strategies that return an array of invested money per asset. Ideal for statefull strategies.
API:
wealth_strategy, returns_strategy = sequential_backtest_market(market_history; date_range=date_range)
do market, past_returns
# ... Strategy definition ...
return investment_decision
end
Arguments:
strategy_logic::Function
: Function that represents the investment strategy.market_history::MarketHistory
: Market history.
Optional Keywork Arguments:
date_range
: Dates to be simulated with corresponding entries in the market history.
TestUtils
PortfolioOpt.TestUtils
— ModuleTestUtils
Some commom test utilities for portfolio optimization formulations.
Mainly: - get_test_data
that returns a TimeArray of prices for 6 assets.
PortfolioOpt.TestUtils.get_test_data
— Methodget_test_data(;
start_date::Date=Date(2009, 9, 1), end_date::Date=start_date + Year(1) + Month(3)
)
Get test data (Prices) from MarketData.
PortfolioOpt.TestUtils.max_sharpe
— Methodmax_sharpe(Σ::Array{T, 2}, r̄::Array{T, 1}, rf::T) where {T<:Real}
Maximize sharp coefficient allocation.
PortfolioOpt.TestUtils.mean_variance
— Methodmean_variance(returns::Array{T, 2}; digits::Union{Nothing,Int}=nothing) where {T<:Real}
Mean and Variance of returns