Hello,
I am running a backtest and my `data` variable contains a single symbol (in this case DWAC which is now DJT) and when I do data[symbol] it is null. I hypothesized that this might be because there is some other change that happened to the stock at the time I am testing. So, I looked into it and found out that the stock was changed tickers a day or two after that. How can this happen?
Mia Alissi
Hello Bryson,
In QuantConnect, when a stock changes its ticker symbol, the data associated with the old symbol will not be updated to the new symbol. This is because the data is associated with the specific symbol at the time it was collected.
However, QuantConnect provides an event handler
OnSymbolChangedEvents
that provides information on ticker changes. This can be used to handle such situations in your algorithm. Here is an example of how to use it in Python:In this example,
symbol_changed_events
is a dictionary where the key is the old symbol and the value is the new symbol. You can use this to update yourdata
variable when a symbol change occurs.Also, it's a good practice to check if the data for a symbol exists before accessing it. You can do this by using an
if
statement like this:This will prevent your algorithm from throwing an error when the data for a symbol is
None
.Sources:
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.
Bryson Reaume
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!