Open Side Menu Go to the Top
Register
algorithmic LIBOR/TBILL trading strategy algorithmic LIBOR/TBILL trading strategy

01-04-2008 , 03:13 AM
Hey guys,

so basically, i want to re-create an LTCM type trade. i want to execute a strategy that is betting on convergence for the LIBOR/Tbill spreads when the spread is 1 Zaway from the long term mean. i don't have the VBA skills for this though so i want to lay out what i did via excel and then maybe somebody w/ VBA ability could help me execute this in VBA so i could then refine it (and thus be able to test other trading strategies in the future).

i have daily data from 1/2/1987 until 12/24/2007.

the mean spread over the period is 47.5bps and the stdev is 32.9bps.

if the spread deviates by, say, 1Z i want to go short it (bet the spread will increase) and long it (bet the spread will decrease) depending on the direction of the spread. i want to stay short/long until the spread returns to 0.5 Zs at which point i want to exit the trade and wait until the next time the spread moves away from its long term mean by 1 Z (we can hpefully replace 1 with "zl" and "zs" to represent the Zscores away from the mean for which i want to long/short respective).

EDIT: for those that don't know, a "Z" here is the "Zscore." if a mean is mu and a standard deviation is s and an observation is t then Z = (t-mu)/s ... it is a measure of how many standard deviations away from the mean an observation is at any given period of time.

so i want to compute returns for the strategy where those rules are met.

the data is laid out simply:



