Contents 1 Assignment

2

1.1 Your goal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

2

1.2 The paper . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

2

1.3 The program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

3

1.4 The presentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

3

1.5 Assessment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

3

1.6 Important dates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

3

2 The data: Asset prices across macroeconomic investments

3

3 The baseline strategy and code

4

3.1 The strategy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

4

3.2 Choosing quantities of each long and short position . . . . . . . . . . . . . . . . . . . . . .

7

3.3 The strategy in code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

11

1

4 Extending the baseline to your strategy

1 1 .1

12

Assignment Your goal

Your goal is to use your logs from this semester to try to improve on a “trend-following” macroeconomic investment strategy. In other words, you are to use macroeconomic theory to improve on the control group of an entirely statistical-based strategy.

1 .2

The paper

You will write up a (at least) 5 page paper on the motivation of your strategy, thesis, historical performance, and conviction level. Your goal is for this to be interesting to the reader, and to be useful (i.e. does your strategy work?).

1 .3

The program

You will use the program described below as your starting point to backtest your strategy.

1 .4

The presentation

You will describe to class succinctly in 5-10 minutes what you did, and what the main results were.

2

1 .5

Assessment

Your grade will be based on the completeness and critical mindedness of all your analysis, presentation, and paper.

1 .6

Important dates

Your presentation is Thursday, December 15, in the classroom, from 2-5pm. Your paper should be dropped off with me either at the presentation, or in the basket on my office door by Friday, December 15, at 5pm. I will have OH from 11:30am-on on Wed December 14. If you need to put out any fires, I might be able to meet Tuesday as well.

2

The data: Asset prices across macroeconomic investments

All MATLAB documentation for this project is available here:

http://tinyurl.com/hbs9p58

MATLAB file momentumData.m organizes and cleans up the raw data in data.xlsx. The below figures summarize how this data evolves over time, and correlations across prices.

3

Figure 1: Prices of assets over sample.

US 2 Yr

112 110 108 Jul 2013 Jan 2017

German 2 Yr

US 5 Yr

125 120 115 Jul 2013 Jan 2017

German 5 Yr

US 10 Yr

140 130 120 Jul 2013 Jan 2017

US 30 Yr

UK 10 Yr

200 150 100 Jul 2013 Jan 2017

140 120 100 Jul 2013 Jan 2017

German 30 Yr

Japan 10 Yr

Canada 10 Yr

Australia 3 Yr

Australia 10 Yr

German 10 Yr

114 112 110 Jul 2013 Jan 2017

140 130 120 Jul 2013 Jan 2017

Italy 10 Yr

France 10 Yr

Sugar

Oats

Hogs

Soybean

Soybean Oil

Platinum

Silver

Cotton

Coffee

Copper

Cocoa

Live Cattle

Brent Crude

Crude Oil

Gas Oil

Gold

USD

EUR

150

200 150 100 100 Jul 2013 Jan 2017 Jul 2013 Jan 2017

200 150 100 Jul 2013 Jan 2017

200 1600 150 1500 100 1400 Jul 2013 Jan 2017 Jul 2013 Jan 2017

160 100 100 98 140 98 96 120 96 Jul 2013 Jan 2017 Jul 2013 Jan 2017 Jul 2013 Jan 2017

30 1000 200 2000 20 500 100 1000 10 0 0 0 Jul 2013 Jan 2017 Jul 2013 Jan 2017 Jul 2013 Jan 2017 Jul 2013 Jan 2017 60 2000 30 100 80 40 1000 20 60 20 0 10 Jul 2013 Jan 2017 Jul 2013 Jan 2017 Jul 2013 Jan 2017 Jul 2013 Jan 2017

Soybean Meal

600 400 200 Jul 2013 Jan 2017

Corn

600 400 200 Jul 2013 Jan 2017

3000 4 3000 200 200 2000 2 2000 100 100 1000 0 1000 0 0 Jul 2013 Jan 2017 Jul 2013 Jan 2017 Jul 2013 Jan 2017 Jul 2013 Jan 2017 Jul 2013 Jan 2017 200 1000 1400 150 1.4 100 500 1200 100 1.2 0 0 1000 50 1 Jul 2013 Jan 2017 Jul 2013 Jan 2017 Jul 2013 Jan 2017 Jul 2013 Jan 2017 Jul 2013 Jan 2017 4 GBP AUD CAD YEN NZD 10 2 1 1 1.5 1 1.5 0.8 0.8 1 0.8 1 0.6 0.6 0.5 0.6 Jul 2013 Jan 2017 Jul 2013 Jan 2017 Jul 2013 Jan 2017 Jul 2013 Jan 2017 Jul 2013 Jan 2017

CHF

S&P 500

HangSeng

Russel 2000

Germany DAX

France CAC 40

TOPIX

SPI 200

S&P/TSX

