Effacer les filtres
Effacer les filtres

Subscripted assignment dimension mismatch in linprog optimization

2 vues (au cours des 30 derniers jours)
Stefano Di Vito
Stefano Di Vito le 29 Mar 2018
Hello everybody! I get the following error while performing my linear program (in order to calculate the objective function value on 100 different points.) Here's the code:
T=size(X,1);
N=size(X,2);
M=2+N;
tau=zeros(N,P);
Xtau=zeros(P,T);
H=zeros(P,T+M);
for j=1:P % P is the number of portfolios
tau(:,j)=matpesi(:,j); % weights vector
Xtau(j,:)=(X*tau(:,j))'; %obj function variables Beta-coeff. row-vector
H(j,:)=[1 -1 zeros(1,N) -1/T*(Xtau(j,:))]; % each row of the matrix h contains the coefficients of objective function
Aeq=[ones(N,1) -ones(N,1) -eye(N) -1/T*(X')];
beq=zeros(N,1);
C=-eye(T,T);
for s=1:T-1
C(s,s+1)=1;
end
A=[zeros(T,M) C; -eye(M,T+M) ];
b=[-1/T*ones(T,1); zeros(M,1)];
end
x=zeros(T+M,P);
for c=1:P
f=H(c,:);
options = optimoptions('linprog','Algorithm','interior-point','Display','final','MaxIterations',10e5);
[x(:,c),fval(:,c),exitflag]=linprog(f,A,b,Aeq,beq)
fval(fval<1.0000e-6)=0.0;
end
end
Once i run the code i get the error written in the title. I'm facing problems at indexing the "f" coefficient vector. To be clearer, i should perform the LP for each of the 100 rows of matrix H( each row should be a "f"coeff. vector for the function linprog.) This means i should perform the test on each of the 100 portfolios. Literally, i should obtain a vector of fvals, as each one of its elements should tell me if the correspondant portfolio is efficient or not under second order stochastic dominance assumptions. Anyone could help me? Thank you in advance

Réponses (1)

Alan Weiss
Alan Weiss le 2 Avr 2018
I am suspicious of this line:
f=H(c,:);
It seems that you intended to write
f=H(C,:);
Alan Weiss
MATLAB mathematical toolbox documentation

Catégories

En savoir plus sur Portfolio Optimization and Asset Allocation dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by