so in this example, i would be long the spread from where N=32 and simply hold that trade until N=44. at which point i would calculate the annualized returns = - [Product(1+Return(32:44))^(250/(t1-t0 +1)) - 1] where t1=N1 and t0=N0 (this is negative since the returns assume i'm net short the spread...it would be simply =[product...] if the spread was at -1Z) ... assuming 250 trading day count convention. then, i would wait until the next point that Z <>=1 at which point i'd bet on convergence again according to those above steps.

EXCEL SUMMARY: ...

here is a picture to help visualize the strategy:



every time the red line crosses +1 or -1, the strategy goes into effect and stays in effect until the red line crosses +.5 or -.5.

so i just tested this without VBA and it is working perfectly but it takes way to many steps and is nowhere near effecient. it has nothing but nested IF(AND(OR(...)..)) type statements and then one final step to make sure the returns all face the correct way (i.e. if the spread is -1Z away it gives a positive return if it goes from -1.1Zs away to -0.90Zs away but gives a negative return if it goes from 1Z away to 1.5Zs away)

the strategy looks absolutely amazing on paper (and i thought of it mostly by myself yay!!! )

it gives an annualized total return (not counting financing costs, opporutnity costs etc.) of 234.28% with a st.dev of 15.99 %. if we assume a 10% financing cost and a 6% opportunity cost (from avg 3mo tbill annualized returns), then we get about a 218.28% excess return on about a 15.99% vol (different when you take out the tbill returns but whatever) for an Information Ratio of 13.65

so i want to be able to refine this strategy, but to do that, i think it is WAAAAYYY more efficient to do it in VBA.

thanks,
Barron

EDIT: obviously this is a very very simple algorithm..ideally the trading strategy would use the Zscore to compute a signal that would take X % of the maximum position based upon the Zscore relative to the max (and this wouldn't be a simple linear function either). it would be an S curve where the signal approaches -100% or +100% far quicker at the beginning than it does at the end.....buuuuut, i have to start somewhere, right?
algorithmic LIBOR/TBILL trading strategy Quote
01-04-2008 , 04:11 AM
Barron this is really good stuff. I found it interesting and easy to follow, but I will qualify that because I am in my last year of a finance undergrad.
I'm interested in what are the mean and std dev of the returns for the first 10 years vs the last 10 years.
algorithmic LIBOR/TBILL trading strategy Quote
01-04-2008 , 04:40 AM
Quote:
Originally Posted by maniacut
Barron this is really good stuff. I found it interesting and easy to follow, but I will qualify that because I am in my last year of a finance undergrad.
I'm interested in what are the mean and std dev of the returns for the first 10 years vs the last 10 years.
again, keep in mind that this is just the VERY first step to defining a trading strategy imo.

we'd still have to go through and fix the signal so that it isn't just binary. right now it is OFF or ON. it needs to be at 0% between -1 and 1 Zs away and then gradually move from 0% to -100% or +100% in a non-linear fashion as the spread moves more and more out of line given a max position.

that being said, with this elementary trading rule (that i basically picked off the top of my head as a starting point), the returns look like this:



the results fromt he first 10 years are:

Avg: 91.67%
StDev: 9.38%
(not really) IR: 9.78

the results from the last 10 years are:

Avg: 474.10%
StDev: 20.45%
(not really) IR: 23.19

now just from looking at this, it seems the strategy would do fantastically better if you let it get more and more invested as the spread got more and more positively far from 0 in Z terms and just let it do what it does when it goes to -1 Zs (the actual structure of the Z graph in the first post shows why)... i.e. the strategy does great in its simple form when the spread is choppy (like it is for a period from about N=3600 to N=4900) but loses a TON of power when the spread blows waaaaaaayyyyyyyyy out after crossing 1Z like from about N=1 to N=800

this is kind of datamining in a sense though b/c i'm picking the strategy from time T looking back at time t0-T and NOT being able to see time T to time Tn.

if you're a finance major then you know this is concept as a filtration. all info is taken into account from time t0 to t1 (at time t1) and if it were normally distributed in expectation, the expectation at t0 should equal the expectation at t1 (i.e. a martingale... a few more steps and we'd derive brownian motion).

anyways, back to this trading strategy, it needs much more work but it hought it would be interesting to post what i have so far and ask for help writing VBA code to generalize this strategy.

another important thing is that it assumes that you are able to size the trades such that the change in the spread is exactly the return you'd get on the position. this assumption probably costs a ton in trading costs but is what i think we'd want to do in reality (i.e. if the spread collapses from 79bps to 50bps then you want to be making 79/50-1 as your return). trading costs are not included in the analysis and it definitely detracts from it and there are many many more steps to take before implementings omething like this but i think it is instructive to go through it like this.

Barron

Last edited by DcifrThs; 01-04-2008 at 02:56 PM.
algorithmic LIBOR/TBILL trading strategy Quote
01-04-2008 , 08:01 AM
what securities would you be trading?
algorithmic LIBOR/TBILL trading strategy Quote
01-04-2008 , 09:22 AM
Quote:
Originally Posted by stinkypete
what securities would you be trading?
Very interesting read....I was going to ask the same question as Pete?
algorithmic LIBOR/TBILL trading strategy Quote
01-04-2008 , 01:11 PM
Quote:
Originally Posted by stinkypete
what securities would you be trading?
if it was me personally doing it...it would have to be 3mo Eurodollar futures and 13week Tbill Futures....but a bigger bank can get spot LIBOR daily and purchase 3mo tbills weekly.

since for a person it is a Tbill Futures contract, youd have to get the eurodollar futures... for now, the ED rates are close enough to LIBOR rates that i don't think i lose much in translation for this analysis.

SIDENOTE: i now understand the reason that i looked for in the other thread for eurodollar contract specification (it makes it identical tot hat of the 13week tbill)! since tbill is a $1million face value bond w/ 3 "interest" payment months, it matches the price of the 3mo interest on a tbill since it too is the interest on a $1million contract each month.

so i would have to use those contracts to execute this trade if i personally were to do this. institutions, however, could purchase Tbills outright since there is an auction every week and also get LIBOR spot (i think). so for this analysis, we'd haev to assume that it is a bank like citibank or maybe even non-registered banks can get LIBOR (does goldman get it? not sure...). so imagine that it is for a prop trading desk in a bank that can get spot LIBOR.

the problem, again, with me persoanlly executing this trade is that when the spreads spike, there is already discounting of reduction of spreads in the futures markets (as pointed out in the earlier thread)

i have calculated everything here off of the constant maturity tbill yield (which i guess i should be converting to 360day basis from 365 for complete accuracy) and LIBOR rates at the close of business, daily.

Barron
algorithmic LIBOR/TBILL trading strategy Quote
01-04-2008 , 01:31 PM
TO ANYBODY:

if you want to see the spreadsheet i made for this strategy, feel free to PM me your email and i'll email it to you.

Barron
algorithmic LIBOR/TBILL trading strategy Quote
01-04-2008 , 02:04 PM
could you explain the actual trading strategy in a little more detail?

if you're the institutional trader and trading t-bills/libor spot, what are you actually doing? are you shorting one and going long on the other? wouldn't you need huge amounts of leverage to get the returns you claim? maybe i'm not asking the right questions becuase i dont see what the actual trading strategy is, but please do explain.
algorithmic LIBOR/TBILL trading strategy Quote
01-04-2008 , 02:21 PM
Quote:
Originally Posted by stinkypete
could you explain the actual trading strategy in a little more detail?

if you're the institutional trader and trading t-bills/libor spot, what are you actually doing? are you shorting one and going long on the other? wouldn't you need huge amounts of leverage to get the returns you claim? and how do you get leverage at a rate better than the t-bill or libor rates? maybe i'm not asking the right questions becuase i dont see what the actual trading strategy is, but please do explain.
the strategy's position is either:

a) long 3mo Tbills, short 3mo LIBOR (when spreads are >1Z below mean). this position is held until the spread comes back to <.5Z below mean.

