Back

Applying EmaCrossAlphaModel to a Universe of Futures

I am trying to adapt the EmaCrossAlphaModel to a large universe of futures, using the Algorithm Framework.

the algorithm is initialized by 

class MovingAverageCrossTrendFollowing(QCAlgorithm):

def Initialize(self):
self.SetStartDate(2019, 1, 1) # Set Start Date
self.SetStartDate(2019, 3,30) # Set End Date
self.SetCash(100000) # Set Strategy Cash
self.UniverseSettings.Resolution = Resolution.Daily
self.AddAlpha(MovingAverageCrossAlphaModel(50, 200, Resolution.Minute))

self.SetExecution(ImmediateExecutionModel())

self.SetPortfolioConstruction(EqualWeightingPortfolioConstructionModel())

self.SetUniverseSelection(FuturesUniverseSelectionModel(self.SelectFuturesSymbols))


def SelectFuturesSymbols(self, utcTime):
tickers = [Futures.Indices.SP500EMini,
#Many more futures
Futures.Dairy.NonfatDryMilk]
return [ Symbol.Create(ticker, SecurityType.Future, Market.USA) for ticker in tickers]

where 

FuturesUniverseSelectionModel(self.SelectFuturesSymbols)

just filters the futures by expiration date:

class FuturesUniverseSelectionModel(FutureUniverseSelectionModel):

def __init__(self, select_future_chain_symbols):
super().__init__(timedelta(1), select_future_chain_symbols)

def Filter(self, filter):
return (filter.Expiration(timedelta(0), timedelta(90))
.OnlyApplyFilterAtMarketOpen())

The Update method in MovingAverageCrossAlphaMode starts with a selection of the contract with the highest open interest per chain:

def Update(self, algorithm, data):
for chain in data.FutureChains:

#1. Filter to choose popular contracts with OpenInterest > 1000
popularContracts = [contract for contract in chain.Value if contract.OpenInterest>1000]

#2. If the length of contracts in this chain is zero, continue to the next chain
if len(popularContracts) is 0:
continue

#3. Sort our contracts by open interest in descending order and save to sortedByOIContracts
sortedByOIContracts = sorted(popularContracts, key=lambda k : k.OpenInterest, reverse=True)

#4. Save the contract with the highest open interest to self.liquidContract
liquidContract = sortedByOIContracts[0]

#5. Generate insights based on EMA crossings

return insights

As the attached backtest shows, however, the Update method is never called, despite the initialization

self.UniverseSettings.Resolution = Resolution.Daily

What is the problem, here? 

Update Backtest








0

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.


Hey Filib,

I created an Futures EMA cross over AlphaModel. Instead of the contract with the highest open interest, we track the front month contract of each futures chain. We will rollover to the new front month contract when each one expires. This way we can keep a continuous contract to reference each chain. Each time there is a new front month contract, we also use historical data to warmup the indicators because prices change between contracts.

We store all our indicator and rolling window data in SymbolData objects. But instead of keying the SymbolData dictionary by the contract's symbol, we key it by the chain's symbol. This way we can reference each chain with one contract.  

I hope you find this example useful. Please let me know if you have any questions or issues.

2

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.


Update Backtest





0

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.


Loading...

This discussion is closed