## 原文链接： http://tecdat.cn/?p=11878

Nelson-Siegel- [Svensson]模型是拟合收益曲线的常用方法。它的优点是其参数的经济可解释性，被银行广泛 使用 。但它不一定在所有情况下都有效：模型参数有时非常不稳定，无法收敛。

```3.  for(j in 1:N_SIMULATIONS)

5.  {

10.      npo = c(newYields, oldYields)

12.      plot(MATURITY_BASES, oldYields, ylim=c(min(npo), max(npo)))

14.      lines(MATURITY_BASES, oldYields)

16.      points(MATURITY_BASES, newYields, col="red", pch=4)

18.      points(newMATs, newNsYields, col="blue")

20.      lines(newMATs, newNsYields, col="blue")```

`maxDistanceArray[j] = max( abs(oldYieldsArray[j,] - newNsYieldsArray[j,]) )`

_maxDistanceArray_的概率密度   如下所示：

```3.  idx = intersect(intersect(which(b0 < q_b0), which(b1 < q_b1)), which(b2 < q_b2))

5.  par(mfrow=c(3,3))

7.  plot(density(log(b0)))

9.  plot(density(log(b1)))

11.  plot(density(log(b2)))

13.  plot(density(log(b0[idx])))

15.  plot(density(log(b1[idx])))

17.  plot(density(log(b2[idx])))

19.  plot(density(b0[idx]))

21.  plot(density(b1[idx]))

23.  plot(density(b2[idx]))

29.  b0 = b0-mean(b0)

31.  b1 = b1-mean(b1)

33.  b2 = b2-mean(b2)

37.  #训练神经网络

39.  X = cbind(b0, b1, b2)

41.  Y = array(0, dim=(N_SIMULATIONS-1))

43.  Y[idx] = 1```

```1.  SPLT = 0.8

3.  library(keras)

5.  b = floor(SPLT*(N_SIMULATIONS-1))

14.  plot(history)

16.  model %>% evaluate(x_test, y_test)```