ns

语法

ns(maturity, yield, [method='nm'], [maxIter], [bounds], [initialGuess], [seed])

语法

使用 NS 模型和指定的优化方法,拟合债券的收益率曲线。

返回一个字典,详见 nss

语法

initialGuess 可选参数,数值向量,表示使函数最优化的参数的初始猜测。长度为 4,每个值分别表示 β0, β1, β2, λ 的初始猜测,默认值为 [0.01, 0.01, 0.01, 1.0]。

其余参数详见 nss

语法

传入指定的模型名称与参数,使用 bfgs 优化方法,拟合债券的收益率曲线。
maturity = [1,2,3,4,5,8,10,15,20,25,30]
yield = [0.0039,0.0061,NULL,NULL,0.0166,NULL,0.0258,NULL,NULL,0.0332,NULL]
model = ns(maturity, yield, method='bfgs');
model;
/*Output
modelName->ns
params->[0.037907009765789,-0.032345632006991,-0.048221596538028,1.48711064869407]
fminResult->xopt->[0.037907009765789,-0.032345632006991,-0.048221596538028,1.48711064869407]
fopt->7.682740281926149E-8
gopt->[0.000007050477817,-0.000001557728067,8.217072418048589E-7,-7.435919702203364E-8]
iterations->29
Hinv->#0                  #1                    #2                   #3                   
------------------- --------------------- -------------------- ---------------------
1.046957491287936   -2.422265785994416    4.016547235964936    174.575362711334378  
-2.422265785994413  20.767722224747515    -55.516118469836506  -1160.911707217612729
4.016547235964929   -55.516118469836506   162.441840532431541  3127.297987855009978 
174.575362711334378 -1160.911707217613638 3127.297987855011797 72743.950482441126951

warnFlag->0
fcalls->165
gcalls->33

predict->nssPredict
*/
若更换优化算法为 nm,返回值将发生变化。
model = ns(maturity, yield, method='nm');
model;
/*Output
modelName->ns
modelName->ns
params->[-0.017297505365068,0.016544815374471,0.142682692134247,14.720778706012911]
fminResult->xopt->[-0.017297505365068,0.016544815374471,0.142682692134247,14.720778706012911]
fopt->0.000001443427918
iterations->446
fcalls->740
warnFlag->0

predict->nssPredict
*/

相关函数nss