Implementing Robust Mean-Variance Optimization with Nonlinear Constraints
Summary
The note describes how to formulate a robust mean-variance portfolio problem for a constrained optimizer such as MATLAB’s fmincon. Portfolio variance remains the objective, while the minimum expected return over an uncertainty region becomes a nonlinear constraint. For a spherical uncertainty set centered on the estimated return vector, the worst-case return is computed from the estimate, the portfolio weights, and the uncertainty radius.
The suggested implementation passes the variance objective and a separate constraint function to the optimizer; the constraint is written in the nonpositive form expected by fmincon. The answer also mentions using a shrinkage covariance matrix as a possible objective input, but leaves that choice unresolved. It provides an implementation approach rather than numerical results or a comparison of robust formulations, and the cited equations’ dependence on optimized weights is not resolved beyond expressing the worst-case return directly as a function of weights.
Key ideas
- Robust portfolio optimization can minimize variance subject to a worst-case return floor.
- A spherical uncertainty region yields a worst-case return constraint based on the return estimate, weights, and uncertainty radius.
- The optimizer can receive portfolio variance as its objective and worst-case return as a nonlinear constraint.
- A shrinkage covariance matrix is one possible input to the variance objective.
- The note does not establish which covariance specification is preferable.
Tags
Full text
# Robust Bayesian portfolio optimization in matlab?
# Robust Bayesian portfolio optimization in matlab?
I am working through this paper.
I want to implement the robust Bayesian optimization (see pages 6 onward) in Matlab using fmincon.
Here is a brief overview of my problem:
Let $\alpha$ be the vector of returns and let $w$ be ta set of weights representing a portfolio.
Then, our usual mean-variance problem is to find the resultant portfolio weights that minimize the portfolio variance $\sigma^2(x)=w' \Sigma w$.
In the robust framework, the vector of returns is assumed to lie in some uncertainty region, call it $U$. Here, the authors define that region to be the sphere centered at $\alpha$ with radius equal to $|\chi| \cdot \alpha$ with $\chi \in [0,1]$.
In other words, our optimization problem now becomes:
$\min_\omega\omega'\Sigma\omega$ subject to $\min_Ur_p \geq r_0$
where $\Sigma$ is a positive definite matrix and $\omega$ is a vector of weights that sum to 1. Also: $r_p=\alpha'\omega$.
The authors show that:
$$\min_U r_p=|\alpha||w|[cos(\phi)-\chi]$$
where $\phi$ is the angle between the two vectors $\alpha$ and $\omega$.
They give the formula for the "the robust covariance matrix family" - (see page 7, eq. 13) as well as the formula for the optimized weights (see page 7, eq. 12).
I am trying to implement this in Matlab. However, one cannot use equations (12) or (13) as both equations require the optimized weights to be known.
My question is therefore, is there a method to implement a robust optimization such as this OR any suggestions as to how I could go about doing this???
## Answer by SRKX (score 3, accepted)
https://quant.stackexchange.com/a/7114
From a general point of view and to answer directly to your originial question, you should only have to modify the inputs to the MATLAB function you refer to. As a matter of fact, `fmincon` is an optimizer looking to process a broad variety of problems as explained in the documentation:
> `fmincon` attempts to find a constrained minimum of a scalar function of several variables starting at an initial estimate. This is generally referred to as constrained nonlinear optimization or nonlinear programming.
You will not have to modify anything to the algorithm per say. You just need to make sure to get the inputs right which in this case is the target function you pass to `fmincon`.
For example, if you only want to use a shrinked matrix (given by equation 9 on page 5) to obtain a more robust mean variance portfolio, you can do the following:
```
SigmaHat=...;
robustMinVar = fmincon(@(x)(x' * SigmaHat * x), ...);
```
where `SigmaHat` is the shrinked covariance matrix you previously computed.
I assume you are willing to compute the following:
$$\underset{w}{\arg \min} ~ \sigma^2(w) \quad \text{s.t.} \quad \underset{U_\alpha}{\arg \min} ~ r_P \geq r_0$$
You need to generate two functions:
- $f(w)$, the target function
- $c(w)$ a constraint function.
The constraint function is supposed to return the value of $\underset{U_\alpha}{\arg \min} ~ r_P$ and can be computed as mentioned in the formula.
So in your script, simply do:
```
% Here I define my variables
alpha=...;
chi=...;
r0=...;
function r=bayesConst(w)
r= -(alpha' * w - chi* sqrt(sum(alpha.^2))*sqrt(sum(w.^2))-r0);
end
```
Note here that you create a function within the script to inject the variable `alpha` and `chi` and `r0`. Notice also that I set up the function such that it has the form $c(w) \leq 0$. You have to input this in `fmincon` as a non-linear constraint (the `nonloncon` argument).
Now the other function is just computing the minimum variance with $w$, but I don't know if we should use the shrinked covariance matrix (of page 7) or not I would say yes intuitively.Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.