Adjust delisting liquidation time (#5203)

* Adjust delisting liquidation time

- Adjust delisting liquidation time to 15 min before market closes.
  Adding unit tests. Updating existing.
- Handle `Statistics.CompoundingAnnualPerformance` invalid calculation
  to avoid exception.
- AlgorithmManager will not handle delisting events in live trading
- Fix bug where due to a split driven liquidation matching delisting
  date a position in the option would remain open. Reproduced by
  `BasicTemplateOptionsFrameworkAlgorithm`

* Address review

- Address review add documentation on delisting offset span
This commit is contained in:
Martin-Molinero
2021-01-22 14:41:29 -03:00
committed by GitHub
parent 5d8a62c2e1
commit 3ccf428498
32 changed files with 227 additions and 71 deletions
@@ -97,7 +97,7 @@ class FutureOptionCallITMExpiryRegressionAlgorithm(QCAlgorithm):
self.Log(f"{self.Time} -- {orderEvent.Symbol} :: Price: {self.Securities[orderEvent.Symbol].Holdings.Price} Qty: {self.Securities[orderEvent.Symbol].Holdings.Quantity} Direction: {orderEvent.Direction} Msg: {orderEvent.Message}")
def AssertFutureOptionOrderExercise(self, orderEvent: OrderEvent, future: Security, optionContract: Security):
expectedLiquidationTimeUtc = datetime(2020, 6, 19, 4, 1, 0)
expectedLiquidationTimeUtc = datetime(2020, 6, 19, 20, 0, 0)
if orderEvent.Direction == OrderDirection.Sell and future.Holdings.Quantity != 0:
# We expect the contract to have been liquidated immediately
@@ -96,7 +96,7 @@ class FutureOptionPutITMExpiryRegressionAlgorithm(QCAlgorithm):
self.Log(f"{self.Time} -- {orderEvent.Symbol} :: Price: {self.Securities[orderEvent.Symbol].Holdings.Price} Qty: {self.Securities[orderEvent.Symbol].Holdings.Quantity} Direction: {orderEvent.Direction} Msg: {orderEvent.Message}")
def AssertFutureOptionOrderExercise(self, orderEvent: OrderEvent, future: Security, optionContract: Security):
expectedLiquidationTimeUtc = datetime(2020, 6, 19, 4, 1, 0)
expectedLiquidationTimeUtc = datetime(2020, 6, 19, 20, 0, 0)
if orderEvent.Direction == OrderDirection.Buy and future.Holdings.Quantity != 0:
# We expect the contract to have been liquidated immediately
@@ -17,7 +17,7 @@ class FuturesAndFuturesOptionsExpiryTimeAndLiquidationRegressionAlgorithm(QCAlgo
self.expectedExpiryWarningTime = datetime(2020, 6, 19)
self.expectedExpiryDelistingTime = datetime(2020, 6, 20)
self.expectedLiquidationTime = datetime(2020, 6, 19, 0, 1, 0)
self.expectedLiquidationTime = datetime(2020, 6, 19, 16, 0, 0)
self.SetStartDate(2020, 1, 5)
self.SetEndDate(2020, 12, 1)