Hi everyone,
I just wanted to share the 10th video of my free algorithmic trading course with you. In this video, we look at how to analyze and evaluate the performance of your trading bots. If you are new to the series, you can check out an overview of all the videos here.
You can clone the code from this video from the backtest that I attached below.
Let me know if you have any questions or comments.
Cheers,
Louis
Vladimir
Louis,
In your example code, when I replaced "SPY" with "QQQ" on line 7,
I got an AttributeError: 'NoneType' object has no attribute 'Price'.
Why?
Spacetime
need to check data before accessing it
below code can help
Vladimir
Spacetime
Thank you for your response.
Why the original data check
if not self.sma.IsReady or self.spy not in data or self.bnd not in data: return
is good for "SPY"
or if I use price = self.Securities[self.spy].Price?
Spacetime
I do not know the reasons why. Maybe someone more knowledgeable can shed some light.
Dan Root
Love the series, keep up the good work!
Varad Kabade
Hi Vladimir and Spacetime,
It's possible for
to be false and
is still true
Sometimes although the key for a security may be available in the slice data, the bar data for that security may not be available. For example, this may happen when non-price(splits,dividends, etc) data is available for that symbol while bar data is not.
Best,
Varad Kabade
Spacetime
Varad kabade ,
thank you for explaining it
it makes more sense now
Vladimir
Warad Kabade,
which code is more reliable
if data[self.spy].Price >= self.sma.Current.Value:
or
if self.Securities[self.spy].Price >= self.sma.Current.Value:
Varad Kabade
Hi Vladimir,
We recommend using
instead of
because the latter contains the price at which the asset was traded at last, which may not be ideal if the current data does not contain any TradeBar for the given asset. However, in general, they have the same value, so we can use the latter if we only care about the security price no matter when it was recorded.
Best,
Varad Kabade
Vladimir
Varad kabade,
Thanks for reply
If
We recommend using
if data[self.spy].Price >= self.sma.Current.Value:
instead of
if self.Securities[self.spy].Price >= self.sma.Current.Value:
then
why I get
AttributeError : 'NoneType' object has no attribute 'Price'
if I change on line 7 "SPY" to "QQQ"???
Spacetime
Vladimir , you still have to check data before accessing it
Varad Kabade
Hi Vladimir,
The above error occurs because even though the current slice Object (data) consists of data for our given symbol, it is non-trade data (Splits, Dividends, Delistings, etc.) hence data.Bars[symbol] is a null-type object. Refer to the attached backtest for the above demo.
Best,
Varad Kabade
Vladimir
Varad kabade
I have never seen such a long data test in any public algorithm.
if not self.sma.IsReady or self.spy not in data or self.bnd not in data:
return
if self.spy in data.Splits or self.spy in data.Dividends or self.spy in data.Delistings and self.spy not in data.Bars:
return
Last two questions:
Why in the original algorithm published by Louis SPY does not issue a warning without this lengthy test?
Where in the documentation is it explained?
Daniel Wash
Thanks for doing these videos, really helpful 😊
Varad Kabade
Hi Vladimir,
Why in the original algorithm published by Louis SPY does not issue a warning without this lengthy test?
This happens because when self.spy in data.Dividends is true, consequently data[self.spy] is None. During the backtest interval in the original algorithm by Louis, there is no event of type Dividend. Therefore, we don't encounter the error. We don't need a long test; I was just describing how the TradeBars and QuoteBars are not the only data event in our Slice object. The following test is enough:
Where in the documentation is it explained?
Please refer to the following doc for information regarding different data events. Refer to the attached backtest.
Best,
Varad Kabade
Mitch Christow
Hi Louis,
Absolutely amazing video series. Thanks for creating these great tutorials. Are you planning on creating more videos or is the series completed? I would really like to see a tutorial that covers how to write custom modules for the algorithm framework from scratch. It would be great to have a video on how to create a custom class for each framework module (universe selection, alpha creation, portfolio construction, execution, and risk management). Is that something that you are planning on creating? Thanks again for these fantastic tutorials.
Cheers,
Mitch
Louis Szeto
Hi Mitch
While waiting for Louis’s video series updating, we also have examples of custom modules of our framework. They’re well-explained and could be easily mimicked. Please find them on the Alpha Framework docs’ top boxes on each modules’ page, or in this collection. Also, implementation of their structures could be found here (alpha, portfolio construction, execution, risk management). We encourage members to try and build their own ones. Practice makes perfect!
Best
Louis Szeto
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.
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!