12
Efficient Frontier [An Excel based Gadget] Version 2 [Includes Version 1 plus a whole lot more] Portfolio Selection using Modern Portfolio Theory Programmed by George Pruitt [[email protected]] Tech support @ George.p.pruitt@gmail or [email protected] The Markowitz mean-variance theory is considered classical asset allocation. The overall objective, of this theory, is to derive an optimal portfolio where risk and return are analyzed simultaneously. Harry Markowitz introduced the concepts in 1952 and was later awarded the Nobel Prize for his research. However, many people do believe the foundation of the theory is built upon sand. First off, Harry assumed returns strictly followed a Gaussian distribution and we know that is not the case. There are better probability distributions that can be used to describe returns. The Gaussian or Normal distribution is the one the graphs the very familiar Bell Curve. Second, Harry didn’t investigate what causes the underlying structure that created the return stream. Things change over time and since MPT relies extensively on estimates any form of distortion between reality and assumed estimates can cause the model to spawn conclusions that vary widely from reality. With that being said you may ask, “Why waste time on MPT and why not give me the good stuff?” Nobody has come up with a probability distribution that accurately reflects investment returns. So, assuming a Normal Distribution and basing trading decisions from history is not that far of a stretch. This is what we do when we develop a trading algorithm – we hope that history repeats itself. In the Markowitz mean-variance portfolio theory, one models the rate of returns on assets as random variables. The goal is to find the optimal weights of each component in the portfolio. In the context of the Markowitz theory, the best set of weights is one in which the portfolio achieves an acceptable expected rate of return with minimal volatility. Return variance poses as volatility in this theory. Here is a chart of 10,000 simulations using a portfolio of 20+ markets applied to a simple algorithm. The different simulations varied the weights of each component in the portfolio. The best portfolio generated the highest Sharpe Ratio. The Efficient Frontier is simply the left side border of the scatter plot. Any point on the curve creates an efficient portfolio. The portfolio that maximizes return

Efficient Frontier [An Excel based Gadget]files.constantcontact.com/b44b4df7001/0074e574-675... · Equity Curve: The optimal curve versus the original curve. Efficient Frontier Gadget

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Efficient Frontier [An Excel based Gadget]files.constantcontact.com/b44b4df7001/0074e574-675... · Equity Curve: The optimal curve versus the original curve. Efficient Frontier Gadget

Efficient Frontier [An Excel based Gadget] Version 2 [Includes Version 1 plus a whole lot more]

Portfolio Selection using Modern Portfolio Theory

Programmed by George Pruitt [[email protected]]

Tech support @ George.p.pruitt@gmail or [email protected]

The Markowitz mean-variance theory is considered classical asset allocation. The overall objective, of

this theory, is to derive an optimal portfolio where risk and return are analyzed simultaneously. Harry

Markowitz introduced the concepts in 1952 and was later awarded the Nobel Prize for his research.

However, many people do believe the foundation of the theory is built upon sand. First off, Harry

assumed returns strictly followed a Gaussian distribution and we know that is not the case. There are

better probability distributions that can be used to describe returns. The Gaussian or Normal

distribution is the one the graphs the very familiar Bell Curve. Second, Harry didn’t investigate what

causes the underlying structure that created the return stream. Things change over time and since MPT

relies extensively on estimates any form of distortion between reality and assumed estimates can cause

the model to spawn conclusions that vary widely from reality. With that being said you may ask, “Why

waste time on MPT and why not give me the good stuff?” Nobody has come up with a probability

distribution that accurately reflects investment returns. So, assuming a Normal Distribution and basing

trading decisions from history is not that far of a stretch. This is what we do when we develop a trading

algorithm – we hope that history repeats itself.

In the Markowitz mean-variance portfolio theory, one models the rate of returns on assets as random

variables. The goal is to find the optimal weights of each component in the portfolio. In the context of

the Markowitz theory, the best set of weights is one in which the portfolio achieves an acceptable

expected rate of return with minimal volatility. Return variance poses as volatility in this theory. Here is

a chart of 10,000 simulations using a portfolio of 20+ markets applied to a simple algorithm. The

