# Question:I am confused - LSSolve and QP

## Question:I am confused - LSSolve and QP

Maple

I am confused by the below results.

Why does LSSolve (given an arbitrary expected return) produce a higher risk
adjusted return than QPSolve which explicity is given an objective to maximize
risk adjusted returns? ie minimize Transpose(W).Cov.W-Transpose(W).ev
This to me seems very strange?!

Also, how do you specify in the objective function for LSSolve to maximize
risk adjusted returns? Now we have simply provide LSSolve with some user specified
arbitrary expected returns.

restart:
randomize():
with(ListTools):
with(LinearAlgebra):
with(ArrayTools):
with(Statistics):
with(plots):
with(Optimization):

nstock := 200:
nr := 50:
ER := 10:

W := Vector([seq(w[i], i = 1 .. nstock)]):
R := RandomMatrix(nr, nstock, outputoptions = [datatype = float[8]]):
Cov := CovarianceMatrix(R):
ev := Vector([seq(ExpectedValue(Column(R, i)), i = 1 .. nstock)], datatype = float[8]):
y := Vector(nr, fill = ER, datatype = float[8]):

s1 := Optimization[LSSolve](convert(R.W-y, list)):
s2 := Optimization[QPSolve](Transpose(W).Cov.W-Transpose(W).ev):

data1 := eval(R.W, s1[2]):
data2 := eval(R.W, s2[2]):

ExpectedValue(data1)/Variance(data1);
ExpectedValue(data2)/Variance(data2);

display({CumulativeSumChart(data1, color = red, legend = "LSSolve", markers = false, thickness = 3), CumulativeSumChart(data2, color = green, legend = "QPSolve", markers = false, thickness = 3)});

5.095080396 10^16
1.960000001

﻿