本文介绍了Python:使用CVXOPT进行二次编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用CVXOPT进行二次编程,以使用均值方差优化来计算组合的最佳权重. http://abel.ee.ucla中有一个很好的例子.edu/cvxopt/userguide/coneprog.html#quadratic-programming .但是,参数采用正则化形式(根据作者).该示例是基本版本.我希望在其中做一些更复杂的问题:

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

其中p是资产收益.

我不知道的内容(请参考 http://abel.ee.ucla.edu/cvxopt/examples/book/portfolio.html 和上面的优化问题):

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.我认为这些参数设置了约束,但我不确定:

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.我认为这是规范形式"的最小化问题的一部分,我不确定这意味着什么:

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.qp的参数是什么(solver.qp是二次优化器):

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 ]

看看文档,我很确定mu * S(第一个参数)是要最小化的目标函数,而-pbar是返回值.但是,这看起来像一个最大化问题(最大化负收益).

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.

推荐答案

我阅读了文档,并且我认为您必须将函数与以下参数一起使用.我假设x的大小为n:

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是从垂直堆叠的

 -a
 +I_n
 -I_n

其中,I_n是大小为n x n的单位矩阵.相应的右侧h

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

即:一个-gnWbnC1-Wb.

HTH.

这篇关于Python:使用CVXOPT进行二次编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 01:04