Is it possible to collect all of the stocks in the Universe in the Initialize method? I would like to add all of the securities whose dollar volume is greater than 90% on the first day of the backtest. The problem is that universe is not valid until after Initialize.
Is there another way of adding all stocks with a certain feature on the first day of backtesting?
public override void Initialize() {
// ...
Universe universe = Universe.DollarVolume.Percentile(90);
AddUniverse(universe);
Log("S: " + universe.Members.Count); // logs S: 0
foreach (Symbol s in universe.Members.Keys) {
AddSecurity(SecurityType.Equity, s, Resolution.Daily);
}
}
Jared Broad
Not really they way you're thinking -- since the backtest hasn't started by that point. But in "OnData" the backtest has started and you can use the security list. You could create a boolean and toggle it when you go into the method?
bool setup = false; public void OnData(TradeBars data) { if (!setup) { //Finish your algorithm setup setup = true; } }
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.
Jared Broad
Actually re-reading your post I think you're misunderstanding universes a little bit -- what you're trying to do in your code snippet happens automatically. Can you share more about what you're trying to achieve? Perhaps you only want daily data not minute data? This is done via the UniverseSettings object:
public override void Initialize() { UniverseSettings.Resolution = Resolution.Daily; }
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.
Sam Grayson
Now I see what you are saying. I like the `bool setup` thing because that gives me a hook to put code that I want to run once after data has become available.
Sam Grayson
I realized that the example I gave was a poor one, because as you said, that happens automatically.
Sam Grayson
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!