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:

  1. class ShortAvailabilityDataAlgorithm(QCAlgorithm):
  2. def Initialize(self):
  3. self.SetBrokerageModel(InteractiveBrokersBrokerageModelWithShortable())
  4. class InteractiveBrokersBrokerageModelWithShortable(InteractiveBrokersBrokerageModel):
  5. def __init__(self):
  6. super().__init__()
  7. 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:

  1. def OnData(self, data):
  2. # Gets all Symbols that are shortable, as well as the quantity shortable for them.
  3. # Returns a Dictionary of quantity shortable (long) keyed by Symbol.
  4. all_shortable_symbols = self.AllShortableSymbols()
  5. # Gets the quantity shortable for the given asset. Zero if not shortable
  6. shortable_quantity = self.ShortableQuantity(self.appl)
  7. # Determines if the Symbol is shortable at the brokerage.
  8. # Use a given order's quantity to check if it is currently shortable,
  9. # taking into account current holdings and open orders.
  10. is_shortable = self.Shortable(self.appl, 1000000)

Please find a working example below:

Author

Alexandre Catarino

July 2021