LEAN is the open source
algorithmic trading engine powering QuantConnect. Founded in 2013 LEAN has been built by a
global community of 80+ engineers and powers more than a dozen hedge funds today.
Alpha League Competition: $1,000 Weekly Prize Pool
Qualifying Alpha Streams Reentered Weekly Learn
more
Hello there! I'm new to QuantConnect and this is my first post. I am trying to figure out how to use coarse universe selection to give me a basket of stocks to work with each day. Specifically I would like to filter stocks by looking at the values of various indicators, kind of like a stock scanner. I found the EMA cross universe selection example which I have been using as a starting point. However, it looks like the CoarseFundamental object has only one price point. Unless I'm missing something, this limits my filtering options when it comes to using indicators. How would I go about filtering by an indicator like ATR (or NATR), which would require more information, specifically the open, close, high, and low?
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.
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.
Currently, Coarse Universe selection only have closing price:
class CoarseFundamental {
public long Volume; // Traded shares
public decimal DollarVolume; // Traded shares x Price
public decimal Price; // Yesterday close price
public Symbol Symbol; // Asset symbol
}
In order to use bar indicators (those that need OHLC), you will need to add securities to the universe. When securities are added and removed from an universe, OnSecuritiesChanged event is triggered and we can make a History Request and update the bar indicator:
private List<Symbol> _allowedSymbols;
public override void OnSecuritiesChanged(SecurityChanges changes)
{
// Create a list of ATR
var atrList = new List<AverageTrueRange>();
foreach (var security in changes.AddedSecurities)
{
// Creat an ATR and update it with Historical data
var atr = new AverageTrueRange(security.Symbol, 14);
foreach (var bar in History(security.Symbol, 20, Resolution.Daily))
{
atr.Update(bar);
}
atrList.Add(atr);
}
// On the two symbols with the lowerest ATR are allowed to be traded
_allowedSymbols = atrList.OrderBy(x => x).Select(x => x.Name).Take(2).ToList();
}
Finally in OnData, we will use _allowedSymbols filter which symbols to trade.
1
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.
Thanks Alexandre. I gave up trying to do any kind of advanced filtering with universe selection, and now I'm focusing on keeping track of indicators in a custom wrapper class and doing filtering in OnData, like you suggested. I ended up using a similar approach, guided mostly by your responses to another question about universe + history. I've found your code snippets to be very helpful!
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.
Loading...
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!
You do not have enough QC Credit to send this award, get a QC Credit Pack
here.
Award Sent Successfully
Thank you for giving back to the community.
Processing...
Choose a Credit Pack
Payment Confirmation
QuantConnect Credit (QCC) can be applied to your cloud-invoices or
gifted to others in the community with Community Awards in recognition of their contributions.
Community Awards highlight the awesome work your fellow community members are doing and inspires
high quality algorithm contributions to the community. Select an option below to add
QuantConnect Credit to your account:
$5
500 Credit Points
 
$10
1,000 Credit Points
 
$18
2,000 Credit Points
10% bonus
$45
5,000 Credit Points
10% bonus
03/23XXXX XXXX XXXX 0592
We will charge your default organization credit card on file, click
here to update.