0

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)
  • A standard approach is to add a risk term to the model. (Search for Mean-Variance Portfolio Optimization). This makes the model quadratic, so LpSolve is not a suitable solver/ – Erwin Kalvelagen Aug 19 '20 at 08:46
  • Thanks for the answer. Unfortunately I have to solve it with linear optimization. Maybe someone has an idea how the solver would invest evenly, i.e. not leave out any stocks? – user14016089 Aug 20 '20 at 07:59
  • Without a risk term, an LP will always pick just the most rewarding instruments. You can add all kinds of constraints to prevent this such as no instrument more than so many percent, sector constraints etc. The standard approach, however, is to use risk to formalize an incentive for diversification. Portfolio models start out as QPs or related technologies. I assume this is homework, so you may want to check with your teacher. – Erwin Kalvelagen Aug 20 '20 at 16:20

0 Answers0