Hello QuantConnect Community!
We have an interesting question from Sergey Kolpakov in the following thread:
Shorting Bubbles At The Top #10630
It was asked whether QuantConnect provides information about short availability.
The answer is yes. It is a fairly new feature that has arrived with Atreyu integration (they provide the data).
Basically, all we need to do is adding a custom brokerage model that sets the ShortableProvider:
class ShortAvailabilityDataAlgorithm(QCAlgorithm):
def Initialize(self):
self.SetBrokerageModel(InteractiveBrokersBrokerageModelWithShortable())
class InteractiveBrokersBrokerageModelWithShortable(InteractiveBrokersBrokerageModel):
def __init__(self):
super().__init__()
self.ShortableProvider = AtreyuShortableProvider(SecurityType.Equity, Market.USA)
If the security is not shortable, QuantConnect/Lean will invalidate the order.
We can avoid placing orders that will be rejected by using the following methods from QCAlgorithm:
def OnData(self, data):
# Gets all Symbols that are shortable, as well as the quantity shortable for them.
# Returns a Dictionary of quantity shortable (long) keyed by Symbol.
all_shortable_symbols = self.AllShortableSymbols()
# Gets the quantity shortable for the given asset. Zero if not shortable
shortable_quantity = self.ShortableQuantity(self.appl)
# Determines if the Symbol is shortable at the brokerage.
# Use a given order's quantity to check if it is currently shortable,
# taking into account current holdings and open orders.
is_shortable = self.Shortable(self.appl, 1000000)
Please find a working example below:
Laurent Crouzet
Useful new feature, thanks!
Sergey Kolpakov
Hi!
Thank you for adding the feature!
When using this brokerage model I noticed that these invalid orders don't trigger OnOrderEvent function so if I need to control Limit Orders I can't use OnOrderEvent function.so I can't detect if the limit was triggered.
Is there any way to catch the moment of Short Availability check?
Sergey Kolpakov
Here's an example of the problem.
I'd like to check if the order is triggered but short is not available.
Louis Szeto
Hi Sergey,
Thanks for reporting this. We've created a GitHub Issue to have the problem addressed. Subscribe to our progress here.
Best,
Louis Szeto
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.
Vidal boreal
Any C# version example?
Louis Szeto
Hi Vidal
Please check the dataset page for C# implementation examples.
Best
Louis Szeto
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.
Vidal boreal
Thanks Louis.
Seems It is not shortable for the stock even (shortablequantity > 0).
Louis Szeto
Hi Vidal
Please provide the time and symbol of the issue, or the code snippet, for further assistance. Thanks!
Best
Louis Szeto
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.
Demid Fedorov
Hi, has something changed with respect to this functionality? When I try to run the code now or if I try to add it to another algorithm, I get an error saying 'name 'AtreyuShortableProvider' is not defined'…
Alexandre Catarino
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!