23
$\begingroup$

I would like to optimize a portfolio allocation (maximizing the exposure or the expected return), but with VaR or CVaR contraints. (some parts of my portfolio cannot exceed a certain VaR)

How can I achieve that? Is there a way to turn the problem into a linear programming problem? or to approximate the results?

Any links or ideas are welcome.

$\endgroup$
2
  • $\begingroup$ For VaR: I think you can turn it into a mean-variance problem and choose the portfolio with the highest expected return on the frontier for which the VaR constraint holds. $\endgroup$
    – Bob Jansen
    Aug 10, 2012 at 5:14
  • $\begingroup$ @BobJansen I have several VaR constraints on several groups of assets in my portfolio. I cannot manually adjust every day the expected returns of all my assets to ensure the VaR constraints. Ideally I would have to model the constraint in the optimization problem. $\endgroup$ Aug 10, 2012 at 5:25

5 Answers 5

11
$\begingroup$

In my experience, a VaR or CVaR portfolio optimization problem is usually best specified as minimizing the VaR or CVaR and then using a constraint for the expected return. As noted by Alexey, it is much better to use CVaR than VaR. The main benefit of a CVaR optimization is that it can be implemented as a linear programming problem. Another option I have tried is the technique in this paper:

http://www.math.uwaterloo.ca/~tfcolema/articles/bank_article.pdf

Another option is the two-step heuristic where one first finds the mean-variance efficient frontier and then you could calculate whatever are the relevant portfolio statistics on only the mean-variance efficient portfolios. In this way you could exclude portfolios that have too high a VaR or CVaR (or mixed CVaR deviation) for your consideration.

However, as you say you are particularly concerned about the VaR or CVaR of certain parts of your portfolio. As noted above, VaR constraints for different different groups of assets would require non-linear constraints. However, CVaR constraints for different assets could be calculated using linear constraints (though it would also be possible to implement a relatively slower methodology using non-linear constraints). For guidance on how to implement this as a linear constraint, it might help to follow

http://www.soa.org/library/proceedings/arch/2008/arch-2008-iss1-cox-lin.aspx

with the only difference that you would want to calculate the CVaR over the relevant groups of securities.

$\endgroup$
6
  • $\begingroup$ The second link seems very interesting, thanks. I have read carefully the paper. however, I truggle to understand how they replace the expectancy that is in formula (9) page 8, with a sum over $j$. What are these $r_{ij}$ and what is $m$? Apart from that, the solution is quite elegant... Can be solved with a very standard optimizer. $\endgroup$ Aug 13, 2012 at 17:54
  • $\begingroup$ If I am not wrong these $m$ are the Monte Carlo simulations that @David Nehme is mentioning in his answer. I guess $m$ has to be high enough. 1000? 2000? Do you have an idea? $\endgroup$ Aug 14, 2012 at 1:21
  • $\begingroup$ It would have to do with the uncertainty in your estimates of the expected shortfall. I normally use 10,000 but I don't focus on the ends of the tails (like 1% or smaller), in which case you might need more simulations to get reasonable estimates of the tails. $\endgroup$
    – John
    Aug 14, 2012 at 1:37
  • $\begingroup$ Thanks for your input, makes sense. What about $r_{ij}$ ? The return of asset $i$ in simulation $j$ ? Do you really have to simulate them or can you take simply the past ones? i would like to avoid modelling the returns, as it could create errors (bad tail correlation estimation etc.) Now if you need 10,000 of them I understand you have to simulate. But is it not dangerous? $\endgroup$ Aug 14, 2012 at 2:45
  • 1
    $\begingroup$ @RockScience $\sum_{j \in J} r_{ij} = |J| \bar{r_i}$ if the monte carlo simulations match your expected return forecast. $\endgroup$ Aug 18, 2012 at 16:12
9
$\begingroup$

The VaR constraint is convex and quadratic and can be handled with any solver supports quadratic constraints, like Guribi, cplex (from IBM) or xpress (from FICO).

The CVaR can be formulated as a linear program if you are able to perform monte-carlo simulations on the returns. Briefly, the LP model is

\begin{eqnarray*} c &\ge& \alpha + {1 \over (1-\beta)|J|} \sum_{j\in J} z_j \\ z_j &\ge& \sum_{i \in I} r_{ij} x_i - \alpha \hspace{0.2in} \forall j \in J \end{eqnarray*} Where c is the cvar at $\beta$ confidence, $I$ is the set of investments, $x_i$ is the level of investment in $i$, $J$ is the set of monte-carlo scenarios, $r_{ij}$ is the unexpected loss of investment $i$ in simulation $j$. $\alpha$ is the loss of the $100 \cdot \beta$ percentile scenario, and ${1 \over (1-\beta)|J|} \sum_j z_j$ is the average unexpected loss (in excess of alpha) of the worst $(1-\beta)|J|$ scenarios.

