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
LoganW
Please see this back test of a simpler algorithm with the exact same futures contracts data lines that is working
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.
Louis Szeto
Hi LoganW
There could be slices that contains no FutureChains data due to numerous reasons like non-regular market event or no data at that time. If that is the case on the first OnData call, the line “self.liquidContract = sortedByOIContracts[0]” will not be run, causing that error. We recommend adding a check after the for-loop:
Best
Louis
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.
Shile Wen
Hi Zach,
The algorithm has many technical and stylistic issues, and since it seemed to be a popular algorithm, we've rewrote it to use the SymbolData pattern, replaced the History calls with RollingWindows, and fixed many stylistic issues. Please view the updated algorithm in the attached backtest.
Best,
Shile Wen
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.
Zach Oakes
Thanks ! It's very cool. It's like an MR take on Trend -- brilliant interpretation, and MUCH nicer than my translation.
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.
Mohamed Ajmal
How can we implement stoploss / reduce drawdown in this algorithm?
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.
Varad Kabade
Hi Mohamed Ajmal,
In the last backtest attached by Shile he has implemented the stop-loss which is triggered every day after 10 minutes of market open:
Refer to the following code snippet.
Best,
Varad Kabade
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.
Andres Arizpe
This appears to be a very interesting algo.
Is there any documentation I might use to get a basic understanding of it?
Cheers,
Andres
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.
Varad Kabade
Hi Andres Arizpe,
The above algorithm consists of components like the scheduled events, rolling window, and standard python libraries like numpy and pandas. We recommend going through the following docs[1, 2], and regarding the libraries, please look for their homepage/documentation. Please feel free to ask any specific doubts about the above algorithm.
Best,
Varad Kabade
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!