Introduction

The term structure of commodities usually refers to the difference between Futures prices of different maturities at a given time point. The shape of the Futures curve is essential to commodity hedgers and speculators as Futures price serves as a forecast of future spot price. The Futures price curve contains the information about Futures supply and demand conditions. This algorithm will examine the role of term structure signals for the design of profitable trading strategies in commodity Futures markets.

Method

Concepts of Futures

Before starting the algorithm, we first introduce a few concepts related to commodity Futures. Backwardation is defined as conditions when the Futures price is below the current spot price and contango as conditions when the Futures price is above the current spot price. The Futures term structure curve is a representation of the backwardation/contango rate for the different maturities of Futures contracts. This price gap between different maturity contracts is quantified as the roll return. The contango/backwardation rates are calculated by taking the price difference between the spot market price and the Futures contract price. This difference can be expressed as a percentage over the time to expiration and then annualised to calculate an annual roll return.

\[R_t = \left[ln(P_{t,n})-ln(P_{t,d})\right]\times\frac{365}{N_{t,d}-N_{t,n}}\]

Where \(P_{t,n}\) is the price of the nearest-to-maturity contract at time \(t\). \(P_{t,d}\) is the price of the distant contract at time \(t\). \(N_{t,n}\) is the number of days between time \(t\) and the maturity of the nearby contract and \(N_{t,d}\) is the number of days between time \(t\) and the maturity of the distant contract.

Calculation of Roll Return

To calculate the roll return, first we sort the FuturesChain by expiry and select the first two contracts as the nearest-to-maturity contract and the the distant contract.

for symbol, chain in self.chains.items():
    contracts = sorted(chain, key = lambda x: x.expiry)
    # R = (log(Pn) - log(Pd)) * 365 / (Td - Tn)
    # R - Roll returns
    # Pn - Nearest contract price
    # Pd - Distant contract price
    # Tn - Nearest contract expire date
    # Pd - Distant contract expire date
    near_contract = contracts[0]
    distant_contract = contracts[-1]
    price_near = near_contract.last_price if near_contract.last_price>0 else 0.5*float(near_contract.ask_price+near_contract.bid_price)
    price_distant = distant_contract.last_price if distant_contract.last_price>0 else 0.5*float(distant_contract.ask_price+distant_contract.bid_price)
    if distant_contract.expiry == near_contract.expiry:
        self.debug("ERROR: Near and distant contracts have the same expiry!" + str(near_contract))
        return
    expire_range = 365 / (distant_contract.expiry - near_contract.expiry).days
    roll_returns[symbol] = (np.log(float(price_near)) - np.log(float(price_distant)))*expire_range

Backwardation and Contango

In the next step, we will split the Futures based on backwardation and contango. If the roll return is greater than 0, the term structure of commodity Futures prices is downward-sloping and so that the market is in backwardation. Conversely, a negative roll return signals an upward-sloping price curve and a contangoed market.

positive_roll_returns = { symbol: returns for symbol, returns in roll_returns.items() if returns > 0 }
negative_roll_returns = { symbol: returns for symbol, returns in roll_returns.items() if returns < 0 }
backwardation = sorted(positive_roll_returns , key = lambda x: positive_roll_returns[x], reverse = True)[:quintile]
contango = sorted(negative_roll_returns , key = lambda x: negative_roll_returns[x])[:quintile]

Algorithm Trade

The algorithm buys 20% of commodities with the highest roll-returns and shorts the 20% of commodities with the lowest roll-returns and holds the long-short positions for one month.

for short_symbol in contango:
    sort = sorted(self.chains[short_symbol], key = lambda x: x.expiry)
    self.set_holdings(sort[1].symbol, -0.5/count)

for long_symbol in backwardation:
    sort = sorted(self.chains[long_symbol], key = lambda x: x.expiry)
    self.set_holdings(sort[1].symbol, 0.5/count)


Reference

  1. Fuertes, Ana-Maria and Miffre, Joƫlle and Rallis, Georgios, Tactical Allocation in Commodity Futures Markets: Combining Momentum and Term Structure Signals (April 22, 2010). Journal of Banking and Finance 34, 2530-2548. Online Copy
  2. Quantpedia - Term Structure Effect in Commodities