b) short 3mo Tbills, long 3mo LIBOR (when spreads are >1z above mean). this position is held until the spread comes back to <.5Z above mean.

to execute a), the institution would purchase n $1mil 3mo Tbills in the spot market and then sell n*A $1mil LIBOR obligations in the interbank spot market where A is the duration/risk exposure adjustment.

to execute b), the institution would sell n $1mil 3mo Tbills in the spot market and then buy n*A $1mil LIBOR obligations in the interbank spot market.

to execute the LIBOR leg of a) and the tbill leg of b), the institution would have to have the leverage you mention.

in order to get the tbill leg set, the institution would engage in a reverse repo for 1 $1mil face value tbill, then reverse repo it again, take the bill and sell another, and another, and another etc. until requisite leverage is reached (i haven't calced exactly how many would need to be sold, but i doubt it is too many).

in order to get the LIBOR let set, i'm not 100% sure what the institution would have to do. but i'd wager that these bets DO occurr so they do something, whatever it is they do to get short spot LIBOR (i.e. give those interest payments or whatever...then borrow more to give more interest payments, betting that LIBOR will rise)...basically, this is the leg i'm least sure about (obviously)...nor do i know what/how leverage would be taken to get A*n $1mil interest payments set such that the 1tick change in the spread results in that proportional return.

Barron
algorithmic LIBOR/TBILL trading strategy Quote
01-04-2008 , 03:55 PM
i knew this trading strategy looked too good to be true...

i just double checked my spreadsheet and the st.dev wasn't on a 250 day basis.

Return 234.35%
St.Dev 252.78%
approx IR 0.93

so that looks much more realistic. i still think it is a powerful strategy so i decided to refine it.

logically, the spread can blow out by far more than it can compress...so the trigger for being long the spread should be significantly higher in Z terms than the trigger for being short the spread.

currently, i have the following trading rules:

Short Spread if n is <= -1 Z away from mean
Long Spread if n is >= 1 Z away from mean

Exit position if n is <= -0.5 Z away from mean
Exit position if n is >= 0.5 Z away from mean

i changed it to these:

Short Spread if n is <= -0.75 Z away from mean
Long Spread if n is >= 2.5 Z away from mean

Exit position if n is <= -0.25 Z away from mean
Exit position if n is >= 1 Z away from mean

and the results went to this:

Return 693.66%
St.Dev 283.80%
approx IR 2.44

so now i have to think about how to construct a variable signal that gets bigger as the #Zs move away in an S curve.

so this is another example of me being ******ed/human. but at least i have a nifty trading strategy spreadsheet set up to test this.

Barron
algorithmic LIBOR/TBILL trading strategy Quote
01-04-2008 , 05:15 PM
Barron,

I've written bunches of programs like this. But I always write them in Perl or C++. I could code this up for you if you don't need it to be in Visual Basic.
algorithmic LIBOR/TBILL trading strategy Quote
01-04-2008 , 05:29 PM
Quote:
Originally Posted by Central Limit
Barron,

I've written bunches of programs like this. But I always write them in Perl or C++. I could code this up for you if you don't need it to be in Visual Basic.
how would i use that? i don't even know what C++ is really

i know how to use VBA and matlab, but not well enough to do this...

thanks,
Barron
algorithmic LIBOR/TBILL trading strategy Quote
01-04-2008 , 06:51 PM
Quote:
Originally Posted by DcifrThs
again, keep in mind that this is just the VERY first step to defining a trading strategy imo.

we'd still have to go through and fix the signal so that it isn't just binary. right now it is OFF or ON. it needs to be at 0% between -1 and 1 Zs away and then gradually move from 0% to -100% or +100% in a non-linear fashion as the spread moves more and more out of line given a max position.

that being said, with this elementary trading rule (that i basically picked off the top of my head as a starting point), the returns look like this:



the results fromt he first 10 years are:

Avg: 91.67%
StDev: 9.38%
(not really) IR: 9.78

the results from the last 10 years are:

Avg: 474.10%
StDev: 20.45%
(not really) IR: 23.19

now just from looking at this, it seems the strategy would do fantastically better if you let it get more and more invested as the spread got more and more positively far from 0 in Z terms and just let it do what it does when it goes to -1 Zs (the actual structure of the Z graph in the first post shows why)... i.e. the strategy does great in its simple form when the spread is choppy (like it is for a period from about N=3600 to N=4900) but loses a TON of power when the spread blows waaaaaaayyyyyyyyy out after crossing 1Z like from about N=1 to N=800

this is kind of datamining in a sense though b/c i'm picking the strategy from time T looking back at time t0-T and NOT being able to see time T to time Tn.

if you're a finance major then you know this is concept as a filtration. all info is taken into account from time t0 to t1 (at time t1) and if it were normally distributed in expectation, the expectation at t0 should equal the expectation at t1 (i.e. a martingale... a few more steps and we'd derive brownian motion).

