Problem with xts object

3

Package 'YieldCurve'

Personal, I'm using this package and I'm having a problem.

MatrizCurva<-MatrizUmaLinha20colunas[1,1:20]
[1] 0.1164000 0.1264816 0.1265631 0.1366446 0.1467260 0.1568073 0.1668885 0.179694  
[9] 0.1770501 0.1771306 0.1772109 0.1772908 0.1773703 0.1774496 0.1775284 0.1076068
[17] 0.1776847 0.1777621 0.1778391 0.17079155

> class(MatrizEttjDiaria[1,1:20])
[1] "numeric"

maturityBOND <- seq(1,20,1)
maturityBOND

[1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20

The first function that is to return betas and lambda is ok:

NSParameters <- Nelson.Siegel( MatrizCurva, maturityBOND)

NSParameters
   beta_0       beta_1       beta_2     lambda
[1,] 0.111046 -0.004705511 -0.003196441 0.08965621

It returns right. In the pdf it says MatrixCurva must be an xts type object. In my case MatrixCurve is a numeric object:

class(MatrizCurva )
[1] "numeric"

But it still does.

Now, when I call the NSrates function it has the following problem:

> NSParameters <- NSrates(NSParameters[1,],maturityBOND)
Error in matrix(0, nrow(Coeff), length(maturity)) : 
  non-numeric matrix extent

Should I turn to xts?

Actually, I've been trying to transforms into xts and the thing does not come out.

    
asked by anonymous 26.07.2015 / 02:17

1 answer

1

Just convert your data to a xts object. For this, you need to select a order.by argument that must be a date. I've put the current date, but you should use something that makes sense in your analysis.

library("YieldCurve")

MatrizCurva <- c(0.1164000, 0.1264816, 0.1265631, 0.1366446, 0.1467260, 0.1568073, 0.1668885, 0.179694,  
0.1770501, 0.1771306, 0.1772109, 0.1772908, 0.1773703, 0.1774496, 0.1775284, 0.1076068,
0.1776847, 0.1777621, 0.1778391, 0.17079155)

maturityBOND <- 1:20    

NSParameters <- Nelson.Siegel(MatrizCurva, maturityBOND)

nspar <- xts(NSParameters, Sys.Date())

nsrate <- NSrates(nspar, maturityBOND)

Final result:

> nsrate
                  X1        X2        X3        X4        X5        X6        X7
2015-07-26 0.1095283 0.1238727 0.1356903 0.1453332 0.1531076 0.1592796 0.1640806
                  X8        X9       X10       X11       X12       X13       X14
2015-07-26 0.1677111 0.1703454 0.1721342 0.1732082 0.1736803 0.1736481 0.1731957
                 X15       X16       X17       X18       X19       X20
2015-07-26 0.1723957 0.1713102 0.1699929 0.1684897 0.1668397 0.1650763
    
26.07.2015 / 05:20