Description |
a path of a gaussion ornstein uhlenbeck short rate process and the corresponding yield curve.
|
Source |
created by myself with GNU R, see source below
|
Date |
3 july 2007
|
Author |
Thomas Steiner
|
Permission
(Reusing this image) |
Thomas Steiner put it under the CC-by-SA 2.5.
|
R-source:
## einfachstes bsp, yields in Vasicek, Notation wie Brigo/Mercurio
#übernimmt log(z) als Parameter (nichtnegativ)
yvas<-function(ttm,para,rt) {
lambda=exp(para$lambda)
theta=exp(para$theta)
sigma2=(exp(para$sigma))^2
B=1/lambda*(1-exp(-lambda*ttm))
lnA=(theta-sigma2/(2*lambda^2))*(B-ttm)-sigma2/(4*lambda)*B^2
return( -(lnA-B*rt)/ttm )
}
### OU-levy processes ################################
## starting at time t=0 at Z_0=para$r until time t=T in "steps" equidistant steps; mean reversion "mr"
## parameters of the distribution of the bdlp are stored in param
process.ou<-function(para,type,T=1,steps=500) {
dt=T/(steps-1)
ou=array(para$r,dim=steps)
if (type=="cauchy") {
dLt=rcauchy(steps-1, location=para$location, scale=para$scale*dt)
} else if (type=="gamma") {
dLt=rgamma(n=steps-1, shape=para$shape, scale=para$scale*dt)
} else if (type=="IG") {
dLt=rinvGauss(n=steps-1, nu=(para$delta*dt)/para$gamma, lambda=(para$delta*dt)^2)
} else if (type=="norm") {
dLt=rnorm(n=steps-1, mean=para$lambda*para$theta*dt, sd=para$sigma*dt)
} else {
print("process.ou:: this type of OU-process is not yet implemented")
}
for (tm in 1:(steps-1)) {
ou[tm+1]=ou[tm]-para$lambda*ou[tm]*dt+dLt[tm]
}
return (ou)
}
set.seed(28019180)
time=seq(0,14,length=700)
pa=list(lambda=2,theta=0.04,sigma=0.2,r=0.08)
lpa=list(lambda=log(pa$lambda),theta=log(pa$theta),sigma=log(pa$sigma)) #log-parameter
gou=process.ou(pa,"norm",T=4,steps=length(time))
plot(time,gou,type="l",lwd=2,axes=F,xlab="Zeit",ylab="Zins",main="Zinsen im Vasicek-Modell",cex.main=2)
abline(h=pa$theta-pa$sigma^2/(2*pa$lambda^2),lty="dotted",col="grey")
lines(time,yvas(time,lpa,pa$r),col="purple",lwd=2)
yticks=axTicks(2)
axis(1)
axis(side=2,at=yticks,labels=paste(format(100*yticks,digits=3),"%",sep=""))
text(x=10.4,y=0.0325,expression(paste("d",r[t]==2(0.04-r[t]),"dt+",0.2,r[t],"d", W[t])),cex=1.4)
Click on a date/time to view the file as it appeared at that time.
The following pages on the English Wikipedia link to this file (pages on other projects are not listed):