Hopefully this qualifies as Minimal, Reproducible Example and someone can help me out with this code.
library(optiSolve)
FTS <- c(8, 8, 10, 2, 5, 1, 3, 6)
Cov <- c(0.023801666, 0.023935526, 0.018494568, 0.012663140, 0.016676765, 0.028792692, 0.023068401, 0.024407815,
0.023935526, 0.024926042, 0.018528980, 0.013119386, 0.017192802, 0.028997799, 0.023407262, 0.025106585,
0.018494568, 0.018528980, 0.026670757, 0.015840553, 0.017851583, 0.023631761, 0.019703954, 0.020754188,
0.012663140, 0.013119386, 0.015840553, 0.013486637, 0.014444182, 0.017956016, 0.015204153, 0.016168328,
0.016676765, 0.017192802, 0.017851583, 0.014444182, 0.019917086, 0.024940618, 0.020290438, 0.021399794,
0.028792692, 0.028997799, 0.023631761, 0.017956016, 0.024940618, 0.052322481, 0.038991019, 0.039761303,
0.023068401, 0.023407262, 0.019703954, 0.015204153, 0.020290438, 0.038991019, 0.031687623, 0.032587550,
0.024407815, 0.025106585, 0.020754188, 0.016168328, 0.021399794, 0.039761303, 0.032587550, 0.035434308)
Cov<-matrix(Cov, ncol = 8)
FTS_Vector <- FTS
Cov_Matrix <- Cov
constraint1 <- quadcon(Q = Cov_Matrix, dir = "<=", val = 0.00002)
constraint2 <- lincon(t(rep(0,length(FTS_Vector))),
d=rep(0, nrow(t(FTS_Vector))),
dir=rep("==",nrow(t(FTS_Vector))),
val = rep(0, nrow(t(FTS_Vector))),
id=1:ncol(t(FTS_Vector)),
name = nrow(t(FTS_Vector)))
constraint_LB <- lbcon(rep(-0.025,length(FTS_Vector)))
constraint_UB <- ubcon(rep(0.025,length(FTS_Vector)))
func_linear <- linfun(FTS_Vector, name = "lin.fun")
funcion_obj <- cop(func_linear, max = T, ub = constraint_UB, lb = constraint_LB, lc = constraint2, qc = constraint1)
opt_func <- solvecop(funcion_obj, solver = "alabama")
opt_func$x
# x 0.024999999 0.005325077 0.025000000 -0.025000000 -0.002023949 -0.024246830 -0.025000000 0.025000000
s <- sum(opt_func$x)
# s 0.004054297
I think the code is working as intended with the exception of constraint2. This is attempting to add the constraint that sum of x = 0, by this is not what i am getting for my results (using some other data the sum of x is significantly different from 0).