- %Parameters initial valus for one factor Vasicek model
- alpha=1.3;
- gamma=0.05;
- rho=0.06;
- q=0.1;
- Maturity=3;
- rInit=0.05;
- NbStep=1000;
- DeltaT=Maturity/NbStep;
- %Initialisation of the answer vector
- r=zeros(1,NbStep);
- r(1)=rInit;
- %For each step, we simulate the rate following the model
- for i=2:NbStep
- r(i)=r(i-1)+alpha*(gamma-r(i-1))*DeltaT+ ...
- rho*sqrt(DeltaT)*randn(1);
- end
- %Parameters of model to rate R.
- RInfinity=gamma+rho*q/alpha-rho^2/(2*alpha^2);
- %Vector of time steps
- t=[0:1:NbStep-1]*DeltaT;
- %Computation of rates for the points represented in vector r
- R=RInfinity + ...
- (r-RInfinity).*(1-exp(-alpha*(Maturity-t)))./(alpha*(Maturity-t))+ ...
- rho^2.*((1-exp(-alpha*(Maturity-t))).^2)./(4*alpha^3*(Maturity-t));
- %Graph of the interest rate as function of maturity
- plot([t,Maturity],[R,rInit]);
- ylabel('R[t,T]');
- xlabel('t');