【问题标题】:Get an X(std) value of efficient frontier from a given Y(mean) value with cvxopt?使用 cvxopt 从给定的 Y(mean) 值获取有效边界的 X(std) 值?
【发布时间】:2021-08-29 14:35:50
【问题描述】:

我正在尝试使用 cvxopt (Python) 进行投资组合优化,我能够使用以下代码获得有效边界,但是,我无法指定 Y 值(均值或回报)并获得相应的 X 值(标准或风险),如果有人对此有所了解,如果您能分享,我将不胜感激:

def optimal_portfolio(returns_vec, cov_matrix):
    n = len(returns_vec)

    N = 1000
    mus = [10 ** (5 * t / N - 1.0) for t in range(N)]

    # Convert to cvxopt matrices
    S = opt.matrix(cov_matrix)

    pbar = opt.matrix(returns_vec)

    # Create constraint matrices
    G = -opt.matrix(np.eye(n))  # negative n x n identity matrix
    h = opt.matrix(0.0, (n, 1))
    A = opt.matrix(1.0, (1, n))
    b = opt.matrix(1.0)

    #solvers.options["feastol"] =1e-9
    # Calculate efficient frontier weights using quadratic programming
    portfolios = [solvers.qp(mu * S, -pbar, G, h, A, b)['x']
                  for mu in mus]
    ## CALCULATE RISKS AND RETURNS FOR FRONTIER
    returns = [blas.dot(pbar, x) for x in portfolios]
    risks = [np.sqrt(blas.dot(x, S * x)) for x in portfolios]
    ## CALCULATE THE 2ND DEGREE POLYNOMIAL OF THE FRONTIER CURVE
    m1 = np.polyfit(returns, risks, 2)
    x1 = np.sqrt(m1[2] / m1[0])
    # CALCULATE THE OPTIMAL PORTFOLIO
    wt = solvers.qp(opt.matrix(x1 * S), -pbar, G, h, A, b)['x']
    return np.asarray(wt), returns, risks
   
return_vec = [0.055355,
    0.010748,
    0.041505,
    0.074884,
    0.039795,
    0.065079
]

cov_matrix =[[ 0.005329, -0.000572, 0.003320, 0.006792, 0.001580, 0.005316],
[-0.000572, 0.000625, 0.000606, -0.000266, -0.000107, 0.000531],
[0.003320, 0.000606, 0.006610, 0.005421, 0.000990, 0.006852],
[0.006792, -0.000266, 0.005421, 0.011385, 0.002617, 0.009786],
[0.001580, -0.000107, 0.000990, 0.002617, 0.002226, 0.002360],
[0.005316, 0.000531, 0.006852, 0.009786, 0.002360, 0.011215]]

weights, returns, risks = optimal_portfolio(return_vec, cov_matrix)


fig = plt.figure()
plt.ylabel('Return')
plt.xlabel('Risk')
plt.plot(risks, returns, 'y-o')
print(weights)
plt.show()

我想找到给定回报值对应的风险值。

非常感谢!

【问题讨论】:

  • 如果我提供的答案是您想要的,请告诉我?

标签: python portfolio cvxopt quadratic-programming


【解决方案1】:

不确定我是否正确理解了您的问题,但如果您正在寻找给定回报的解决方案,那么您应该使用所需的最小回报作为约束

def optimal_portfolio(returns_vec, cov_matrix, Y):
h1 = opt.matrix(0.0, (n, 1))
h2 = np.matrix(-np.ones((1,1))*Y)
h = concatenate (h1,h2)

这最终将返回基于下限 Y 的最佳投资组合。然后您可以以相同的方式添加上限,以便您可以固定 Y 的值

【讨论】:

    猜你喜欢
    • 2018-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多