We have choosen a freely available strategy based on a scientific paper from Quantpedia to show how we can implement a strategy that requires a characteristic of an asset that is not found in equity, forex or CDF: the term structure. The term structure of futures contracts refers to the price curve formed by the prices of futures contracts over various expiration months.
The following strategy relies on the idea that commodity futures prices depend on the net positions of hedgers. The general message is that producers and consumers of the underlying commodity transfer the risk of price fluctuations to speculators, who are willing to undertake this risk in the hope of a large positive return. If the supply by short hedgers exceeds the demand by long hedgers (namely, hedgers are net short), the futures price today has to be a downward-biased estimate of the futures price at maturity. This is to induce speculators to take long positions in commodity futures markets. The increase in the futures price as maturity approaches is referred to as normal backwardation. Conversely, if hedgers are net long, the futures price today has to exceed the futures price at maturity to
persuade speculators to take short positions in commodity futures markets. The decrease in the futures price as maturity approaches is traditionally referred to as contango. Thus, normal backwardation and contango arise as a result of the inequality between the long and short positions of hedgers, which require the intervention of speculators to restore equilibrium. (source)
If commodity futures returns directly relate to the propensity of hedgers to be net long or net short, it becomes natural to design an active strategy that buys backwardated contracts and shorts contangoed contracts. The price gap between different-maturity contracts, called roll-return (R) or implied yield, can be used as a signal of whether a market is in backwardation or contango:
// 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
Simple trading strategy:
This simple strategy buys each month the 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. The contracts in each quintile are equally-weighted. The investment universe is all commodity futures contracts.
This exercise was an opportunity to use the TradingCalendar object, introduced with the Options and Futures Support, that informs us about a variety of events relevant to currently trading instruments.
Unfortunatelly, for the tested period, the strategy is not as profitable as announced at Quantpedia, where the period is 1979-2004. However, since there are a strong confidence in anomaly's validity, there is probably margin for improvement.
Note: this strategy was proposed by at this thread.
Alex Muci
Hello Alexandre Catarino,
would it be possible to have the same in Python?
Cheers,
A
TWI PropTrader
Alexandre,
Please can you attach an upto date strategy. The backtest keeps on failing in Q2/3 2016
Thanks
Alexandre Catarino
Frank Wilson, I ran the backtest from 2006 to yesterday (Nov 20th 2017) and it didn't fail.
Alex Muci, we will see if QC team can come up with a python version shortly and add it to the tutorials.
Alexandre Catarino
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!