Subscripted assignment dimension mismatch.

1 次查看(过去 30 天)
Hi all,
every time I run this function I get the following error message:
Subscripted assignment dimension mismatch.
Error in volas (line 12)
LMMVol(i,j) = RebonatoFormula(point(4), point(5), point(6),
point(7), psi, point(1:3), maturities, rates, i, i+j)
%tenorDate+tenorDate
function [sse] = volas(point, tenorDate, maturities, rates, maturity, marketData) %point=[beta(1) beta(2) beta(3) a b c d]
LMMVol=zeros(tenorDate-1);
alph=[point(4) point(5) point(6) point(7)];
psi = CoTerminalVolaCallibration(alph, point(1:3), maturities, rates, maturity, tenorDate, tenorDate+tenorDate, marketData);
for i=1:tenorDate-1
for j=1:tenorDate-i
%RebonatoFormula
LMMVol(i,j) = RebonatoFormula(point(4), point(5), point(6), point(7), psi, point(1:3), maturities, rates, i, i+j) %tenorDate+tenorDate
CompData(i,j) = marketData(i,j)
end
end
errors = LMMVol - CompData;
sse = sum(sum(errors .^ 2));
end
when i take away (i,j) from LMMVol in line 12, the code works but instead of the needed LMMVol-Matrix with dimension tenorLength-1 (or 10), I only get a scalar.
Does anyone know how I will get a matrix as a result?
Thanks a lot.
  1 个评论
the cyclist
the cyclist 2013-8-20
Can you supply examples of the input parameters, so that you have self-contained code that we can actually run and show the error?

请先登录,再进行评论。

回答(2 个)

Iain
Iain 2013-8-20
The error is due to the fact that the RebonatoFormula function does not always output scalar values.
You need to determine exactly what it outputs, and handle that instead of assuming that it just outputs a scalar value.

Mario
Mario 2013-8-20
编辑:Walter Roberson 2013-8-20
absolutely:
function V = RebonatoFormula(a, b, c, d, psi, beta, maturities, rates, maturity, tenorDate) %horizon
CORR=CorrelationMatrix(beta, maturities, tenorDate-1, maturity, tenorDate);
V=0;
for indexI=maturity:tenorDate-1
for indexJ=maturity:tenorDate-1
test=quad(@vola,0,maturity);
V=V+weights(indexI, maturity, tenorDate, rates)*weights(indexJ, maturity, tenorDate, rates)*rates(indexI)*rates(indexJ)*CORR(indexI,indexJ)*quad(@vola,0,maturity); %S.15 Formel (Zähler+Integral)
end
end
V=sqrt((1/maturity)*V*(1./swapRate^2));
function v = vola(time)
v1 = VolFunc(a, b, c, d, psi(indexI), time, maturity);
v2 = VolFunc(a, b, c, d, psi(indexJ), time, maturity);
v = v1.*v2;
end
function w = weights(index, maturity, tenorDate, rates)
helper= cumprod(1./(1+rates(maturity:tenorDate-1)));
nom = helper(index-maturity+1);
denom = cumsum(helper);
w = nom./denom(tenorDate-maturity);
end
function S = swapRate
S = rates(maturity:tenorDate-1)*weights(maturity:tenorDate-1, maturity, tenorDate, rates)';
end
end
function CORR = CorrelationMatrix(beta, maturities, horizon, startRate, endRate)
CORR=zeros(endRate-startRate);
for i = startRate:endRate
for j = startRate:endRate
CORR(i,j) = CorrFunc(beta, horizon, maturities(j), maturities(i));
end
end
end
Inputs:
marketData=[0.252000000000000,0.218000000000000,0.191000000000000,0.173000000000000,0.159000000000000,0.147000000000000,0.139000000000000,0.131000000000000,0.128000000000000,0.124000000000000;0.235000000000000,0.201000000000000,0.179000000000000,0.163000000000000,0.150000000000000,0.140000000000000,0.133000000000000,0.125100000000000,0.122000000000000,0.118000000000000;0.214000000000000,0.187000000000000,0.168000000000000,0.153000000000000,0.142000000000000,0.132000000000000,0.126000000000000,0.119000000000000,0.117000000000000,0.113000000000000;0.194000000000000,0.174000000000000,0.157000000000000,0.144000000000000,0.134000000000000,0.126000000000000,0.120000000000000,0.114000000000000,0.111000000000000,0.108000000000000;0.180000000000000,0.163000000000000,0.147000000000000,0.135000000000000,0.127000000000000,0.119000000000000,0.114000000000000,0.108000000000000,0.106000000000000,0.103000000000000;0.168000000000000,0.153000000000000,0.138000000000000,0.130000000000000,0.122000000000000,0.116000000000000,0.112000000000000,0.106000000000000,0.104000000000000,0.101000000000000;0.159000000000000,0.146000000000000,0.134000000000000,0.126000000000000,0.120000000000000,0.115000000000000,0.111000000000000,0.106000000000000,0.104000000000000,0.101000000000000;0.151000000000000,0.140000000000000,0.130000000000000,0.124000000000000,0.118000000000000,0.113000000000000,0.109000000000000,0.104000000000000,0.103000000000000,0.100000000000000;0.145000000000000,0.135000000000000,0.128000000000000,0.121000000000000,0.116000000000000,0.111000000000000,0.108000000000000,0.103000000000000,0.102000000000000,0.099000000000000;0.139000000000000,0.132000000000000,0.125000000000000,0.119000000000000,0.115000000000000,0.111000000000000,0.108000000000000,0.103000000000000,0.102000000000000,0.099000000000000];
rates=[.0299 .0366 .041 .0444 .0475 .0497 .0514 .0522 .053 .054]';
maturity = 1;
maturities = [[3,4,5,6,7,8,9,10,11,12;4,5,6,7,8,9,10,11,12,13;5,6,7,8,9,10,11,12,13,14;6,7,8,9,10,11,12,13,14,15;7,8,9,10,11,12,13,14,15,16;8,9,10,11,12,13,14,15,16,17;9,10,11,12,13,14,15,16,17,18;10,11,12,13,14,15,7,17,18,19;11,12,13,14,15,16,17,18,19,20;12,13,14,15,16,17,18,19,20,21;]];
tenorDate = 11;
horizon= tenorDate+tenorDate;
startRate= 10;
endRate= tenorDate+tenorDate-2;
index=maturity:tenorDate-1;
psi=ones(1,tenorDate-1);
a=0;
b=.2;
c=.3;
d=.1;
beta=[.2 .1 .05]';
time=0;
time_k=10;
alph=[a b c d];
point=[beta(1) beta(2) beta(3) a b c d];

类别

Help CenterFile Exchange 中查找有关 Feature Calibration 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by