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Ā
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?
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")
Ā
Jasper van Merle
Hi Avi,
Do you see āIn TradingAfterMarketClose Functionā in the logs after the backtest completes?
Avi Dix
No I do not see any of the messages in the logs. I can upload the logs if you wish.
Jasper van Merle
Hi Avi,
That would be very helpful, please do.
Avi Dix
Here is the log
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.
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
Ā
Ā
Ā
Ā
Jasper van Merle
Hi Avi,
I mean that if your algorithm doesn't have to process any data during a backtest (because it doesn't subscribe to anything or because you don't have the required data on disk), the scheduled events don't get fired.
What data did you add and where? Your algorithm subscribes to SPY minute and hourly data, but from the lack of āIn OnData Functionā messages and the following log line it is clear that LEAN is not able to find such data in the date range of your backtest:
2021-07-28T15:56:24.0149633Z TRACE:: Debug: Algorithm Id:(main) completed in 0.86 seconds at 0k data points per second. Processing total of 1 data points.
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
Avi Dix
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!