The resulting LP instances are very dense and large, so it requires delayed column and constraint generation for non-trivial problems.

$\endgroup$
2
  • $\begingroup$ This should be the accepted answer. The chosen answer above is the right answer to a different question! $\endgroup$ Jul 11, 2016 at 19:07
  • 5
    $\begingroup$ Ahhhh!. Just one thing @David. VaR is NOT convex. This is the main motivation to have CVaR constraints at all. VaR is more intuitive but it's not convex... that's the main problem. $\endgroup$ Jul 11, 2016 at 19:10
4
$\begingroup$

You can find a good example on CVaR optimization in the book "Portfolio Optimization with R/Rmetrics" By Diethelm Wuertz, Yohan Chalabi, William Chen, Andrew Ellis.

#load library fPortfolio
library(fPortfolio)

#use indicies LPP2005, see http://www.pictet.com/en/home/lpp_indices.html
lppData  <-  100*LPP2005.RET[,1:6]

#create portfolio specification
frontierSpec  <- portfolioSpec();

#optimization criteria - CVaR
setType(frontierSpec)  <- "CVAR"

#set optimization algorithm
setSolver(frontierSpec)  <- "solveRglpk"

#set confidence level CVaR
setAlpha(frontierSpec)  <- 0.05

#number of portfolios in efficient frontier
setNFrontierPoints(frontierSpec)  <- 25

#optimize, without shortselling
frontier <- portfolioFrontier(data = lppData, spec = frontierSpec, constraints="LongOnly");

#build efficient frontier graph
tailoredFrontierPlot(object=frontier,mText="Mean-CVaR Frontier (Long only)",risk="CVaR");
weightedReturnsPlot(frontier)

I don't recommend you to use VaR optimization for two reasons:

  1. VaR is not a subbaditive risk measure, therefore your portfolio could be highly undiversified.
  2. It's more challenging computationally than CVaR optimization
$\endgroup$
3
  • $\begingroup$ You might want to adjust this code, if possible, to incorporate CVaR constraints on a group of assets, rather than just minimizing the CVaR. $\endgroup$
    – John
    Aug 10, 2012 at 20:03
  • 1
    $\begingroup$ +Alexey, do you have this ebook "Portfolio Optimization with R/Rmetrics"? On the google preview at page 333 it seems that I read that quadratic constraints are treated in the other ebook "Advanced Portfolio Optimization with R/Rmetrics" If you have the book, can you confirm if there are such examples? books.google.com.sg/… $\endgroup$ Aug 13, 2012 at 11:46
  • $\begingroup$ The eBook "Portfolio Optimization with R/Rmetrics" is available for free at the author's website rmetrics.org/ebooks. There is no such a book titled "Advanced Portfolio Optimization with R/Rmetrics" available although it is mentioned in some footnotes. I believe the author made an error in writing those footnotes, as their only book on Portfolio Optimization with R is the one that you already have read. $\endgroup$
    – DrJerryTAO
    Nov 4, 2023 at 9:25
4
$\begingroup$

I think what you're looking for is a type of solver called a second-order cone program (SOCP) solver. This is just like a quadratic program (QP) solver, except the constraints can be quadratic as well as the objective function. There is an open-source implementation in python via the CVXOPT module.

$\endgroup$
3
  • $\begingroup$ indeed. I need quadratic constraints. The objective function is linear but the VaR constraint is definitely quadratic. Will have a look at your link. Thanks $\endgroup$ Aug 10, 2012 at 12:36
  • $\begingroup$ it seems that even though CVXOPT is open source, it only contains interfaces to the solvers in MOSEK, which is not open source. $\endgroup$ Aug 14, 2012 at 3:11
  • $\begingroup$ No, that's not correct. It has it's own solvers, plus the option to use MOSEK if you have that installed. It's not a dependency. $\endgroup$ Aug 14, 2012 at 14:59
3
$\begingroup$

You could define your optimization problem as a typical linear risk/return optimization problem(1), then use some predicted return as the return component and VaR or cVaR as the risk component. This will not be linear, however you can use an evolutionary algorithm, or some other exotic search algorithm, to maximize for return given a limit on VaR or cVar. The tricky part is to make a good utility/fitness function, i.e., a smooth one.

In essence what you will be doing is to generate a bunch of random feasible portfolios, making sure to throwing out any that have too large of a VaR. The remaining feasible portfolios are ranked based on the utility/fitness function. Keep some of the best once (survival of the fittest) and based on these make small random alterations to the portfolios (mutations). Then re-rank the portfolios. Redo this for several generations. Eventually you should be optimizing based on VaR. There are many tools and frameworks that can do this for you. I used Encog last time I did something like it.

(1) Utility(portfolio) = PredictedReturn(portoflio) - VaR(portoflio)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.