Hi All,
Started looking into QuantConnect today and have a couple of basic questions after the first few boot camp tutorials! It's my first post here, so thanks a lot for helping out a complete noob.
I'm looking at the second tutorial:
class BootCampTask(QCAlgorithm):
def Initialize(self):
#1-2. Set Date Range
self.SetStartDate(2013, 10, 7)
self.SetEndDate(2013, 10, 11)
self.AddEquity("SPY", Resolution.Daily)
def OnData(self, data):
pass
I have 3 questions:
- I assume the BootCampTask class inherits its methods and attributes from the QCAlgorithm class, i.e. the methods self.SetStartDate, self.SetEndDate, self.AddEquity() and self.SetCash() are nothing more than methods defined in parent class QCAlgorithm and hence accessible with self (although they don't seem to follow standard python naming conventions)?
- I then tried looking under the hood to see what these methods actually look like, but couldn't find a python class QCAlgorithm on github containing them. I did find one that's written in C# (here) but unsure if this is the method that's ultimately called and how it would work across languages (assume there must be some kind of "conversion" in between)?
- I was also wondering what happens in the back-end when we hit "Submit"? I assume QuantConnect makes an instance of the BootCampTask class and then calls the Initialize() and OnData() methods.. I assume that's why we always have to include those two and give them the same name?
Matt S
In general, it would be very helpful if somebody could direct me to a source (be it a webpage, webinar, ...) that explains to beginners how the LEAN engine works and how all components fit together. If this doesn't exist yet, I think it would be extremely beneficial for everyone starting out to create something like that! At this moment, the github that contains the LEAN code is just a collection of files and folders to me.. Many thanks!
Conor Flynn
Hey Matt,
I'll do my best to answer your questions and hopefully help you understand QuantConnect a bit better!
1/2) You got the essential gist of the methods correct. They are used to help set up the parameters for your backtest so that you observe and test the proper data. SetStartDate(), SetEndDate(), and SetCash() never really need to be accessed just called as they define the dates/starting cash for your backtest (they act as "setter" methods). AddEquity() is a little more complex as what it is telling the engine to do is to get the data stream for that equity based on the resolution you choose. Overall, there isn't really much need to see what is going on behind the scenes so long as you understand how these functions operate.
3) The reason you always have to include these methods are because they are the core of your program. Initialize() is essentially a Constructor + Main Method combo. It is where you set up all of your variables as well as the backtest parameters and initialize your data streams. This runs one time at the start of the backtest or program initialization. OnData() is a little bit different, it runs whenever there is an update in the data and is based on the resolution of your data. Say for example you set your resolution to hourly when calling the AddEquity() method, it would then run once every hour, on the hour. It is used to observe the data at the time and is mainly where orders are placed and where calculations are made.
Hopefully this all makes sense and let me know if you have any more questions!
-Conor
Matt S
Thanks a lot Conor, this is extremely helpful! Quite a number of new concepts from me here, so time to start digging. I'm sure I'll be back with more soon!
In the meantime, if anybody else knows a general source that explains to beginners how the LEAN engine works, please let me (and other beginners of course!) know. Many thanks.
Matt S
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!