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
I want to know if it's possible to check for example at 10:00 the most traded stocks based on Volume of stocks traded. For what I understand this code is not doing that, because it checks for "yesterday" volume, not the volume up to 10:00 of the same day:
def MyCoarseFilterFunction(self, coarse):
sortedByVolume = sorted(coarse, key=lambda x: x.Volume, reverse=True)
filtered = [ x.Symbol for x in sortedByVolume if x.Price > 10 and x.Volume > 50000 ]
return filtered[:100]
What I want is to check for universe of stocks that have more than 50.000 volume traded (not dollars, number of stocks), at 10:00.
I can acomplish this only by setting up "MyCoarseFilterFunction" inside a scheluded function?
Appreciate someone can point me in the right direction.
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.
It is not possible to subscribe to security datafeeds through cumulative intraday volume filtering inside a universe selection method. However, we can create a workaround to determine which of the securities in our universe pass the intraday volume requirements by add a universe and a scheduled event to our algorithm.
In the CoarseSelectionFunction, we filter the stocks by the price threshold.
def CoarseSelectionFunction(self, coarse):
self.volume_by_symbol = {c.Symbol: 0 for c in coarse if c.Price > 400}
return list(self.volume_by_symbol.keys())
We then track the cumulative volume for all the symbols in the universe from the open until 10AM.
def OnData(self, data):
if len(self.volume_by_symbol) == 0:
# universe is ready. Access with self.universe
return
for symbol in self.volume_by_symbol.keys():
if data.ContainsKey(symbol):
self.volume_by_symbol[symbol] += data[symbol].Volume
Lastly, we define the SelectUniverse method to filter by the intraday volume seen thus far.
def SelectUniverse(self):
self.universe = []
for symbol, volume in self.volume_by_symbol.items():
if volume > 50000:
self.universe.append(symbol)
self.volume_by_symbol.clear()
See the attached backtest for reference. Also, consider reviewing our documentation on scheduled events.
Best, Derek Melchin
0
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.
In regards to the first question, the only limit imposed on the number of securities an algorithm's universe can have is from the amount of available RAM. If needed, the backtesting node on an account can be upgraded to increase the RAM. See the specs of the available nodes in our documentation.
To resolve the error the backtest throws when setting `c.Price > 300`, we need to add
and data[symbol] is not None
to the condition on line 32. See the attached backtest for reference.
For the second post above, setting the argument passed to the universe method to 3000 returns a larger universe. We just need to ensure we build the project after making changes.
Best, Derek Melchin
2
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.
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.