November 11th, 2013, 8:58 am
Dear MrIsaksen,Thank you so much for sharing.I found two problems in your code:the first one and the fatal one : in the 'HWmodelMC_short.m' file, in line 149 :echo offfor i=1:nsteps, % Random vector dz (slow, but requires less memory) dz=randn(npaths,1)*sqrt(dt); % 1: Calculate increments dr=(theta-ar)dt+?dz dr(:,i)=theta(i)-a*r(:,i)*dt+sigma*dz(:,1);%dz(:,i); %(here is line 149) % 2: Cumulate r by: r(t+1)=r(t)+dr(t) r(:,i+1)=r(:,i)+dr(:,i);endecho onyou should have a bracket for the 'theta(i)-a*r(:,i)' part, isn't it?i.e. , it should be like this : dr(:,i)=(theta(i)-a*r(:,i))*dt+sigma*dz(:,1);%dz(:,i);the second problem(a tiny one): it seems that mtit (plot the main title for all the subplots) seems not to be a built-in function in matlab. i know there is such function on the mathworks forum, but you should mention that or stored this function in the zip-file.As to the theta function in the hull white model, there is matlab built-in function, actually matlab has offered a detailed example for the hull white model. You could use which +function name to find the location of the function and then see the matlab codeHow do you deal with the negative rates?Do you also have some code with the BK model?Kind RegardsYU