When an investor or a trader has a portfolio of stocks, it is necessary to understand how to allocate his capital among them. However, this can be tricky when the number of stocks in the portfolio is of a high magnitude (hundreds and thousands). In order to help, most portfolio managers implement some form of convex optimization that optimizes their reward function, which could range from expected returns to Sharpe ratio to some proprietary measure that they have developed. One of the approaches is using the Conditional Value at Risk (CVaR) as the loss function. This would be the topic of this article.
CVaR, also known as Expected Shortfall (ES), is a measure of how much can be an investor can expect to lose in the bottom percentiles (defined by the investor). For example, at a 5% interval, the CVaR would be the expected loss given that the loss is in the bottom 5%. To represent it mathematically, we first need to define a loss function f(x,y) with x being the weights in the portfolio and y being the risk factors that make up the portfolio. So, the probability that the loss of the portfolio does not exceed a certain threshold is given by
Now we can define our Value at Risk (VaR) and subsequently the CVaR as such:
Now that we understand what CVaR is, we can move on to looking at optimization methods.
The Technologies Poised to Change the World in 2019 - Data Driven Investor
It is not easy to imagine a technology that will receive as much publicity as the blockchain did last year but there's…
Most optimization libraries deal with convex optimization, which can be solved in numerous ways and relatively effectively. This is mainly due to the fact that if an optimization problem is convex, that is to say, both the objective function and the constraints are convex, then any local minimum found is guaranteed to be the global minimum as well. This result is very useful as the algorithm will not encounter multiple minima in the function space, and potentially confuse itself. Furthermore, the condition that the functions be convex allows for the functions to be non-noisy, which can be an issue with optimization algorithms that involve derivatives of the functions.
Within convex optimization, there are different optimization classes, such as…. The simplest of those classes is the Linear Programming (LP) optimization problem, which is really every analyst’s dream, as the solutions are easily found and definitely stable.
Unfortunately, CVaR optimization is not a convex optimization problem as it involves an integral over a probability space that we do not know fully (after all, we only have finite samples of data to model the probability distribution). Therefore, optimizing CVaR by itself is almost impossible to achieve with any consistency and stability.
Making CVaR into LP
The key to optimizing CVaR would be to make it in to a LP problem. This is where the genius lies. There are three steps to making CVaR into an LP problem. The first is to realize that the following function is has an equivalent optimum as the CVaR:
Second, we need to realize that optimizing the CVaR with a constraint on the portfolio returns is equivalent to optimizing portfolio returns with a CVaR constraint. This gives us the optimization as maximizing returns (or some other measure), while constraining CVaR to a minimal percentage of the portfolio. This is similar to how big organization manage their risk and use CVaR as a constraint measure.
Lastly, we need to approximate the integral as a finite sum over samples of data and their estimated probabilities. This is done by either using historical data or by Monte Carlo sampling from the distribution attained from historical data. To read more about how to statistically model historical data, do check out the following article. However, the final optimization problem boils down to the following:
This problem can be implemented in most current software like cvxpy for python or MATLAB. I shall leave that as an exploration for the enthusiastic reader!