Calibration of Vasicek through "lsqnonlin"

조회 수: 4 (최근 30일)
Fulvio Rizzardini
Fulvio Rizzardini 2016년 1월 10일
댓글: Brendan Hamm 2016년 1월 11일
Hi, I have to calibrate the parameters of the Vasicek model. I want to use "lsqnonlin", but it doesn't work. This is my code:
x=[0.01 0.3 0.1];
epsilon=randn;
t=[0.25, 0.5, 0.75, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 15, 20, 25, 30];
r=spotrate'; %they are short rate with the maturities t.
r0=spotrate(1);
rate = r0+x(1)*(x(2)-r0)*t+x(3)*sqrt(t)*epsilon; %thanks to Vasicek model
sigma = std(rate);
price = 100*exp(-t.*rate); % ZCB price
K=100./(1+t.*r); %strike price K
put= blsprice(price, K, rate+1, t, sigma) %rate+1 because, otherwise, I can have negative rate
fun=@(x) blsprice(100*exp(-t.*(r0+x(1)*(x(2)-r0)*t+x(3)*sqrt(t)*epsilon)), K, 1+(r0+x(1)*(x(2)-r0)*t+x(3)*sqrt(t)*epsilon), t, sigma)-CAP %cap is an array with the prices of some caps.
x0=[0.1, 0.3, 0.2]
z = lsqnonlin(fun, x0)
I have these errors:
Error in
@(x)blsprice(100*exp(-t.*(r0+x(1)*(x(2)-r0)*t+x(3)*sqrt(t)*epsilon)),K,1+(r0+x(1)*(x(2)-r0)*t+x(3)*sqrt(t)*epsilon),t,sigma)-CAP
Error in snls (line 329)
newfvec = feval(funfcn{3},xcurr,varargin{:});
Error in lsqncommon (line 156)
snls(funfcn,xC,lb,ub,flags.verbosity,options,defaultopt,initVals.F,initVals.J,caller,
...
Error in lsqnonlin (line 238)
lsqncommon(funfcn,xCurrent,lb,ub,options,defaultopt,caller,...
Thank you
  댓글 수: 2
Walter Roberson
Walter Roberson 2016년 1월 11일
Please show the complete error message. For example did it complain about matrix dimensions not being compatible? Did it complain about subscript out of range?
Brendan Hamm
Brendan Hamm 2016년 1월 11일
Hard to help without more information. Quite frankly it is difficult to follow what you are trying to do.
Why have you generated one sample from the standard normal distribution, rather than a new sample for each time step? Why are you using this value in the objective? Why are there no bounds on the values of your parameters?
Also, I should point out this is NOT the solution of the Vasicek model:
rate = r0+x(1)*(x(2)-r0)*t+x(3)*sqrt(t)*epsilon; %thanks to Vasicek model
This may make you rethink your parameters in the model.
Furthermore, you are using the same sample from the normal distribution for all time steps. The link here has some information about calibrating the Vasicek model using Least-Squares and also using MLE and includes code.

댓글을 달려면 로그인하십시오.

답변 (1개)

Ian Noell
Ian Noell 2016년 1월 11일
This question is more likely to receive an answer if it related to MathWorks Financial toolboxes rather than Model-Based Calibration toolbox. Model-Based Calibration toolbox is targeted at engine calibration problems.

카테고리

Help CenterFile Exchange에서 Interest-Rate Instruments에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by