maximize Sharpe ratio in portfolio optimization

I am trying to understand how to maximize Sharpe ratio in portfolio optimization.

\boxed{\begin{align}\max\>&\frac{r^Tx-r_f}{\sqrt{x^TQx}}\\ & \sum_i x_i = 1\\ & x_i\ge 0\end{align}}

In order to solve this problem using general QP solver, according to a post, we could transform the problem into the following:

\boxed{\begin{align}\min\>&y^TQy\\ & \sum_i (r_i-r_f) y_i = 1\\ & \sum_i y_i = \kappa\\ & Ay \sim \kappa b \\ & y_i,\kappa \ge 0\end{align}}

and retrieve optimal by $x^*_i := y^*_i / \kappa^*$.

I got lost with the math. How did it work?

• This question may be related quant.stackexchange.com/questions/39137/… and the Tutuncu reference mentioned therein (Tutuncu/Cournejols is also referenced in a footnote of the post you linked) Commented May 3, 2018 at 21:07
• There is a brief discussion on Pages 159-160 of the Cornuejols Tutuncu book, which is available online math.ku.dk/~rolf/CT_FinOpt.pdf Is that helpful? Commented May 5, 2018 at 1:06

Q is given. Q is a 11 by 11 matrix.

f = [0;0;0;0;0;0;0;0;0;0;0];
n = 10;
rf = 0.0082;
% Optimization problem data
lb = zeros(n+1,1);
ub = inf*ones(n+1,1);
Aeq = [( AvrReturn- rf)' 0;ones(1,n) -1];
beq = [1; 0];
A = [eye(n),-1*ones(n,1)];
b = zeros(n,1);
y = x4(1:n);
k = x4(n + 1);
x = x4/k;

• Nice code. In the call to quadprog, the first argument is H. Should that be Q? Isn't Q 10 by 10? (10 being the number of risky securities, i.e. the length of x and y, which in the program is called $n$). Commented Apr 14, 2020 at 21:36
• Also, should the last line be x = y/k; ? x4 is too big, length is (n+1). Commented Apr 14, 2020 at 21:42
• Yea it should be Q to align with the question above but in my working I used H. Q is 10 by 10 based the number of assets. I added a column of zeros and a row of zeros to it 11 by 11 matrix, in order for the program to run, otherwise it won't run. Commented Apr 16, 2020 at 14:47
• Yea noob2, is okay writing the last line as x = y/k. Commented Apr 16, 2020 at 14:54
• I will not upvote this answer without some fixes. It does not work as written. We need to show code that takes Q (10 by 10), assumed given, and creates an 11 by 11 matrix H that is used later. Otherwise no one knows where H in line 9 comes from. Commented May 15, 2020 at 7:28

A nice algorithmic solution is given by the master himself, W. F. Sharpe, in his paper "An Algorithm for Portfolio Improvement", October 1978, Graduate School of Business, Stanford University.

• The code is here web.stanford.edu/~wfsharpe/mat/gqp.txt the paper is here gsb.stanford.edu/faculty-research/working-papers/… Commented Sep 8, 2018 at 22:12
• The problem that Kalvelagen is addressing in his post and the problem that Sharpe solves are not the same. Sharpe finds a line with a given slope that is tangent to the efficient frontier. The problem in this post is to find, among all lines that go through the risk free point $(0,r_f)$ (and which of course all have different slopes) to find the one that is tangent to the efficient frontier. Sharpe does not have the risk free rate in his algorithm, while it is a key parameter in this problem. Commented Sep 8, 2018 at 22:58
The text passage discusses the mathematical formulation and optimization techniques for maximizing the Sharpe ratio in portfolio optimization. It includes a transformation of the original problem into a form that can be solved using a quadratic programming (QP) solver, along with some comments and references to additional resources.
single_question

the passage contains a single mathematical question about how the transformation of the sharpe ratio maximization problem works. however, no explicit answer to this question is provided within the text.
Given a text passage, determine:
    1. If it contains a mathematical question (including word problems or calculations)
    2. If an answer to that mathematical question is provided in the text

First, describe the content structure you found in 1-2 sentences.

Then provide your analysis in the following format:
TYPE: <one of the following values>
- NO_QUESTION
- SINGLE_QUESTION
- SINGLE_QUESTION_WITH_ANSWER
- MULTIPLE_QUESTIONS
- MULTIPLE_QUESTIONS_WITH_ANSWERS
system
maximize Sharpe ratio in portfolio optimization

I am trying to understand how to maximize Sharpe ratio in portfolio optimization.

\boxed{\begin{align}\max\>&\frac{r^Tx-r_f}{\sqrt{x^TQx}}\\ & \sum_i x_i = 1\\ & x_i\ge 0\end{align}}

In order to solve this problem using general QP solver, according to a post, we could transform the problem into the following:

\boxed{\begin{align}\min\>&y^TQy\\ & \sum_i (r_i-r_f) y_i = 1\\ & \sum_i y_i = \kappa\\ & Ay \sim \kappa b \\ & y_i,\kappa \ge 0\end{align}}

and retrieve optimal by $x^*_i := y^*_i / \kappa^*$.

I got lost with the math. How did it work?

• This question may be related quant.stackexchange.com/questions/39137/… and the Tutuncu reference mentioned therein (Tutuncu/Cournejols is also referenced in a footnote of the post you linked) Commented May 3, 2018 at 21:07
• There is a brief discussion on Pages 159-160 of the Cornuejols Tutuncu book, which is available online math.ku.dk/~rolf/CT_FinOpt.pdf Is that helpful? Commented May 5, 2018 at 1:06

Q is given. Q is a 11 by 11 matrix.

f = [0;0;0;0;0;0;0;0;0;0;0];
n = 10;
rf = 0.0082;
% Optimization problem data
lb = zeros(n+1,1);
ub = inf*ones(n+1,1);
Aeq = [( AvrReturn- rf)' 0;ones(1,n) -1];
beq = [1; 0];
A = [eye(n),-1*ones(n,1)];
b = zeros(n,1);
y = x4(1:n);
k = x4(n + 1);
x = x4/k;

• Nice code. In the call to quadprog, the first argument is H. Should that be Q? Isn't Q 10 by 10? (10 being the number of risky securities, i.e. the length of x and y, which in the program is called $n$). Commented Apr 14, 2020 at 21:36
• Also, should the last line be x = y/k; ? x4 is too big, length is (n+1). Commented Apr 14, 2020 at 21:42
• Yea it should be Q to align with the question above but in my working I used H. Q is 10 by 10 based the number of assets. I added a column of zeros and a row of zeros to it 11 by 11 matrix, in order for the program to run, otherwise it won't run. Commented Apr 16, 2020 at 14:47
• Yea noob2, is okay writing the last line as x = y/k. Commented Apr 16, 2020 at 14:54
• I will not upvote this answer without some fixes. It does not work as written. We need to show code that takes Q (10 by 10), assumed given, and creates an 11 by 11 matrix H that is used later. Otherwise no one knows where H in line 9 comes from. Commented May 15, 2020 at 7:28

A nice algorithmic solution is given by the master himself, W. F. Sharpe, in his paper "An Algorithm for Portfolio Improvement", October 1978, Graduate School of Business, Stanford University.

• The code is here web.stanford.edu/~wfsharpe/mat/gqp.txt the paper is here gsb.stanford.edu/faculty-research/working-papers/… Commented Sep 8, 2018 at 22:12
• The problem that Kalvelagen is addressing in his post and the problem that Sharpe solves are not the same. Sharpe finds a line with a given slope that is tangent to the efficient frontier. The problem in this post is to find, among all lines that go through the risk free point $(0,r_f)$ (and which of course all have different slopes) to find the one that is tangent to the efficient frontier. Sharpe does not have the risk free rate in his algorithm, while it is a key parameter in this problem. Commented Sep 8, 2018 at 22:58
user
The text passage discusses the mathematical formulation and optimization techniques for maximizing the Sharpe ratio in portfolio optimization. It includes a transformation of the original problem into a form that can be solved using a quadratic programming (QP) solver, along with some comments and references to additional resources.

TYPE: SINGLE_QUESTION

The passage contains a single mathematical question about how the transformation of the Sharpe ratio maximization problem works. However, no explicit answer to this question is provided within the text.