Hi all, I've been using the techniques from boot camp to filter for the highest OI. This was working fine until I created a new project this morning and tried backtesting with the same code. It is now giving a run time error saying that .liquidContract does not exist.
Error Message:
[ERROR] FATAL UNHANDLED EXCEPTION:Extensions.SetRuntimeError(): Extensions.SetRuntimeError(): RuntimeError at 11/11/2022 2:30:00 PM UTC. Context: OnData Python.Runtime.PythonException: 'HyperActiveOrangeCat' object has no attribute 'liquidContract', File "/QuantConnect/backtesting/./cache/algorithm/project/main.py", line 96, in OnData, price = self.Securities[self.liquidContract.Symbol].Price, at Python.Runtime.PythonException.ThrowLastAsClrException(), at Python.Runtime.PyObject.Invoke(PyTuple args, PyDict kw), at Python.Runtime.PyObject.TryInvoke(InvokeBinder binder, Object[] args, Object& result), at CallSite.Target(Closure , CallSite , Object , PythonSlice ), at System.Dynamic.UpdateDelegates.UpdateAndExecuteVoid2[T0,T1](CallSite site, T0 arg0, T1 arg1), at QuantConnect.AlgorithmFactory.Python.Wrappers.AlgorithmPythonWrapper.OnData(Slice slice) in /LeanCloud/CI.Builder/bin/Debug/src/QuantConnect/Lean/AlgorithmFactory/Python/Wrappers/AlgorithmPythonWrapper.cs:line 632, at QuantConnect.Lean.Engine.AlgorithmManager.Run(AlgorithmNodePacket job, IAlgorithm algorithm, ISynchronizer synchronizer, ITransactionHandler transactions, IResultHandler results, IRealTimeHandler realtime, ILeanManager leanManager, IAlphaHandler alphas, CancellationToken token) in /LeanCloud/CI.Builder/bin/Debug/src/QuantConnect/Lean/Engine/AlgorithmManager.cs:line 523,ApiConnection.TryRequest(backtest/status/update): Error: The operation has timed out.
Stack Trace:
'HyperActiveOrangeCat' object has no attribute 'liquidContract'
at OnData
price = self.Securities[self.liquidContract.Symbol].Price
at Python.Runtime.PythonException.ThrowLastAsClrException()
at Python.Runtime.PyObject.Invoke(PyTuple args in main.py: line 95
Relevant Code
Initialize:
self.es = self.AddFuture(Futures.Indices.SP500EMini, Resolution.Tick)
self.es.SetFilter(5, 100)
OnData(self, slice):
# Sort contracts for highest Open Interest and create a variable for the highest OI
for chain in slice.FutureChains:
self.popularContracts = [contract for contract in chain.Value if contract.OpenInterest > 1000]
if len(self.popularContracts) == 0:
continue
sortedByOIContracts = sorted(self.popularContracts, key=lambda k : k.OpenInterest, reverse=True)
self.liquidContract = sortedByOIContracts[0]
# Variable for liquid contract price
price = self.Securities[self.liquidContract.Symbol].Price
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!