0

我正在使用差分进化方法对 Nelson Siegel 进行非线性估计。我从一个名为NMOF(Gilli et al.)的包中获得了这个功能,但是,书中的过程只显示了一个单一的观察(日期)。下面是代码

InitialBeta<-c(1, 2 , 0 , 1) ## Random Number
yM<-NS(InitialBeta,tm)

Data <- list(
  yM = yM,
  tm = tm,
  model = NS,
  min = c( 0, -15, -30, 0),
  max = c(15, 30, 30, 30),
  pen.w = 0.1
)

algo <- list(
  nP = 100L,
  nG = 1000L,
  F = 0.50,
  CR = 0.99,
  min = c( 0, -15, -30, 0),
  max = c(15, 30, 30, 30),
  pen = penalty, repair = NULL,
  loopOF = TRUE, loopPen = FALSE,
  loopRepair = FALSE,
  printDetail = TRUE,
  printBar = FALSE)

system.time(sol <- DEopt(OF = OF,
                         algo = algo,
                         Data = Data))`

现在我有 200 个观察值要运行,所以尝试了它apply,即使它有效,估计器也会产生很高的错误,以至于它是不可接受的。下面是我做的修改后的代码

yM<-apply(df,1,NS,tm) ## the df consists of the InitialBeta from different observations

Data <- list(
  yM = yM,
  tm = tm,
  model = NS,
  min = c( 0, -15, -30, 0),
  max = c(15, 30, 30, 30),
  pen.w = 0.1
)

algo <- list(
  nP = 100L,
  nG = 1000L,
  F = 0.50,
  CR = 0.99,
  min = c( 0, -15, -30, 0),
  max = c(15, 30, 30, 30),
  pen = penalty, repair = NULL,
  loopOF = TRUE, loopPen = FALSE,
  loopRepair = FALSE,
  printDetail = TRUE,
  printBar = FALSE)


x<-function(df){
  OF(df, Data = Data)
        DEopt(OF = OF,
              algo = algo,
              Data = Data)
         }


solution<-apply(df,1,x)

我有点困惑,因为从概念上看,它应该产生与原始输出相同的输出,我检查了DEoptand的功能,OF无论我运行它有多少观察,两者似乎都无关紧要。你能帮我找到问题的核心吗?非常感激。请对我放轻松,我还是这个领域的新手。

4

0 回答 0