When i am Backtesting my strategy Locally using Lean it gives the following Error :

Don't have an account? Join QuantConnect Today
QuantConnect Community Discussions
QUANTCONNECT COMMUNITY
LEAN is the open-source algorithmic trading engine powering QuantConnect. Founded in 2012 LEAN has been built by a global community of 180+ engineers and powers more than 300+ hedge funds today.
Join QuantConnect's Discord server for real-time support, where a vibrant community of traders and developers awaits to help you with any of your QuantConnect needs.
The Open-Quant League is a quarterly competition between universities and investment clubs for the best-performing strategy. The previous quarter's code is open-sourced, and competitors must adapt to survive.
Error in local backtesting with Lean due to Rolling Window issue.
Continue ReadingRefer to our Research Guidelines for high quality research posts.
Create an account on QuantConnect for the latest community delivered to your inbox.
Sign Up Today
|
|
|||||||
|
|
||||||||
|
Rolling Window not working Lean Locally
Ishant Jain | June 2021
When i am Backtesting my strategy Locally using Lean it gives the following Error :
QuantConnectâ„¢ 2025. All Rights Reserved
Ishant Jain
The above got resolved i was not importing the libraries,
but after that still i am unable to create a rolling window :
i am creating custom data class NIFTY :
but when i use the Add method to append the elemnts to rolling window,it shows the following error :
20210603 11:00:44.839 ERROR:: Runtime Error: Trying to dynamically access a method that does not exist throws a TypeError exception. To prevent the exception, ensure each parameter type matches those required by the Add method. Please checkout the API documentation.
at OnData in Test_Strategy.py:line 46 :: symbol.hist_window.Add(data[symbol].Value)
TypeError : No method matches given arguments for Add
Trying to dynamically access a method that does not exist throws a TypeError exception. To prevent the exception, ensure each parameter type matches those required by the Add method. Please checkout the API documentation.
at OnData in Test_Strategy.py:line 46 :: symbol.hist_window.Add(data[symbol].Value)
Can Anyone help on this ???
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 Ishant Jain,
Does the algorithm give the same issue in quantconnect.com ?. Please share a backtest highlighting the issue; the above code snippet is not enough to reproduce the issue.
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.
Ishant Jain
Hello Varad Kabade,
No in Quantconnect it doesn't have any issue, i guess it has some issue with the ADD function it accept the live data, that comes from(onData) in a particular format.
I realised this when i print the data[symbol] in onData method :-
As you can see data contains O H L C V format (Rolling window method ADD is working fine on this).
2. When i am running Lean Locally on my system and using a Customised class to read and Subscribe data symbol :
and then if i print the same using Log(data[symbol]) it shows this :
As you can see my data is not in printing in the format of OHLCV so i think its because of this the Add is not working.
Can You Provide any Solution with this Info ????
Best
Ishant Jain
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 Ishant,
It is possible you are missing the import statement for the RollingWindow, which can you do through
If that doesn't work, an alternative would be to use the built-in Python deque from the collections library.
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.
Ishant Jain
Thanks Shile for taking the time to answer the queries 😊!!
Thanks and Yes I was missing that statement.
But still when I am using a class to import Customised data the Add function(Rolling Window's) isn't working.
I think the problem is the Data for eg:
if I use any existing equity in data folder and use self.Log(data[ symbol ]) to print the data slice it shows like this:
On the other hand if I use Custom Data Class and use self.Log(data[ symbol ]) to print the data slice it shows like this:
My Custom class Reader Function Looks like this :
Can you please help why there is difference and how can I solve this Problem ??
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.
Jasper van Merle
Hi Ishant,
Are you still using the code in the screenshot of your first post to create the rolling window? If that is the case, try replacing `TradeBar` with the name of your custom data class in `RollingWindow[TradeBar](self.numdays)`.
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.
Mathew Blonc
was there ever a solution to this problem? This is also none functional for me too with exactly the same issue described above. The data from CustomData is not the same as from existing equity.
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.
Fred Painchaud
Hi All,
This looks like a type mismatch on the C# side (RollingWindow is implemented in C#). RollingWindow is a generic. Are your RollingWindows declared like this:
self.window = RollingWindow[PythonData](…)
?
PythonData is the superclass we use in Python to define Custom Data. That declaration SHOULD make the Add method work (exist).
Fred
P.S. Jasper already pointed in that direction.
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!