Archive for the ‘Strategies’ Category

C# class for spreads

Posted: January 16, 2011 in .NET, C#, Strategies

Per requests, I put together a simple C# class for spreads that we have spoken of to date in this blog.  You can grab it from my sourceforge site (


This post will concern the Chicago-Kansas wheat futures marketplace.  The main goal of this article will be to introduce the reader to these markets, recent histories, trading strategies, and some off the shelve statistics such as correlation, covariance then apply a principle component analysis (PCA)in the next post of this series to show the end user how to construct a basic term structure model.

Wheat is a commodity that is utilized as a food or food derivative trading in many location such as Chicago (CME), Kansas (CBOT), Minneapolis (MGEX), Australia, etc.  For this study we will focus only on the CME and Kansas contracts.

Please if you are going to trade these be familiar with the contract specifications:

CME wheat contract specifications:

Kansas wheat contract specifications:

Some terminology, many grain traders refer to the spread between outrights of different exchanges such as front month Chicago to front month Kansas as the basis.  I will keep this terminology and additionally add that Chicago is always the front basis contract.  So if I say you are long the August basis, I mean long Chicago and short Kansas.

In terms of recent histories both of these contracts have only been trading electronically on CME Globex for a few years now and have picked up tremendous liquidity with such change.  There is now listed calendar swaps, options, and other derivative products such as the SP GCSI index listed on the CME.

There are several trading strategies involving these contracts but the most prevalent is to trade the Chicago to Kansas basis in a 1 to -1 contract fashion in the same expiration.  This by far has been the most popular but with the recent reduction in volatility, I have been showing traders how to take curve plays by doing the front Chicago expiration against the deferred Kansas expiration in a 1 to -1 trading ratio to get more fills.  The risk is somewhat higher as these contracts tend to move more as you are trading more risk on the future expectation of the crop.  There are term structure strategies which we will cover in the next posting covering principle component analysis (PCA) and independent component analysis (ICA).

Many wheat traders say that in the long term that the basis is mean-reverting.  In the spreadsheet I posted on SourceForge recently (CBOT-KC_WheatAnalysis.xlsx), I showed this with a simple spread analysis and variance ratio.  The variance ratio is shown to stabilize very fast and the price ratio is shown to be very stable (i.e. mean reverting).  Is this the case intra-day?  I will have to get data for another future analysis for us.

A clip from this analysis may be seen below:

Moving on to correlation but wait what is correlation? Correlation is a metric that describes the statistical dependence between two or more quantities.  The most widely used correlation is Pearson correlation which is defined as:

Covariance(Chicago,Kansas)/(Stdev(Chicago)*Stdev(Kansas))  where stdev is the standard deviation and these are all based one the asset returns.

There are many types of correlation such as Rank correlation.  See for more decent information.

A plot of this correlation may be found below which shows correlation by contract of Chicago against Kansas:

But wait correlation depends on the covariance? Yes, that is correct and covariance depends on the variance on the individual assets involved.  The covariance may be seen below.

And the variance:

Gadzooks, that crossover of variance may explain the ackward correlations in the Kansas back months term structure.

This is a basic intro to the mechanics of Chicago-Kansas wheat market.  Next time we will venture into constructing a wheat principle component analysis model to trade with!

In the last post we saw some interesting characteristics of butterflies in the eurodollar marketplace.  In this post, we will look at utilizing the double butterfly to calm the storm in more volatile markets.

First, let’s recap what a double butterfly is:  Buying 1 of an expiration, Selling 3 of the next expiration, Buying 3 of the next expiration, and Selling 1 of the next expiration.  With this position, we would say you are long the double butterfly.  The side of the position is always denoted by the side of the nearest to expire contract.

Next, let us start with the agriculture markets of soybeans.  I will construct a CQG double butterfly spread consisting:


WAIT, WHAT DOES THAT MEAN? ZSE is CQG’s symbol for soybeans and ? denotes to always look to the contract that is listed.  In this case, ZSE?1 tells CQG to always look to the front month.  It is a way to continuously roll the front month.

Next, let’s look at Soybean Oil (CQG symbol: ZLE).

Moving on to Soybean Meal (CQG symbol: ZME)

And now to the fun stuff, the crude oil (CQG Symbol: CLE) double butterfly:

And even further fun, heating oil (CQG symbol: HOE)

And lastly, RBOB (CQG: RBE)

Looks pretty wild even for a double butterfly, I know!  My goal here was to show you stability across multiple markets.  If you look at the outright, spread, or even regular butterflies during this same period you will notice considerable volatility/directionality but this strategy tends to be more generous in risk metrics during your holding time frame.

