How to use the optimization toolboox for a value at risk based problem?

1 view (last 30 days)
Hi,
I am currently trying to optimize a portfolio based on the risk measure value at risk (VaR) with the optimization toolbox. I know that the conditional value at risk does have better mathematic properties and so on, but I still need the VaR optimization (optimal asset allocation) for comparison.
So far I tried the following code for my 29 analyzed assets:
m=mean(Returns)
cv=cov(Returns)
m1 = [m.Adidas, m.Allianz, ...]
ValueatRiskE = 0 * ones(1,29);
for i=1:29
ValueatRiskE(i) = quantile(tick2ret(DAX30(:,i)),0.05)
end
pwgt2 = 1/29 * ones(1,29);
Until this point I have the mean of my 29 assets m1 and a vector ValueatRiskE (29*1) that contains each individual VaR per asset. Additionally I have a naive diversification vector pwgt2 = [1/29 1/29 .. 1/29] that could be the starting allocation for my optimization problem.
Now I want to optimize the following problem:
max Value = (ExpectedReturn-r0)/ValueatRiskPortfolio
where
ExpectedReturn = sum(pwgt2.*m1)
ValueatRiskPortfolio = [sqrt(pwgt2*cv*pwgt2')]*1.96
r0=0.00002
Can I now use the following optimization function to get the optimal allocation pwgt2*?
function s = sharp(pwgt2,cv,m1)
s = {sum(pwgt2.*m1)-r0]/sqrt(pwgt2*cv*pwgt2');
end
I tried to enter the objective function "@s", the start point "pwgt2" and the constraints sum(pwgt2)=1 in the optimization toolbox, but it doesnt work. How can I solve this problem?
Thank you in advance for your help! :)
Greets, phanta

Accepted Answer

Alan Weiss
Alan Weiss on 26 May 2015
You probably just didn't pass your extra parameters properly. I assume that you have cv and m1 in your workspace, and you want to optimize over the parameters pwgt2. If so, you should set your objective function to
fun = @(pwgt2)sharp(pgwt2,cv,m1);
and then call
[x,fval,exitflag] = fmincon(fun,x0,...)
Alan Weiss
MATLAB mathematical toolbox documentation
  11 Comments
phanta
phanta on 3 Jun 2015
It works perfectly. I used the optimization toolbox with your suggestions and exported the results to the workspace to get the optimal allocation.
Thank you very much!
Omar Zulaica
Omar Zulaica on 6 Apr 2018
Hi phanta! As I read through your article I realised I went through most of the same issues. Would you mind sharing your final code with us? Thank you!

Sign in to comment.

More Answers (0)

Categories

Find more on Get Started with Optimization Toolbox in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!