different simulations

varied the weights of

each component in

the portfolio. The

best portfolio

generated the

highest Sharpe Ratio.

The Efficient Frontier

is simply the left side

border of the scatter

plot. Any point on

the curve creates an

efficient portfolio.

The portfolio that

maximizes return

Page 2: Efficient Frontier [An Excel based Gadget]files.constantcontact.com/b44b4df7001/0074e574-675... · Equity Curve: The optimal curve versus the original curve. Efficient Frontier Gadget

while minimizing risk generates the highest Sharpe Ratio. This ratio is very simple: average

return/square root(variance). MPT utilizes covariance (variance that moves in the same direction) to

help create a diversified portfolio. As you can guess treasury notes and bonds have a high level of

correlation. That is if you are analyzing them from a pure price perspective. The correlation of these

two instruments might be less if you examine their respective returns from their application to a trading

algorithm. Most of the time the raw correlation is well above 0.9. In the test, I carried out for this

manual, the algorithmic return for these two markets only demonstrated a 0.53 correlation. This is still

a little high, but you don’t need to categorically deny the trading of these two instruments

simultaneously.

The Efficient Frontier Gadget (EFG) only needs monthly returns (the more the better) to generate the

following reports.

Return Matrix:

Displays the monthly returns in one big table.

Correlation Matrix:

Displays the correlation of one market against another

Page 3: Efficient Frontier [An Excel based Gadget]files.constantcontact.com/b44b4df7001/0074e574-675... · Equity Curve: The optimal curve versus the original curve. Efficient Frontier Gadget

Covariance Matrix:

Displays the covariance of one market against another.

Volatility Array:

Displays mean return and volatility in $s.

Page 4: Efficient Frontier [An Excel based Gadget]files.constantcontact.com/b44b4df7001/0074e574-675... · Equity Curve: The optimal curve versus the original curve. Efficient Frontier Gadget

Equity Curve:

The optimal curve versus the original curve.

Efficient Frontier Gadget Interface Worksheet

From the OutPut tab you can choose the number of portfolio simulations and Max Contracts per

market. Another key input is the Investment size. This input determines the risk per market.

.

You should target somewhere between 4000 and 10000. These simulations vary the weighting and

creates 10000 different outcomes or portfolios. Once the simulation has completed the winning

portfolio is displayed along with its Sharpe Ratio, Portfolio Mean and Standard Deviation. The number

of contracts is calculated using the following formula:

Contracts = (Weight * Investment) / Risk

Page 5: Efficient Frontier [An Excel based Gadget]files.constantcontact.com/b44b4df7001/0074e574-675... · Equity Curve: The optimal curve versus the original curve. Efficient Frontier Gadget

Where Risk is defined as square root of variance or standard deviation. If contract size is less than 1

then none of that market is allocated. In some cases, the number of contracts can grow

disproportionally large – this happens often times with Euro Dollar. You can alleviate this problem by

adjusting the maximum number of contracts or trading a larger unit size in your algorithm. You could

use a unit of five Eurodollars and input those returns into the return matrix.

Version 2:

I have added another button to the OutPut tab.

This will allow you to optimize the portfolio without having to reload the data. Since we are dealing with

a random process, you might want to run the process multiple times to get the best component weights.

If you do run the process multiple times, I now store the results in the Efficient Frontier tab starting at

row 2.

Page 6: Efficient Frontier [An Excel based Gadget]files.constantcontact.com/b44b4df7001/0074e574-675... · Equity Curve: The optimal curve versus the original curve. Efficient Frontier Gadget

Multiple optimizations might be needed to get the portfolio you desire. I have also included another

worksheet labeled Paste Chartand Data Here. If you run multiple optimizations, it’s a good idea to keep

track of the individual equity curves and the portfolio weights and number of contracts that created the

equity curve. Here is an example of how I use this worksheet:

Just copy the chart and Paste Special as .png or jpg. I also copy the portfolio performance metrics along

with the weights and number of contracts per market and past beside the chart.

Also in the OutPut tab I provide the necessary information to run the Excel Solver to solve the weighting

scheme that provides the minimization of portfolio standard deviation. I have discovered larger