In the last post, we learned about Pascal’s triangle.

Here is the first red (H1) outright:

Notice the range and stability.  Focus on these as we proceed.

Next we will do a simple H1M1 spread (Long H1, Short M1):

Moving forward to the H1-M1-U1 butterfly (Long, Short 2x, Long):

Next, we try out the double butterfly (long, short 3, long 3, short 1):

And now on to the more exotic structures (Long 1, Short 4, Long 6, Short 4, Long 1):

And slightly more exotic (Long 1, Short 5, Long 10, Short 10, Long 5, Short 1)….you starting to get the point here?

Again notice the reduction in overall portfolio variance as you add more components.  Think about the correlation and volatility curves that we showed you previously.  How are you capitalizing on that?  What are the risks with these strategies in the front of the curve (H0,M0,U0,Z0)?  Consider holding time as you start to build these larger exotic positions as they tend not to move that much.

Up to now we covered some different strategies, packs and butterflies.  There are many more but how do they come up with this stuff anyway? Mathematicians are funny people aren’t they?  Check this out and see if it strikes a memory for high school mathematics:

Now check out what we can do with this!

Row 1: 1 for a single outright.

Row 2: 1 by -1 for a spread.  Example: Long H0M0 spread, that is Long 1 H0 and Short 1 M0.

Row 3: 1 by -2 by 1 for a butterfly.  Example: Long H0M0U0, that is Long 1 Ho, Short 2 M0, and Long 1 U0.

Row 4: 1 by -3 by +3 by -1 for a double butterfly.  Example Long H0MoU0Z0, that is Long 1 H0, Short 3 M0, Long 3 U0, and Long 1 Z0.

So on and so fourth but the general trend (will vary in agricultures and other term structures with crop cycles) will increase the stability as you work down the triangle to create more geometric positions.  Remember to alternate your signs (Long, Short) or you could end up with a net long position.

From the last post, we saw the characteristics of the eurodollar butterflies.  This time around we will take a look at the eurodollar pack characteristics on our tour of exchange listed products.

Wait but what was a eurodollar pack? Buying a pack is to buy 4 of every contract for the listed pack.  Example:  Buying the H0 White pack would give you a H0, M0, U0, and Z0 contract.  They are quoted in net change from the previous trading days settlements.

We’ll start by examining the pack volatility:

Notice the shape of this structure?  Have we seen this elsewhere before.  Get used to it as it is the shape of most short-term interest rate (STIR) products.  You will notice that not only is the back-end the most volatile but also the most illiquid in trading anymore.  You will find liquidity constaints in the blues makes it very difficult to hedge a 5 year treasury instrument effectively let alone a 10 year treasury further out on the curve.


An interesting idea:  Create spreads between multiple packs.  Interesting enough the CME has listed these too!

First, let us examine the white pack:

Now on to the red pack, this is the main hedging point for 2 year treasury products.  There is still sufficient liquidity here to do so as well.

Now on to the green packs which is currently the best place to hedge the 5 year treasury issues in my opinion due to the good liquidity.

Blue pack time; this used to be much better to hedge 5 year issues but much of the great liquidity that we had is long gone now.

And lastly, the gold pack:

In the previous post, we spoke about the various CME exchange listed strategies.  In this post, I will focus specifically on the characteristics of exchange listed eurodollar butterflies.  Many traders and market makers tend to trade and hedge inventory into butterflies because of their inherent stability in volatile markets.  Butterflies are constructed by buying an expiration, selling 2 of the next expiration, and then buying 1 of the next sequential expiration.  They have a quality of being net outright position equal to zero, lower margin than holding outright positions alone, and are less risky in general (again there are some sticky broken butterflies in the agriculture markets) than holding outright positions alone.

First observation, the white butterflies are the most directional as they are tied to the most current market reaction to fed policy and also the most volatile in the term structure.

First, let’s examine the volatility of the eurodollar butterflies:

So from this you can conclude that the front eurodollar butterflies are most tied to short term economic events, changes in federal policy, and other events.  You may also conclude that these butterflies in the whites and reds would be the most directional (not mean reverting).

As can seen below, the white butterflies.  Notice the very directional nature and the associated spread (price ranges) of the white butterflies.

Next, we move on to the red butterflies.  Recall that from the previous post that the 4th White and 1st Red contracts are the most volatile points in the curve.  Notice the effect on the first red (H1) butterfly.

Moving on to the green flies, notice the stability and price ranges.

And moving further along the curve to the blues:

And moving slightly further to the gold butterflies.  Stable?