Quant League is evolving into Strategies, our new home for sharing, discovering, and exploring trading strategies, with improved organization and a better overall experience. Q4-2025 will be the final Quant League.
LEAN is the open-source algorithmic trading engine powering QuantConnect.
Founded in 2012 LEAN has been built by a global community of 180+ engineers and powers more than 300+ hedge funds today.
Join Our Discord Channel
Join QuantConnect's Discord server for real-time support, where a vibrant community of traders and developers awaits to help you with any of your QuantConnect needs.
This research is under review. To publish this research attract three community upvotes.
Actually what I want to do is filter out symbols with price < X during the coarse universe filter so your suggestion on using the history method will not work.
Is there another way I can get the price of the symbol within the Universe Selection?
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.
Mia Alissi
STAFF Pro
,
Yes, you can filter out symbols based on price during the Coarse Universe Selection. The CoarseFundamental object has a Price property that you can use for this purpose. Here is an example of how you can do this in Python:
def CoarseSelectionFunction(self, coarse):
return [x.Symbol for x in coarse if x.Price > X]
In this example, coarse is a list of CoarseFundamental objects, and X is the price threshold you want to use for filtering. This function will return a list of symbols for securities that have a price greater than X.
Please note that the CoarseSelectionFunction is called once per day at midnight, and the coarse list it receives contains data from the previous day. Therefore, the prices you are filtering on are from the close of the previous trading day.
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.
Andres Arizpe
9.1k Pro
,
Yes, I am aware of the fundamentals universe but how do I combine it with the BrainSentiment Universe in order to filter on both sentiment and price?
Cheers,
Andres
Mia Alissi
STAFF Pro
,
To combine the BrainSentimentIndicatorUniverse and the CoarseFundamental universe, you can use the concept of "chained universes". This allows you to fetch fundamental and alternative data on a specific subset of assets.
First, you would define your BrainSentimentIndicatorUniverse to filter based on sentiment. Then, you would chain this with the CoarseFundamental universe to further filter based on price.
Here is an example of how you can do this in Python:
class MyAlgorithm(QCAlgorithm):
def Initialize(self):
self.UniverseSettings.Resolution = Resolution.Daily
self.SetStartDate(2016, 1, 1)
self.SetEndDate(2018, 1, 1)
self.SetCash(100000)
self.AddUniverse(self.CoarseSelectionFunction)
self.AddUniverseSelection(BrainSentimentIndicatorUniverse(self.universe_selection))
def universe_selection(self, alt_coarse: List[BrainSentimentIndicatorUniverse]) -> List[Symbol]:
return [d.symbol for d in alt_coarse if d.total_article_mentions7_days > 0 and d.sentiment7_days]
def CoarseSelectionFunction(self, coarse):
return [x.Symbol for x in coarse if x.Price > X]
In this example, universe_selection is the function that filters the BrainSentimentIndicatorUniverse based on sentiment, and CoarseSelectionFunction is the function that filters the CoarseFundamental universe based on price.
Please note that the CoarseSelectionFunction is called once per day at midnight, and the coarse list it receives contains data from the previous day. Therefore, the prices you are filtering on are from the close of the previous trading day.
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.
Andres Arizpe
9.1k Pro
,
Hi Mia,
Based on your suggestion and the Chanied Universe and Alternative Data (https://www.quantconnect.com/docs/v2/writing-algorithms/universes/equity/chained-universes#00-Introduction), I've been working on the code but I am getting the following error message when I try to return the join of the two filters:
'WellDressedSkyBlueSardine' object has no attribute 'fundamental'
at universe_selection
return list (set(self.fundamental) & set(sortedby30daySentiment))
^^^^^^^^^^^^^^^^
in main.py: line 36
Could you please take a look at the attached code to see why this does not work?
BTW, I also tried doing the BrainSentiment filter first but got the error message when I tried to sort:Â
'<' not supported between instances of 'NoneType' and 'float'
at universe_selection
sortedby30daySentiment = sorted (alt_coarse, key=lambda x: x.sentiment_30_days, reverse=True)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
in main.py: line 33
Mia Alissi
STAFF Pro
,
Based on the error messages you provided, it seems like there are two issues with your code:
'WellDressedSkyBlueSardine' object has no attribute 'fundamental': This error suggests that you are trying to access a 'fundamental' attribute of an object that does not have this attribute. It's likely that 'WellDressedSkyBlueSardine' is a security symbol and you're trying to access its fundamental data. In QuantConnect, you can access a security's fundamental data using the Securities property of the algorithm object, like so: self.Securities[symbol].Fundamentals.
'<' not supported between instances of 'NoneType' and 'float': This error suggests that you are trying to compare a None value with a float, which is not allowed in Python. This could happen if some of the elements in alt_coarse have None as their sentiment_30_days value. You can avoid this error by filtering out these elements before sorting, like so: sorted([x for x in alt_coarse if x.sentiment_30_days is not None], key=lambda x: x.sentiment_30_days, reverse=True).
Without seeing your full code, it's hard to provide a more specific solution. However, I hope these suggestions help you debug your code. If you continue to have issues, I recommend posting your full code and error messages on the QuantConnect Forum for more detailed assistance.
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.
Andres Arizpe
9.1k Pro
,
You've been so helpful, thank you very much. I got rid of the errors with your suggestions but now but the fine filter is not pulling any data from the BrainSentiment Indicator and returns an empty list.
Any idea why? I'm so cloes now….
I've added the backtest if you have a chance to check it out.
Cheers,
AA
Mia Alissi
STAFF Pro
,
Based on the code you provided, it seems like the issue might be with how you're trying to intersect the self.fundamental and sortedby30daySentiment lists in the universe_selection function.
In this line: self.list = list(set(self.fundamental) & set(sortedby30daySentiment)), you're trying to find the intersection of self.fundamental (a list of Symbols) and sortedby30daySentiment (a list of BrainSentimentIndicatorUniverse objects). Since these two lists contain different types of objects, their intersection will always be an empty list.
To fix this issue, you should make sure that both lists contain the same type of objects before trying to find their intersection. For example, you could modify the universe_selection function like this:
def universe_selection(self, alt_coarse: List[BrainSentimentIndicatorUniverse]) -> List[Symbol]:
if self.Time <= self.rebalanceTime:
return self.Universe.Unchanged
self.rebalanceTime = self.Time + timedelta(30)
sortedby30daySentiment = [x.symbol for x in sorted([x for x in alt_coarse if x.sentiment_30_days is not None], key=lambda x: x.sentiment_30_days, reverse=True)]
return list(set(self.fundamental) & set(sortedby30daySentiment))
In this modified version of the function, sortedby30daySentiment is a list of Symbols, just like self.fundamental. Therefore, their intersection will be a list of Symbols that pass both the price filter and the sentiment filter.
I hope this helps! If you have any more questions, feel free to ask.
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.
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!
Allocate to this Strategy
Institutional clients can contact the author and allocate capital to this strategy.
Mia Alissi
Yes, you can filter out symbols based on price during the Coarse Universe Selection. The
CoarseFundamentalobject has aPriceproperty that you can use for this purpose. Here is an example of how you can do this in Python:In this example,
coarseis a list ofCoarseFundamentalobjects, andXis the price threshold you want to use for filtering. This function will return a list of symbols for securities that have a price greater thanX.You can find more information about this in the QuantConnect documentation.
Please note that the
CoarseSelectionFunctionis called once per day at midnight, and thecoarselist it receives contains data from the previous day. Therefore, the prices you are filtering on are from the close of the previous trading day.Sources:
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.
Andres Arizpe
Yes, I am aware of the fundamentals universe but how do I combine it with the BrainSentiment Universe in order to filter on both sentiment and price?
Cheers,
Andres
Mia Alissi
To combine the BrainSentimentIndicatorUniverse and the CoarseFundamental universe, you can use the concept of "chained universes". This allows you to fetch fundamental and alternative data on a specific subset of assets.
First, you would define your BrainSentimentIndicatorUniverse to filter based on sentiment. Then, you would chain this with the CoarseFundamental universe to further filter based on price.
Here is an example of how you can do this in Python:
In this example,
universe_selectionis the function that filters the BrainSentimentIndicatorUniverse based on sentiment, andCoarseSelectionFunctionis the function that filters the CoarseFundamental universe based on price.Please note that the
CoarseSelectionFunctionis called once per day at midnight, and thecoarselist it receives contains data from the previous day. Therefore, the prices you are filtering on are from the close of the previous trading day.Sources:
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.
Andres Arizpe
Hi Mia,
Based on your suggestion and the Chanied Universe and Alternative Data (https://www.quantconnect.com/docs/v2/writing-algorithms/universes/equity/chained-universes#00-Introduction), I've been working on the code but I am getting the following error message when I try to return the join of the two filters:
Could you please take a look at the attached code to see why this does not work?
BTW, I also tried doing the BrainSentiment filter first but got the error message when I tried to sort:Â
Mia Alissi
Based on the error messages you provided, it seems like there are two issues with your code:
'WellDressedSkyBlueSardine' object has no attribute 'fundamental': This error suggests that you are trying to access a 'fundamental' attribute of an object that does not have this attribute. It's likely that 'WellDressedSkyBlueSardine' is a security symbol and you're trying to access its fundamental data. In QuantConnect, you can access a security's fundamental data using theSecuritiesproperty of the algorithm object, like so:self.Securities[symbol].Fundamentals.'<' not supported between instances of 'NoneType' and 'float': This error suggests that you are trying to compare aNonevalue with a float, which is not allowed in Python. This could happen if some of the elements inalt_coarsehaveNoneas theirsentiment_30_daysvalue. You can avoid this error by filtering out these elements before sorting, like so:sorted([x for x in alt_coarse if x.sentiment_30_days is not None], key=lambda x: x.sentiment_30_days, reverse=True).Without seeing your full code, it's hard to provide a more specific solution. However, I hope these suggestions help you debug your code. If you continue to have issues, I recommend posting your full code and error messages on the QuantConnect Forum for more detailed assistance.
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.
Andres Arizpe
You've been so helpful, thank you very much. I got rid of the errors with your suggestions but now but the fine filter is not pulling any data from the BrainSentiment Indicator and returns an empty list.
Any idea why? I'm so cloes now….
I've added the backtest if you have a chance to check it out.
Cheers,
AA
Mia Alissi
Based on the code you provided, it seems like the issue might be with how you're trying to intersect the
self.fundamentalandsortedby30daySentimentlists in theuniverse_selectionfunction.In this line:
self.list = list(set(self.fundamental) & set(sortedby30daySentiment)), you're trying to find the intersection ofself.fundamental(a list of Symbols) andsortedby30daySentiment(a list of BrainSentimentIndicatorUniverse objects). Since these two lists contain different types of objects, their intersection will always be an empty list.To fix this issue, you should make sure that both lists contain the same type of objects before trying to find their intersection. For example, you could modify the
universe_selectionfunction like this:In this modified version of the function,
sortedby30daySentimentis a list of Symbols, just likeself.fundamental. Therefore, their intersection will be a list of Symbols that pass both the price filter and the sentiment filter.I hope this helps! If you have any more questions, feel free to ask.
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.
Andres Arizpe
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!