How to find tangency portfolio (maximize sharpe ratio) using quadprog

20 ビュー (過去 30 日間)
Guro Larsgaard
Guro Larsgaard 2019 年 3 月 15 日
回答済み: Alejandra Pena-Ordieres 2021 年 12 月 3 日
Hi,
We are performing a mean-var portfolio optimazation including serveral constraints. Using Mean-Variance Stochastic goal programming we have found the sub -optimal frontier accountin g for desierable weights in a subset of sustainable assets. Using the code below we were able to find the sub-optimal frontier changing the desired return level (r) . However, we now want to obtain the tangency portfolio as our selected optimal portfolio strategy, but we can´t figure out how. Given a risk free rate of 0.000412 does anyone know how we can find the tangency portfolio (i.e maximizing the sharp ratio) ?
Best regards ,
Agnethe and Guro
C = readtable('V strong.xlsx')
Covariance = table2array(C)
M = readtable('m.xlsx')
Mean_return = table2array(M)
M1 = readtable('h.xlsx')
Mean_return_h = table2array(M1)
nAsset = numel(Mean_return); r = 0.03
e_0 = 0.027900578
%Optimization Problem
portprob = optimproblem;
x = optimvar('x',nAsset,'LowerBound',0,'UpperBound',1);
objective = x'*Covariance*x;
portprob.Objective = objective;
sumcons = sum(x) == 1;
portprob.Constraints.sumcons = sumcons;
averagereturn = dot(Mean_return, x) >= r;
portprob.Constraints.averagereturn = averagereturn;
averagereturn2 = dot(Mean_return_h, x) >= e_0;
portprob.Constraints.averagereturn2 = averagereturn2;
%Run Optimization Problem
options = optimoptions('quadprog','Display','iter','TolFun',1e-10);
tic
[x1,fval1] = solve(portprob,'Options',options);
toc
C2 = readtable('V1.xlsx')
Covariance2 = table2array(C2) %Covariance Matrix All Assets
ReturnStrong = value'*Mean_return
VarStrong = value'*Covariance2*value
RiskStrong = sqrt(VarStrong)
  2 件のコメント
John D'Errico
John D'Errico 2019 年 3 月 15 日
編集済み: John D'Errico 2019 年 3 月 15 日
Note that just as you have learned to assign a field in a structure, you can access it too using the dot, without using getfield.
value = x1.x
John D'Errico
John D'Errico 2019 年 3 月 15 日
編集済み: John D'Errico 2019 年 3 月 15 日
Of course, now you just removed that line completely from your code. But now I note that the code you show never even assigns value, but you use it afterwards. If you just change your code randomly, nobody will ever be able to help you.

サインインしてコメントする。

採用された回答

Alejandra Pena-Ordieres
Alejandra Pena-Ordieres 2021 年 12 月 3 日
Hi Guro,
I understand that you are trying to find the maximum Sharpe ratio portfolio using quadprog. Theoretically, the max Sharpe ratio portfolio is a nonlinear nonconvex problem that cannot be solved using quadprog (quadprog only solves quadratic problems). The natural formulation of the max Sharpe ratio problem looks as follows:
That being said, there is way to rewrite the max Sharpe ratio problem as a quadratic convex optimization problem given some mild assumtpions. The quadratic version of the max Sharpe ratio problem looks like:
and the weights will be given by .
Thus, the solution to the max Sharpe ratio problem can be obtained with the following code:
% Excess returns
mu = muGross - riskFreeRate;
% Portfolio problem
prob = optimproblem('ObjectiveSense','minimize');
% Variables
% Surrogate portfolio weights
y = optimvar('y',nAssets,1);
% Auxiliary variable
tau = optimvar('tau',1,1,'LowerBound',0); % tau >= 0
% Objective
% min y'*Sigma*y
prob.Objective = y'*Sigma*y;
% Constraints
% Sum of means equal to 1
prob.Constraints.sigmaSumToOne = mu'*y == 1;
% Linear equality constraints
prob.Constraints.equalities = A*y == b*tau;
% Linear inequality constraints
prob.Constraints.inequalities = D*y <= d*tau;
% Solve problem
options = optimoptions('quadprog','Display','iter'); % Any other options
x = solve(prob,'options',options);
w = x.y/x.tau;
Notice that to add the risk-free rate, the mean μ should represent the vector of expected excess returns, i.e., the difference between the gross return and the risk-free rate.
An easier way to solve this problem is to use the Portfolio object in MATLAB:
% Create Portfolio object
p = Portfolio('AssetCovar',Sigma,'AssetMean',muGross);
p = setDefaultConstraints(p); % Long-only fully invested
% Set equalities -- Ax = b
p = setEquality(p,A,b);
% Set inequalities -- Dx <= d
p = setInequality(p,D,d);
% Set risk free rate
p.RiskFreeRate = riskFreeRate;
% Find max Sharpe Ratio portfolio
w2 = estimateMaxSharpeRatio(p);
Hope this helps.
Alejandra

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangePortfolio Optimization and Asset Allocation についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by