Hey hey hey!
Late last night we launched our newest feature: Universe selection. This allows the algorithm to define the universe of symbols it would like to receive data for by specifying a function that returns the symbols! QuantConnect currently provides what we call 'coarse' universe selection data. This is an aggregate of daily that includes the daily close, daily volume, and the dollar volume (daily close * EMA30(volume)).
You can add coarse universe selection criteria by using the AddUniverse method. Here's an example of adding a coarse universe selection that takes all symbols with a daily dollar volume of over $1 billion:// in Initialize()
const decimal OneBillion = 1000m*1000m*1000m;
AddUniverse(coarse =>
{
return from c in coarse
where c.DollarVolume >= OneBillion
select c.Symbol;
});
What this code means is that we want to filter the complete unverse of US equity symbols by selecting all symbols with a DollarVolume >= OneBillion! We'll automatically handle pumping the right data for your selected symbols in your OnData method. Also, we won't remove securities that have open orders or positions.
Have a peek at the attached demo coarse universe algorithm example. We welcome feedback and questions!
Jonathan Evans
Michael Handschuh
Max_leverage_yolo
Michael Handschuh
Nat Miletic
Jared Broad
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.
Travis Teichelmann
When I add the top method to Initialize I receive a message that OneBillion doesn't exist in the current context. I've tried changing it to an integer and looking for members that in DollarVolume property but couldn't find anything. Any thoughts?
Michael Handschuh
You can add
const decimal OneBillion = 1000m*1000m*1000m;
. It's just a constant to find stocks with volumes over a billion, Likewise, you could change the volume filter to anything you like!Travis Teichelmann
Perfect! Thank you for updating the code. I modified what you provided to filter the securities based on price. Now all I need to do is implement a gap up and gap percentage method then I can move on to other parts of my algo. Here's what I did.
Stephen Oehler
So this might be a dumb question, but can you apply indicators to the coarse universe selection function? Wondering if I could say, for example, "grab all stocks whose 1-year momentum percent is greater than 10%". :-) Excellent work guys!
Stephen Oehler
Ah found it in an older thread, sorry about that! For those who come here wondering the same thing, here is how you conduct technical analysis in the Coarse Universe filter: https://github.com/QuantConnect/Lean/blob/master/Algorithm.CSharp/EmaCrossUniverseSelectionAlgorithm.cs
Travis Teichelmann
Stephen - You can use indicators on the universe selection, that's actually what I'm working on right now. I've been using the link you provided in another post. https://github.com/QuantConnect/Lean/blob/master/Algorithm.CSharp/EmaCrossUniverseSelectionAlgorithm. Community - I've been looking at the LogReturns indicator and found a way to compare the difference in the current price with yesterday's close. Translating those findings into the coarse universe selection is a bit more tricky. Similar to what Stephen was saying, I want to scan the entire universe for stocks that have gapped up. Then scan those to find ones that have the highest gain. This is one of the biggest parts of my strategy and I've been working on it for a while. So if you could point me in the right direction or give me an example that would be fantastic. Best, -Travis
Michael Handschuh
Hey Travis, you don't need to copy all of your indicators into the project. They should be available without adding the file. Sadly the gap open condition requires open and close prices, but the coarse universe data set only has the daily closing price, so I'm not sure you can detect gap up/down on open. If you're just looking for stocks that had the largest one day gains, take a look at this example algorithm. I used the WSJ top gainers page to find stocks that gained the most in one day... and then shorted them!
Stephen Oehler
Hi Michael, Quick question for ya: If you have indicators that are being used within the Coarse Universe Linq statement, are your indicators updated daily or are they updated at the pace of the Universe Resolution? Example of the indicators being declared and updated within the Linq statement: https://github.com/QuantConnect/Lean/blob/master/Algorithm.CSharp/EmaCrossUniverseSelectionAlgorithm.cs I'm getting too-good-to-be-true results in my algorithm. It uses a certain indicator that requires 20 days of daily data. My Universe resolution is set to minute though, and I'm wondering if I'm getting a self-fulfilling prophecy problem here (maybe benefiting from fill-forwarding?).
Travis Teichelmann
Micheal - Can you backtest live data or is it exclusive to live mode? I've tried to run this algorithm live and made sure the links to WSJ were functional though no trades are being made. I was also inspecting the HTML on the site to find more data to parse. It doesn't seem to be pulling in any data even after I left it running overnight. Trying to run a price filter where d.Price
Stephen Oehler
Hi Travis, I thought I saw someone use custom data with their backtest. Is that the same as "live data" in this case? https://www.quantconnect.com/forum/discussion/418/bubble-algorithm-using-cape-ratio-macd-and-rsi#Item_12 Hopefully I'm not misunderstanding you!
Michael Handschuh
When using indicators in any universe selection function, they will be updated at the same frequency as the universe gets updated. In the case of coarse universes, they will update on a daily time frame. Another thing to note is that we do not apply fill forward to universe selection. If you need more help please post an algorithm demonstrating your issue/concern.
Michael Handschuh
Travis - I'll run the algorithm over this evening with some debugging to see if things are working as expected. Did you make any changes to the example algorithm? I'm not sure what you mean by 'backtest live data.' The NyseTopGainers custom data type is written to support both live and backtesting cases. It supports the backtest case by hitting dropbox (I made a small script to scrape the pages and built a csv from it)
Stephen Oehler
Great, thanks for the validation, Michael!
Michael Handschuh
Clarification on my above statement: We don't apply fill forward to the universe selection data itself, but subscriptions added via universe selection can be set to have fill forward data using the UniverseSettings.FillForward property. This is set to true by default.
Michael Handschuh
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!