fork download
  1. # objective function
  2. eval_f0 <- function(x0, x1, x2, x3, x4, x5){
  3. x1 <- matrix(x0[1:nrow(trd)], ncol = 1)
  4. return( t(x1)%*%x1)
  5. }
  6. # constraint function
  7. eval_inque <- function(x0, x1, x2, x3, x4, x5) {
  8. x2 <- matrix(x0[nrow(trd)+1:nrow(trd)*2], ncol = 1)
  9. x3 <- matrix(x0[nrow(trd)*2+1:nrow(trd)*2+24], ncol = 1)
  10. x4 <- matrix(x0[nrow(trd)*2+25:nrow(trd)*3+25], ncol = 1)
  11. x5 <- matrix(x0[nrow(trd)*3+25:nrow(trd)*4+25], ncol = 1)
  12. return(rbind(c(-1*x2),
  13. c((trd%*%x3-x4%*%Price+x1)-x5),
  14. c(-1*x5),
  15. c(x2-1)))
  16. }
  17. # constraint function
  18. eval_que <- function(x0, x1, x2, x3, x4, x5) {
  19. x2 <- matrix(x0[nrow(trd)+1:nrow(trd)*2], ncol = 1)
  20. x3 <- matrix(x0[nrow(trd)*2+1:nrow(trd)*2+24], ncol = 1)
  21. x4 <- matrix(x0[nrow(trd)*2+25:nrow(trd)*3+25], ncol = 1)
  22. x5 <- matrix(x0[nrow(trd)*3+25:nrow(trd)*4+25], ncol = 1)
  23. return(rbind(c(x2-Market),
  24. c(t(x2%*%(x5-(trd%*%x3-x4%*%Price+x1)))),
  25. c(t(x5)%*%(1-x2))))
  26. }
  27.  
  28.  
  29. res1 <- nloptr( x0=rep(1, nrow(trd)*4+nrow(trd)),
  30. eval_f = eval_f0,
  31. eval_g_ineq = eval_inque,
  32. eval_g_eq = eval_que,
  33. lb = rep(0, nrow(trd)*4+nrow(trd)),
  34. ub = rep(Inf, nrow(trd)*4+nrow(trd)),
  35. opts = list("algorithm"="NLOPT_LD_SLSQP"),
  36. x1 = matrix(nrow(trd), ncol = 1),
  37. x2 = matrix(nrow(trd), ncol = 1),
  38. x3 = matrix(23, ncol = 1),
  39. x4 = matrix(nrow(trd), ncol = 1),
  40. x5 = matrix(nrow(trd), ncol = 1)
  41. )
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:1: error: illegal character: '#'
# objective function
^
Main.java:1: error: class, interface, or enum expected
# objective function
            ^
Main.java:6: error: illegal character: '#'
# constraint function
^
Main.java:17: error: illegal character: '#'
# constraint function
^
4 errors
stdout
Standard output is empty