Hi there,
I recently started working on an algorithmic trading video series using Python and the QuantConnect platform. You can check out the full series on YouTube here. I am adding more videos on an ongoing basis.
Below, I attached the backtest and code from the 4th video of this series. To copy the code, simply click the "Clone Algorithm" button at the top right corner of the backtest.
Let me know if you have any questions or comments.
Louis
.ekz.
Thanks for all the great educational content, Louis!
I send all my other quasi-quants / wannabe-quant friends to your videos. Always great stuff.
Louis
Thank you very much for the award and positive feedback!
Edinson Leandro Medina Alfonzo
Thanks for sharing your knowledge in these videos. Are you going to continue uploading more videos?
Louis
Yes, I will continue uploading videos. If everything goes well, this series could easily have 20+ videos. But since future videos are longer and include more coding and more advanced topics, they take a little longer to make.
Edinson Leandro Medina Alfonzo
Great! I will be attentive to the next videos of your YouTube channel.
Greetings!
Brandon Schleter
Thank you. I was wanting to include something similar to this parameter actually earlier this week, and was thinking cleanest way of doing it. Thanks for doing my heavy lifting.
Lei Humble
Great work. Appreciate @ Louis 😊
Please keep adding more good content.
PauPadilla Greendry
Yeap, Great Work and continue with your content! :)
S_Co46
Louis
Thanks for the comment. Yes, you can specify a specific time to rebalance, however, note that this algorithm uses daily data, so to accomplish that, you would have to switch to a lower resolution.
After that, an easy way to accomplish this, would be to used scheduled events and schedule a rebalancing function at your desired time.
I hope this helps.
Spacetime
you may come across below error:
Runtime Error: AttributeError : 'NoneType' object has no attribute 'Close'
at OnData
price = data[self.spy].Close
Solution:
Lars Klawitter
Hi Louis,
many thanks for consistently sharing great content - much appreciated!
Having looked at most of your tutorials, I noticed that sometimes (like in this example) you are using DataNormalizationMode.Raw.
I always use Adjusted to make sure to account for splits and dividends in historic data, so I've been wondering under what circumstances Raw would be needed.
I can see why it makes sense to look at an unadjusted price in your Take Profit example as you need to determine your profit. But would Adjusted even have the potential to change the price when it comes through as a data slice in OnData?
I would have thought that Adjusted only changes historical data to account for splits and dividends so that the history is consistent with the situation coming through in OnData. But maybe that's a misunderstanding?
I'm currently working on an ML algorithm that uses features derived off a few years of daily price data. Could Adjusted introduce the risk of look ahead bias here? i.e. can you see a reason why I should not be using Adjusted for this purpose?
All the best
Lars
Van Quoc Nguyen
Hi Louis,
a fellow trader, and computer science enthusiast here. Love the series. I finished (except for the Tiingo lesson) the Bootcamp on QuantConnect and just started with your course. I love the way how you edited the video with clearly illustrated examples. Makes it for visual learners a lot easier to grasp the concept. I just finished lesson 4 Handling data but came across something weird when running the backtest.
There is a difference in the backtest result between my equity curve, max. profit, PSR, etc, and the one in your video. I used the exact code, but somehow it yield a different result. It makes me worried about the reliability of the backtest engine itself. Do you know where this is coming from? I was thinking maybe it has to do with the LEAN engine version of the current master branch. Hope you can shine some light.
Hope you can shine some light. 😊
Dante Venafro
I’m using Verified Email
by Unum ID to verify who’s sending me emails.
Could you please verify yourself, so your emails are marked as *✅ Verified*
and stand out in my inbox? I’ll receive your email regardless — but it
takes 30 seconds to verify, and you’ll only need to do it once.
Here is your verification link
(You can also copy/paste unumid.co/verify into a browser.)
Thank you!
Dante
*P.S. If you have any trouble, just reply to this email and you’ll be
connected to Unum ID support.*
Sent by a Verified
[image: Sent by a Verified Unum ID Sender]
Unum ID Sender
Algo_dude
Van Quoc Nguyen You are using 5% take profit - he is testing 10%
Van Quoc Nguyen
algo_dude Thanks for pointing this out.😊
Hans C.
If in backtest error message comes up “ 'QCAlgorithm' is not defined”,
add in the first line the following code:
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.
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!