Question: Maximize a Ratio with QPSolve

If I run the below code which finds the optimal portfolio weights given a portfolio
target return G then I get a nice solution:

restart:
with(Optimization):
with(LinearAlgebra):

n := 4:
C := 10000:
G := .1*C:

X := Vector[column]([seq(x[i], i = 1 .. n)]):
ER := Vector[column]([0.5e-1, -.20, .15, .30]):
Q := Matrix([[0.8e-1, -0.5e-1, -0.5e-1, -0.5e-1], [-0.5e-1, .16, -0.2e-1, -0.2e-1], [-0.5e-1, -0.2e-1, .35, 0.6e-1], [-0.5e-1, -0.2e-1, 0.6e-1, .35]]):

con1 := add(X[i], i = 1 .. n) <= C:
con2 := add(X[i]*ER[i], i = 1 .. n) >= G:
ob := expand(Transpose(X).Q.X):

"Long-Short Portfolio" = QPSolve(ob, {con1, con2});

                   
                          
"Long-Short Portfolio" = [1.90712222540269 10 , [x[1] = 1684.35296260636460,

  x[2] = -1563.61081474927824, x[3] = 682.505399568034591,

  x[4] = 1668.94792994873616]]




However, when I augment the code to maximize the risk adjusted expected portfolio return
then I get an error message. Why is that and how can I solve it?!

restart:
with(Optimization):
with(LinearAlgebra):

n := 4:
C := 10000:
G := .1*C:

X := Vector[column]([seq(x[i], i = 1 .. n)]):
ER := Vector[column]([0.5e-1, -.20, .15, .30]):
Q := Matrix([[0.8e-1, -0.5e-1, -0.5e-1, -0.5e-1], [-0.5e-1, .16, -0.2e-1, -0.2e-1], [-0.5e-1, -0.2e-1, .35, 0.6e-1], [-0.5e-1, -0.2e-1, 0.6e-1, .35]]):

con1 := add(X[i], i = 1 .. n) <= C:
ob := expand((Transpose(X).ER)/(Transpose(X).Q.X));

"Long-Short Portfolio" = QPSolve(ob, con1);

 

Error, (in Optimization:-QPSolve) objective function must be specified as a quadratic polynomial, Matrix, or list

Please Wait...