Python:使用 CVXOPT 进行二次规划
我正在使用 CVXOPT 进行二次规划,以使用均值方差优化来计算投资组合的最佳权重。 http://abel.ee.ucla 有一个很好的例子.edu/cvxopt/userguide/coneprog.html#quadratic-programming。然而,这些论点是正规化的形式(根据作者的说法)。该示例是一个基本版本。我正在寻求解决一些更复杂的问题,其中:
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
假设所有变量都已计算或已知。
文档中提供的基本示例:
min:
x'Sx
s.t.
p'x >= g
1'x = 1
其中 p 是资产回报。
我不知道什么(参考 http://abel. ee.ucla.edu/cvxopt/examples/book/portfolio.html 和上面的优化问题):
1.我认为这些参数设置了约束,但我不完全确定:
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.我相信这是这“调节形式”中的最小化问题,我不确定这是什么意思:
mus = [ 10**(5.0*t/N-1.0) for t in xrange(N) ]
3.qp 的参数是什么(solver.qp 是二次优化器):
xs = [ qp(mu*S, -pbar, G, h, A, b)['x'] for mu in mus ]
查看文档,我很确定 mu*S (第一个参数)是要最小化的目标函数,-pbar 是返回值。然而,这看起来像是一个最大化问题(最大化负回报)。
但我不知道如何使用其他参数。
鉴于我的最小化问题和上述约束,我正在寻求使用优化器的帮助。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我阅读了文档,我认为您必须使用带有以下参数的函数。我假设
x
的大小为n
:垂直堆叠。
G
从I_n
是大小<的单位矩阵 代码>nx n。对应的右侧h
为 即:1个
-g
、n
乘以Wb
和n
次C1-Wb
。HTH。
I read the docs and I think you have to use the function with the following parameters. I assume that
x
has sizen
:G
is vertically stacked fromwhere
I_n
is the identity matrix of sizen x n
. And the corresponding right hand sideh
isThat is: one
-g
,n
timesWb
andn
timesC1-Wb
.HTH.