Various portfolio optimization models
API for Mean Variance Optimization style models. Presented in various formats
- Traditional mean variance (quadratic utility)
- Maximize expected return with risk constraint
- Maximize Sharpe ratio style (expected return / risk)
# Code Demo
from mosek_api import mean_variance, max_ret, max_ir
optimized_portfolio = mean_variance(
alpha, risk_aversion, cov, active_risk=False, active_alpha=False,
long_only=True, return_full_result=False,
benchmark=None, budget=None, max_budget=None,
max_holding=None, min_holding=None, max_active_holding=None, min_active_holding=None,
industry=None, max_ind=None, min_ind=None, max_active_ind=None, min_active_ind=None,
style=None, max_style=None, min_style=None, max_active_style=None, min_active_style=None,
prev_holding=None, max_turnover=None
)
optimized_portfolio = max_ret(
alpha, active_alpha=False, long_only=True, return_full_result=False,
benchmark=None, budget=None, max_budget=None,
cov=None, max_std=None, max_active_std=None,
max_holding=None, min_holding=None, max_active_holding=None, min_active_holding=None,
industry=None, max_ind=None, min_ind=None, max_active_ind=None, min_active_ind=None,
style=None, max_style=None, min_style=None, max_active_style=None, min_active_style=None,
prev_holding=None, max_turnover=None
)
optimized_portfolio = max_ir(
alpha, cov, max_holding=None, long_only=True
)Traditional Mean-Variance optimization is notoriously sensitive to errors in the estimation of inputs. One way that can help to mitigate the gap here is to base optimization only on risk related inputs. Risk based optimization is legit at least from the following two pespectives. From a statistical perspective, the estimation of risk measures (covariance, variance, etc..) is usually more robust than that of expected return. From a financial theory pespective, efficient exposure to risk is the key to harvest risk premium. One can also take the risk based optimization as a mean variance optimization with strong structure assumed as follows:
-
Min Variance:
a. Assmumption to equal MVO:When equal expected return for all securities
b. Optimization condition
-
Risk Parity:
a. Assumption to equal MVO: When equal return to risk contribution for all securities
b. Optimization condition
-
Risk Budget:
b. Optimization condition
-
Maximum Diversification:
a. Assumption to equal MVO: equal correlation and equal expected return for all securities
b. Optimization condition
Min Variance
# Code Demo
from mosek_api import risk_budget
optimized_weight = min_var(cov, long_only=True, budget=1, max_holding=None, min_holding=None)Risk Budget
# Code Demo
from mosek_api import risk_budget
optimized_weight = risk_budget(target_budget, covariance_matrix)When the risk measure is a first order homogeneous function of portfolio, we will be able to decompose the total portfolio risk
Based on the additivity of risk contribution. We can allocate predefined risk (risk contribution):
The above condition is unfortunately not convex directly. While when variance is used as risk measure, we will be able to formulate a restricted version of convex optimization on it. The first order optimal condition of the following optimization problem is exactly the risk budget condition. Hence we can rely on it for risk budget optimization. While it should be noted that, with such implementation, we wil not be able to add further constraints since it will change the 1st order condition.
variable c can be used to scale the summation of budget b. Since leverage does not change the risk budget for first order homogenours risk measures. We can scale w to summation of 1 for fully invest constraint.
Risk Parity
Risk parity portfolio is the equal risk contribution case. It is applied with equal risk contribution with the risk budget optimizer.
# Code Demo
from mosek_api import risk_parity
optimized_weight = risk_parity(covariance_matrix)Maximum Diversification Portfolio
Maximum Diversification portfolio as suggested by its name seeks to maximize the diversification ratio
The maximum diversification is applied with quadractic optimization hence it can be applied with customized feasible set (other constraints like standard deviation threshold, max holding, etc)
# Code Demo
from mosek_api import max_div
# Pure Max diversification with fully invest
optimized_weight = max_div(cov, long_only=True)
# Max diversification with vol target
optimized_weight = max_div_vol(cov, max_std,
max_holding=None, min_holding=None,
budget=1, long_only=True)Black-Litterman is a Bayesian based method for robust portfolio. Suppose r is the security return vector.
- Implied expected return
$\mu^{0} = \lambda \Sigma x^{0}$ - Pior distribution on Expected Return
$\mu \sim N(\mu^{0}, \tau \Sigma)$ - View expressed as linear equations:
$P\mu = Q + \epsilon, \epsilon \sim N(0, \Omega)$ - The posterior distribution of expected return as shown below:
- The posterior distribution of security return as shown below:
# Code Demo
from mosek_api import implied_alpha_decompose, holding_decompose, return_attribute
constraint_attr = holding_decompose(res_dict)
constraint_attr = return_attribute(ret, holding_dict, block_name=None)The goal of constraint attribution is to decompose the ex-post performance into each constraints applied in the optimization. In practical, investors usually add constraint on the portfolio for robust ex-post performance. From a ex-ante perspective, the optimized portfolio will always have worse characteristic since the feasible set is smaller. It requires another perspective to look into how is the constraints working for the portfolios. Constraint attribution is one of the techniques that we can rely on for such purpose.
For a portfolio optimization problem as below. Function f can stand for transaction cost, market impact ..etc. Function g refers to portfolio constraint that we look to decompose.
Assuming all constraint function g are diffrentiable, Scherer & Xu (2007) provide the following decomposition
Lagrangian Dual Decomposition
- The above decomposition originates from the first order condition of KKT.
$\pi_{i}$ is the shadow price of constraint$g_i$ - Formula 1 above is the decompostiohn of implied alpha. Formula 2 is the active holding decomposition
-
$\lambda Q x^{\star}$ is called as implied alpha due to the reason that in an unconstraint MVO optimization, it is the alpha that will lead to$x^{\star}$ as optimal portfolio -
$x_u = \frac{1}{\lambda} Q^{-1} \alpha$ is the solution of the unconstrained optimization$\max_x{\alpha^T x - \frac{1}{2}\lambda x^TQx}$ -
$x_u$ is actually a multiple of the characteristic portfolio of alpha;$\frac{Q^{-1} \alpha}{\alpha^T Q^{-1} \alpha}$ (The minimum variance portfolio given exposure to alpha as 1). - When dealing with linear constraint
$Ax <= 0$ ,$\sum \pi_i \frac{1}{\lambda} Q^{-1}\bigtriangledown g_i(x^{\star}) = \sum \pi_i \frac{1}{\lambda} Q^{-1}A_i$ ,$A_i$ is the i-th constraint of all constraints. We can interprete it as the shadow price weighted characteristic portfolio of each constraints. When the constraint is not binding, the shadow price will be 0 and the constraint will not play with any rule in the decompostion - Tutuncu (2012) argued that, the decomposition of holding is not intuitive due to the high correlation between different constraints (the existence of Q in the equation). In such case the decomposition of implied alpha can provide a more precise decomposition.
Further Analysis by projecting on alpha space
- Another way to further decompose is to project the wegiht on to alpha charateristic portfolio and those orthogonal
- Orthogonal part can be taken as unrewarded risk
Second Order Constraint Decomposition
When the standard deviation constraint is binding. We can perform similar decomposition.
Literature on Constraint Attribution
-
Grinold (2005) is the first to propose the use of Lagrangian Dual decomposition (Basd on the first order condition of KKT). to addres the attribution analysis of portfolio constraints.
-
Tutuncu (2012) provides a sumarization on previous research on the topics. He pointed that for a Mean Variance optimization with linear constraint, we can use the Lagrangian dual decomposition to perform the following decomposition on the optimized portfolio:
a. Utility decomposition b. Implied alpha decomposition c. Active weight decomposition d. Alpha prediction return decomposition -
Scherer & Xu (2007) improved the method based on Grinold (2005). They propose to perform Lagrangian Dual decomposition on the quadratic utility of a MVO. They believed that the investors cared about the utility function instead of weights on individual securities.
-
Lee & Stefek (2009) provides further analysis in terms of ex-ante analysis. The optimized portfolio with constraint can be decomposed into the optimal portfolio (without constraint) and characteristic portfolios weighted by their shadow price. They further decomposed the characteristic portfolio into the projection on alpha characteristic portfolio and those orthogonal to the alpha characteristic portfolio. The second part can be viewed as the ex-ante risk that are note rewarded with ex-ante return
Optimized Portfolio (with constraint) a. Optimal portfolio (without constraint) b. Corresponding characteristic portfolio for each constraint (Weighted by shadow price) I. Projection on alpha characteristic portfolio II. Residual (Orthogonal to alpha characteristic portfolio) -
Stubbs& Vandenbussche (2010) focused more on the ex-post return attribution. Using the ex-post return to understand how is constraint impacting the portfolio. It can help to answer the question: can a certain optimization constraint help to improve ex-post performance? They also provide ways to do such attribution for risk constained portfolio. It will provide a slightly different economic intuition for the decomposition.
Convex Optimization is the minimization of a convex function on a convex set. What makes a convex function special is that local information (gradient or so) can lead us to global opmima.
A convex Problem can be written in the following standard form. For such an optimization to be convex optimization, it is required that
Duality
In general, duality is the other view on an optimization problem. It is about to find the max one among a set of lower bound functions (Lagrangian Function). As long as
Here we are able to transform the convex minimization problem into its dual problem. It is the best lower bound of the primal.
- Weak duality:
$d^{\star} <= p^{\star}$ - Strong duality:
$d^{\star} = p^{\star}$ - For convex optimization, the strong duality holds under the Slater Condition (strict inequality constraint)
KKT Condition
A Necessary condition for optimal solutions of convex problem.
- Primal feasibility
- Dual feasibility :
$\lambda >=0$ - Complementary slackness
$\lambda_i f_i(x) = 0$ . It make sure that$f_0(x^{\star}) = L(x^{\star}, \lambda^{\star}, \upsilon^{\star})$ - Gradient of L with respect to x is 0. It make sure that
$g(\lambda^{\star}, \upsilon^{\star}) = L(x^{\star}, \lambda^{\star}, \upsilon^{\star})$
Shadow Price
Given the primal Problem
The Associated Dual problem is
When Strong duality holds, The optimal value of dual problem equals the optimal value of primal problem. Hence the primal optimal value can be regared as a function of u and v:
-
Optimization Theory
- Boyd & Vandenberghe: Convex Optimization
- Cornuejols, Pena & Tutuncu: Optimization Methods in Finance
-
Survey paper on Portfolio Optimization
- Steinbach(2001); Rubinstein(2002); Fabozzi, Kolm, Pachamanova & Focardi(2007); Markowitz(2014) provides great survey paper on the topic.
- Kolm, Tutuncu, Fabozzi (2013): 60 Years of portfolio optimization: Practical challenges and current trends
-
Constraint Attribution
- Bernd Scherer & Xiaodong Xu (2007): The Impact of Constraints on Value-Added
- Robert Stubbs & Dieter Vendenbussche (2010): Constraint Attribution
- Jennifer Bender, Jyh-Huei Lee & Dan Stefek (2009): Decomposint the Impact of Portfolio Constraints
-
Risk Based Optimization
- Clarke, De Silva & Thorley (2013): Risk Parity, Maximum Diversification, and Minimum Variance: An Analytic Perspective.
- Choueifaty & Coignard (2008): Toward Maximum Diversification