Many thanks to Alexandre Catarino who pointed me at his PreMarketDailyUsEquityUniverse class from this thread: https://www.quantconnect.com/forum/discussion/1522/loading-symbols-at-specific-time It's exactly what I needed to help me load a universe at a specific point in time ahead of market open each day.
I'm running into something very strange though. I was trying to debug an issue (I really must learn how to run my algorithms in Visual Studio directly so I can properly debug) and found something very unsettling. I am [trying] to load the universe with 3 symbols (for prototyping purposes -- I'll add code later to load the real list of symbols, but I wanted to prove to myself the basic order of operations in the algorithm first). The symbols I'm loading are simply:
return new List<string> {"AIG", "BAC", "IBM"};
However, when I run the algorithm and dump some of the output via Debug to the console, I'm seeing I get different symbols in OnData, namely: AIG, BN, IBM. Where did "BN" come from? Where did "BAC" go?
When I change the list of symbols to: {"AIG", "CVX", "IBM"}, the list of items fed to OnData are "AIG", "CHV", "IBM". Where'd CVX go? Where'd CHV come from?
Surely, I'm doing something wrong ??? Anyone care to take a look at this backtest, see the list of symbols I'm trying to add to the backtest and then run the test and see the console output? I'm baffled.
Alexandre Catarino
The Symbol object represents a unique security identifier. This is made of two components, the unique SID and the Value. The value is the current ticker symbol while the SID is constant over the life of a security.
It is implictly converted into a System.String. When it is converted, we get the SID, not the Value. Since the SID is a constant, it contains the original ticker symbol, not the current (nor the one we subcribed to). BAC was Sep 30th 1998 NB until and CVX was CHV until Oct 09th 2011.
In order to get the current symbol, you need to modify your code, e.g.:
string symbol = item.Symbol.Value;
TedVZ
Ooooooh. I feel silly. OK, thank you so much for the prompt, clear and detailed explanation!
TedVZ
And, that totally explains the original problem i was debugging, which had to do with adding symbols to a Dictionary. I was treating the Symbol as a string and so I was running into cases where something I thought should be in the Dictionary, wasn't. Changing the Dictionary to type Dictionary<Symbol, ...> took care of that issue. Doh! Thanks!
TedVZ
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!