[SOLVED] Programming - Homework - Simple Spread Trading

30.00 $

Category:

Description

5/5 - (1 vote)

   Introduction

A spread trading strategy checks a running estimate of the displacement between two related instruments, and makes bets that this displacement will decline whenever it gets large. Here, we define that displacement in terms of recent returns.

     Exercise

3.1      Positions

Create code for a spread-reversion trading strategy that begins on the first day of each month, trades during the month, and closes any open positions the end of each month (i.e. the first potential day for a trade is just after January 1 2020). For this homework, make the unrealistic assumption that you can trade at end-of-day closing prices from the database.

Its trades are equal-sized dollar amounts of X and Y to the nearest integer number of shares, as close as possible to $Nt/100 of each. Note that Nt changes every day, so trade size will depend on which day you open the position. Your gross traded cash is therefore roughly $2Nt/100. Track this number on any open position for later stop loss calculations.

The strategy enters or maintains a position if the size s of difference between the M-day return on X and Y is greater than g, and flattens (exits) the position if the size of the difference is less than j (where j < g). It does so by shorting the security whose recent return is higher. Note that if the change in s is large enough the position can flip from shorting the spread to being long the spread and vice versa, as discussed in class.

You only ever hold, at most, one long and one short position (i.e. one spread position). If you already have a position and the next tick is favorable to it, this simply means you continue to hold the position (except in stop loss situations). Do not adjust position size with the new Nt.

3.2        Mark To Market

When a position is open, keep track of its profits/losses (PnL). You will also want to keep track of cumulative PL across the whole series of opened and closed positions.

3.3       Stop Loss

Include a stop loss parameter s in your strategy. If your simulation experiences a day such that the present position value has lost more than a proportion s of the gross traded cash (|$long| + |$short| at position entry time), then force an exit at current prices, assume no new positions for the remainder of the month, and include this in your accounting.

3.4        End Of Data

Force a position close at the end of the analysis period.

3.5       Capital

Set the capital K for your strategy to the maximum of Nt over the data period, times two[2]. You can use this to evaluate return on capital.

3.6       Data

ETF pairs X,Y (in order) are as given by the last digit of your student number as follows:

  1. FCOM VOX
  2. RYE XOP
  3. PXJ OIH
  4. RYU XLU
  5. RTH XRT
  6. SIVR SLV
  7. HYLD JNK
  8. RING GDX
  9. FTSL SMH
  10. PBE XBI

   Analysis

Study the performance of your strategy as you vary j, g, s, and M. Include plots. You need not run a fancy nonlinear optimizer, but try to find which parameters work well, and explain how you did it. For one or more of the better settings you find, look into correlations to Fama French factor returns.

Be sure to highlight which ETF pair you are analyzing.

[1] The Quandl EOD database and Bloomberg are the best two sources for this. 2Available on Ken French’s website

[2] This setting has lookahead bias but is good enough for now. We set it very large like this to avoid the nonsensical situation of negative capital.