WHAT'S THE WRONG IN MY CODE CVAR CALCULATION?

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 件のコメント

Brendan Hamm
Brendan Hamm 2015 年 9 月 8 日
Can you give an idea of the size of matrice_G and ug. It seems to me that these are likely not of the appropriate size?
Does the program error is you only comment off line 16 or does this only work when both 15 and 16 are commented?
mike mike
mike mike 2015 年 9 月 10 日
編集済み: mike mike 2015 年 9 月 10 日
I answer the first question: Matrice_G 38x85 double;ug 38x1 double; vettore_b 1x85 double; vettore_s 85x1 double; UG 38x1 double; matrice_Ae 10x85 double
I answer the second question: only if the lines are active at the same time lines 15 and 16, the program shows the error, while if active only line 15 or only line 16 the program run. if I take off my line plotFrontier(p) the program run with line all constraints simultaneously . if you want i can send my code.
I used the same matrices and vectors with the function PortFolio instead of Portfolio CVaR and the coding is performed ...sigh!
Brendan Hamm
Brendan Hamm 2015 年 9 月 10 日
I would likely be able to help better with the actual code. If you can, please just attach using the paper clip icon. Thanks.
mike mike
mike mike 2015 年 9 月 10 日

サインインしてコメントする。

回答 (1 件)

Brendan Hamm
Brendan Hamm 2015 年 9 月 14 日

0 投票

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 件のコメント

mike mike
mike mike 2015 年 9 月 14 日
I know that the number of samples of the scenario is low, the reason is that it is a sample program to understand the problem. The complete program, which I did, the number of samples is 2400. however I don't understand yet the problem.In fact in the program the initial portfolio a vector X0 in which, for example, the weight of asset 1 is 10,6. It's true that the equality constraint is not consistent with the value dell'upperbound (10% per asset 1 for example) but if I run the program it should not give error but instead have a region not feasible However, if I choose the upperbound 30% the problem remains and the value 0.3 is compatible with the equality constraint. however If I delete plotfrontier the program does not show me the strange this error
Brendan Hamm
Brendan Hamm 2015 年 9 月 14 日
1. I figured that this was a test problem, but this does not mean that you can have conflicting constraints.
2. If you want to check the feasibility you can use the method estimateBounds.
3.No optimization problem is even run prior to the plotFrontier, so feasibility will not be found before this.
4. I am not sure exactly what is going on to cause this error, but since effectively all you are doing is setting bounds, do this with the bound constraints:
load('dati_ingresso_portafoglio.mat')
m=medie_annuali;
C=nancov(matrici_rendimenti)*195;
AssetScenarios = mvnrnd(m, C, 10);
vettore_b = vettore_b';
p = PortfolioCVaR; %crea oggetto Portafoglio
p = PortfolioCVaR(p,'scenario', AssetScenarios);
% Set Initial Portfolio
Ricchezza=sum(importi_partenza);%patrimonio attuale
X0=importi_partenza/Ricchezza;%stabilisce i pesi del portafoglio iniziale
p = PortfolioCVaR(p,'InitPort',X0);
% Create bounds
lb = zeros(size(nomi_assets));
ub = 0.3*ones(size(nomi_assets));
% Change bounds from old equality constraints
boundIdx = find(any(matrice_Ae)); % Will find the indices of eq const
lb(boundIdx) = p.InitPort(boundIdx);
ub(boundIdx) = p.InitPort(boundIdx);
p = PortfolioCVaR(p,'Name','Allocazione Fondi Comuni','lowerbudget',1, 'upperbudget', 1, 'lowerbound', 0,'upperbound', 0.3);
p = setProbabilityLevel(p, 0.95);%inserisce livello di probabilità
p = PortfolioCVaR(p,'AssetList',nomi_assets,'RiskFreeRate',r0);
p = PortfolioCVaR(p,'BuyCost', vettore_b, 'SellCost', vettore_s);
p = PortfolioCVaR(p,'GroupMatrix',matrice_G, 'UpperGroup', ug);
plotFrontier(p) %traccia la frontiera efficiente
mike mike
mike mike 2015 年 9 月 17 日

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 2015 年 9 月 17 日
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

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeQuadratic Programming and Cone Programming についてさらに検索

質問済み:

2015 年 9 月 6 日

コメント済み:

2015 年 9 月 17 日

Community Treasure Hunt

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

Start Hunting!

Translated by