Hi All-
I would like to log data for the 10 selected tickers from a Coarse Universe. I'm able to print the sorted values (using sortedbyDollarVolume), but what I need are the logs for the 10 tickers that remain after filters are applied. I'm getting errors when I try looping through each ticker in symbols_by_price.
Thanks,
Justin
def CoarseSelectionFilter(self, coarse):
sortedByDollarVolume = sorted(coarse, key=lambda c: c.DollarVolume, reverse=True)
symbols_by_price = [c.Symbol for c in sortedByDollarVolume if c.Price > 1 and c.Price < 5 and c.HasFundamentalData and c.Volume > 50000 and len(c.Symbol.Value) <= 4]
self.filteredByPrice = symbols_by_price[:10]
for c in symbols_by_price[10]: #works for sortedbyDollarVolume, but not for symbols_by_price
self.Log(",Symbol," + str(c.Symbol.Value) + ",DollarVolume," + str(c.DollarVolume) + ",Price," + str(c.Price) + ",Volume," + str(c.Volume))
return self.filteredByPrice
Newoptionz
Hi Justin E
I managed to print the activeUniverse in the attached algo. I think that is what you are after. I don't understand though why the universe changes. I thought the universe is set at the start of the algo in the initialize and then not called again. This universe though seems to update every two months? The algo comes from ‘Part time Larry’s' youtube video shown below and I copied his code from and modified it slightly.
at about minute 25, explains more on your problem.
Newoptionz
Ok, so I see the dynamic universe updates daily or all the time.
Nico Xenox
Hey Justin E,
there are just 3 things I would change to make it work.
line 4: c.Symbol → c
line 8: [10] → [:10]
line 11: return [c.Symbol for c in self.filteredByPrice]
here's the working code:
Hope it helps ;)
Justin E
Thank you Newoptionz and Nico Xenox!
Nico, your suggestions made it work, I also realized from Newoptionz video post that I need c and not c.Symbol.
Justin
Justin E
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!