This is a follow-up to the discussion at: https://www.quantconnect.com/forum/discussion/17210/how-to-get-symbol-price-in-brainsentimentindicatoruniverse/p1
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?
Cheers,
Andres
Mia Alissi
Yes, you can filter out symbols based on price during the Coarse Universe Selection. The
CoarseFundamental
object has aPrice
property that you can use for this purpose. Here is an example of how you can do this in Python:In this example,
coarse
is a list ofCoarseFundamental
objects, andX
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 thanX
.You can find more information about this in the QuantConnect documentation.
Please note that the
CoarseSelectionFunction
is called once per day at midnight, and thecoarse
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.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_selection
is the function that filters the BrainSentimentIndicatorUniverse based on sentiment, andCoarseSelectionFunction
is the function that filters the CoarseFundamental universe based on price.Please note that the
CoarseSelectionFunction
is called once per day at midnight, and thecoarse
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.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 theSecurities
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 aNone
value with a float, which is not allowed in Python. This could happen if some of the elements inalt_coarse
haveNone
as theirsentiment_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
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.fundamental
andsortedby30daySentiment
lists in theuniverse_selection
function.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_selection
function like this:In this modified version of the function,
sortedby30daySentiment
is 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!