1.2 1 0.8 Jul 2013 Jan 2017

250 200 150 Jul 2013 Jan 2017

Netherlands AEX

IBEX 35

300 150 200 100 100 50 Jul 2013 Jan 2017 Jul 2013 Jan 2017

FTSE 100

800 600 400 Jul 2013 Jan 2017

FTSE MIB

600 40 40 60 20 400 30 30 50 15 200 20 20 40 10 Jul 2013 Jan 2017 Jul 2013 Jan 2017 Jul 2013 Jan 2017 Jul 2013 Jan 2017 Jul 2013 Jan 2017 60 50 30 40 40 20 20 30 10 Jul 2013 Jan 2017 Jul 2013 Jan 2017 Jul 2013 Jan 2017

4

Figure 2: Correlations amongst assets over sample.

5

3 3 .1

The baseline strategy and code The strategy

The baseline (control) strategy we wish to consider is an economic theory-free “trend-following” global macroeconomic portfolio. This portfolio works as follows: Using the above asset prices,

pnt : Price of asset n = 1, . . . , N at time t = 1, . . . , T days.

and initial investment, Dt : Dollars available for investment at time t.

You simply watch the trends in each asset. If the price has risen over some number of days, we enter a long position, i.e. we purchase some quantity of the asset.

` : The period over which we look back.

pnt ≥ pnt−` : Price has risen over period we look back, so enter a long position.

If the price has fallen over the same number of days, we enter a short position. This works as follows: Today, you borrow the asset from one party A to sell to another party B at price pnt . You at the same time promise to buy back the asset from party B at some point in the future t + f at whatever price the asset is trading for then. After you buy the asset back from B, you return it to party A, with interest i. This means your net profit from the short position is pnt − (pnt+f + i), so you make money if the price

6

sufficiently falls over the period.

pnt < pnt−` : Price has fallen over period we look back, so enter a short position.

i : Interest rate paid to finance short position.

f : The period of time we hold the short position

While na¨ıve trend-following tells us which position to long or short, we also have to decide how much of each asset to long or short, given the Dt investment. This decision takes the form of a constrained maximization problem.

3 .2

Choosing quantities of each long and short position

By watching trends we break up our n = 1, . . . , N choices of investments into long and short positions. The prices of these assets can be ordered into vectors as,

NL ≤ N : The number of long positions we take long positions in

p0Lt p0St

= p1t . . . pNL t : The prices of assets we take long positions in.

= pNL +1t . . . pN t : The prices of assets we take short positions in.

What we have to decide now is how much of each asset to go long or short in subject to our investment Dt . Our dollars Dt will be broken down in to money spent on long positions today, and short positions.

7

We are buying the assets we go long in, and although we are not purchasing the assets we are shorting, we want to set aside the interest payment necessary to finance our short positions.

Budget constraint : Dt = Lt + St

Allocation to long positions (purchasing cost): Lt =

NL X

qnt pnt

n=1

Allocation to short positions (financing cost): St = i ×

N X

qnt pnt

n=NL +1

qnt : Quantity of asset n purchased or shorted in period t.

We can more simply write the budget constraint in vector notation,

Dt = q0Lt pLt + iq0Lt pSt

q0Lt q0St

(1)

= q1t . . . qNL t : The quantities of assets we take long positions in.

= qNL +1t . . . qN t : The quantities of assets we take short positions in.

Our job is to figure out what qLt an qSt should be. Note, for a given choice, our capital gains (money we make) f periods into the future are

Capital gains: Kt+f =

NL X

qnt (pnt+1 − pnt ) +

n=1

N X n=NL +1

= q0Lt ∆pLt+f − q0St ∆pSt+f 8

qnt (pnt − pnt+1 )

(2)

∆pLt+f = pLt+f − pLt

for

∆pSt+f = pSt+f − pSt

Recall, f was the period we previously assumed you hold a short position in. We’ll assume this is also the frequency at which you reoptimize your portfolio. For example, if f = 30, you only change your investments every 30 days. Given we have to pay fees and taxes on our capital gains, only if our capital gains are positive, our funds available in period t + f are

Dt+f = Dt + (1 − 1Kt+f >0 c)Kt+f

“Indicator function”: 1Kt+f >0 =

(3)

1 if Kt+f > 0 if Kt+f ≤ 0.

c : Brokerage costs and taxes.

We want to choose long and short positions in such a way to maximize the return on our investment, but while only exposing us to an amount of risk we are willing to take, and without violating our budget constraint. Specifically we want to maximize the mean of capital gains while minimizing its variance. Our maximization problem takes the form of the following Lagrangian:

L = max E(Kt+f ) − (γ/2)Var(Kt+f ) − λ(Dt − q0Lt pLt − iq0St pSt ) qLt ,qSt

Expected capital gains: E(Kt+f ) = E(∆pt+f ) = E

∆p0Lt+f

9

q0Lt

−q0St

∆p0St+f

0

E(∆pt+f )

(4)

0 Variance of capital gains: Var(Kt+f ) = q0Lt −q0St Var(∆pt+f ) q0Lt −q0St 0 ΣLL ΣSL Variance-covariance matrix of returns : Var(∆pt+f ) = Σ = ΣSL ΣSS Coefficient of risk aversion: 0 < γ < 1. Bigger means more risk averse.

λ : Lagrange multiplier.

Note, we can estimate E(∆pt ) and Var(∆pt ) from the data. In the code (explained below), this is done at a given point in time by looking at data over the lookback period `. Σ is related to the large variancecovariance matrix of returns we looked at previously. The fact that the variance of capital gains depends on this matrix is why it’s so important. The Lagrangian may also be written out in expanded form as, dropping the +f ’s for clarity,