anyways, back to this trading strategy, it needs much more work but it hought it would be interesting to post what i have so far and ask for help writing VBA code to generalize this strategy.

another important thing is that it assumes that you are able to size the trades such that the change in the spread is exactly the return you'd get on the position. this assumption probably costs a ton in trading costs but is what i think we'd want to do in reality (i.e. if the spread collapses from 79bps to 50bps then you want to be making 79/50-1 as your return). trading costs are not included in the analysis and it definitely detracts from it and there are many many more steps to take before implementings omething like this but i think it is instructive to go through it like this.

Barron
here is the returns as best as i can understand how to maximize them ex post:

Short Spread if n is <= -0.65 Z away from mean
Exit position if n is >= -0.55 Z away from mean
Long Spread if n is >= 2.50 Z away from mean
Exit position if n is <= 1.00 Z away from mean

Return 1370.46%
St.Dev 280.96%
approx IR 4.88




basically, the trigger to execute the strategy on the short side and the length of Zs you want it to run has to be way way tighter than the long side since the long side distribution is a ton bigger. you want to create as many opportunities to earn positive returns while at the same time, not putting yourself in a position to get caught when it moves big against you.

Barron
algorithmic LIBOR/TBILL trading strategy Quote
01-04-2008 , 06:53 PM
the quantnet forums host spreadsheets so here it is:


