JF96
JF96

Reputation: 169

Dynamic nelson siegel

I'm trying to get a dynamic Nelson Siegel model to work. This website shows how to calculate it, but whenever I try to extend this for more maturities, I get an error is my code so far:

# Load statespacer
library(statespacer)
library(xts)

# Load the dataset
#data("FedYieldCurve")
#y <- FedYieldCurve[FedYieldCurve$Month >= "1985-01-01" & FedYieldCurve$Month <= "2000-12-01", ]
#years <- y$Month # Used for plots later on
#y <- as.matrix(y[-1])
xts_data <- xts(yields$USA[, -which(names(yields$USA) == "dates")], order.by = yields$USA$dates)
# Identify the positions of the last observation in each month
eom_positions <- endpoints(xts_data, on = "months")

# Subset the data to include only end-of-the-month observations
y <- xts_data[eom_positions, ]
y=y[,-1]
# Specifying the list
self_spec_list <- list()

# We want to specify the H matrix ourselves
self_spec_list$H_spec <- TRUE

# We have got 6 state parameters: 3 factors and 3 fixed means
self_spec_list$state_num <- 6

# In total we need 20 parameters:
#   1 for lambda
#   1 for sigma2 (H)
#   6 for the variance - covariance matrix Sigma_eta (Q)
#   9 for the vector autoregressive coefficient matrix Phi
#   3 for the means mu
self_spec_list$param_num <- 20

# R is a fixed diagonal matrix
self_spec_list$R <- diag(1, 6, 6)

# P_inf is a matrix of zeroes, as all state parameters are stationary
self_spec_list$P_inf <- matrix(0, 6, 6)

# Needed because we want to use collapse = TRUE
# The fixed means only appear in the state equations, 
# not in the observation equations. So the 4th, 5th, and 6th state parameters
# are state_only.
self_spec_list$state_only <- 4:6

self_spec_list$sys_mat_fun <- function(param) {
  
  # Maturities of the interest rates
  maturity=c(3,  6,   12 ,  24 ,  36, 
             48, 60, 84  ,96  ,108, 120, 240, 360) 
  
  # The constant lambda
  lambda <- exp(2 * param[1])
  
  # The variance of the observation errors
  sigma2 <- exp(2 * param[2])
  H <- sigma2 * diag(1, 13, 13)
  
  # Z matrix corresponding to the factors
  lambda_maturity <- lambda * maturity
  z <- exp(-lambda_maturity)
  Z <- matrix(1, 13, 3) 
  Z[, 2] <- (1 - z) / lambda_maturity
  Z[, 3] <- Z[, 2] - z
  
  # Variance of the state disturbances
  Q <- Cholesky(param = param[3:8], decompositions = FALSE, format = matrix(1, 3, 3))
  
  # Vector autoregressive coefficient matrix, enforcing stationarity
  Tmat <- CoeffARMA(A = array(param[9:17], dim = c(3, 3, 1)),
                    variance = Q,
                    ar = 1, ma = 0)$ar[,,1]
  
  # Initial uncertainty of the factors
  T_kronecker <- kronecker(Tmat, Tmat)
  Tinv <- solve(diag(1, dim(T_kronecker)[1], dim(T_kronecker)[2]) - T_kronecker)
  vecQ <- matrix(Q)
  vecPstar <- Tinv %*% vecQ
  P_star <- matrix(vecPstar, dim(Tmat)[1], dim(Tmat)[2])
  
  # Adding parts corresponding to the fixed means to the system matrices
  Z <- cbind(Z, matrix(0, 13, 3)) # Not used in the observation equation
  Q <- BlockMatrix(Q, matrix(0, 3, 3)) # Fixed, so no variance in its errors
  a1 <- matrix(param[18:20], 6, 1) # Fixed means go into the initial guess
  Tmat <- cbind(Tmat, diag(1, 3, 3) - Tmat)
  Tmat <- rbind(Tmat, cbind(matrix(0, 3, 3), diag(1, 3, 3)))
  P_star <- BlockMatrix(P_star, matrix(0, 3, 3))
  
  # Return the system matrices
  return(list(H = H, Z = Z, Tmat = Tmat, Q = Q, a1 = a1, P_star = P_star))
}

self_spec_list$transform_fun <- function(param) {
  lambda <- exp(2 * param[1])
  sigma2 <- exp(2 * param[2])
  means <- param[18:20]
  return(c(lambda, sigma2, means))
}

initial <- c(-1, -2, -1, -1, 1, 0, 0, 0, 4, 0, 0, 0, 3, 0, 0, 0, 2, 0, 0, 0)

# Fit the state space model
fit <- statespacer(y = y,
                   self_spec_list = self_spec_list,
                   collapse = TRUE,
                   initial = initial,
                   method = "BFGS",
                   verbose = TRUE,
                   standard_errors = TRUE)

This is the data I'm using:

