问题
I'm using CVXOPT to do quadratic programming to compute the optimal weights of a potfolio using mean-variance optimization. There is a great example at http://abel.ee.ucla.edu/cvxopt/userguide/coneprog.html#quadratic-programming. However, the arguments are in a regularized form (according to the author). The example is a basic version. I am looking to do a bit of a more complex problem where:
min:
x'Sx
s.t.:
x'a >= g
x'1 = 0
x >= -Wb
x <= c1 - Wb
where:
x: active weights of assets (active weight = portfolio weight - benchmark weight)
S: covariance matrix of asset returns
a: expected stock excess returns
g: target gain
Wb: weights of assets in the benchmark
c: upper limit (weight) of any asset in the portfolio
Assume all the variables are computed or known.
The basic example presented in the documentation:
min:
x'Sx
s.t.
p'x >= g
1'x = 1
Where p are the asset returns.
What I do not know (referring to the code at http://abel.ee.ucla.edu/cvxopt/examples/book/portfolio.html and optimization problem above):
1.I think these arguments setup the constraints but I'm not entirely sure:
G = matrix(0.0, (n,n))
G[::n+1] = -1.0
h = matrix(0.0, (n,1))
A = matrix(1.0, (1,n))
b = matrix(1.0)
2.I believe this is part of the minimization problem in "regulated form", which I'm not sure what means:
mus = [ 10**(5.0*t/N-1.0) for t in xrange(N) ]
3.What the arguments to qp are (solver.qp is the quadratic optimizer):
xs = [ qp(mu*S, -pbar, G, h, A, b)['x'] for mu in mus ]
Looking at the documentation, I'm pretty sure that mu*S (the first argument) is the objective function to be minimzed and -pbar are the returns. This looks like a maximization problem however (maximizing negative returns).
I do not know, however how the other arguments are used.
I am looking for help using the optimizer given my minimization problem and constraints above.
回答1:
I read the docs and I think you have to use the function with the following parameters. I assume that x
has size n
:
P = S
q = (0,....0)
A = (1, ...... 1)
b = (0)
G
is vertically stacked from
-a
+I_n
-I_n
where I_n
is the identity matrix of size n x n
. And the corresponding right hand side h
is
-g
Wb
...
Wb
C1-Wb
...
C1-Wb
That is: one -g
, n
times Wb
and n
times C1-Wb
.
HTH.
来源:https://stackoverflow.com/questions/7572698/python-using-cvxopt-for-quadratic-programming