File Exchange

image thumbnail

CVaR Portfolio Optimization

version 2.0.0 (263 KB) by MathWorks Quant Team
Conditional Value at Risk (CVaR) portfolio optimization with the PortfolioCVaR object


Updated 18 Sep 2018

View License

This example shows a Conditional Value at Risk (CVaR) portfolio optimization workflow, which includes:
* How to simulate asset scenarios based on normal distribution and the empirical distribution
* How to construct a portfolio using PortfolioCVaR object
* How to evaluate the efficient frontier
* How to extract the portfolio weights
* How to calculate CVaR of the portfolio

Cite As

MathWorks Quant Team (2020). CVaR Portfolio Optimization (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (14)

i have a question maybe someone can help me. I try to use the simulation, but I already have returns and no courses. Executing the code stumbles over the command = ret = tick2ret (T {:, symbol}) ;. However, I have to create a double for RET. Does anyone know the tool for this?

Tony Tran

I am confused at the following code.

pRet1 = estimatePortReturn(p1,w1);
pRisk1 = estimatePortRisk(p1,w1);
pRet2 = estimatePortReturn(p1,w2); % p2, w2 ???
pRisk2 = estimatePortRisk(p1,w2); % p2, w2 ???

The last two rows should be p2 instead of p1?


Very good video! However, when I try it on my own data the plotAssetHist(symbol,ret) does not seem to work. It tells me "Undefined function 'plotAssetHist' for input arguments of type 'cell'." Is this because symbol is of type "cell"? If yes, why does it work in the video then?

ding wei

Great introduction to CVaR portfolio optimization in Matlab. Since Yahoo closed there historical stock data API could you (Seth DeLand?) provide the matrices that are generated when using "fetch the data" segment of the program?. I want to get a sense of the matrix structure so I can start modifying the code. I'm new to Matlab and computational finance so any help would be greatly appreciated.



I am getting this error:Error using yahoo/fetch (line 387)
Unable to return historical data for given security.

Error in CVaRPortfolioOptimizationExample (line 47)
Price.(bondETFTickers{ii}) = fetch(C,bondETFTickers{ii},...


Mosif Khan

It's a good example for the PortfolioCVaR object. I had to use tick2ret instead of price2ret.



Major update for the example using newer capabilities of MATLAB and Toolboxes

Updated license

Minor code cleanup, fixed some typos in comments.

MATLAB Release Compatibility
Created with R2018a
Compatible with R2018a to any release
Platform Compatibility
Windows macOS Linux