R: Shape-based decomposition of the yield-adjustment term in the AFNS model

This post covers Steeley (2014) shape-based decomposition of the yield-adjustment term in the AFNS model using R.



Yield-adjustment term in AFNS model



CDR (2011) showed that the arbitrage-free Nelson-Siegel (AFNS) model includes a yield-adjustment term aimed at enforcing the no-arbitrage restriction. This result is obtained by fixing the mean parameters of the state variables under the Q-measure (risk-neutral measure) at zero.

source: CDR (2011)


Steeley (2014) developed a shape-based decomposition to interpret this seemingly complicated term by employing familiar level, slope, and curvature factor loadings. The decomposition is of the following nice form.

source: Steeley (2014)

You can refer to Steeley (2014) for the interpretation of these four components.


R code


The following R code calculates the yield-adjustment term using the original equation from CDR (2011) and the new representation introduced by Steeley (2014). Naturally, these two are equivalent. The parameter estimates utilized for the decay parameter and volatility matrix can be found in CDR (2011).

Specifically, when creating a function for Steeley's (2014) decomposition, I use simplified notations and calculations to improve clarity.

 
graphics.off(); rm(list = ls()) # clear and remove
 
#-----------------------------------------------------
# CDR (2011) Yield adjustment term of AFNS model
#-----------------------------------------------------
AFNS.C.CDR2011<-function(s, la, t) {
    
    s11=s[1,1]; s12=0;      s13=0
    s21=s[2,1]; s22=s[2,2]; s23=0
    s31=s[3,1]; s32=s[3,2]; s33=s[3,3]
    
    A=s11^2+s12^2+s13^2; D=s11*s21+s12*s22+s13*s23
    B=s21^2+s22^2+s23^2; E=s11*s31+s12*s32+s13*s33 
    C=s31^2+s32^2+s33^2; F=s21*s31+s22*s32+s23*s33
    
    r1 <- A*t^2/6
    r2 <- B*(1/(2*la^2)-(1-exp(-la*t))/(la^3*t) + 
             (1-exp(-2*la*t))/(4*la^3*t))
    r3 <- C*(1/(2*la^2)+exp(-la*t)/(la^2)-t*exp(-2*la*t)/(4*la) -
             3*exp(-2*la*t)/(4*la^2)-2*(1-exp(-la*t))/(la^3*t) +
             5*(1-exp(-2*la*t))/(8*la^3*t))
    r4 <- D*(t/(2*la)+exp(-la*t)/(la^2)-(1-exp(-la*t))/(la^3*t))
    r5 <- E*(3*exp(-la*t)/(la^2)+t/(2*la)+t*exp(-la*t)/(la) -
             3*(1-exp(-la*t))/(la^3*t))
    r6 <- F*(1/(la^2)+exp(-la*t)/(la^2)-exp(-2*la*t)/(2*la^2-
             3*(1-exp(-la*t))/(la^3*t)+3*(1-exp(-2*la*t))/(4*la^3*t))
    
    return(r1+r2+r3+r4+r5+r6)
}
 
#-----------------------------------------------------
# Steeley (2014) Shape-based yield adjustment term
#-----------------------------------------------------
AFNS.C.Steeley<-function(s, la, t) {
    
    A=sum(s[1,]^2);     B=sum(s[2,]^2);     C=sum(s[3,]^2)
    D=sum(s[1,]*s[2,]); E=sum(s[1,]*s[3,]); F=sum(s[2,]*s[3,])
    
    Sf <- function(la) {return((1-exp(-la*t))/(la*t))}
    Cf <- function(la) {return((1-exp(-la*t))/(la*t)-exp(-la*t))}
    
    ANS <- (B+C+2*F)/(2*la^2- ((B+C+2*F)/(la^2))*Sf(la) - 
           ((C+D+3*E+F)/(la^2))*Cf(la)
    CDR5<- ((2*B+2*C+4*F)/(2*la)^2)*Sf(2*la) + 
           ((3*C+2*F)/(2*la)^2)*Cf(2*la)
    FNS <- E*(t*exp(-la*t)/la) - (C/2)*(t*exp(-2*la*t)/(2*la)) 
    QF  <- ((D+E)/(2*la))*+ (A/6)*t^2
    
    return(ANS + CDR5 + FNS + QF)
}
 
 
mat <- 1:360/12 # maturity in years
 
#-----------------------------------------------------
# AFNS independent-factor
#-----------------------------------------------------
la_ind = 0.5975
sigma_ind <- matrix(c(
    0.00510,           0,
    0,      0.0110,      0,
    0,      0,      0.0264
),3,3)
 
C_ind1 <- AFNS.C.CDR2011(sigma_ind, la_ind, mat)
C_ind2 <- AFNS.C.Steeley(sigma_ind, la_ind, mat)
 
#-----------------------------------------------------
# AFNS correlated-factor
#-----------------------------------------------------
la_cor = 0.8244
sigma_cor <- matrix(c(
     0.0154,       0,      0,
    -0.0013,  0.0117,      0,
    -0.1641-0.05900.0001
),3,3, byrow = TRUE)
 
C_cor1 <- AFNS.C.CDR2011(sigma_cor, la_cor, mat)
C_cor2 <- AFNS.C.Steeley(sigma_cor, la_cor, mat)
 
#-----------------------------------------------------
# Figure
#-----------------------------------------------------
x11(width=6, height=6); 
matplot(mat, -cbind(C_ind2, C_cor2)*10000, type="l"
        lty=1:2, lwd=4, col=c(4,6),
        ylab = "Yield-adjustment term in basis points"
        xlab = "Maturity in years",
        main = "Yield adjustment term of AFNS model")
 
legend("topright", col=c(4,6), lty=1:2, lwd=3, cex=1,
       legend=c("AFNS indep.-factor""AFNS corr.-factor"))
 
cs


The figure below illustrates slight variations in the yield-adjustment terms between two AFNS models: one incorporating independent factors and the other incorporating correlated factors, as previously demonstrated by CDR (2011).



Reference

CDR (2011): Christensen, J.H.E., Diebold, F.X., and Rudebusch, G.D., 2011. The affine arbitrage-free class of Nelson-Siegel term structure models. Journal of Econometrics 164, 4-20.

Steeley (2014): Steeley, J.M., 2014. A shape-based decomposition of the yield-adjustment term in the arbitrage-free Nelson and Siegel (AFNS) model of the yield curve, Applied Financial Economics 24, 661-669.






No comments:

Post a Comment