[R-sig-finance] fBonds svensson fitting
Krishna Kumar
kriskumar at earthlink.net
Tue Jan 24 04:38:54 CET 2006
Thomas Steiner wrote:
>
>
>>r = nlm(f=nelson,p=c(1,10,10,10),y=fwdcrv,steptol=1e-10,iterlim=500)
>>
>>
>
>
>
>>How do you calculate forward rates out of SWAP (Libor) rates?
Typically you have money-market/cash , futures and swap rates so it is a
little more involved and there are other considerations
such as smoothness of the forward and day counts etc. If you want an
ugly way of doing this (caveat emptor)
Let us say we have the swap crv object with the first row being a cash
rate (1 year) rate. The columns are
tenor in years, day count between two tenor points and the swap/cash rates.
> swapcrv
Tenor days.360 Rates
1 1 1.022222 0.0359
2 2 1.011111 0.0390
3 3 1.011111 0.0403
4 4 1.013889 0.0409
5 5 1.016667 0.0414
6 6 1.013889 0.0418
7 7 1.019444 0.0423
8 8 1.011111 0.0427
9 9 1.013889 0.0430
10 10 1.013889 0.0434
---------------------------------------------
dfcurve<-function(swapcrv)
{
#First construct a discount curve!
##assumes the first point is cash and rest are swap rates
n<-dim(swapcrv)[1]
dfcrv<-matrix(0,n,2)
dfcrv[,1]<-swapcrv[,1]
dfcrv[,2]<-1/(1+swapcrv[,2]*swapcrv[,3])
dfcrv[-1,2]<-dfcrv[-1,2]*(1-(cumsum(swapcrv[-n,2]*dfcrv[-n,2]))*swapcrv[-1,3])
return(dfcrv)
}
df.to.fwd<-function(dfcurve,tenor,interp="linear")
{
#function to compute the forward curve at the tenor points given a dfcurve!
#do linear interpolation of the dfactors or cubic spline from akima package!
tenor<-c(0,tenor)
n<-length(tenor)
fwd.tenor<-array(0,n)
df.tenor<-array(0,n)
if(interp=="spline")
{
df.tenor<-aspline(dfcurve[,1],dfcurve[,2],tenor)$y
} else
{
df.tenor<-approx(dfcurve[,1],dfcurve[,2],tenor)$y
}
df.tenor[1]<-1
fwd.tenor<-(df.tenor[-n]/df.tenor[-1] -1)/diff(tenor)
return(list(fwd=fwd.tenor,df=df.tenor))
}
-----------------------------------------------
So now you can do
> dfcrv <- dfcurve(swapcrv)
And then construct the forward curve from the discount curve.
> df.to.fwd(dfcrv,tenor=seq(0.5,10,by=0.5),interp="spline")
There are many ways to construct these curves and you will find this
exhaustive paper useful
(http://www.cam.wits.ac.za/mfinance/papers/interpolation.pdf )
Best,
Kris
More information about the R-sig-finance
mailing list