Python CVXPY 最小化百分位变量投资组合优化

问题描述

我有一组投资组合回报:

public void onBindViewHolder(@NonNull final UserViewHolder holder,final int position) {
 if(position == Security.alert_position) {
            holder.state.setText("< Activated >");
            holder.state.setTextColor(Color.RED);
            holder.cards.setBackgroundColor(0x33FF0000);
        }
}

和一组对冲工具对数回报:

    total
Scenario    
20160608    -131,225.96
20160609    -3,526,055.32
20160610    -23,529,796.59
20160613    -21,268,638.69
20160614    -10,528,552.12
... ...
20210528    5,643,877.68
20210531    236,667.34
20210601    8,244,154.88
20210602    -2,213,117.88
20210603    4,807,859.21

我正在使用它来计算历史 VaR,给定投资组合中这些工具的特定权重:

        SPY US Equity   EEM US Equity   TLT US Equity   DXY Index   HYG US Equity
Scenario                    
20160608    0.00    0.01    0.01    -0.00   0.00
20160609    -0.00   -0.01   0.01    0.00    -0.00
20160610    -0.01   -0.03   0.00    0.01    -0.00
20160613    -0.01   -0.01   0.00    -0.00   -0.01
20160614    -0.00   -0.00   -0.00   0.01    -0.00
... ... ... ... ... ...
20210528    0.00    0.01    -0.00   0.00    -0.00
20210531    0.00    0.00    0.00    -0.00   0.00
20210601    -0.00   0.02    -0.00   0.00    -0.00
20210602    0.00    0.00    0.00    0.00    0.00
20210603    -0.00   -0.01   -0.00   0.01    -0.00

我正在尝试运行优化,以从对冲投资组合中选择最佳的工具权重,以生成 var 变量的最小值。

我尝试使用 CVXPY 来优化它,但是我收到了这个错误: NotImplementedError:不允许严格的不等式。

我相信这是因为 CVXPY 没有分位数函数

weights = np.array([-0.5,-0.5,0.5,-0.5])
var = np.quantile((hedge_returns*weights).sum(axis=1) + port_returns,confidence)

这里有什么替代方法的想法吗?

谢谢!

其他想法,对结果矩阵进行排序,并选择正确的间隔,但排序我正在努力。

n = 5
confidence = 0.05
weights = cp.Variable(n)

var = np.quantile(((hedge_returns*np.array(weights)).sum(axis=1) + port_returns),confidence)

obj = cp.Minimize(var)

prob = cp.Problem(objective=obj)

prob.solve()  # Returns the optimal value.
print("status:",prob.status)
print("optimal value",prob.value)
print("optimal var",x.value,y.value)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)