Strategy Library
Momentum Effect in Commodities Futures
Method
As the strategy needs the continuous futures contract, we import the custom data from Quandl. We create a universe of tradable commodity futures from all available commodity futures traded on CME and ICE. They are all liquid and active continuous contracts #1. The data from Quandl are non-adjusted price based on spot-month continuous contract calculations. The data resolution is daily.
The first step is importing the data.
from QuantConnect.Python import PythonQuandl for symbol in self.symbols: self.AddData(QuandlFutures, symbol, Resolution.Daily) class QuandlFutures(PythonQuandl): def __init__(self): self.ValueColumnName = "Settle"
Here we use the indicator RateOfChange(period)
to simulate the momentum return. Here the period is 12 months.
As we are using the custom data, the indicator initialization should use the history request to update the value manually.
All indicators are saved in the dictionary
self.roc
.
self.roc = {} for symbol in self.symbols: self.AddData(QuandlFutures, symbol, Resolution.Daily) self.roc[symbol] = RateOfChange(period) hist = self.History([symbol], 400, Resolution.Daily).loc[symbol] for i in hist.itertuples(): self.roc[symbol].Update(i.Index, i.value)
In OnData(self, data)
, indicators for all futures contracts are updated every day with the settlement price.
We rank the contracts by the last 12-month return and divide them into quintiles. In the trading part, the algorithm goes long on the quintile with the highest momentum return and goes short on the quintile with the lowest momentum return. The portfolio is rebalanced each month.
You can also see our Documentation and Videos. You can also get in touch with us via Chat.
Did you find this page helpful?