I would like to find the optimal weighting for the 10 stocks, but he always only invests in the ones with the highest return. I want every share to be included. Thank you in advance for the help.
# Load LP
require(lpSolve)
#No short sales!!!! #100% investment
# Coefficient vector of the objective function
C = c(-4.77, -0.87, -7.99, 0.9, -4.71, -4.04, -11.22, 7.56, 5.75, -4.64)
#Matrix with restrictions
A = matrix (c(1,-4.77, 1,-0.87, 1,-7.99, 1,0.9, 1,-4.71,
1,-4.04, 1,-11.22, 1,7.56, 1,5.75, 1, -4.64)
,nrow=2)
# Vector with maximum values for the restriction
B = cbind(1,-2.4)
# Specifying the restriction sign
ConstraintDirection = c("=",">=")
# Solution
Solution = lp(direction="max",
objective.in = C,
const.mat = A,
const.dir = ConstraintDirection,
const.rhs = B,
int.vec = 1:20 ,
compute.sens=TRUE)