Overall Statistics
Total Trades
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
Probabilistic Sharpe Ratio
0.003%
Loss Rate
83%
Win Rate
17%
Profit-Loss Ratio
0.15
Alpha
0
Beta
0
Annual Standard Deviation
1.826
Annual Variance
3.333
Information Ratio
-0.541
Tracking Error
1.826
Treynor Ratio
0
Total Fees
$42.09
Estimated Strategy Capacity
$5200000.00
Lowest Capacity Asset
GME SC72NCBXXAHX
Portfolio Turnover
19.23%
# region imports
from AlgorithmImports import *
# endregion

class ShortAvailabilityDataAlgorithm(QCAlgorithm):

    def Initialize(self) -> None:

        self.SetStartDate(2021, 1, 1)
        self.SetEndDate(2021, 7, 1)
        self.SetCash(1000)
        self.SetBrokerageModel(InteractiveBrokersBrokerageModelWithShortable())
        self.equity = self.AddEquity("GME")

        self.Schedule.On(
            self.DateRules.EveryDay(self.equity.Symbol),
            self.TimeRules.AfterMarketOpen(self.equity.Symbol, 10),
            self.Rebalance)

    def Rebalance(self) -> None:
        symbol = self.equity.Symbol

        # Total shortable quantity is None if there is no information
        total_shortable_quantity = self.equity.TotalShortableQuantity
        if not total_shortable_quantity:
            total_shortable_quantity = 0
        self.Plot('Total Shortable Quantity', symbol, total_shortable_quantity)

        # First, let's not rebalance if there are no shares to short
        if self.ShortableQuantity(symbol) < 0: return

        # Then, test whether we can short the desired quantity
        quantity = self.CalculateOrderQuantity(symbol, -1)
        if self.Shortable(symbol, quantity):
            self.MarketOrder(symbol, quantity)

    def OnMarginCallWarning(self) -> None:
        self.Liquidate()
 
class InteractiveBrokersBrokerageModelWithShortable(InteractiveBrokersBrokerageModel):
    def GetShortableProvider(self, security):
        return LocalDiskShortableProvider("axos")