Excel BERT R package "Yield Curve" Nelson Siegel estimation : Error in matrix(0, nrow(Coeff), length(maturity)) : non-numeric matrix extent

I am using Basic Excel R Toolkit (BERT) to code R functions for Excel, and I want to use the Nelson Siegel estimation function "NSrates" which is under the R package "Yield Curve".

For that, I have written an R function in BERT, with the goal of calling it in Excel and feeding it with Excel Range inputs directly.

The steps I've performed so far:

1. I have installed the BERT extension on my computer from https://bert-toolkit.com/

2. I have installed all the required packages for the following code to work:

This is the code I wrote in BERT:

NelsonSiegel_current <- function(matCurrent, matRangeCurrent, rateRangeCurrent) {
  
  library("YieldCurve")

  NSParameters <- Nelson.Siegel(rate = rateRangeCurrent, maturity = matRangeCurrent)
  print(NSParameters)

  NSrateCurrent <- NSrates(NSParameters[1,],matCurrent)
 
  return(NSrateCurrent)

  }

2. I tried to call the function in Excel just as in the image below (the input ranges are also visible in the picture):

Calling the function in Excel

3. I received a !VALUE error in Excel just as in the image below:

Function error in Excel

4. I looked for the error in BERT compiler :

BERT NSrates error

I think the problem is within the NSrates function, as I am feeding it with Excel Ranges, but I have no idea of which format I should convert the ranges to in order for this to work.

I tried to convert the Excel ranges into R vectors using as.vector(t(MY_RANGE)) but the "NSrates" function still gave me the same error. I am expecting that the "NSrates" function should give a numeric value as an output in Excel.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.