Overall Statistics
Total Trades
2
Average Win
17.05%
Average Loss
0%
Compounding Annual Return
-20.266%
Drawdown
3.700%
Expectancy
-1
Net Profit
-1.702%
Sharpe Ratio
0.369
Sortino Ratio
0.451
Probabilistic Sharpe Ratio
42.819%
Loss Rate
100%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
-0.056
Beta
-0.575
Annual Standard Deviation
0.114
Annual Variance
0.013
Information Ratio
0.849
Tracking Error
0.252
Treynor Ratio
-0.074
Total Fees
$1.00
Estimated Strategy Capacity
$1300000.00
Lowest Capacity Asset
GOOCV W6HEW4GGEUZQ|GOOCV VP83T1ZUHROL
Portfolio Turnover
2.72%
from AlgorithmImports import *

class CustomOptionAssignmentAlgorithm(QCAlgorithm):
    def Initialize(self):
        self.SetStartDate(2015, 12, 1)
        self.SetEndDate(2015, 12, 28)
        self.SetCash(100000)

        self.SetSecurityInitializer(MySecurityInitializer(self.BrokerageModel, FuncSecuritySeeder(self.GetLastKnownPrices)))

        option = self.AddOption("GOOG")
        option.SetFilter(
            lambda option_filter_universe: option_filter_universe.CallsOnly().Strikes(-65, 0).Expiration(0, 30)
        )

    def OnData(self, data):
        if self.Portfolio.Invested:
            return

        for canonical_symbol, chain in data.OptionChains.items():
            min_expiry = min([contract.Expiry for contract in chain])
            contracts = sorted(
                [contract for contract in chain if contract.Expiry == min_expiry],
                key=lambda contract: contract.Strike
            )
            if contracts:
                self.MarketOrder(contracts[0].Symbol, -1)


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)   
        if security.Type == SecurityType.Option:
            security.SetOptionAssignmentModel(MyOptionAssignmentModel())


class MyOptionAssignmentModel(NullOptionAssignmentModel):

    def GetAssignment(self, parameters: OptionAssignmentParameters) -> OptionAssignmentResult:
        option = parameters.Option
        # Check if the contract is ITM
        if option.Right == OptionRight.Call and option.Underlying.Price > option.StrikePrice \
            or option.Right == OptionRight.Put and option.Underlying.Price < option.StrikePrice:
            return OptionAssignmentResult(option.Holdings.AbsoluteQuantity, "MyTag")
        return OptionAssignmentResult.Null