Short Availability

Key Concepts

Introduction

To short a security, you need to borrow shares from another investor or organization that owns the shares. A shortable provider is a model that tracks the number of shares that are available for you to borrow. A shortable provider can make your backtest results more realistic because it doesn't let you place a short trade if there are no shares available for you to borrow.

Set Providers

The brokerage model of your algorithm automatically sets the settlement model for each security, but you can override it. To manually set the shortable provider of a security, call the SetShortableProvider method on the Security object.

// In Initialize
var security = AddEquity("SPY");
security.SetShortableProvider(new AtreyuShortableProvider(SecurityType.Equity, Market.USA));
# In Initialize
security = self.AddEquity("SPY")
security.SetShortableProvider(AtreyuShortableProvider(SecurityType.Equity, Market.USA))

You can also set the shortable provider in a security initializer. If your algorithm has a universe, use the security initializer technique. In order to initialize single security subscriptions with the security initializer, call SetShortableProvider before you create the subscriptions.

// In Initialize
SetSecurityInitializer(CustomSecurityInitializer);
AddEquity("SPY");

private void CustomSecurityInitializer(Security security)
{
    security.SetShortableProvider(new AtreyuShortableProvider(SecurityType.Equity, Market.USA));
}
# In Initialize
self.SetSecurityInitializer(self.CustomSecurityInitializer)
self.AddEquity("SPY")

def CustomSecurityInitializer(self, security: Security) -> None:
    security.SetShortableProvider(AtreyuShortableProvider(SecurityType.Equity, Market.USA))

Default Behavior

The brokerage model of your algorithm automatically sets the shortable provider for each security. The default brokerage model is the DefaultBrokerageModel, which uses the NullShortableProvider.

Provider Structure

Shortable providers must implement the IShortableProvider interface. Shortable providers that implement the IShortableProvider interface must implement the AllShortableSymbols and ShortableQuantity methods. The AllShortableSymbols method receives the local time of the algorithm and returns a dictionary that represents the shortable quantity for each Symbol in the algorithm. The ShortableQuantity method receives a Symbol and the local time of the algorithm and returns the shortable quantity.

class MyShortableProvider : IShortableProvider
{
    public Dictionary<Symbol, long> AllShortableSymbols(DateTime localTime)
    {
        return new Dictionary<Symbol, long>();
    }

    public long? ShortableQuantity(Symbol symbol, DateTime localTime)
    {
        return long.MaxValue;
    }
}
# Not currently supported

LEAN doesn't currently support custom shortable providers in Python. To track the feature progress, subscribe to GitHub Issue #6374.

Get Short Availability

To check if a security has shares available to short, call the Shortable method.

// Check if there are any shares available to short a security
var isShortable = Shortable(symbol);

// Check if there are a certain quantity of shares available
var isShortableQuantity = Shortable(symbol, quantity);
# Check if there are any shares available to short a security
is_shortable = self.Shortable(symbol)

# Check if there are a certain quantity of shares available
is_shortable_quantity = self.Shortable(symbol, quantity)

To check how many shares are available for a security to short, call the ShortableQuantity method.

var quantity = ShortableQuantity(symbol);
quantity = self.ShortableQuantity(symbol)

To get all the symbols that are shortable and their respective shortable quantities, call the AllShortableSymbols method.

var quantityBySymbol = AllShortableSymbols();
quantity_by_symbol = self.AllShortableSymbols()

Order Failures

If you place an order to short more shares than are available to borrow, LEAN rejects the order and applies the following tag: "Order exceeds maximum shortable quantity for Symbol ticker (requested short: quantity)".

Borrowing Costs

In live trading, your brokerage charges an interest fee when you borrow shares to short a security. In backtesting, we don't currently simulate short interest fees. Subscribe to GitHub Issue #4563 to track the feature progress.

You can also see our Videos. You can also get in touch with us via Discord.

Did you find this page helpful?

Contribute to the documentation: