MATLAB: Calculating a withdrawl plan? For Loop – In an assignment A(I) = B, the number of elements in B and I must be the same. –

??? in an assignment a(i) = bfor loopthe number of elements in b and i must be the same.

I try to calculate a withdrawl plan from a portfolio.
InitVal = 100
R_until_85 = 0.35
iNumObs = 10
iNumSim = 100
mRetRisky = [0,0194563288529693 -0,0566781000933427;
0,0492829304809960 -0,0768978197776796]
%Preallokation
mSimPrice=NaN(iNumObs,iNumSim);
this is the result i want to get:
vInitVal = repmat(InitVal,1,size(mRetRisky,2));
vR_until_85 = repmat(R_until_85,1,size(mRetRisky,2));
% vInitVal_1 = (vInitVal-vR_until_85) .* exp(mRetRisky(1,:));
% vInitVal_2 = (vInitVal_1-vR_until_85) .* exp(mRetRisky(2,:));
% vInitVal_3 = (vInitVal_2-vR_until_85) .* exp(mRetRisky(3,:));
but the Loop isn't working, where is the difference?:
for i=1:iNumObs;
vInitVal = (vInitVal-R_until_85) .* exp(mRetRisky(i,:));
mSimPrice(i) = vInitVal;
end
Cheers Thanks!!

Best Answer

  • mSimPrice(:,:,i) = vInitVal;