Goal: Filter by ticker length of ≤ 4 characters or if it contains ‘"." in the ticker. (Python solution)
A problem is the hash code after the ticker, for example, QRTEA WSRW88XX4PR9. I would want to filter this ticker out because it has more than 4 characters. An example of a ticker with a “,” is ACER.W
Why? I do this because tickers that have more than 4 characters sometimes denotes that they have bankruptcy proceedings or “.” means they have special voting rights, classes, or warrants attached to the shares. I don't want any of these in the algo.
More about ticker lengths and letter meanings.
Nico Xenox
Hey Justin E
I'm guessing you want to do that with an universe. For that you can simply check the length of the Symbol Value.
This will put every Symbol with less or equal of 4 characters into a list.
Justin E
Hi Nico-
I implemented this in the coarse filter as follows. It doesn't seem to work as I'm finding tickers of > 4 characters and it seems to be getting many of the ticker lengths wrong. I log the ticker followed by the count of the # of characters in the scheduled event that finds my symbol targets before the next trading day, as you can see in my screenshots below.
Another oddity is the logs from OnSecuritiesChanged added securities don't match the same “Data” array later. For instance, HGMCY was never found in the OnSecuritiesChanged log but somehow was printed in the Scheduled Event “Scan Targets”.
Any ideas about what's going wrong?
Nico Xenox
Hey Justin E
Thats weird, it worked when I tried it with my example. Did u check the length of the self.Data.keys? Is it the same as the length in the returned symbols from the coarse filter?
Justin E
Hi Nico Xenox
I attached the backtest.
Issue #1: Some tickers have wrong character lengths.
Issue #2: Tickers are mysteriously appearing or not appearing. ( “Added to universe” and “Symbols in Data dict:” should match tickers, but they don't)
Tickers appear or disappear when being added to arrays
Wrong character count
Nico Xenox
Hey Justin E
Justin E
Hi Nico Xenox
You're right! That was my issue, I now see that len(symbol.Value) is correct when also logging symbol.Value.
Just so I understand, if I were going to search one of these tickers in Yahoo Finance, I would be searching for the symbol.Value and not the symbol, correct? In your example, DNA is the ticker I would search on Yahoo Finance and not SRNG, right? If so, why are they different whereas others are mostly identical/matching?
Nico Xenox
Yes that is correct. The ticker in the hash code symbol.symbol represents the first ticket name. So DNA was once named SRNG or it merged together. I don’t know the past of that company. Whereas other companies have not changed there ticker and still trade under the same name.
you can read more about this here.
Hope it helps ;)
Please consider liking and closing this thread if your happy with my answer.
Justin E
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!