portfolios are either unsolvable or the solutions are “out in left field.” Hence the use of the random

number generator.

Page 7: Efficient Frontier [An Excel based Gadget]files.constantcontact.com/b44b4df7001/0074e574-675... · Equity Curve: The optimal curve versus the original curve. Efficient Frontier Gadget

The Efficient Frontier Gadget Data Format:

The format for the data is quite simple – all it needs is Monthly Date and Monthly Returns separated by

a comma in individual files. The date must be consistent for the entire database. In other words, if your

date has slashes that separate the month/day/year, then make sure your entire database follows this

nomenclature. Also your data should run from oldest month to newest month. If you are missing a few

months of data, that is OK. TradeStation doesn’t output a monthly return for those months that don’t

trade. Please do not include headers in the text files. Here is a great example of the format that

represents Euro currency [EC.csv].

20110601,-11187.5

20110701,-4068.75

20110801,-1812.5

20110901,8350

20111001,1725

20111101,-1162.5

20111201,6225

20120101,-2587.5

20120201,3187.5

20120301,-6550

20120401,-3337.5

20120501,9243.75

Page 8: Efficient Frontier [An Excel based Gadget]files.constantcontact.com/b44b4df7001/0074e574-675... · Equity Curve: The optimal curve versus the original curve. Efficient Frontier Gadget

20120601,-3012.5

20120701,-3537.5

20120801,1837.5

20120901,3375

20121001,-4175

20121101,-2650

20121201,2412.5

20130101,-1037.5

20130201,300

The first two letters of your file names should represent the market the data reflects. If you trade

soybeans, corn or any other single letter commodity symbol, then simply put a dash as the second

character. Here is a good name for a soybean file S-.csv.

Importing data from TradeStation for the Efficient

Frontier Gadget

Here we will describe the process of collecting the monthly data you will need to run this gadget.

On your Strategy Performance Report, go to the Monthly Periodical Returns tab and save just that page

to an Excel spreadsheet on your desktop. Go to the spreadsheet, highlight the date and P/L series under

Mark-To-Market Period Analysis

and copy just the date and P/L to another blank worksheet…so you should have the following:

Page 9: Efficient Frontier [An Excel based Gadget]files.constantcontact.com/b44b4df7001/0074e574-675... · Equity Curve: The optimal curve versus the original curve. Efficient Frontier Gadget

From here, sort the data from the oldest to newest date by highlighting both columns, right clicking and

choosing sort oldest to newest…make sure to include both date and P/L fields

Page 10: Efficient Frontier [An Excel based Gadget]files.constantcontact.com/b44b4df7001/0074e574-675... · Equity Curve: The optimal curve versus the original curve. Efficient Frontier Gadget

This will produce the following:

In order for the program to read the P/L values properly, we

need to adjust the number format. To do this, highlight just the

P/L column, right click and choose Format Cells

Page 11: Efficient Frontier [An Excel based Gadget]files.constantcontact.com/b44b4df7001/0074e574-675... · Equity Curve: The optimal curve versus the original curve. Efficient Frontier Gadget

A new window will pop up with several tabs at the top. Go to the Number tab, click on the Currency

category on the left, and make sure the symbol indicated is “none” via the dropdown menu and

negative

numbers are

displayed

with a minus

(-) sign

Next, click on

the Number

category

(above the Currency category), and make sure the “Use 1000 Separator” box is unchecked. You can

keep decimal places at 2.

Click OK, and your data series will look like this:

Page 12: Efficient Frontier [An Excel based Gadget]files.constantcontact.com/b44b4df7001/0074e574-675... · Equity Curve: The optimal curve versus the original curve. Efficient Frontier Gadget

Now, all we need to do is save the data as a comma delimited file (CSV). Simply save your data as a CSV

by choosing Save As – then pulling the drop down menu under Save as type: CSV (comma delimited):

Your version of Excel may or may not have several CSV’S to choose from (see above). Make sure you

select the CSV(comma delimited) type. Name the file (e.g. JYMonthly) and save it to your desktop. The

saved file will be depicted as below, indicating that it is indeed comma delimited.