2

可重现的代码:

#install.packages('DEoptim')
#install.packages('forecast')
#install.packages('quantmod')

require(compiler)
require(DEoptim)
require(forecast)
require(quantmod)

Symbols <- 'DGS10'
getSymbols(Symbols, src = 'FRED', from = '1950-01-01')

fn <- cmpfun(function(n){
  x <- tail(DGS10, n)
  bic <- auto.arima(x = x, max.p = 20, max.q = 20, ic = 'bic', d = 0)$bic
  return(bic)
})

DEoptim(fn = fn, lower = 100, upper = nrow(DGS10), 
        control = DEoptim.control(strategy = 6, itermax = 500))

最后一个命令返回

Error in DEoptim(fn = fn, lower = c(100), upper = c(nrow(DGS10)), control = DEoptim.control(strategy = 6,  : 
  REAL() can only be applied to a 'numeric', not a 'integer'

虽然fn函数的输出是

[1] "numeric"          "vector"           "index_timeSeries"

在我看来这适合DEoptim算法。

我的R会话:

R version 3.0.1 (2013-05-16)
Platform: i386-w64-mingw32/i386 (32-bit)

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] compiler  stats     graphics  grDevices datasets  utils     methods   base     

other attached packages:
 [1] DEoptim_2.2-2       forecast_4.06       quantmod_0.4-0      TTR_0.22-0         
 [5] xts_0.9-4           zoo_1.7-10          Defaults_1.1-1      KFAS_0.9.11        
 [9] latticeExtra_0.6-24 lattice_0.20-15     RColorBrewer_1.0-5  rcom_3.1-2         
[13] rscproxy_2.0-5     

loaded via a namespace (and not attached):
 [1] colorspace_1.2-2   fracdiff_1.4-2     grid_3.0.1         nnet_7.3-6        
 [5] parallel_3.0.1     quadprog_1.5-5     timeDate_3010.98   timeSeries_3010.97
 [9] tools_3.0.1        tseries_0.10-32   
4

0 回答 0