structure(c(5.824, 5.941, 5.94, 5.803, 5.596, 5.328, 5.032, 4.583, 
4.013, 4.064, 4.127, 4.328, 3.967, 3.955, 3.778, 3.378, 3.339, 
2.911, 3.286, 3.59, 3.382, 3.162, 3.14, 3.088, 3.065, 3.306, 
3.212, 3.273, 3.215, 3.13, 3.286, 3.403, 3.299, 3.236, 3.69, 
3.925, 4.431, 4.811, 4.807, 4.849, 5.034, 5.423, 5.671, 6.243, 
6.496, 6.416, 6.168, 6.123, 6.08, 5.826, 5.586, 5.596, 5.525, 
5.576, 5.569, 5.46, 5.157, 5.047, 5.101, 5.253, 6.169, 6.36, 
6.226, 6.339, 5.911, 5.691, 5.366, 5.358, 5.31, 5.578, 5.382, 
5.55, 5.532, 5.413, 5.27, 5.318, 5.38, 5.263, 5.316, 5.433, 5.445, 
5.23, 5.327, 5.252, 5.233, 5.316, 5.241, 5.2, 4.909, 4.488, 4.358, 
4.599, 4.539, 4.455, 4.721, 4.522, 4.659, 4.841, 5.043, 4.888, 
5.212, 4.959, 5.278, 5.554, 5.74, 5.908, 6.022, 6.152, 6.118, 
6.335, 6.225, 6.354, 6.369, 6.278, 6.403, 6.175, 5.706, 4.801, 
4.701, 4.137, 3.957, 3.57, 3.653, 3.466, 3.3, 2.36, 1.945, 1.796, 
1.81, 1.915, 1.874, 2.105, 1.902, 1.895, 1.752, 1.687, 1.667, 
1.513, 1.42, 1.288, 1.214, 1.195, 1.194, 1.128, 1.145, 1.094, 
0.973, 1.023, 1.055, 1.006, 1.045, 1.045, 1.001, 1.004, 1.013, 
1.012, 1.166, 1.396, 1.63, 1.762, 1.797, 1.997, 2.132, 2.376, 
2.589, 2.737, 2.988, 3.131, 3.183, 3.123, 3.34, 3.686, 3.717, 
3.927, 4.223, 4.307, 4.38, 4.582, 4.741, 4.815, 4.911, 5.072, 
5.241, 5.153, 5.115, 5.005, 5.108, 5.093, 5.09, 5.147, 5.119, 
5.072, 4.995, 4.958, 4.945, 4.98, 4.212, 4.085, 4.076, 3.357, 
3.397, 2.064, 1.825, 1.492, 1.624, 2.018, 2.166, 1.874, 1.957, 
1.604, 0.941, 0.431, 0.268, 0.352, 0.447, 0.421, 0.283, 0.29, 
0.348, 0.261, 0.238, 0.178, 0.167, 0.16, 0.197, 0.153, 0.189, 
0.241, 0.243, 0.229, 0.227, 0.202, 0.195, 0.198, 0.172, 0.206, 
0.192, 0.17, 0.173, 0.178, 0.106, 0.114, 0.102, 0.158, 0.046, 
0.056, 0.057, 0.056, 0.061, 0.081, 6.033, 6.182, 6.317, 6.15, 
5.734, 5.413, 5.093, 4.678, 4.092, 4.199, 4.306, 4.501, 4.319, 
4.251, 4.056, 3.625, 3.453, 3.059, 3.517, 3.826, 3.589, 3.365, 
3.28, 3.29, 3.263, 3.616, 3.444, 3.529, 3.378, 3.368, 3.473, 
3.633, 3.59, 3.515, 3.986, 4.438, 5.092, 5.376, 5.498, 5.373, 
5.547, 5.941, 6.15, 6.897, 7.195, 6.797, 6.422, 6.485, 6.316, 
5.791, 5.634, 5.706, 5.675, 5.709, 5.618, 5.456, 5.186, 5.032, 
5.242, 5.473, 6.169, 6.36, 6.226, 6.339, 5.925, 5.708, 5.418, 
5.372, 5.516, 5.578, 5.673, 6.011, 5.903, 5.782, 5.675, 5.44, 
5.585, 5.466, 5.373, 5.515, 5.501, 5.226, 5.401, 5.396, 5.397, 
5.424, 5.381, 5.38, 4.859, 4.4, 4.185, 4.502, 4.532, 4.505, 4.877, 
4.718, 4.772, 4.984, 5.072, 5.132, 5.308, 5.201, 5.438, 5.714, 
5.989, 6.285, 6.268, 6.267, 6.261, 6.298, 6.091, 6.108, 6.216, 
6.091, 6.145, 5.915, 5.351, 4.593, 4.472, 4.126, 3.985, 3.706, 
3.803, 3.548, 3.423, 2.533, 2.112, 2.155, 2.227, 2.342, 2.281, 
2.654, 2.354, 2.341, 2.135, 1.877, 1.827, 1.575, 1.508, 1.55, 
1.346, 1.365, 1.304, 1.25, 1.262, 1.174, 1.086, 1.267, 1.365, 
1.161, 1.308, 1.384, 1.28, 1.281, 1.228, 1.204, 1.558, 1.785, 
1.99, 2.077, 2.005, 2.21, 2.279, 2.594, 2.759, 2.929, 3.206, 
3.362, 3.354, 3.288, 3.452, 3.812, 3.764, 4.025, 4.293, 4.361, 
4.406, 4.581, 4.741, 4.838, 4.916, 5.084, 5.235, 5.108, 5.022, 
4.918, 4.989, 4.95, 5.018, 5.093, 4.979, 4.925, 4.879, 4.964, 
4.939, 4.845, 4.202, 4.067, 4.048, 3.246, 3.29, 2.08, 1.76, 1.527, 
1.843, 2.235, 2.361, 2.272, 2.176, 1.802, 1.328, 0.911, 0.367, 
0.504, 0.704, 0.566, 0.492, 0.481, 0.536, 0.482, 0.433, 0.402, 
0.37, 0.266, 0.474, 0.307, 0.325, 0.425, 0.42, 0.355, 0.315, 
0.284, 0.242, 0.261, 0.215, 0.27, 0.286, 0.26, 0.269, 0.313, 
0.218, 0.19, 0.189, 0.205, 0.104, 0.11, 0.116, 0.117, 0.113, 
0.122, 6.928, 6.836, 7.057, 6.928, 6.468, 6.103, 5.81, 5.479, 
4.835, 5.202, 5.35, 5.709, 5.548, 5.292, 4.927, 4.479, 4.205, 
3.858, 4.465, 4.888, 4.648, 4.242, 3.971, 4.023, 3.86, 4.322, 
4.066, 4.195, 3.918, 3.935, 4.062, 4.288, 4.306, 4.192, 4.742, 
5.295, 5.855, 6.12, 6.314, 5.753, 6.077, 6.537, 6.758, 7.365, 
7.618, 7.209, 6.737, 6.793, 6.607, 5.911, 5.815, 5.93, 5.979, 
5.98, 5.716, 5.447, 5.243, 5.002, 5.526, 5.896, 6.17, 6.36, 6.226, 
6.339, 6.483, 6.239, 5.864, 5.679, 5.979, 6.003, 6.208, 6.554, 
6.401, 6.325, 6.189, 5.828, 6.064, 5.882, 5.706, 5.834, 5.738, 
5.383, 5.625, 5.653, 5.661, 5.643, 5.556, 5.566, 4.841, 4.321, 
4.165, 4.561, 4.586, 4.629, 5.216, 5.064, 5.133, 5.506, 5.608, 
5.723, 5.825, 5.695, 5.887, 6.123, 6.355, 6.723, 6.647, 6.6, 
6.811, 6.806, 6.48, 6.399, 6.262, 6.07, 5.999, 5.686, 5.158, 
4.628, 4.44, 4.23, 4.335, 4.25, 4.303, 3.844, 3.672, 2.88, 2.448, 
2.879, 3.07, 3.205, 3.103, 3.768, 3.272, 3.243, 2.883, 2.259, 
2.147, 1.7, 1.686, 2.08, 1.615, 1.707, 1.523, 1.497, 1.497, 1.335, 
1.314, 1.76, 1.989, 1.473, 1.839, 2.066, 1.841, 1.839, 1.658, 
1.59, 2.348, 2.57, 2.716, 2.713, 2.42, 2.638, 2.576, 3.036, 3.104, 
3.315, 3.647, 3.83, 3.699, 3.621, 3.68, 4.069, 3.858, 4.222, 
4.434, 4.467, 4.458, 4.575, 4.738, 4.884, 4.926, 5.106, 5.224, 
5.017, 4.836, 4.742, 4.749, 4.662, 4.871, 4.982, 4.697, 4.628, 
4.646, 4.977, 4.925, 4.57, 4.183, 4.031, 3.991, 3.021, 3.074, 
2.112, 1.629, 1.598, 2.281, 2.673, 2.647, 2.537, 2.392, 1.981, 
1.565, 0.992, 0.776, 0.959, 0.982, 0.807, 0.912, 0.925, 1.125, 
1.128, 0.983, 0.959, 0.901, 0.674, 1.152, 0.822, 0.82, 1.029, 
0.973, 0.777, 0.611, 0.555, 0.478, 0.431, 0.343, 0.469, 0.603, 
0.571, 0.69, 0.849, 0.61, 0.481, 0.459, 0.359, 0.2, 0.247, 0.25, 
0.254, 0.243, 0.219, 7.228, 7.263, 7.462, 7.253, 6.814, 6.363, 
6.106, 5.866, 5.151, 5.7, 5.856, 6.255, 6.078, 5.87, 5.432, 4.958, 
4.742, 4.35, 4.956, 5.478, 5.171, 4.668, 4.427, 4.446, 4.256, 
4.707, 4.41, 4.491, 4.247, 4.251, 4.36, 4.62, 4.65, 4.509, 5.069, 
5.662, 6.177, 6.395, 6.59, 6.145, 6.608, 7.099, 7.296, 7.835, 
8.005, 7.558, 7.052, 7.082, 6.864, 6.031, 5.982, 6.126, 6.072, 
6.042, 5.805, 5.497, 5.314, 5.136, 5.663, 6.025, 6.329, 6.553, 
6.415, 6.515, 6.668, 6.414, 6.01, 5.784, 6.147, 6.176, 6.35, 
6.72, 6.553, 6.479, 6.365, 5.895, 6.209, 5.956, 5.788, 5.91, 
5.759, 5.411, 5.625, 5.674, 5.696, 5.611, 5.57, 5.544, 4.788, 
4.299, 4.207, 4.551, 4.589, 4.62, 5.245, 5.103, 5.19, 5.564, 
5.653, 5.784, 5.872, 5.749, 5.947, 6.154, 6.39, 6.752, 6.671, 
6.526, 6.745, 6.741, 6.407, 6.339, 6.184, 6.017, 5.954, 5.62, 
5.114, 4.703, 4.545, 4.382, 4.588, 4.508, 4.563, 4.12, 3.965, 
3.26, 2.879, 3.31, 3.534, 3.66, 3.54, 4.209, 3.76, 3.654, 3.314, 
2.71, 2.53, 2.012, 2.076, 2.503, 2.021, 2.167, 1.923, 1.935, 
1.962, 1.596, 1.663, 2.31, 2.552, 1.949, 2.375, 2.605, 2.397, 
2.353, 2.152, 2.012, 2.898, 3.138, 3.169, 3.124, 2.78, 2.924, 
2.848, 3.308, 3.284, 3.472, 3.822, 3.992, 3.773, 3.674, 3.685, 
4.125, 3.864, 4.224, 4.462, 4.447, 4.413, 4.533, 4.711, 4.881, 
4.937, 5.099, 5.19, 4.975, 4.756, 4.664, 4.658, 4.549, 4.782, 
4.901, 4.609, 4.581, 4.573, 4.929, 4.95, 4.56, 4.208, 4.103, 
4.011, 3.158, 3.211, 2.341, 1.923, 1.889, 2.54, 2.943, 2.892, 
2.787, 2.642, 2.331, 1.995, 1.285, 0.993, 1.361, 1.398, 1.147, 
1.391, 1.44, 1.663, 1.631, 1.51, 1.463, 1.431, 1.134, 1.725, 
1.387, 1.366, 1.617, 1.525, 1.271, 0.993, 0.849, 0.719, 0.659, 
0.514, 0.733, 1.022, 1.002, 1.198, 1.355, 1.024, 0.818, 0.823, 
0.557, 0.334, 0.417, 0.413, 0.403, 0.367, 0.307, 7.542, 7.614, 
7.805, 7.516, 7.105, 6.665, 6.436, 6.215, 5.53, 6.072, 6.199, 
6.58, 6.441, 6.225, 5.841, 5.351, 5.258, 4.935, 5.531, 5.969, 
5.693, 5.203, 4.897, 4.925, 4.765, 5.121, 4.804, 4.894, 4.585, 
4.575, 4.666, 4.961, 5.004, 4.834, 5.406, 6.041, 6.51, 6.681, 
6.877, 6.548, 6.804, 7.298, 7.506, 7.925, 8.013, 7.627, 7.132, 
7.164, 6.951, 6.102, 6.033, 6.201, 6.134, 6.093, 5.859, 5.56, 
5.397, 5.231, 5.757, 6.125, 6.442, 6.667, 6.508, 6.612, 6.776, 
6.509, 6.103, 5.862, 6.243, 6.277, 6.436, 6.812, 6.633, 6.559, 
6.441, 5.95, 6.277, 6.027, 5.818, 5.922, 5.78, 5.435, 5.656, 
5.69, 5.722, 5.621, 5.557, 5.565, 4.825, 4.277, 4.249, 4.542, 
4.592, 4.609, 5.273, 5.144, 5.25, 5.624, 5.702, 5.847, 5.922, 
5.806, 6.007, 6.188, 6.427, 6.785, 6.698, 6.453, 6.68, 6.679, 
6.335, 6.28, 6.105, 5.962, 5.908, 5.552, 5.069, 4.779, 4.651, 
4.536, 4.848, 4.773, 4.83, 4.401, 4.263, 3.647, 3.318, 3.751, 
4.01, 4.126, 3.986, 4.659, 4.26, 4.073, 3.754, 3.17, 2.919, 2.329, 
2.472, 2.934, 2.433, 2.634, 2.328, 2.38, 2.434, 1.972, 2.087, 
2.867, 3.066, 2.431, 2.862, 3.03, 2.875, 2.796, 2.587, 2.436, 
3.317, 3.523, 3.521, 3.459, 3.085, 3.186, 3.1, 3.54, 3.482, 3.616, 
3.953, 4.117, 3.864, 3.73, 3.713, 4.15, 3.884, 4.232, 4.481, 
4.456, 4.406, 4.517, 4.681, 4.876, 4.957, 5.099, 5.174, 4.966, 
4.749, 4.646, 4.634, 4.518, 4.763, 4.878, 4.587, 4.586, 4.567, 
4.921, 4.97, 4.589, 4.253, 4.208, 4.12, 3.297, 3.349, 2.573, 
2.221, 2.184, 2.803, 3.218, 3.14, 3.041, 2.895, 2.686, 2.432, 
1.615, 1.283, 1.637, 1.709, 1.414, 1.72, 1.916, 2.141, 2.104, 
1.976, 1.914, 1.896, 1.588, 2.237, 1.882, 1.86, 2.112, 2, 1.704, 
1.4, 1.236, 1.035, 0.977, 0.848, 1.117, 1.537, 1.498, 1.692, 
1.844, 1.516, 1.278, 1.309, 0.965, 0.652, 0.69, 0.706, 0.679, 
0.603, 0.513, 7.868, 7.98, 8.163, 7.791, 7.407, 6.978, 6.778, 
6.578, 5.92, 6.458, 6.556, 6.918, 6.82, 6.594, 6.264, 5.756, 
5.792, 5.54, 6.127, 6.479, 6.234, 5.757, 5.382, 5.419, 5.29, 
5.548, 5.21, 5.309, 4.931, 4.907, 4.98, 5.312, 5.368, 5.168, 
5.753, 6.433, 6.856, 6.977, 7.176, 6.966, 7.009, 7.507, 7.727, 
8.023, 8.026, 7.702, 7.217, 7.25, 7.043, 6.175, 6.086, 6.279, 
6.198, 6.144, 5.915, 5.624, 5.482, 5.328, 5.855, 6.225, 6.557, 
6.784, 6.605, 6.713, 6.89, 6.608, 6.201, 5.943, 6.344, 6.381, 
6.526, 6.908, 6.718, 6.643, 6.521, 6.007, 6.348, 6.102, 5.849, 
5.937, 5.802, 5.46, 5.685, 5.706, 5.747, 5.631, 5.545, 5.584, 
4.861, 4.264, 4.301, 4.535, 4.598, 4.606, 5.302, 5.185, 5.305, 
5.684, 5.75, 5.904, 5.972, 5.862, 6.059, 6.223, 6.464, 6.811, 
6.706, 6.381, 6.611, 6.617, 6.267, 6.228, 6.033, 5.924, 5.877, 
5.486, 5.032, 4.856, 4.742, 4.662, 5.033, 5.037, 5.081, 4.653, 
4.504, 3.953, 3.628, 4.19, 4.457, 4.534, 4.35, 4.993, 4.599, 
4.492, 4.171, 3.588, 3.307, 2.638, 2.842, 3.365, 2.829, 3.055, 
2.733, 2.807, 2.865, 2.347, 2.495, 3.372, 3.582, 2.914, 3.348, 
3.457, 3.353, 3.24, 3.025, 2.859, 3.736, 3.907, 3.873, 3.795, 
3.389, 3.448, 3.353, 3.773, 3.68, 3.761, 4.084, 4.241, 3.955, 
3.787, 3.743, 4.176, 3.905, 4.241, 4.5, 4.466, 4.399, 4.502, 
4.65, 4.872, 4.978, 5.099, 5.157, 4.956, 4.742, 4.627, 4.608, 
4.486, 4.744, 4.854, 4.565, 4.59, 4.559, 4.913, 4.989, 4.618, 
4.299, 4.314, 4.23, 3.437, 3.489, 2.808, 2.522, 2.483, 3.07, 
3.497, 3.393, 3.3, 3.153, 3.048, 2.878, 1.951, 1.577, 1.917, 
2.024, 1.685, 2.054, 2.402, 2.628, 2.585, 2.451, 2.374, 2.371, 
2.051, 2.761, 2.387, 2.365, 2.619, 2.485, 2.145, 1.814, 1.63, 
1.356, 1.299, 1.186, 1.507, 2.061, 2.003, 2.196, 2.343, 2.017, 
1.746, 1.803, 1.379, 0.974, 0.965, 1.003, 0.957, 0.841, 0.72, 
8.222, 8.249, 8.439, 8.366, 8.016, 7.583, 7.493, 7.318, 6.684, 
7.269, 7.284, 7.59, 7.619, 7.348, 7.098, 6.603, 6.46, 6.234, 
6.671, 6.915, 6.727, 6.243, 5.901, 5.961, 5.851, 6.043, 5.663, 
5.69, 5.258, 5.18, 5.244, 5.623, 5.646, 5.473, 5.999, 6.665, 
7.041, 7.145, 7.341, 7.133, 7.174, 7.651, 7.875, 8.058, 8.011, 
7.725, 7.284, 7.301, 7.125, 6.281, 6.197, 6.409, 6.294, 6.218, 
6.018, 5.726, 5.568, 5.49, 6.025, 6.333, 6.679, 6.884, 6.721, 
6.817, 6.988, 6.723, 6.322, 6.041, 6.441, 6.5, 6.598, 6.974, 
6.783, 6.712, 6.571, 6.059, 6.398, 6.153, 5.885, 5.951, 5.816, 
5.525, 5.695, 5.722, 5.752, 5.632, 5.534, 5.579, 4.949, 4.363, 
4.481, 4.643, 4.647, 4.654, 5.332, 5.251, 5.368, 5.697, 5.809, 
5.951, 6.018, 5.915, 6.092, 6.26, 6.51, 6.798, 6.616, 6.242, 
6.461, 6.493, 6.192, 6.172, 5.924, 5.904, 5.855, 5.511, 5.102, 
5.023, 4.844, 4.814, 5.224, 5.254, 5.296, 4.899, 4.691, 4.283, 
3.943, 4.506, 4.804, 4.839, 4.634, 5.237, 4.881, 4.81, 4.525, 
4.06, 3.711, 3.089, 3.353, 3.775, 3.3, 3.506, 3.181, 3.28, 3.34, 
2.815, 2.974, 3.895, 4.02, 3.408, 3.826, 3.886, 3.798, 3.688, 
3.476, 3.328, 4.137, 4.284, 4.239, 4.151, 3.744, 3.783, 3.69, 
4.063, 3.954, 3.958, 4.244, 4.382, 4.094, 3.895, 3.84, 4.247, 
3.974, 4.303, 4.551, 4.499, 4.419, 4.534, 4.63, 4.89, 5.046, 
5.14, 5.18, 4.998, 4.761, 4.652, 4.628, 4.496, 4.751, 4.86, 4.589, 
4.641, 4.615, 4.93, 5.038, 4.703, 4.43, 4.469, 4.371, 3.682, 
3.754, 3.187, 2.975, 2.916, 3.396, 3.777, 3.681, 3.625, 3.469, 
3.425, 3.404, 2.385, 1.862, 2.345, 2.781, 2.317, 2.794, 3.187, 
3.342, 3.273, 3.159, 3.054, 3.094, 2.796, 3.54, 3.194, 3.189, 
3.426, 3.246, 2.86, 2.502, 2.388, 1.978, 1.971, 1.954, 2.239, 
2.815, 2.836, 2.959, 3.058, 2.784, 2.492, 2.601, 2.172, 1.609, 
1.47, 1.63, 1.552, 1.378, 1.279, 8.258, 8.29, 8.476, 8.415, 8.063, 
7.649, 7.621, 7.479, 6.811, 7.422, 7.416, 7.719, 7.782, 7.473, 
7.253, 6.786, 6.645, 6.407, 6.856, 7.056, 6.838, 6.422, 6.038, 
6.084, 6.022, 6.193, 5.808, 5.838, 5.399, 5.324, 5.382, 5.788, 
5.794, 5.634, 6.13, 6.792, 7.142, 7.237, 7.432, 7.225, 7.263, 
7.73, 7.957, 8.079, 8.005, 7.739, 7.321, 7.329, 7.168, 6.336, 
6.255, 6.477, 6.345, 6.256, 6.072, 5.779, 5.613, 5.575, 6.114, 
6.39, 6.743, 6.937, 6.783, 6.872, 7.041, 6.784, 6.386, 6.093, 
6.493, 6.563, 6.636, 7.011, 6.819, 6.749, 6.599, 6.087, 6.425, 
6.18, 5.905, 5.96, 5.823, 5.558, 5.701, 5.73, 5.756, 5.633, 5.529, 
5.577, 4.993, 4.414, 4.573, 4.697, 4.672, 4.678, 5.348, 5.286, 
5.401, 5.704, 5.84, 5.977, 6.042, 5.944, 6.109, 6.279, 6.534, 
6.792, 6.571, 6.17, 6.385, 6.429, 6.153, 6.143, 5.868, 5.894, 
5.843, 5.523, 5.138, 5.11, 4.896, 4.894, 5.325, 5.369, 5.409, 
5.028, 4.789, 4.454, 4.106, 4.672, 4.987, 5, 4.784, 5.367, 5.031, 
4.978, 4.711, 4.306, 3.922, 3.321, 3.618, 3.989, 3.545, 3.74, 
3.412, 3.526, 3.587, 3.056, 3.222, 4.169, 4.25, 3.665, 4.076, 
4.11, 4.03, 3.922, 3.71, 3.571, 4.347, 4.482, 4.43, 4.336, 3.928, 
3.956, 3.865, 4.214, 4.096, 4.06, 4.327, 4.455, 4.165, 3.951, 
3.89, 4.284, 4.009, 4.335, 4.578, 4.516, 4.429, 4.549, 4.619, 
4.899, 5.08, 5.161, 5.191, 5.019, 4.77, 4.665, 4.638, 4.5, 4.754, 
4.863, 4.601, 4.667, 4.643, 4.939, 5.063, 4.747, 4.497, 4.549, 
4.444, 3.807, 3.891, 3.383, 3.209, 3.139, 3.565, 3.922, 3.83, 
3.793, 3.633, 3.621, 3.677, 2.608, 2.008, 2.565, 2.901, 2.474, 
2.961, 3.337, 3.464, 3.404, 3.292, 3.193, 3.257, 2.987, 3.714, 
3.406, 3.401, 3.64, 3.463, 3.06, 2.7, 2.627, 2.18, 2.199, 2.234, 
2.479, 3.045, 3.104, 3.181, 3.267, 3.029, 2.743, 2.856, 2.45, 
1.85, 1.649, 1.847, 1.75, 1.575, 1.494, 8.3, 8.336, 8.518, 8.47, 
8.117, 7.721, 7.759, 7.65, 6.947, 7.586, 7.557, 7.857, 7.957, 
7.608, 7.418, 6.979, 6.84, 6.589, 7.051, 7.205, 6.957, 6.61, 
6.183, 6.215, 6.203, 6.35, 5.96, 5.992, 5.545, 5.473, 5.526, 
5.959, 5.948, 5.801, 6.266, 6.924, 7.248, 7.334, 7.527, 7.322, 
7.357, 7.814, 8.043, 8.103, 8, 7.755, 7.36, 7.358, 7.214, 6.394, 
6.315, 6.547, 6.397, 6.295, 6.127, 5.833, 5.66, 5.662, 6.205, 
6.449, 6.81, 6.993, 6.846, 6.929, 7.096, 6.847, 6.452, 6.146, 
6.547, 6.629, 6.677, 7.049, 6.856, 6.788, 6.628, 6.116, 6.453, 
6.209, 5.925, 5.968, 5.831, 5.592, 5.706, 5.739, 5.759, 5.633, 
5.524, 5.575, 5.039, 4.465, 4.667, 4.753, 4.698, 4.703, 5.365, 
5.321, 5.435, 5.712, 5.872, 6.003, 6.068, 5.973, 6.128, 6.299, 
6.559, 6.786, 6.525, 6.097, 6.307, 6.364, 6.114, 6.114, 5.811, 
5.883, 5.83, 5.535, 5.173, 5.198, 4.951, 4.975, 5.428, 5.487, 
5.527, 5.162, 4.89, 4.631, 4.275, 4.844, 5.177, 5.167, 4.939, 
5.502, 5.185, 5.152, 4.903, 4.561, 4.138, 3.56, 3.891, 4.209, 
3.797, 3.981, 3.65, 3.779, 3.841, 3.304, 3.476, 4.452, 4.487, 
3.931, 4.334, 4.341, 4.269, 4.163, 3.952, 3.821, 4.564, 4.685, 
4.627, 4.527, 4.118, 4.134, 4.044, 4.368, 4.241, 4.164, 4.412, 
4.53, 4.238, 4.008, 3.941, 4.321, 4.045, 4.367, 4.604, 4.533, 
4.44, 4.565, 4.608, 4.908, 5.116, 5.183, 5.202, 5.04, 4.78, 4.678, 
4.648, 4.504, 4.757, 4.865, 4.613, 4.693, 4.671, 4.948, 5.088, 
4.792, 4.565, 4.631, 4.518, 3.936, 4.031, 3.583, 3.449, 3.368, 
3.737, 4.071, 3.983, 3.966, 3.8, 3.822, 3.96, 2.837, 2.157, 2.79, 
3.024, 2.635, 3.132, 3.49, 3.59, 3.538, 3.43, 3.337, 3.423, 3.182, 
3.894, 3.622, 3.617, 3.862, 3.687, 3.265, 2.903, 2.872, 2.387, 
2.433, 2.52, 2.725, 3.28, 3.379, 3.408, 3.482, 3.28, 3.001, 3.117, 
2.734, 2.096, 1.83, 2.069, 1.951, 1.776, 1.712, 8.336, 8.383, 
8.558, 8.517, 8.174, 7.79, 7.877, 7.825, 7.075, 7.725, 7.667, 
7.951, 8.059, 7.747, 7.574, 7.146, 7.038, 6.763, 7.22, 7.323, 
7.046, 6.732, 6.331, 6.34, 6.361, 6.478, 6.076, 6.095, 5.692, 
5.611, 5.649, 6.089, 6.055, 5.906, 6.404, 7.046, 7.338, 7.431, 
7.616, 7.404, 7.451, 7.891, 8.115, 8.127, 7.997, 7.769, 7.399, 
7.387, 7.255, 6.451, 6.372, 6.61, 6.449, 6.333, 6.175, 5.888, 
5.704, 5.738, 6.297, 6.506, 6.867, 7.048, 6.905, 6.986, 7.146, 
6.901, 6.518, 6.196, 6.593, 6.68, 6.718, 7.085, 6.89, 6.828, 
6.656, 6.143, 6.482, 6.237, 5.946, 5.978, 5.841, 5.618, 5.713, 
5.749, 5.765, 5.635, 5.521, 5.577, 5.076, 4.509, 4.732, 4.808, 
4.724, 4.728, 5.382, 5.352, 5.462, 5.721, 5.902, 6.027, 6.093, 
6.001, 6.144, 6.315, 6.575, 6.777, 6.48, 6.031, 6.241, 6.313, 
6.086, 6.091, 5.755, 5.874, 5.821, 5.546, 5.204, 5.255, 5.005, 
5.052, 5.518, 5.578, 5.607, 5.245, 4.991, 4.797, 4.418, 4.975, 
5.303, 5.265, 5.094, 5.627, 5.317, 5.287, 5.041, 4.721, 4.354, 
3.783, 4.126, 4.43, 4.03, 4.186, 3.889, 4.015, 4.06, 3.551, 3.713, 
4.694, 4.725, 4.177, 4.554, 4.574, 4.492, 4.369, 4.195, 4.055, 
4.751, 4.888, 4.809, 4.692, 4.306, 4.3, 4.2, 4.523, 4.376, 4.254, 
4.497, 4.599, 4.301, 4.064, 3.988, 4.354, 4.081, 4.398, 4.629, 
4.551, 4.45, 4.581, 4.597, 4.916, 5.145, 5.204, 5.213, 5.058, 
4.789, 4.69, 4.658, 4.509, 4.76, 4.869, 4.625, 4.718, 4.696, 
4.957, 5.112, 4.829, 4.632, 4.705, 4.581, 4.063, 4.159, 3.753, 
3.688, 3.58, 3.886, 4.218, 4.123, 4.112, 3.966, 4.004, 4.191, 
3.063, 2.291, 2.98, 3.147, 2.784, 3.281, 3.643, 3.709, 3.656, 
3.566, 3.469, 3.566, 3.376, 4.061, 3.808, 3.835, 4.067, 3.878, 
3.469, 3.09, 3.081, 2.591, 2.65, 2.768, 2.969, 3.498, 3.616, 
3.637, 3.683, 3.498, 3.257, 3.36, 2.98, 2.339, 1.999, 2.258, 
2.15, 1.961, 1.901, 8.419, 8.502, 8.653, 8.606, 8.302, 8.022, 
8.163, 8.198, 7.564, 8.015, 8.023, 8.217, 8.327, 8.093, 8.033, 
7.674, 7.591, 7.516, 7.822, 7.78, 7.545, 7.322, 6.961, 6.989, 
7.009, 7.07, 6.712, 6.619, 6.113, 6.039, 6.001, 6.39, 6.418, 
6.294, 6.764, 7.259, 7.493, 7.614, 7.808, 7.586, 7.622, 8.017, 
8.194, 8.183, 8.044, 7.854, 7.58, 7.566, 7.463, 6.719, 6.679, 
6.923, 6.715, 6.567, 6.393, 6.162, 5.971, 6.051, 6.544, 6.747, 
7.026, 7.13, 7.004, 7.103, 7.258, 7.046, 6.732, 6.409, 6.739, 
6.884, 6.895, 7.216, 7.06, 7.006, 6.867, 6.352, 6.68, 6.452, 
6.182, 6.107, 5.971, 5.822, 5.938, 5.957, 5.974, 5.825, 5.659, 
5.742, 5.249, 4.881, 5.091, 5.038, 5.031, 5.027, 5.582, 5.616, 
5.675, 5.869, 6.025, 6.167, 6.145, 6.117, 6.239, 6.382, 6.59, 
6.635, 6.289, 5.931, 6.084, 6.14, 6.002, 5.918, 5.738, 5.945, 
5.856, 5.651, 5.45, 5.511, 5.284, 5.402, 5.807, 5.801, 5.813, 
5.534, 5.344, 5.35, 4.816, 5.298, 5.532, 5.489, 5.437, 5.87, 
5.638, 5.655, 5.514, 5.278, 4.875, 4.515, 4.88, 4.996, 4.689, 
4.783, 4.568, 4.728, 4.7, 4.249, 4.446, 5.378, 5.259, 4.852, 
5.152, 5.153, 5.091, 4.969, 4.83, 4.747, 5.335, 5.414, 5.346, 
5.243, 4.935, 4.899, 4.791, 5.036, 4.85, 4.604, 4.761, 4.806, 
4.544, 4.334, 4.207, 4.508, 4.276, 4.601, 4.8, 4.733, 4.574, 
4.721, 4.571, 4.942, 5.211, 5.274, 5.244, 5.113, 4.895, 4.782, 
4.739, 4.583, 4.838, 4.941, 4.701, 4.848, 4.821, 5.04, 5.173, 
4.93, 4.815, 4.851, 4.747, 4.328, 4.414, 4.2, 4.223, 4.107, 4.333, 
4.622, 4.454, 4.49, 4.33, 4.271, 4.384, 3.342, 2.545, 3.427, 
3.542, 3.288, 3.821, 4.162, 4.179, 4.141, 4.021, 3.899, 4.061, 
3.967, 4.532, 4.341, 4.395, 4.591, 4.385, 4.01, 3.651, 3.723, 
3.201, 3.345, 3.604, 3.767, 4.12, 4.347, 4.286, 4.309, 4.169, 
3.956, 4.098, 3.782, 3.159, 2.567, 2.838, 2.714, 2.54, 2.554, 
8.637, 8.787, 8.898, 8.861, 8.627, 8.509, 8.787, 9.041, 8.534, 
8.667, 8.76, 8.79, 8.933, 8.793, 8.936, 8.659, 8.749, 9.083, 
9.068, 8.716, 8.515, 8.452, 8.154, 8.196, 8.223, 8.141, 7.801, 
7.48, 6.818, 6.735, 6.563, 6.9, 7.01, 6.908, 7.35, 7.643, 7.781, 
7.935, 8.142, 7.899, 7.965, 8.296, 8.403, 8.303, 8.123, 8, 7.889, 
7.86, 7.805, 7.126, 7.138, 7.4, 7.131, 6.918, 6.716, 6.557, 6.344, 
6.502, 6.949, 7.13, 7.291, 7.279, 7.175, 7.296, 7.46, 7.293, 
7.071, 6.737, 6.978, 7.211, 7.181, 7.436, 7.328, 7.284, 7.179, 
6.642, 6.983, 6.769, 6.513, 6.288, 6.148, 6.103, 6.239, 6.231, 
6.243, 6.062, 5.823, 5.942, 5.488, 5.38, 5.587, 5.351, 5.438, 
5.416, 5.856, 5.982, 5.97, 6.067, 6.198, 6.36, 6.229, 6.287, 
6.375, 6.48, 6.623, 6.463, 6.031, 5.775, 5.855, 5.897, 5.88, 
5.696, 5.694, 6.026, 5.892, 5.776, 5.757, 5.849, 5.676, 5.908, 
6.246, 6.148, 6.132, 5.956, 5.832, 6.143, 5.352, 5.753, 5.876, 
5.813, 5.902, 6.216, 6.069, 6.144, 6.122, 5.983, 5.5, 5.37, 5.782, 
5.656, 5.434, 5.447, 5.306, 5.505, 5.382, 4.961, 5.194, 6.116, 
5.815, 5.526, 5.748, 5.719, 5.664, 5.526, 5.408, 5.364, 5.858, 
5.877, 5.806, 5.702, 5.442, 5.37, 5.243, 5.423, 5.195, 4.847, 
4.941, 4.945, 4.701, 4.502, 4.339, 4.6, 4.388, 4.716, 4.895, 
4.831, 4.639, 4.794, 4.535, 4.976, 5.303, 5.367, 5.285, 5.182, 
5.018, 4.889, 4.83, 4.663, 4.922, 5.018, 4.796, 5.016, 4.978, 
5.143, 5.254, 5.06, 5.058, 5.052, 4.965, 4.67, 4.744, 4.771, 
5, 4.851, 4.953, 5.186, 4.905, 5.002, 4.83, 4.646, 4.688, 3.696, 
2.834, 3.971, 4.074, 3.948, 4.558, 4.914, 4.846, 4.817, 4.665, 
4.492, 4.751, 4.816, 5.236, 5.118, 5.243, 5.388, 5.126, 4.788, 
4.42, 4.611, 4.017, 4.287, 4.784, 4.926, 5.024, 5.441, 5.261, 
5.233, 5.143, 4.981, 5.186, 4.929, 4.291, 3.275, 3.572, 3.434, 
3.261, 3.366), class = c("xts", "zoo"), index = structure(c(672969600, 
675648000, 678240000, 680918400, 683596800, 686188800, 688867200, 
691459200, 694137600, 696816000, 699321600, 7.02e+08, 704592000, 
707270400, 709862400, 712540800, 715219200, 717811200, 720489600, 
723081600, 725760000, 728438400, 730857600, 733536000, 736128000, 
738806400, 741398400, 744076800, 746755200, 749347200, 752025600, 
754617600, 757296000, 759974400, 762393600, 765072000, 767664000, 
770342400, 772934400, 775612800, 778291200, 780883200, 783561600, 
786153600, 788832000, 791510400, 793929600, 796608000, 799200000, 
801878400, 804470400, 807148800, 809827200, 812419200, 815097600, 
817689600, 820368000, 823046400, 825552000, 828230400, 830822400, 
833500800, 836092800, 838771200, 841449600, 844041600, 846720000, 
849312000, 851990400, 854668800, 857088000, 859766400, 862358400, 
865036800, 867628800, 870307200, 872985600, 875577600, 878256000, 
880848000, 883526400, 886204800, 888624000, 891302400, 893894400, 
896572800, 899164800, 901843200, 904521600, 907113600, 909792000, 
912384000, 915062400, 917740800, 920160000, 922838400, 925430400, 
928108800, 930700800, 933379200, 936057600, 938649600, 941328000, 
943920000, 946598400, 949276800, 951782400, 954460800, 957052800, 
959731200, 962323200, 965001600, 967680000, 970272000, 972950400, 
975542400, 978220800, 980899200, 983318400, 985996800, 988588800, 
991267200, 993859200, 996537600, 999216000, 1001808000, 1004486400, 
1007078400, 1009756800, 1012435200, 1014854400, 1017532800, 1020124800, 
1022803200, 1025395200, 1028073600, 1030752000, 1033344000, 1036022400, 
1038614400, 1041292800, 1043971200, 1046390400, 1049068800, 1051660800, 
1054339200, 1056931200, 1059609600, 1062288000, 1064880000, 1067558400, 
1070150400, 1072828800, 1075507200, 1078012800, 1080691200, 1083283200, 
1085961600, 1088553600, 1091232000, 1093910400, 1096502400, 1099180800, 
1101772800, 1104451200, 1107129600, 1109548800, 1112227200, 1114819200, 
1117497600, 1120089600, 1122768000, 1125446400, 1128038400, 1130716800, 
1133308800, 1135987200, 1138665600, 1141084800, 1143763200, 1146355200, 
1149033600, 1151625600, 1154304000, 1156982400, 1159574400, 1162252800, 
1164844800, 1167523200, 1170201600, 1172620800, 1175299200, 1177891200, 
1180569600, 1183161600, 1185840000, 1188518400, 1191110400, 1193788800, 
1196380800, 1199059200, 1201737600, 1204243200, 1206921600, 1209513600, 
1212192000, 1214784000, 1217462400, 1220140800, 1222732800, 1225411200, 
1228003200, 1230681600, 1233360000, 1235779200, 1238457600, 1241049600, 
1243728000, 1246320000, 1248998400, 1251676800, 1254268800, 1256947200, 
1259539200, 1262217600, 1264896000, 1267315200, 1269993600, 1272585600, 
1275264000, 1277856000, 1280534400, 1283212800, 1285804800, 1288483200, 
1291075200, 1293753600, 1296432000, 1298851200, 1301529600, 1304121600, 
1306800000, 1309392000, 1312070400, 1314748800, 1317340800, 1320019200, 
1322611200, 1325289600, 1327968000), tzone = "UTC", tclass = "Date"), .Dim = c(250L, 
12L), .Dimnames = list(NULL, c("6m", "1y", "2y", "3y", "4y", 
"5y", "7y", "8y", "9y", "10y", "20y", "30y")))

I need to get the level slope and curvature. The error I'm getting:

Error in tcrossprod(y_temp, A_star) : non compatible arguments

Upvotes: 2

Views: 125

Answers (0)

Related Questions