L = max q0Lt E(∆pLt ) − q0Lt E(∆pSt ) − (γ/2)[q0Lt ΣLL qLt + 2q0St ΣSL qLt + q0St ΣSS qSt ] qLt ,qSt

− λ[Dt − q0Lt pLt − iq0St p0St ] (5)

The three first order conditions are,

∂L = 0 : E(∆pLt )0 − γ(q0Lt ΣLL + q0St ΣSL ) + λp0Lt = 00 ∂qLt ∂L = 0 : − E(∆pSt )0 − γ(q0St ΣSS + q0Lt Σ0SL ) + λip0St = 00 ∂qSt

10

∂L = 0 : Dt − q0Lt pLt − iq0Lt pSt = 0 ∂λ This is a system of N + 1 equations and N + 1 unknowns: The quantities of long and short positions qLt and qSt , as well as the Lagrange multiplier λ. This system of equations may be written in matrix form,

γΣ0SL

pLt qLt E(∆pLt ) γΣLL −E(∆pSt ) = γΣSL γΣSS ipSt qSt 0 0 Dt λ pLt ipSt 0 | {z } | {z } a

B

So the solution, which tells us what the optimal quantities of long and short positions to take, subject to risk tolerance γ and budget Dt , is the solution to the above with constraints qLt > 0 and qSt > 0. This solution is sometimes known as the “mean-variance frontier”, or, optimal portfolio allocation in terms of risk and reward. λ is the shadow value of investing more money into this strategy.

3 .3

The strategy in code

The MATLAB program momentumStrategy.m takes the above mathematics and puts it into code. Note, at the beginning of the code are some parameters you may adjust to your liking. Using the baseline, we get the results summarized in the below figures. The portfolio loses some value, and then gain some of it back. Notice the portfolio value is “step-wise.” This is because in the code, I only let the portfolio repotimize every 30 days. You can easily change this by changing the variable f, which corresponds to f in the previous mathematics.

11

Figure 3: Evolution of original $1,000,000 over period using “trend-following”.

10.05

10 5

10

9.95

9.9

9.85

9.8

9.75

9.7

9.65 Jul 2013

Jan 2014

Jul 2014

Jan 2015

12

Jul 2015

Jan 2016

Jul 2016

Jan 2017

Figure 4: Portfolio holdings using “trend-following”.

10000 6

4000 2

1.5

2

1

1

0.5

0

0

13

HangSeng

3

S&P/TSX FTSE MIB Germany DAX Netherlands AEX CAD AUD GBP EUR Gas Oil Crude Oil Brent Crude Hogs Australia 10 Yr Australia 3 Yr Canada 10 Yr France 10 Yr Italy 10 Yr German 30 Yr German 10 Yr German 5 Yr US 30 Yr US 10 Yr US 5 Yr US 2 Yr 2

Coffee

S&P 500 Live Cattle Cocoa Italy 10 Yr German 2 Yr

4

SPI 200 IBEX 35 TOPIX France CAC 40 Russel 2000 HangSeng USD Gold Copper Coffee Oats Japan 10 Yr German 2 Yr UK 10 Yr

2.5

Corn

0

US 2 Yr

5

Hogs

0

Australia 10 Yr

2000

S&P/TSX

1

5 positions, end of sample 10Short

3 4 positions, end of sample 10Long

6

12000 7

Short positions, beginning of sample 14000

Long 10 5 positions, beginning of sample 8

5

4

8000

3

6000

4

Extending the baseline to your strategy

First, make sure you can get the code as is to work. I have tested it, and it works, so that should be point 1. You are tasked with extending the code to look at whatever you are interested in. For example, if you’re interested in just a subset of the data, perhaps you can “clip” some of it off (alter momentumStrategy.m accordingly). Otherwise, you might change some parameters, i.e. the variable f. Play around with it! Remember, a good practice is to re-run the code whenever you make a change, to zero-out errors. Good luck.

14