Overall Statistics
Total Orders
42
Average Win
3.23%
Average Loss
-21.16%
Compounding Annual Return
-99.998%
Drawdown
99.600%
Expectancy
-0.800
Net Profit
-99.548%
Sharpe Ratio
-0.542
Sortino Ratio
-0.245
Probabilistic Sharpe Ratio
0.003%
Loss Rate
83%
Win Rate
17%
Profit-Loss Ratio
0.15
Alpha
-1.52
Beta
2.274
Annual Standard Deviation
1.826
Annual Variance
3.333
Information Ratio
-0.675
Tracking Error
1.813
Treynor Ratio
-0.435
Total Fees
$42.09
Estimated Strategy Capacity
$5200000.00
Lowest Capacity Asset
GME SC72NCBXXAHX
Portfolio Turnover
19.23%
#region imports
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Linq;
    using System.Globalization;
    using System.Drawing;
    using QuantConnect;
    using QuantConnect.Algorithm.Framework;
    using QuantConnect.Algorithm.Framework.Selection;
    using QuantConnect.Algorithm.Framework.Alphas;
    using QuantConnect.Algorithm.Framework.Portfolio;
    using QuantConnect.Algorithm.Framework.Execution;
    using QuantConnect.Algorithm.Framework.Risk;
    using QuantConnect.Algorithm.Selection;
    using QuantConnect.Parameters;
    using QuantConnect.Benchmarks;
    using QuantConnect.Brokerages;
    using QuantConnect.Util;
    using QuantConnect.Interfaces;
    using QuantConnect.Algorithm;
    using QuantConnect.Indicators;
    using QuantConnect.Data;
    using QuantConnect.Data.Consolidators;
    using QuantConnect.Data.Custom;
    using QuantConnect.DataSource;
    using QuantConnect.Data.Fundamental;
    using QuantConnect.Data.Market;
    using QuantConnect.Data.UniverseSelection;
    using QuantConnect.Notifications;
    using QuantConnect.Orders;
    using QuantConnect.Orders.Fees;
    using QuantConnect.Orders.Fills;
    using QuantConnect.Orders.Slippage;
    using QuantConnect.Scheduling;
    using QuantConnect.Securities;
    using QuantConnect.Securities.Equity;
    using QuantConnect.Securities.Future;
    using QuantConnect.Securities.Option;
    using QuantConnect.Securities.Forex;
    using QuantConnect.Securities.Crypto;   
    using QuantConnect.Securities.Interfaces;
    using QuantConnect.Storage;
    using QCAlgorithmFramework = QuantConnect.Algorithm.QCAlgorithm;
    using QCAlgorithmFrameworkBridge = QuantConnect.Algorithm.QCAlgorithm;
#endregion
using QuantConnect.Data.Shortable;
namespace QuantConnect
{
    public class ShortAvailabilityDataAlgorithm : QCAlgorithm
    {
        private Equity _equity;
        
        public override void Initialize()
        {
            SetStartDate(2021, 1, 1);
            SetEndDate(2021, 7, 1);
            SetCash(1000);
            SetSecurityInitializer(new MySecurityInitializer(BrokerageModel, new FuncSecuritySeeder(GetLastKnownPrices)));
            _equity = AddEquity("GME");
            
            Schedule.On(
                DateRules.EveryDay(_equity.Symbol),
                TimeRules.AfterMarketOpen(_equity.Symbol, 10),
                Rebalance);
        }
        
        public void Rebalance()
        {
            var symbol = _equity.Symbol;

            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));

            // Then, 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);
                security.SetShortableProvider(new InteractiveBrokersShortableProvider());    
            }
        }
    }
}