The Sharpe ratio:
​
Lets suppose you want to invest 100 dollars in two stocks A and B, with expected return rates of 0.1% and 0.15% respectively. Suppose that stocks A and B are uncorrelated. How should you distribute your 100 dollars in order to get the maximum payoff?
​
Answer: Assuming, there is no volatility (variance) in the stock value, this question is easy. Just invest all of your money in stock B.
​
Now suppose stock A and B have volatilities (variance) of 0.1 and 0.2, respectively? Stock B is more valuable but has higher volatility and thus is more of a risky investment. What do you do now? To answer this question, one metric we can use is "the Sharpe Ratio".
​
This metric wants to maximize the return while at the same time minimize the volatility (Risk). Let x be the percentage amount you invest in stock A, y be the percentage amount you invest in stock B. Clearly x+y=1 so that y=1-x. In this case the Sharpe ratio is given by:
Notice that this definition makes sense: You can increase the Sharpe ratio by increasing the expected profit or by decreasing the variance (Risk). Using this definition, the correct answer to this particular problem is invest 72.73 into stock A and 27.27 into stock B. The maximum Sharpe ratio in this case is 1.25. But how did I arrive at this answer?
​
Solution:
​
I essentially set up the problem for you above, just take the first derivative of the Sharpe ratio and set it to zero. You will get the critical value for x at which the Sharpe ratio is maximum. Now what if you invest in N stocks with nonzero Risk? The sharpe ratio will be defined by:
​
​
​
One can usually carry out the calculation for 2 stocks, with some effort. 3 stocks and beyond, the calculation becomes harder. Thus, we will use numerical simulations to help us analyze our portfolio.
Note on diversification:
​
Assuming you have a portfolio of n uncorrelated investments, as seen from the uncorrelated equation, the Sharpe ratio is of order O(1/√n). Thus, the more assets you have, the better you can manage your risk. Beware! This assumes little to no correlation! I will tell you how to compute correlation next.
​
​
Computing Return Rates, Volatility, Correlation:
​
​​
Usually Volatility and Correlation is straight forward to compute. The Return Rate depends on the individual investor. Are you interested in weekly, monthly, or yearly return rate? Depending on your choice, this could be different. I summarize the definitions below:
With all our definitions in place, let us generate a few hundred random portfolios (using 5 stocks: APPL,AMZN,FB,KO,GOOGL), i.e. choose random positive weights x_i summing up to 1 to see what we get:
The upper boundary of the figure is a hyperbolic curve. This is the location of efficient portfolios. There is a spot on the curve for which one can maximize the ratio of return vs risk. This location is the Sharpe Ratio. Lets see how one can arrive at this location using the Lagrange Multipliers method:
​
While this may seem complicated to implement, it is actually not so bad if you use Python (Tensorflow). Here is the description of the Algorithm:
​
Algorithm:
​
1) Set the weights x_i to randomly numbers chosen numbers and compute the Sharpe Ratio.
2) repeat step 1) for a few iterations and choose the values of x_i which best maximizes the Sharpe Ratio.
3) Using tensorflow with tf.Variable set to the x_i and initialized to the x_i found in part 2,
Minimize the negative of the Loss function (Note: To maximize the Loss function we can equivalently minimize its negative.)
​
Note: The x_i should be positive and sum to 1. There are several ways to implement the algorithm such that this constraint holds.
That answers our question to a certain extent. The code is provided at Github Ricard0000.
​
Final thoughts:​
​
-
This page presents a statistical way of Portfolio optimization. It is still very much up to the reader to determine through non-Statistical means weather or not he/she believes an investment will be good.
-
Volatility is not necessarily constant. In general, it could be a function of time.
-
How should we define the Sharpe Ratio for time dependent variance? Should we define a Sharpe Ratio as a function of time? Should we just average the variance over some time interval? This depends on the individuals personal preference.
​
​
​
Future Endeavor:​
-
It would be nice to incorporate time dependent risk into the Sharpe ratio.
-
We should update this in time i.e. have a running Sharpe ratio.
-
It would also be nice to have a good way to model variance as a time-series and a way to determine if one stock is correlated with another. Then we can combine this information with our Sharpe ratio.
-
It would be nice to look at the entire S & P 500.