全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 R语言论坛
2702 1
2008-09-22

请问有人有写过建构各天期公债殖利率的程序吗?是Svensson(1994)

在Nelson-Siegel model多加一个额外的驼峰,请大家帮个忙,谢谢。

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2015-1-22 22:06:27
Nelson-Siegel model用的是YieldCurve包 Nelson.Siegel()函数  
不过你要Svensson model,那就用OptionsPdf包 OptionsPdf-package()

#strike prices
X <- matrix( c(92.00, 94.00, 94.50, 95.00, 95.50, 96.00, 96.50, 97.00,
        97.50, 98.00, 98.50, 99.00, 99.50, 100.0, 100.5, 101.0,
        101.5, 102.0, 102.5, 103.0, 103.5 ) )
        
#call prices; Mx1 vector
C <- matrix( c( 5.13,   3.25,   2.83,   2.40,  2.00,  1.64,   1.31,   1.02,
        0.770,  0.570,  0.400,  0.280,  0.190, 0.130, 0.0800, 0.0500,
        0.0400, 0.0300, 0.0200, 0.0100, 0.0100 ) )

#Forward price, scalar or Mx1 vector
F <- 97.05               

#time to expiry in years, scalar
k <- 48/365               

#Interest rate: LIFFE margining&lt;-&gt;no discounting
r <- 0                    

#weight matrix for price errors
W <- diag( length(F)+length(X) )  


#  Two states: solving for 2 means, 2 standard deviations, and
#  one probability of the first normal distribution.
#  Estimation: (a) Assuming a probability and then optimizing wrt.
#                     mean1, mean2, std1, and std2.
#                     (b) (a) is repeated for (Nprob) different values of
#                     the probability between 0.01 and 0.49.
#  Uses forward rate and option data.
  
#initial parameter guess
par0 <- c(4.58, 4.58, 0.025, 0.005)  

#Number of different probabilites in [0.01,0.49] to try
#NProb x 5 matrix to store loop results in NProb <- 43         
                     
#probabilities to try   
Prob   <- matrix(c( linspace(0.03,0.47,NProb) ))   
Par2M  <- repmat( NaN,NProb,4)

#NProb x 1 vector to store loss fn values
Loss2M <- repmat( NaN,NProb,1 )   

i <- 1;                              
  #looping over different probabilities
  for (i in 1:NProb) {

        #[Prob(i);1-Prob(i)][[PROB(i)的1-PROB(ⅰ)]]
        Probi <- matrix(c( Prob, 1-Prob ) )
  
        results2 <- optim(par0, OptionMixLNormLoss,
                        gr=NULL, Probi, k, r, X, F, C, W)

        Par2M[i,] <- t(c( results2$par ))
        Loss2M <- t(c( results2$value ))
  }

  #index of iteration with minimum loss
  MinLossIndex <- find( Loss2M==min(Loss2M) )

  #Parameters at minimum loss
  par2 <- matrix(c(Par2M[MinLossIndex,], Prob[MinLossIndex]))

  S <- linspace(4.47, 4.68, 100)

  pdf2 <- MixedNormalPdf( matrix(S), matrix(c(par2[1:2])),
                matrix(c(par2[3:4]^2)), matrix(c(par2[5],1-par2[5])) )

  plot( S, pdf2$pdf, type="b", col="red",  xlab="log Bund price",
                main="Pdf from LIFFE Bunds option data, 6 April 1994 - 2")   

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

分享

扫码加好友,拉您进群