HERE IS THIS SPREADSHEET, CLICK THIS LINK AND DOWNLOAD IT TO YOUR COMPUTER
http://www.quantnet.org/forum/attach...3&d=1199481256

Barron

Last edited by DcifrThs; 01-04-2008 at 09:43 PM.
algorithmic LIBOR/TBILL trading strategy Quote
01-04-2008 , 08:49 PM
for strategies like this, IR really doesn't tell the whole story, as the return distribution tends have have a lot of both skew and kurtosis - I'd be interested in seeing a TS of cum returns though, to see if they actually do have a "picking up nickels in front of a steamroller" type distribution.
algorithmic LIBOR/TBILL trading strategy Quote
01-04-2008 , 09:05 PM
Quote:
Originally Posted by edtost
for strategies like this, IR really doesn't tell the whole story, as the return distribution tends have have a lot of both skew and kurtosis - I'd be interested in seeing a TS of cum returns though, to see if they actually do have a "picking up nickels in front of a steamroller" type distribution.
i have a chart of cum returns...is that what you want? what is a TS?

Barron
algorithmic LIBOR/TBILL trading strategy Quote
01-04-2008 , 09:08 PM
Barron

This thread is very intriguing .Could you PM that spread sheet so I can take a look?

Thanks,
Stephen
algorithmic LIBOR/TBILL trading strategy Quote
01-04-2008 , 09:35 PM
Quote:
Originally Posted by stephenNUTS
Barron

This thread is very intriguing .Could you PM that spread sheet so I can take a look?

Thanks,
Stephen

thanks...

now, to Stephen and EVERYBODY... the spreadsheet is IN THE LINK a few posts up. just click on that link and save as whatever you want. that is the spreadsheet i built.



