Hello,
Sorry in advance for the noob question, I am coding my first algos on QC :)
While I am implementing my trading logic in the OnData() method, I'd like to get some returns in the console, print variables, check their types, etc... I also want to check my code constantly so as to be sure I didn't mistype anything, etc..
To give one concrete example, I am coding a Futures algo and the future contract chain structure is as follow:
def OnData(self, slice):
for chain in slice.FutureChains:
for contract in chain.Value:
pass
I'd like to be able to display the length of each chain, the volume of each contract, check by myself the type of a chain, etc..
Currently, when I am coding my OnData() method I am completely in the dark, and the only way I find to get some returns is to run a full backtest and print some Logs.
The research environment seems to be there also for that purpose, but as the OnData() method and its variables are not available there, it doesn't help much.
Is it for instance possible to get only one slice of data in the research environnement so as to check whether the OnData() code is correct and access the variables before pasting the code in main.py?
Thanks for your help
Adam W
The Debugger tool can be very useful here. If you're unfamiliar with VSCode Debugger take a look at this. Basically you click the line numbers (set breakpoints), and then you can execute the code step-by-step while inspecting variables interactively.
Jonathan Krief
Thanks for your answer Adam 😊
So that would mean I have to install LEAN locally right? Is it the preferred way to build serious algos on QC or do most people use QC terminal?
I am much more familiar with PyCharm (and DataSpell from the same company which allows to run notebooks in an IDE environment). Do you think it's possible to use those IDEs instead of VSCode?
Generally, I have almost always been working on Jupyter Notebooks in the past, running my code chunk-by-chunk, checking my code at every step, inspecting and dissecting the variables… If there is a way to build my algos by first coding them in a notebook I would still prefer to do so.
Currently, I am getting crazy by running backtests after backtests every time I need to check something in my code. I guess that's not the proper way to code on QC and I am wondering how most people proceed to build their trading logic in OnData()…
Adam W
If you're on the new v3 QC environment (in account settings), you can actually just use the Debugger on here. The button to the right of “Backtest Project” starts up the debugger after you select some breakpoints (think of the code in between breakpoints as a chunk).
On the far right side of the cloud IDE, you should also see a “Run and Debug” icon. The `Variables` table lets you inspect the current variables in the scope, and you can also interactively inspect/run expressions under `Watch` (e.g. checking the length of something). Let me know if that isn't clear.
I enjoy running the code chunk-by-chunk in Jupyter as well. Personally, my workflow consists of 1) Prototyping strategies locally (using data downloaded from the LEAN CLI) in Jupyter with simple vectorized backtests, 2) Rewriting the code for production/into the LEAN API format, 3) Backtest on QC Cloud
Jonathan Krief
Ok, it's a great answer, I understand better how to proceed now, thank you.
A few points:
For the rest I will study your answer more thoroughly before coming back if needed
Jonathan Krief
Jonathan Krief
Please,
where do I check for and change my environment version? I can't find anything neither in my terminal or in my settings page
Adam W
I think you are probably on v3 already. At some point it was in beta and an optional toggle, but possibly QC has rolled it out officially.
Are you still having trouble with the Debugger? Take a look at this help page or perhaps this video.
Try this to get the hang of it:
Jonathan Krief
Thanks again Adam for this very helpful answer, the links and the detailed explanation are exactly what I needed :)
How come the documentation v2 is so well hidden ? Until I got some links from you I couldn't find it on the website?
Louis Szeto
Hi Jonathan
The docs v2 is still under editing and not officially released yet, so it is “hidden”. But no worries, it will be published shortly. 😊
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.
Jonathan Krief
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!