QuantConnect
US Equities Short Availability
Introduction
The US Equity Short Availability dataset provides the available shares for open short positions and their borrowing cost in the US Equity market. The data covers 10,500 US Equities, starts in January 2018, and is delivered on a daily frequency. This dataset is created using information from the exchanges.
This dataset depends on the US Equity Security Master dataset because the US Equity Security Master dataset contains information on splits, dividends, and symbol changes.
For more information about the US Equities Short Availability dataset, including CLI commands and pricing, see the dataset listing.
About the Provider
QuantConnect was founded in 2012 to serve quants everywhere with the best possible algorithmic trading technology. Seeking to disrupt a notoriously closed-source industry, QuantConnect takes a radically open-source approach to algorithmic trading. Through the QuantConnect web platform, more than 50,000 quants are served every month.
Getting Started
The following snippets demonstrate how to request data from the US Equities Short Availability dataset.
Interactive Brokers Data
security.set_shortable_provider(InteractiveBrokersShortableProvider())
security.SetShortableProvider(new InteractiveBrokersShortableProvider());
Axos Clearing Data
security.set_shortable_provider(LocalDiskShortableProvider("axos"))
security.SetShortableProvider(new LocalDiskShortableProvider("axos"));
Requesting Data
To add US Equities Short Availability data to your algorithm, set the shortable provider of each US Equity in your algorithm.
class ShortAvailabilityDataAlgorithm(QCAlgorithm): def initialize(self) -> None: self.set_start_date(2019, 1, 1) security = self.add_equity("AAPL") # Set shortable provider as IB security.set_shortable_provider(InteractiveBrokersShortableProvider()) self._symbol = security.symbol
public class ShortAvailabilityDataAlgorithm : QCAlgorithm { private Symbol _symbol; public override void Initialize() { SetStartDate(2019, 1, 1); var security = AddEquity("AAPL"); // Set shortable provider as IB security.SetShortableProvider(new InteractiveBrokersShortableProvider()); _symbol = security.Symbol; } }
Accessing Data
To check how many shares are available for a security to short, call the ShortableQuantity
shortable_quantity
method of the ShortableProvider
shortable_provider
var shortableProvider = Securities[_symbol].ShortableProvider; // Get the shortable quantity of the selected symbol at the selected time var shortableQuantity = shortableProvider.ShortableQuantity(_symbol, Time); // Check if there are a certain quantity of shares available var quantity = 100; var isShortableQuantity = Shortable(_symbol, quantity);
shortable_provider = self.securities[self._symbol].shortable_provider # Get the shortable quantity of the selected symbol at the selected time shortable_quantity = shortable_provider.shortable_quantity(self._symbol, self.time) # Check if there are a certain quantity of shares available quantity = 100; is_shortable_quantity = self.shortable(self._symbol, quantity)
To check borrowing cost, call the FeeRate
fee_rate
or RebateRate
rebate_rate
method of the ShortableProvider
shortable_provider
var feeRate = shortableProvider.FeeRate(_symbol, Time); var rebateRate = shortableProvider.RebateRate(_symbol, Time);
fee_rate = shortable_provider.fee_rate(self._symbol, self.time); rebate_rate = shortable_provider.rebate_rate(self._symbol, self.time);
Example Applications
The US Equities Short Availability dataset enables you to accurately design strategies harnessing information about short availability. Examples include the following use cases:
- Avoiding short orders that the brokerage will reject
- Selecting securities based on how many shares are available to short
Classic Algorithm Example
The following example algorithm shorts GameStop every day there are shares available to short. If the algorithm receives a margin call, it liquidates the position and start again on the next day.
from AlgorithmImports import * class ShortAvailabilityDataAlgorithm(QCAlgorithm): def initialize(self) -> None: self.set_start_date(2021, 1, 1) self.set_end_date(2021, 7, 1) self.set_cash(1000) # Seed the security price as the last known price, such that the price data is immediately available at initial rebalance self.set_security_initializer(MySecurityInitializer(self.brokerage_model, FuncSecuritySeeder(self.get_last_known_prices))) self.equity = self.add_equity("GME") # Set up daily rebalance scheduled event, since shortable quantity is updated daily self.schedule.on( self.date_rules.every_day(self.equity.symbol), self.time_rules.after_market_open(self.equity.symbol, 10), self.rebalance) def rebalance(self) -> None: symbol = self.equity.symbol # You can obtain the shortable quantity to decide the submission of a short order shortable_quantity = self.equity.shortable_provider.shortable_quantity(symbol, self.time) if not shortable_quantity: shortable_quantity = 0 # Fee and rebate rate is also available, such that you can calculate the expected return and decide if the margin is worthwhile self.plot('Total Shortable Quantity', symbol, shortable_quantity) self.plot('Borrowing Cost', "Fee Rate", self.equity.shortable_provider.fee_rate(symbol, self.time)) self.plot('Borrowing Cost', "Rebate Rate", self.equity.shortable_provider.rebate_rate(symbol, self.time)) # Test whether we can short the desired quantity quantity = self.calculate_order_quantity(symbol, -1) if self.shortable(symbol, quantity): self.market_order(symbol, quantity) def on_margin_call_warning(self) -> None: self.liquidate() class MySecurityInitializer(BrokerageModelSecurityInitializer): def __init__(self, brokerage_model: IBrokerageModel, security_seeder: ISecuritySeeder) -> None: super().__init__(brokerage_model, security_seeder) def initialize(self, security: Security) -> None: super().initialize(security) # Set the shortable provider as your broker for accurate short reality modeling security.set_shortable_provider(InteractiveBrokersShortableProvider())
public class ShortAvailabilityDataAlgorithm : QCAlgorithm { private Equity _equity; public override void Initialize() { SetStartDate(2021, 1, 1); SetEndDate(2021, 7, 1); SetCash(1000); // Seed the security price as the last known price, such that the price data is immediately available at initial rebalance SetSecurityInitializer(new MySecurityInitializer(BrokerageModel, new FuncSecuritySeeder(GetLastKnownPrices))); _equity = AddEquity("GME"); // Set up daily rebalance scheduled event, since shortable quantity is updated daily Schedule.On( DateRules.EveryDay(_equity.Symbol), TimeRules.AfterMarketOpen(_equity.Symbol, 10), Rebalance); } public void Rebalance() { var symbol = _equity.Symbol; // You can obtain the shortable quantity to decide the submission of a short order // Fee and rebate rate is also available, such that you can calculate the expected return and decide if the margin is worthwhile Plot("Total Shortable Quantity", symbol, _equity.ShortableProvider.ShortableQuantity(symbol, Time) ?? 0m); Plot("Borrowing Cost", "Fee Rate", _equity.ShortableProvider.FeeRate(symbol, Time)); Plot("Borrowing Cost", "Rebate Rate", _equity.ShortableProvider.RebateRate(symbol, Time)); // Test whether we can short the desired quantity var quantity = CalculateOrderQuantity(symbol, -1m); if (Shortable(symbol, quantity)) { MarketOrder(symbol, quantity); } } public override void OnMarginCallWarning() { Liquidate(); } class MySecurityInitializer : BrokerageModelSecurityInitializer { public MySecurityInitializer(IBrokerageModel brokerageModel, ISecuritySeeder securitySeeder) : base(brokerageModel, securitySeeder) {} public override void Initialize(Security security) { base.Initialize(security); // Set the shortable provider as your broker for accurate short reality modeling security.SetShortableProvider(new InteractiveBrokersShortableProvider()); } } }
Framework Algorithm Example
The following example algorithm shorts GameStop every day there are shares available to short. If the algorithm receives a margin call, it liquidates the position and start again on the next day.
from AlgorithmImports import * from QuantConnect.DataSource import * class ShortAvailabilityDataAlgorithm(QCAlgorithm): def initialize(self) -> None: self.set_start_date(2021, 1, 1) self.set_end_date(2021, 7, 1) self.set_cash(1000) # Seed the security price as the last known price, such that the price data is immediately available at initial rebalance self.set_security_initializer(MySecurityInitializer(self.brokerage_model, FuncSecuritySeeder(self.get_last_known_prices))) self.set_universe_selection(ManualUniverseSelectionModel( [Symbol.create("GME", SecurityType.EQUITY, Market.USA)])) # Emit down-direction insights to short all securities in the universe self.set_alpha(ConstantAlphaModel(InsightType.PRICE, InsightDirection.DOWN, timedelta(1))) self.set_portfolio_construction(EqualWeightingPortfolioConstructionModel()) self.set_execution(ShortableExecutionModel()) # On Margin Call, emit flat-direction insights to liquidate the positions def on_margin_call_warning(self) -> None: self.emit_insights([Insight.price(kvp.Key, timedelta(1), InsightDirection.FLAT) for kvp in self.securities if kvp.Value.invested]) class ShortableExecutionModel(ExecutionModel): def __init__(self) -> None: self.targets_collection = PortfolioTargetCollection() def execute(self, algorithm: QCAlgorithm, targets: List[PortfolioTarget]) -> None: '''Immediately submits orders for the specified portfolio targets. Args: algorithm: The algorithm instance targets: The portfolio targets to be ordered''' # for performance we check count value, OrderByMarginImpact and ClearFulfilled are expensive to call self.targets_collection.add_range(targets) if self.targets_collection.count > 0: for target in self.targets_collection.order_by_margin_impact(algorithm): # calculate remaining quantity to be ordered quantity = OrderSizing.get_unordered_quantity(algorithm, target) # If the quantity is negative, ensure that the security is shortable if quantity > 0 or algorithm.shortable(target.symbol, quantity): algorithm.market_order(target.symbol, quantity) self.targets_collection.clear_fulfilled(algorithm) class MySecurityInitializer(BrokerageModelSecurityInitializer): def __init__(self, brokerage_model: IBrokerageModel, security_seeder: ISecuritySeeder) -> None: super().__init__(brokerage_model, security_seeder) def initialize(self, security: Security) -> None: super().initialize(security) # Set the shortable provider as IB security.set_shortable_provider(InteractiveBrokersShortableProvider())
public class ShortAvailabilityDataAlgorithm : QCAlgorithm { public override void Initialize() { SetStartDate(2021, 1, 1); SetEndDate(2021, 7, 1); SetCash(1000); // Seed the security price as the last known price, such that the price data is immediately available at initial rebalance SetSecurityInitializer(new MySecurityInitializer(BrokerageModel, new FuncSecuritySeeder(GetLastKnownPrices))); SetUniverseSelection(new ManualUniverseSelectionModel( QuantConnect.Symbol.Create("GME", SecurityType.Equity, Market.USA))); // Emit down-direction insights to short all securities in the universe SetAlpha(new ConstantAlphaModel(InsightType.Price, InsightDirection.Down, TimeSpan.FromDays(1))); SetPortfolioConstruction(new EqualWeightingPortfolioConstructionModel()); SetExecution(new ShortableExecutionModel()); } // On Margin Call, emit flat-direction insights to liquidate the positions public override void OnMarginCallWarning() { EmitInsights(Securities .Where(kvp => kvp.Value.Invested) .Select(kvp => Insight.Price(kvp.Key, TimeSpan.FromDays(1), InsightDirection.Flat)) .ToArray()); } public class ShortableExecutionModel : ImmediateExecutionModel { private readonly PortfolioTargetCollection _targetsCollection = new PortfolioTargetCollection(); public override void Execute(QCAlgorithm algorithm, IPortfolioTarget[] targets) { _targetsCollection.AddRange(targets); // for performance we check count value, OrderByMarginImpact and ClearFulfilled are expensive to call if (_targetsCollection.Count > 0) { foreach (var target in _targetsCollection.OrderByMarginImpact(algorithm)) { // calculate remaining quantity to be ordered var quantity = OrderSizing.GetUnorderedQuantity(algorithm, target); // If the quantity is negative, ensure that the security is shortable if (quantity > 0 || algorithm.Shortable(target.Symbol, quantity)) { algorithm.MarketOrder(target.Symbol, quantity); } } _targetsCollection.ClearFulfilled(algorithm); } } } class MySecurityInitializer : BrokerageModelSecurityInitializer { public MySecurityInitializer(IBrokerageModel brokerageModel, ISecuritySeeder securitySeeder) : base(brokerageModel, securitySeeder) {} public override void Initialize(Security security) { base.Initialize(security); // Set the shortable provider as IB security.SetShortableProvider(new InteractiveBrokersShortableProvider()); } } }