Skip to content

Portfolio Optimization

September 11, 2013

Lets suppose you wish to invest your money in a number of companies (say 4). You’ve got a certain amount of money, but you’re not quite sure in what ratios you must invest.

For example, if you choose to invest a total amount of $100,000 in four different companies, namely, Apple (AAPL), Google (GOOG), IBM (IBM) and Microsoft (MSFT). Firstly, you must have a method to analyse historic data of these companies within a certain time period, lets say 1st January, 2011 to 31st December, 2011. You think of it as a long term investment. You purchase stocks, hold them for the entire year and sell them on the end date. Before you even think of trying to mathematically predict the portfolio performance, you need to train your Algorithms with computations on historic data.

We start with creating permutations of the various ratios that we can divide (0, 1) into. For simplicity, I chose 10% as the increment-decrement value. For each ratio allocation, we wish to calculate the daily_returns of your portfolio. With the daily_returns for the time period obtained, we then wish to calculate the overall cumulative_return. But we DO NOT take cumulative_return as our criteria for the optimized portfolio.

Now comes the part when we decide what allocation can be taken as the Optimized one. We denote a quantity that I’m going to describe now as ‘Sharpe ratio’. Sharpe ratio tell you how much returns can we obtain for a certain amount of risk that we take while investing. So, higher the sharpe_ratio, higher are the returns for a certain investment risk. Now how do we quantify risk? For simplicity (and a good approximation), we take it as the mathematical standard deviation of daily_returns. It is also sometimes called the volatility. Once we have the sharpe_ratios for all the combinations of allocations, we think of the Optimized portfolio as the one which outputs the maximum Sharpe ratio.

There shouldn’t be much difficulty in coding a solution for the above problem. Try playing around with the QSTK modules and try to get familiar with the variety of modules that numpy includes. Numpy and scipy along with matplotlib (for plotting) and pandas (for providing high performance data structures) is a very powerful tool.

You can find my code in my github repository for Computational-Finance here. Suggestions are invited and please contact me in case of issues regarding the same. In further edits, I’ll try putting together the analysis with a couple of plots.

Good night for now!

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: