I would like one of my universe filters to be based on avg volume (shares) , not dollar volume. Is there any way to do this? Thanks
QUANTCONNECT COMMUNITY
I would like one of my universe filters to be based on avg volume (shares) , not dollar volume. Is there any way to do this? Thanks
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.
Gurumeher Sawhney
Yes! When using QuantConnects universe selection the data can be filtered by getting todays total volume using CourseFundamental.Volume. This is by using the coarse selection function, which passes CoarseFundamental objects for filtering. In the backtest below you can see an example on how the coarse selection is used:
Jarrod Holder
It seems the original questions is related to average volume over a given time. I am also having issues with this. The code below always returns 0.0 for average volume and I do not know why. Any help is appreciated.
AddEquity("SPA", Resolution.Daily); var avgVolume14Days = SMA("SPA", 14, Resolution.Daily, x => ((TradeBar)x).Volume); Console.Write("avgVolume14Days: " + avgVolume14Days);
// Console displays avgVolume14Days: 0.0
Gurumeher Sawhney
When trying to implement the code above I was receiving the correct output. If the SMA value was outputted right after its initialization, then the value will be 0 since indicators are not ready when you first create them. The indicators will be ready based upon their period and their status can be checked via indicator.IsReady. Once the data is fed into the SMA, the correct values exist. The algorithm below is how the SMA should be implemented:
Jarrod Holder
Thanks for the reply. It appears that since the data for SMA is only accessible after the OnData function has fired, you wouldn't be able to use that information in a Universe creation filter. Correct?
What I ended up doing was creating a getAvgVol function:
// Symbol and Volume from Universe coarse filter private decimal getAvgVol(Symbol sym, decimal volume) { // Symb decimal totalVolume = 0; var hist = History(sym, TimeSpan.FromDays(14), Resolution.Daily).ToList(); foreach(var tb in hist) { totalVolume += tb.Volume; } return totalVolume > 0 ? volume/totalVolume : 0; }
Vidal boreal
Hi Gurumeher Sawhney,Â
I have the same problem when screening stocks with 20 days average volume in the universe.
Is there any way to do it in python?
Jack Simonson
Hi KY,
There's a number of ways to do it in Python. You can do this inside of the Universe Selection functions themselves (Coarse or Fine), or you can create another function and call it inside Universe Selection. I've attached a backtest with an example of how you could perform this screening inside of Universe Selection. Hope this helps!
Vidal boreal
Thanks Jack. This help and it is just similar to the filtering of stock price above sma.
Mark Axmann
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!