[R-SIG-Finance] the package nmof

mmm ammm mmm@mmm1900 @end|ng |rom gm@||@com
Sat Jan 26 03:25:35 CET 2019


Dear all,
i'm hoping that one of you can help me in the following code that is
used for asset selection based on nmof package and please guide me
where is the mistake:

the error message is: "Error in colSums(x) : 'x' must be an array of
at least two dimensions".

The entire code is below (it works with DEopt) but does not with PSO;
it is for asset selection exaclty from the package nmof.

require("NMOF")
na<-31

nn<- read.table("n.txt") # n is the a 31*31 matrix.
Sigma <- data.matrix(nn)

OF2 <- function(x, data) {
#  res <- colSums (data$Sigma %*% x * x)
res <- colSums (Sigma %*% x * x)
#z<-c(x,x)
n <- colSums (x); res <- res / n^2
}
#######  pso  #############
data <- list(
na = na,
max = rep( 0.05, na),
min = rep(-0.05, na)
)
algo <- list(nP = 31L,
nG = 1000L,
c1 = 0.5,
c2 = 1.5,
#min = data$min, max = data$max,
max = rep( 0.05, na), min = rep(-0.05, na),
#repair = repair, pen = penalty,
iner = 0.7, initV = 1, maxV = 0.2
#printBar = FALSE, printDetail = TRUE
)
#x<-array(x, c(2,2))

system.time(sol <- PSopt(OF = OF2,algo = algo, data))



More information about the R-SIG-Finance mailing list