Overall Statistics
Total Trades
1
Average Win
0%
Average Loss
0%
Compounding Annual Return
0.000%
Drawdown
0.000%
Expectancy
0
Net Profit
0.000%
Sharpe Ratio
10.786
Probabilistic Sharpe Ratio
99.997%
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
0
Beta
0
Annual Standard Deviation
0
Annual Variance
0
Information Ratio
-8.021
Tracking Error
0.052
Treynor Ratio
2.275
Total Fees
$50000.00
Estimated Strategy Capacity
$84000000000000.00
Lowest Capacity Asset
AAPL R735QTJ8XC9X
import random
class CryingAsparagusCormorant(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2021, 11, 10)
        self.SetCash(100000000000000000)
        self.AAPL = self.AddEquity("AAPL", Resolution.Minute).Symbol
        self.Securities["AAPL"].SetFillModel(CustomFillModel(self))
        # self.Securities["AAPL"].SetLeverage(4)
        self.order = {}


    def OnData(self, data):
        if not self.Portfolio.Invested:
            self.order[self.AAPL] = self.MarketOrder(self.AAPL, 10000000)
        if self.order[self.AAPL].Status == OrderStatus.PartiallyFilled:
            self.Debug("partially filled")
            
    def OnSecuritiesChanged(self, changes):
        for stock in changes.AddedSecurities:
            self.Securities[stock.Symbol].SetLeverage(4)
        
class CustomFillModel(ImmediateFillModel):
    
    def __init__(self, algorithm):
        self.algorithm = algorithm
        self.absoluteRemainingByOrderId = {} 

    def MarketFill(self, asset, order):
        absoluteRemaining = order.AbsoluteQuantity
        if order.Id in self.absoluteRemainingByOrderId.keys():
            absoluteRemaining = self.absoluteRemainingByOrderId[order.Id]
        # self.algorithm.Debug(str(absoluteRemaining) + " absoluteRemaining")
        
        # Create the object
        fill = super().MarketFill(asset, order) 
        volume = self.algorithm.Securities["AAPL"].Volume
        
        # Set this fill amount
        if abs(volume) < abs(absoluteRemaining):
            # self.algorithm.Debug("HERE")
            fill.FillQuantity = absoluteRemaining - (absoluteRemaining - volume)
        else:
            fill.FillQuantity = absoluteRemaining
            absoluteRemaining = 0
        # self.algorithm.Debug(str(volume) + " volume")
        # self.algorithm.Debug(str(order.Quantity) + " Order quantity")
        # self.algorithm.Debug(str(fill.FillQuantity) + " Fill quantity")
        if absoluteRemaining <= 0:
            fill.Status = OrderStatus.Filled
            if self.absoluteRemainingByOrderId.get(order.Id):
                self.absoluteRemainingByOrderId.pop(order.Id)
        else:
            if volume < absoluteRemaining:
                self.absoluteRemainingByOrderId[order.Id] = (absoluteRemaining - volume)
            else:
                self.absoluteRemainingByOrderId[order.Id] = absoluteRemaining
            fill.Status = OrderStatus.PartiallyFilled

        return fill
        
import random
class CryingAsparagusCormorant(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2021, 11, 10)
        self.SetCash(100000000000000000)
        self.AAPL = self.AddEquity("AAPL", Resolution.Minute).Symbol
        self.Securities["AAPL"].SetFillModel(CustomFillModel(self))
        self.order = {}


    def OnData(self, data):
        if not self.Portfolio.Invested:
            self.order[self.AAPL] = self.MarketOrder(self.AAPL, 10000000)
        if self.order[self.AAPL].Status == OrderStatus.PartiallyFilled:
            self.Debug("partially filled")
        
class CustomFillModel(ImmediateFillModel):
    
    def __init__(self, algorithm):
        self.algorithm = algorithm
        self.absoluteRemainingByOrderId = {} 

    def MarketFill(self, asset, order):
        absoluteRemaining = order.AbsoluteQuantity
        if order.Id in self.absoluteRemainingByOrderId.keys():
            absoluteRemaining = self.absoluteRemainingByOrderId[order.Id]
        # self.algorithm.Debug(str(absoluteRemaining) + " absoluteRemaining")
        
        # Create the object
        fill = super().MarketFill(asset, order) 
        volume = self.algorithm.Securities["AAPL"].Volume
        
        # Set this fill amount
        if abs(volume) < abs(absoluteRemaining):
            # self.algorithm.Debug("HERE")
            fill.FillQuantity = absoluteRemaining - (absoluteRemaining - volume)
        else:
            fill.FillQuantity = absoluteRemaining
            absoluteRemaining = 0
        # self.algorithm.Debug(str(volume) + " volume")
        # self.algorithm.Debug(str(order.Quantity) + " Order quantity")
        # self.algorithm.Debug(str(fill.FillQuantity) + " Fill quantity")
        if absoluteRemaining <= 0:
            fill.Status = OrderStatus.Filled
            if self.absoluteRemainingByOrderId.get(order.Id):
                self.absoluteRemainingByOrderId.pop(order.Id)
        else:
            if volume < absoluteRemaining:
                self.absoluteRemainingByOrderId[order.Id] = (absoluteRemaining - volume)
            else:
                self.absoluteRemainingByOrderId[order.Id] = absoluteRemaining
            fill.Status = OrderStatus.PartiallyFilled

        return fill