Hi,
First time posting here, so please be gentle. 😊
I am trying to use Lean CLI for python using VS Code. But the debugger does not stop at the breakpoint.
I went through various help articles and documentations, and also tried searching through google but still could not find the solution. It works fine if one has simple boilerplate example.
I went here to look for information but could not resolve it
here is an example code that I am using
+ Expand
from AlgorithmImports import *
class GeekyTanCat(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2021, 6, 24)
self.SetCash(100000)
self.Schedule.On(self.DateRules.EveryDay(), self.TimeRules.At(16, 1), self.TradingAfterMarketClose)
self.AddEquity("SPY")
def OnData(self, data):
self.Debug("In OnData Function")
pass
def TradingAfterMarketClose(self):
self.Debug("In TradingAfterMarketClose Function")
pass
I am trying to stop the debugger at “self.Debug …” but it never stops, neither it gives me any error for me to resolve it.
I would highly request somebody to make a You tube video on a somewhat complex tutorial. The one here does not tell much
(13) Debugging Python Algorithmic Trading Strategies in VSCode - LEAN CLI - YouTube
Please let me know if this is not the right place to post it, I would post it at the right place.
Thank you,
Avi
Jasper van Merle
Hi Avi,
I tried to reproduce your issue locally but my breakpoints do seem to get hit on the algorithm you provided.
What `self.Debug()` call are you setting the breakpoint on? If you're setting it on the one in OnData and it doesn't break, that may mean OnData isn't called because of missing local data.
Also, can you try setting a breakpoint on the `self.AddEquity()` call and see if that breakpoint gets hit correctly?
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.
Avi Dix
Thank you for your response.
As suggested I put a break point on self.AddEquity("SPY"). It hits that break point.
I can understand why it may not hit the breakpoint in OnData function. But it should hit the breakpoint in self.Debug("In TradingAfterMarketClose Function") when the function is called during the day at 16:01 hrs. It is not hitting the breakpoint at self.Debug("In TradingAfterMarketClose Function")
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 Avi,
Do you see “In TradingAfterMarketClose Function” in the logs after the backtest completes?
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.
Avi Dix
No I do not see any of the messages in the logs. I can upload the logs if you wish.
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 Avi,
That would be very helpful, please do.
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.
Avi Dix
Here is the log
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 Avi,
It seems like this is a data issue after all. If there's no data points for your algorithm to process, no events get triggered. If you change your algorithm slightly by setting the start date back 3 months and adding the Resolution.Daily parameter to the AddEquity call so it uses the SPY sample data we provide, the event does get triggered and your breakpoint should get hit.
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.
Avi Dix
Sorry, Could you please explain it a little more ? I have added SPY data, so it should have some data
What do you mean by Data ? I am trying to understand what exactly is wrong, so that I can solve the problem in future.
and the problems related to this issue
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.
Avi Dix
Thank you for your explanation, it makes sense. I will add the data and repeat the test.
Thank you for being patient so far and your prompt replies
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!