WHAT'S THE WRONG IN MY CODE CVAR CALCULATION?

2 views (last 30 days)
if I used the following code
load('dati_ingresso_portafoglio.mat')
m=medie_annuali;
C=nancov(matrici_rendimenti)*195;
AssetScenarios = mvnrnd(m, C, 10);
p = PortfolioCVaR; %crea oggetto Portafoglio
p = PortfolioCVaR(p,'scenario', AssetScenarios);
p = PortfolioCVaR(p,'Name','Allocazione Fondi Comuni','lowerbudget', 1, 'upperbudget', 1, 'lowerbound', 0,'upperbound', 0.1);
p = setProbabilityLevel(p, 0.95);%inserisce livello di probabilità
Ricchezza=sum(importi_partenza)+cash;%patrimonio attuale
X0=importi_partenza/Ricchezza;%stabilisce i pesi del portafoglio iniziale
be(1)=X0(1);be(2)=X0(2);be(3)=X0(3);be(4)=X0(4);be(5)=X0(5);be(6)=X0(11);be(7)=X0(12);be(8)=X0(25);be(9)=X0(36);be(10)=X0(52);
p = PortfolioCVaR(p,'InitPort',X0);% introduce pesi del portafoglio attuale di partenza con l'aggiunta di cash aggiuntivo detenuto nel conto freerisk
p = PortfolioCVaR(p,'AssetList',nomi_assets,'RiskFreeRate',r0);% introduce nomi degli assets in portafoglio
p = PortfolioCVaR(p,'BuyCost', vettore_b, 'SellCost', vettore_s);%introduce i costi di acquisti e/o vendita dei vari assets
p = PortfolioCVaR(p,'AEquality',matrice_Ae, 'bEquality',be);
p = PortfolioCVaR(p,'GroupMatrix',matrice_G, 'UpperGroup', ug)
plotFrontier(p) %traccia la frontiera efficiente
The file CVAR.M uses the data in the file dati_ingresso_portafoglio.mat ( Carriers and matrix data inside this file appears to be consistent with the problem) and it's attached together CVAR.m.
if I run the program Matlab shows the following error
Error using vertcat
Dimensions of matrices being concatenated are not consistent.
Error in cvar_optim_transform (line 261)
Error in PortfolioCVaR/estimateFrontier (line 63)
[AI, bI, AE, bE, lB, uB, f0, f, x0] = cvar_optim_transform(obj);
Error in PortfolioCVaR/plotFrontier (line 106)
pwgt = obj.estimateFrontier(NumPorts);
Error in CVAR (line 18)
plotFrontier(p) %traccia la frontiera efficiente
I have noticed that if you just take off line 15 ( p = PortfolioCVaR(p,'BuyCost...) or line 16 only ( p = PortfolioCVaR(p,'GroupMatrix...) the program works;
the program shows the above error if there are both rows 15 and 16
  4 Comments
Brendan Hamm
Brendan Hamm on 10 Sep 2015
I would likely be able to help better with the actual code. If you can, please just attach using the paper clip icon. Thanks.

Sign in to comment.

Answers (1)

Brendan Hamm
Brendan Hamm on 14 Sep 2015
The problem with your setup has nothing to do with the lines you mentioned, but rather with the equality constraints conflicting with the bounds. You set an upper bound on each asset to be 10%, but your equality constraints with matrice_Ae and be are effectivelly only setting bounds, and some of these are greater than 10%. You enforce Asset 1 has exactly a weight of 0.1060 and assets 11 and 25 have the same issue. What is it you were trying to do with these constraints?
I also want to make sure that when you use this in practice you generate many more samples for your Scenarios.
  4 Comments
mike mike
mike mike on 17 Sep 2015

THANK YOU FOR THE CODE, I HAVE SOLVED THE PROBLEM WITH YOUR COUNCIL, BUT NOW I WANT TO UNDERSTAND WHAT IS THE PROBLEM OF ERROR. A BUG FOR MATLAB? :-)

Brendan Hamm
Brendan Hamm on 17 Sep 2015
I don't have access to the source code where the error is occuring, so I can't look any deeper into it than that. I suspect that it does not expect any hard bounds to be coded in a linear equality constraint and that this is causing issues. You can submit this as a bug at: Bug Reports

Sign in to comment.

Categories

Find more on Portfolio Optimization and Asset Allocation 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!