(it has no new additions though like what i'm about to post)

Barron
algorithmic LIBOR/TBILL trading strategy Quote
01-04-2008 , 09:37 PM
Quote:
Originally Posted by DcifrThs
i have a chart of cum returns...is that what you want? what is a TS?

Barron
Ed,

here is the return distribution in its complete form (wiht all the 3806 entries at 0):



EDIT: to read this, each bar represents the sum of the entries from the tick mark to the left up until and not including the tick mark that you're looking at. ... i.e. 5% bar is all entries from 0-5% (not including 5%).

and here it is with the scale set at 500:



overall, you can clearly see the negative returns are waaaaaaayyyyyyy outnumbered in terms of size by the positive returnsand the skew of the strategy is away from the left hand tail of the distribution.... it is the opposite of picking up pennies in front of a steamroller...it is losing many pennies, like paying a premium, and then picking up thousand dollar bills every once in a while.

Barron
algorithmic LIBOR/TBILL trading strategy Quote
01-04-2008 , 10:01 PM
Quote:
Originally Posted by edtost
for strategies like this, IR really doesn't tell the whole story, as the return distribution tends have have a lot of both skew and kurtosis - I'd be interested in seeing a TS of cum returns though, to see if they actually do have a "picking up nickels in front of a steamroller" type distribution.
here is the cumulative return chart:



thats in log form so the returns are absolutely sickeningly large.

Barron
algorithmic LIBOR/TBILL trading strategy Quote
01-05-2008 , 02:03 PM
If I were going to do this I would first try assume that the optimal amount of leverage is some mathematical function of Z and use excel's solver optimize the coefficient. I use two out of sample periods. I would use the first to figure out the best functional form (i.e. choose the functional form that performs the best in the first out of sample period). Then optimize the model over the insample period and the first out of sample period and then use the second out-of-sample period to test this optimized model.

This would take about 10 minutes in sas or matlab, but I think can be done in excel with some work.
algorithmic LIBOR/TBILL trading strategy Quote
01-05-2008 , 03:17 PM
thanks barron,. this actually looks really interesting.

by TS i meant time series, so the graph above was exactly what i was looking for.
algorithmic LIBOR/TBILL trading strategy Quote
01-06-2008 , 03:32 AM
so as this spread has blown out in the past 6 months, at what point would you have gotten short libor yields and long tbill yield? i feel like you would've gotten pretty hurt on this trade recently, given that your z-score wouldve been calculated using data over the past 5 years which have been fairly quiet. this just has the feeling of one of those trades where you will eat like bird but **** like an elephant.... its also very interesting to me that you are using historical data and then trying to use it to justify a trade to put on today, because the current status of the cash mkt (central bank interaction/massive injections of liquidity, unwillingness of banks to let go of cash on their balance sheets, new margin restraints, etc) make me want to question all this past data that you are using to make decisions. Id rather you tell me that you have faith in central banks calming down the liquidity crunch and that you believe the libor/tbill spread will narrow again in the next year, rather than you pulling some data from 15 years ago that has diddly **** to do with what is going on now.
algorithmic LIBOR/TBILL trading strategy Quote
01-06-2008 , 04:33 PM
Quote:
Originally Posted by Jason Strasser (strassa2)
so as this spread has blown out in the past 6 months, at what point would you have gotten short libor yields and long tbill yield?
other way around, it would have gotten long libor yields and short the tbill once it hit 2.5 Zs. the strategy is akin to long vol.

Quote:
i feel like you would've gotten pretty hurt on this trade recently, given that your z-score wouldve been calculated using data over the past 5 years which have been fairly quiet.
i used data back to 1/2/1987 and would never build something with just 5 years data.

Quote:
this just has the feeling of one of those trades where you will eat like bird but **** like an elephant.... its also very interesting to me that you are using historical data and then trying to use it to justify a trade to put on today, because the current status of the cash mkt (central bank interaction/massive injections of liquidity, unwillingness of banks to let go of cash on their balance sheets, new margin restraints, etc) make me want to question all this past data that you are using to make decisions. Id rather you tell me that you have faith in central banks calming down the liquidity crunch and that you believe the libor/tbill spread will narrow again in the next year, rather than you pulling some data from 15 years ago that has diddly **** to do with what is going on now.
i think your first sentance from this quote has the strategy backasswords. you sh*t like a bird but eat like an elephant. you earn the most when vol picks up and lose a bit here and there in less crazy times.

the rest of it though has much more meat as i'll deal with in my next post.

thanks for your thoughts,
Barron
algorithmic LIBOR/TBILL trading strategy Quote
01-06-2008 , 04:53 PM
so after thinking about it some more, i've come to the conclusion that my work here was for naught.

1) The first huge mistake is the following: dSpread != Returns…not by a long shot. I realized this on the car-ride home from foxwoods today with the simple example of the spread hitting 2.5Zs and triggering the long position. Assuming the LIBOR spot price is arranged like futures (ie. 95= 100-yield, yield=5% IMM), if LIBOR is at 5% and trading at 95 and say the tbill CMY is at 3.5%, and you held tbills constant and the strategy returns 50%, the price of LIBOR moves up by only 75bps to 95.75. That would be a 50% reduction in the spread but only a .79% return. In order to generate the 50% return, you’d need to lever that trade 63.33 times. That is basically insane and not prudent.

2) The strategy is basically a technical strategy with stops. The fundamental assumption is that the banking system returns to “normal” as defined by history. But history changes and it is possible historical relationships like this break down. That isn’t taken into account. Further, the entry and exit points were “optimized” simply by maximizing returns based on historical dSpread data. Those points, as defined by history, could also change.

3) The costs of implementing this strategy would be monumental compared to the returns. In order to generate the LIBOR trade, one possibility is a total return swap where you could owe whatever return index, receive spot LIBOR and then hedge out your short position in the whatever return index. That isn’t cheap though from what I gather.

so while it was interesting building this strategy, i am going to move towards something I can build logically, execute easily, and implement cheaply.

thanks for reading, though in the end the result was me being wrong

Barron
algorithmic LIBOR/TBILL trading strategy Quote

      
m