March 14th, 2006, 5:26 pm
Hi there, the code below seems to be working. There were some inconsistencies with your discounting intervals. Let me know if you need any clarifications.Kyriakosclear;clc;R0 = 0.05;sigma = 0.1;alpha = 0.6;bita = 0.06;nSim = 10000;N = 360;dt = 1/N;R = R0*ones(N+1,nSim);%Simulatedfor i=1:N W = randn(1,nSim/2); R(i+1,: ) = R(i,: ) + dt*alpha*(bita-R(i,: ))... +sigma*sqrt(dt*R(i,: )).*[W, -W];endy = 1./cumprod(1+dt*R);y0 = mean(y')';T0 = dt*(1:N+1)';P0 = -log(y0)./T0;plot(T0,P0); hold on;%Closed formT=1;N=30;gamma=sqrt(alpha^2+2*sigma^2);for T=1:N TT = T/N; B(T)=2*(exp(gamma*TT)-1)/((gamma+alpha)*(exp(gamma*TT)-1)+2*gamma); A(T)=(2*gamma*(exp((alpha+gamma)*TT/2))/((gamma+alpha)*(exp(gamma*TT)-1)+2*gamma))^(2*alpha*bita/sigma^2); P(T)=A(T)*exp(-B(T)*R0); Y(T)=-log(P(T))/TT; if T>1 f(T)=-log(P(T)/P(T-1)); else f(T)=-log(P(T)); endendplot((1:N)./N, Y,'r*');axis([0 1 -Inf Inf]);grid on;