Hi evertybody, I'd like my Universe Selection Model to filter the stocks based not only with the highest DollarVolume but also with stocks that are EBT (Easy-to-borrow) and return the top 100 "using python", is there a way to achieve this?
I'll appreciate any help!
Derek Melchin
Hi Yaros,
First we import the data provider.
from QuantConnect.Data.Shortable import AtreyuShortableProvider
In the `Initialize` method, we create an instance of the `AtreyuShortableProvider`.
self.shortable = AtreyuShortableProvider(SecurityType.Equity, Market.USA)
We can then use the data inside our universe selection method
def CoarseSelection(self, coarse): quantityBySymbol = self.shortable.AllShortableSymbols(self.Time) shortable = [] for cf in coarse: if not quantityBySymbol.ContainsKey(cf.Symbol): continue if quantityBySymbol[cf.Symbol] != 0: shortable.append(cf) sorted_by_dollar_volume = sorted(shortable, key=lambda x: x.DollarVolume, reverse=True) return [cf.Symbol for cf in sorted_by_dollar_volume[:100] ]
See the attached backtest for reference.
Best,
Derek Melchin
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.
Yaros
I want to thank you for your help, the answer was fantastic and I
appreciate it.
Best regards,
Yaros
question, when I set my Universe Selection Model to use the Algorithm
Framework, I am getting the following error, will you tell me why it could
be, I literally copy your code.
ERROR MESSAGE:
During the algorithm initialization, the following exception has
occurred: AttributeError : USA
at __init__
self.shortable = AtreyuShortableProvider(SecurityType.Equity in
universe_selection.py:line 51
AttributeError : USA
THIS IS MY CODE
*from Selection.FundamentalUniverseSelectionModel import
FundamentalUniverseSelectionModelfrom QuantConnect.Data.Shortable import
AtreyuShortableProviderclass
MyUniverseSelectionModel(FundamentalUniverseSelectionModel): def
Derek Melchin
Hi Yaros,
Please try attaching the code again.
Best,
Derek Melchin
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.
Yaros
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!