Hello guys,
I encountered this issue recently once i tried to work on futures in a FutureUniverseSelectionModel. I even splitted futures i need in to categories, based on exchanges they are traded. I separated them, to see where the issue is. Because if I dont use FutureUniverseSelectionModel, but initialize them separatly, it works.
I found on the forum here a answer, suggestion, but the thread was created some time ago. And it does not work anymore. Probably something has been changed.
Anyways here is a copy from the concole:
Runtime Error: SystemError : <bound method 'OnWarmupFinished'> returned a result with an error set SystemError : <bound method 'OnWarmupFinished'> returned a result with an error set (Open Stacktrace)
from FuturesUniverseSelectionModel import FuturesUniverseSelectionModel
class ParticleQuantumThrustAssembly(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2017, 1, 1) # Set Start Date
self.SetCash(100000) # Set Strategy Cash
self.UniverseSettings.Resolution = Resolution.Minute
self.SetUniverseSelection(FuturesUniverseSelectionModel(self.SelectFuturesSymbols))
self.symbol = {}
def OnData(self, data):
# Loop over each available futures chain from slice.FutureChains data
for chain in data.FutureChains:
self.popularContracts = [c for c in chain.Value if c.OpenInterest > 500]
if len(self.popularContracts) == 0: continue
sortedByOIContracts = sorted(self.popularContracts, key=lambda k: k.OpenInterest, reverse=True)
self.liquidContract = sortedByOIContracts[0]
under = self.liquidContract.UnderlyingSymbol
self.Plot("Future", str(under), self.liquidContract.LastPrice)
self.Plot("Volume", str(under), self.liquidContract.Volume)
self.Plot("OpenInterest", str(under), self.liquidContract.OpenInterest)
if under not in self.symbol:
self.symbol[under] = self.liquidContract.Symbol
if self.symbol[under] == self.liquidContract.Symbol: continue
else:
self.symbol[under] = self.liquidContract.Symbol
self.Debug(f"{self.symbol[under]} -- Expiry: {self.liquidContract.Expiry.date()}, {self.Time}")
def SelectFuturesSymbols(self, utcTime):
softTickers = [
Futures.Softs.Cocoa,
Futures.Softs.Sugar11CME,
]
energyTickers = [
Futures.Energies.CrudeOilWTI,
Futures.Energies.NaturalGas,
Futures.Energies.Gasoline,
Futures.Energies.HeatingOil,
]
metalTickers = [
Futures.Metals.Gold,
Futures.Metals.Copper,
]
currencyTickers = [
Futures.Currencies.CAD,
Futures.Currencies.JPY,
Futures.Currencies.CHF,
Futures.Currencies.EUR,
Futures.Currencies.GBP,
]
grainTickers = [
Futures.Grains.Wheat,
Futures.Grains.Corn,
Futures.Grains.Soybeans,
Futures.Grains.SoybeanMeal,
Futures.Grains.SoybeanOil,
Futures.Grains.Oats,
]
indexTickers = [
Futures.Indices.SP500EMini
]
indices = [ Symbol.Create(indexTickers, SecurityType.Future, Market.CME) for ticker in indexTickers]
energy = [ Symbol.Create(energyTickers, SecurityType.Future, Market.NYMEX) for ticker in energyTickers]
grains = [ Symbol.Create(grainTickers, SecurityType.Future, Market.CBOT) for ticker in grainTickers]
softs = [ Symbol.Create(softTickers, SecurityType.Future, Market.NYMEX) for ticker in softTickers]
metals = [ Symbol.Create(metalTickers, SecurityType.Future, Market.Comex) for ticker in metalTickers]
currencies = [ Symbol.Create(currencyTickers, SecurityType.Future, Market.CME) for ticker in currencyTickers]
# allTickes = indices + energy + currencies + grains + metals + energy + softs
return energy
################################
from Selection.FutureUniverseSelectionModel import FutureUniverseSelectionModel
from datetime import date, timedelta
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(180))
.OnlyApplyFilterAtMarketOpen())
Sergej Gorev
I found my error. It was just a typo in the creation of lists of symbols.
insted of
indices = [ Symbol.Create(indexTickers, SecurityType.Future, Market.CME) for ticker in indexTickers]
change to
indices = [ Symbol.Create(ticker, SecurityType.Future, Market.CME) for ticker in indexTickers]
Another thing is important as well. Market should be explicitly chosen for each future/ future group. You can get some information on which exchange each future is traded here.
Happy trading!
Jared Broad
Thank you for sharing the answer back to the community Sergej. I'll see about updating the documentation to include the right exchange.
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.
Sergej Gorev
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!