Markowitz Whitepaper
Markowitz Whitepaper
Markowitz Whitepaper
1. Introduction
This article was hugely inspired by Ernie Chans work, so thanks Ernie for
providing us with so much insight.
If you are active in the algorithmic trading field you will have come across
Ernie Chans books1. He has a sizeable section dedicated to portfolio management
and describes how to use the Kelly formula to apply the optimum leverage in
order to maximise returns. This approach was first applied and popularised by
Thorpe2. Recently, Ernie has posted a very interesting piece of work on his blog3
which unifies the portfolio management approaches of Kelly and Markowitz and
his modern portfolio theory. This post is based on his work, please have a look at
his post now, before you read on.
Markowitz is generally regarded as a serious academic theory whereas Thorpe
was just a mathematically-minded Black-Jack player who also made a couple of
hundred millions on the stock market. The Kelly formula works on the assumption
that, with respect to your bankroll, there is an optimum fraction you can bet to
maximise your profits. However, both theories work on the (mostly inaccurate)
assumption that returns are normally distributed. In reality we often have fatter
tails, which means that we should at least reduce the amount of leverage that we
use. Even though we may maximise our profits with straight-Kelly, such a strategy
can also suffer from enormous drawdowns and anyone who experienced the darker
side of trading psychology knows what that means.
If you had a look at his post you may have realised that there is a lot of algebra
happening and some of you may want to know how they can use this in practical
terms. In this post I will walk you through his work and provide you with code
examples that illustrate the concepts. I hope you enjoy it and get a little more
enlightened in the process. In this post I used random data rather than actual
stock data, which will hopefully help you to get a sense of how to use modelling
and simulation to improve your understanding of the theoretical concepts. Dont
forget that the skill of an algo-trader is to put mathematical models into code and
this example is great practise.
As a final note I would like to point out that from my experience there are
a lot of people with IT experience reading these articles who do not always
have the in-depth mathematical background. For that reason I try not to jump
too many steps to increase the educational value. So lets start with importing a few modules, which we need later and produce a series of normally distributed returns. CVXOPT is a convex solver which you can easily download with
sudo pip install cvxopt.
1
http://epchan.blogspot.com.au
http://www.eecs.harvard.edu/cs286r/courses/fall12/papers/Thorpe_
KellyCriterion2007.pdf
3
http://epchan.blogspot.com.au/2014/08/kelly-vs-markowitz-portfolio.html
2
TOM STARKE
R = pT w
where R is the expected return, pT is the transpose of the vector for the mean
returns for each time series and w is the weight vector of the portfolio. p is a Nx1
column vector, so pT turns into a 1xN row vector which can be multiplied with the
Nx1 weight (column) vector w to give a scalar result. This is equivalent to the dot
product used in the code. Keep in mind that Python has a reversed definition of
rows and columns and the accurate Numpy version of the previous equation would
be R = matrix(w)*matrix(p).T
Next, we calculate the standard deviation with
(2)
= wT Cw
where C is the covariance matrix of the returns which is a NxN matrix. Please
note that if we simply calculated the simple standard deviation with the appropriate weighting using std(array(ret_vec).T*w) we would get a slightly different
bullet. This is because the simple standard deviation calculation would not take
covariances into account. In the covariance matrix, the values of the diagonal
represent the simple variances of each asset while the off-diagonals are the variances between the assets. By using ordinary std() we effectively only regard the
diagonal and miss the rest. A small but significant difference.
wT Cw
TOM STARKE
for w on the expected portfolio return RT w whilst keeping the sum of all the
weights equal to 1:
X
(4)
wi = 1
i
I will call . When I read this article I was intrigued and wanted to see this for
myself, which gave me the motivation for this article.
So lets start with calculating the optimal Kelly portfolio. This is very simply
done by the equation:
w = C 1 R
(5)
TOM STARKE
f (x) = ax2 + bx + c
f 0 (x) = 2ax + b
Since we know that our tangent goes through the origin, its equation will be
t(x) = xf 0 (x) which gives us
(8)
(2ax + b) = ax2 + bx + c
and after some algebra we can calculate the x-value for the intercept:
r
c
(10)
x=
a
(11)
m = 2 ca + b
Notice that the for the tangent we obtain 2 solutions and my code is written to
obtain the positive one. If you change the bias on the returns to negative you
will notice that the bullet will also shift towards the negative tangent and you can
calculate the solutions for this case.
p l o t ( x , ( 2 ( s q r t (m1 [ 0 ] m1 [ 2 ] ) )+m1 [ 1 ] ) x , k )
x1 = s q r t (m1 [ 2 ] / m1 [ 0 ] )
y1 = m1 [ 0 ] x1 2 + m1 [ 1 ] x1 + m1 [ 2 ]
p l o t ( [ x1 ] , [ y1 ] , ko , m a r k e r s i z e =10)
TOM STARKE
r e t u r n k/ f l o a t ( sum ( k ) )
## CONDITIONING
G = matrix ( 0 . 0 ,
G [ : : n+1] = 1.0
h = matrix ( 0 . 0 ,
A = matrix ( 1 . 0 ,
b = matrix ( 1 . 0 )
OPTIMIZER
(n , n) )
(n , 1 ) )
(1 ,n) )