我正在研究一个问题,我需要在Matlab中使用IBM Cplex工具最大化Sharpe比率来找到重新平衡的投资组合。从我的想法,我已经添加了所有条件和约束,但当我尝试解决它时,我得到整数不可行。
以下是代码:
% mu and covariance matrix Q is given
% No of stocks
n = 20;
% Risk free rate
r = 0.045;
% Optimization problem data
lb = zeros(n,1);
ub = inf*ones(n,1);
A = [(mu' - r) 0; ones(1,n) -1];
lhs = [1;0];
rhs = [1;0];
b = 1;
% Define continuous and binary variables
variabtype = [char(ones([1 n])*('C')) char(ones([1 1])*('B'))];
% Compute minimum variance portfolio
cplex1 = Cplex('minYK');
% cplex1.Model.sense = 'minimize';
cplex1.addCols(zeros(n+1,1), [], [lb; 0], [ub; inf], variabtype);
cplex1.addRows(lhs, A, rhs);
cplex1.Param.qpmethod.Cur = 6; % concurrent algorithm
cplex1.Param.barrier.crossover.Cur = 1; % enable crossover
cplex1.Model.Q = [2*Q zeros(n,1)];
答案 0 :(得分:1)
夏普比率问题本身不是二次方程序,但是可以将其转换为二次方程序(Link Here)。然后按照以下步骤操作,确保均值收益的维数与您的程序一致(如果是行或列,则相应地对其进行摆放)。
Q=[Q;zeros(1,n)];
Q=[Q zeros(n+1,1)];
%% CPLEX Solution
% Initialize the CPLEX object
cplex3 = Cplex('max_Sharpe');
cplex3.Model.sense = 'minimize';
% Optimization problem data
lb = zeros(n+1,1);
ub = inf*ones(n+1,1);
%
A = [[( mu- r_rf/252) 0];[ones(1,n) -1]; [eye(n,n) -1*ones(n,1)]];
y = ones(n+1,1);
lhs = [1; 0; -inf*ones(n,1)];
rhs = [1; 0; zeros(n,1)];
y = ones(n+1,1);
% Add objective function and bounds on variables to CPLEX model
cplex3.addCols(zeros(n+1,1), [], lb, ub);
% Add constraints to CPLEX model
cplex3.addRows(lhs, A, rhs);
% Add quadratic part of objective function to CPLEX model
cplex3.Model.Q = 2*Q;
% Set CPLEX parameters
cplex3.Param.qpmethod.Cur = 6;
cplex3.Param.barrier.crossover.Cur = 1;% Concurrent algorithm
% Optimize the problem
cplex3.DisplayFunc = [];
cplex3.solve();
y = cplex3.Solution.x(1:n);
k = cplex3.Solution.x(n+1);
w_maxsharpe = y/k;