Python:使用 CVXOPT 进行二次规划

发布于 2024-12-06 19:12:29 字数 1531 浏览 2 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

花伊自在美 2024-12-13 19:12:29

我阅读了文档,我认为您必须使用带有以下参数的函数。我假设x的大小为n

P = S
q = (0,....0)

A = (1, ...... 1)
b = (0)

垂直堆叠。

 -a
 +I_n
 -I_n

GI_n是大小<的单位矩阵 代码>nx n。对应的右侧h为 即

  -g
  Wb
  ...
  Wb
  C1-Wb
  ...
  C1-Wb

:1个-gn乘以WbnC1-Wb

HTH。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文