Overall Statistics
Total Orders
42
Average Win
3.23%
Average Loss
-21.16%
Compounding Annual Return
-99.998%
Drawdown
99.600%
Expectancy
-0.800
Start Equity
1000
End Equity
4.52
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%
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)
        self.set_security_initializer(MySecurityInitializer(self.brokerage_model, FuncSecuritySeeder(self.get_last_known_prices)))

        self.equity = self.add_equity("GME")

        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
        
        shortable_quantity = self.equity.shortable_provider.shortable_quantity(symbol, self.time)
        if not shortable_quantity:
            shortable_quantity = 0
        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))

        # Then, 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)
        security.set_shortable_provider(InteractiveBrokersShortableProvider())