539011274c
Python Virtual Environments / build (push) Has been cancelled
Benchmarks / build (push) Has been cancelled
Build & Test Lean / build (push) Has been cancelled
Regression Tests / build (push) Has been cancelled
Research Regression Tests / build (push) Has been cancelled
* Support extended market hours in AddFuture() * Support extended market hours in AddFutureContract() * Add C# regression algorithm * Add Python regression algorithm * Add regression algorithm for future contracts * Add regression algorithm checking market hour ranges * Fixed future regression algorithms to use extended market hours * Fixed future regression algorithms to use extended market hours * Fixed future regression algorithms to use extended market hours * Fixed AddFutureOptionContractFromFutureChainRegressionAlgorithm to use extended market hours * Update future market hours to include extended in market hours database * Fixed AddFutureOptionContractDataStreamingRegressionAlgorithm to use extended market hours * Fixed AddFutureOptionContractFromFutureChainRegressionAlgorithm to use extended market hours * Fixed AddFutureContractWithContinuousRegressionAlgorithm to use extended market hours * Fixed BasicTemplateContinuousFutureAlgorithm to use extended market hours * Fixed BasicTemplateFuturesAlgorithm to use extended market hours * Fix BasicTemplateFuturesDailyAlgorithm to use extended market hours * Fixed BasicTemplateFuturesFrameworkAlgorithm to use extended market hours * Fixed BasicTemplateFuturesHistoryAlgorithm to use extended market hours * Fixed ContinuousBackMonthRawFutureRegressionAlgorithm to use extended market hours * Fixed ContinuousFutureBackMonthRegressionAlgorithm to use extended market hours * Fixed ContinuousFutureHistoryRegressionAlgorithm to use extended market hours * Fixed ContinuousFutureLimitIfTouchedOrderRegressionAlgorithm to use extended market hours * Fixed ContinuousFutureRegressionAlgorithm to use extended market hours * Fixed DelistedFutureLiquidateRegressionAlgorithm to use extended market hours * Fixed AutomaticIndicatorWarmupDataTypeRegressionAlgorithm to use extended market hours * Fixed ConsolidateRegressionAlgorithm to use extended market hours * Fixed DelistingFutureOptionRegressionAlgorithm to use extended market hours * Fixed EqualWeightingPortfolioConstructionModelFutureRegressionAlgorithm to use extended market hours * Fixed FutureContractsExtendedMarketHoursRegressionAlgorithm to use extended market hours * Fixed FutureMarketOpenAndCloseRegressionAlgorithm to use extended market hours * Fixed FutureMarketOpenConsolidatorRegressionAlgorithm to use extended market hours * Fixed FutureOptionBuySellCallIntradayRegressionAlgorithm to use extended market hours * Fixed FutureOptionCallITMExpiryRegressionAlgorithm to use extended market hours * Fixed FutureOptionCallITMGreeksExpiryRegressionAlgorithm to use extended market hours * Fixed FutureOptionCallOTMExpiryRegressionAlgorithm to use extended market hours * Fixed FutureOptionDailyRegressionAlgorithm to use extended market hours * Fixed FutureOptionHourlyRegressionAlgorithm to use extended market hours * Fixed FutureOptionMultipleContractsInDifferentContractMonthsWithSameUnderlyingFutureRegressionAlgorithm to use extended market hours * Fixed FutureOptionPutITMExpiryRegressionAlgorithm to use extended market hours * Fixed FutureOptionPutOTMExpiryRegressionAlgorithm to use extended market hours * Fixed FutureOptionShortCallITMExpiryRegressionAlgorithm to use extended market hours * Fixed FutureOptionShortCallOTMExpiryRegressionAlgorithm to use extended market hours * Fixed FutureOptionShortPutITMExpiryRegressionAlgorithm to use extended market hours * Fixed FutureOptionShortPutOTMExpiryRegressionAlgorithm to use extended market hours * Fixed FuturesAndFuturesOptionsExpiryTimeAndLiquidationRegressionAlgorithm to use extended market hours * Fixed FuturesExpiredContractRegression to use extended market hours * Fixed FutureSharingTickerRegressionAlgorithm to use extended market hours * Fixed HistoryWithDifferentContinuousContractDepthOffsetsRegressionAlgorithm to use extended market hours * Fixed HistoryWithDifferentDataMappingModeRegressionAlgorithm to use extended market hours * Fixed HistoryWithDifferentDataNormalizationModeRegressionAlgorithm to use extended market hours * Fixed LimitOrdersAreFilledAfterHoursForFuturesRegressionAlgorithm to use extended market hours * Fixed OpenInterestFuturesRegressionAlgorithm to use extended market hours * Fixed RegisterIndicatorRegressionAlgorithm to use extended market hours * Fixed SetHoldingsFutureRegressionAlgorithm to use extended market hours * Fixed WarmupFutureRegressionAlgorithm to use extended market hours * Fixed AddFutureOptionSingleOptionChainSelectedInUniverseFilterRegressionAlgorithm to use extended market hours * Fixed AlgorithmHistoryTests to use extended market hours for futures * Fixed AlgorithmTradingTests to use extended market hours for futures * Fixed BrokerageSetupHandlerTests to use extended market hours for futures * Fixed TimeRulesTests to use extended market hours for futures * Fixed FutureOptionMarginBuyingPowerModelTests to use extended market hours for futures * Fixed FutureMarginBuyingPowerModelTests to use extended market hours for futures * Fixed FileSystemDataFeedTests to use extended market hours for futures * Fixed QuantBookHistoryTests to use extended market hours for futures * Split BasicTemplateContinuousFutureAlgorithm to have an extended market version * Fixed FutureMarketOpenAndCloseRegressionAlgorithm to use extended market hours * Split BasicTemplateFuturesAlgorithm to have an extended market version * Split BasicTemplateFuturesAlgorithm to have an extended market version * Split BasicTemplateFuturesFrameworkAlgorithm to have an extended market version * Split BasicTemplateFuturesHistoryAlgorithm to have an extended market version * Revert AddFutureContractWithContinuousRegressionAlgorithm * Revert AddFutureOptionContractDataStreamingRegressionAlgorithm and added data * Revert AddFutureOptionContractFromFutureChainRegressionAlgorithm * Revert AddFutureOptionSingleOptionChainSelectedInUniverseFilterRegressionAlgorithm * Revert ConsolidateRegressionAlgorithm * Revert Algorithm.CSharp/ContinuousBackMonthRawFutureRegressionAlgorithm.cs * Revert ContinuousFutureBackMonthRegressionAlgorithm * Revert ContinuousFutureHistoryRegressionAlgorithm * Revert ContinuousFutureLimitIfTouchedOrderRegressionAlgorithm * Revert ContinuousFutureRegressionAlgorithm * Revert Algorithm.CSharp/DelistedFutureLiquidateRegressionAlgorithm.cs * Revert EqualWeightingPortfolioConstructionModelFutureRegressionAlgorithm * Split FutureMarketOpenAndCloseRegressionAlgorithm to have an extended market version * Split FutureMarketOpenConsolidatorRegressionAlgorithm to have an extended market version * Revert FutureOptionBuySellCallIntradayRegressionAlgorithm * Revert FutureOptionCallITMExpiryRegressionAlgorithm * Revert FutureOptionDailyRegressionAlgorithm * Revert FutureOptionPutITMExpiryRegressionAlgorithm * Revert FutureSharingTickerRegressionAlgorithm * Revert FuturesAndFuturesOptionsExpiryTimeAndLiquidationRegressionAlgorithm * Revert FuturesExpiredContractRegression * Revert HistoryWithDifferentContinuousContractDepthOffsetsRegressionAlgorithm * Revert HistoryWithDifferentDataMappingModeRegressionAlgorithm * Revert HistoryWithDifferentDataNormalizationModeRegressionAlgorithm * Revert OpenInterestFuturesRegressionAlgorithm * Revert RegisterIndicatorRegressionAlgorithm * Revert SetHoldingsFutureRegressionAlgorithm * Revert WarmupFutureRegressionAlgorithm * Revert AutomaticIndicatorWarmupDataTypeRegressionAlgorithm * Some cleanup * Address changes request * Address changes request * Add more Class III Milk data to fix DelistingFutureOptionDailyRegressionAlgorithm
78 lines
3.5 KiB
Python
78 lines
3.5 KiB
Python
# QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
|
# Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License
|
|
|
|
from AlgorithmImports import *
|
|
|
|
### <summary>
|
|
### This regression algorithm tests In The Money (ITM) future option calls across different strike prices.
|
|
### We expect 6 orders from the algorithm, which are:
|
|
###
|
|
### * (1) Initial entry, buy ES Call Option (ES19M20 expiring ITM)
|
|
### * (2) Initial entry, sell ES Call Option at different strike (ES20H20 expiring ITM)
|
|
### * [2] Option assignment, opens a position in the underlying (ES20H20, Qty: -1)
|
|
### * [2] Future contract liquidation, due to impending expiry
|
|
### * [1] Option exercise, receive 1 ES19M20 future contract
|
|
### * [1] Liquidate ES19M20 contract, due to expiry
|
|
###
|
|
### Additionally, we test delistings for future options and assert that our
|
|
### portfolio holdings reflect the orders the algorithm has submitted.
|
|
### </summary>
|
|
class FutureOptionBuySellCallIntradayRegressionAlgorithm(QCAlgorithm):
|
|
|
|
def Initialize(self):
|
|
self.SetStartDate(2020, 1, 5)
|
|
self.SetEndDate(2020, 6, 30)
|
|
|
|
self.es20h20 = self.AddFutureContract(
|
|
Symbol.CreateFuture(
|
|
Futures.Indices.SP500EMini,
|
|
Market.CME,
|
|
datetime(2020, 3, 20)
|
|
),
|
|
Resolution.Minute).Symbol
|
|
|
|
self.es19m20 = self.AddFutureContract(
|
|
Symbol.CreateFuture(
|
|
Futures.Indices.SP500EMini,
|
|
Market.CME,
|
|
datetime(2020, 6, 19)
|
|
),
|
|
Resolution.Minute).Symbol
|
|
|
|
# Select a future option expiring ITM, and adds it to the algorithm.
|
|
self.esOptions = [
|
|
self.AddFutureOptionContract(i, Resolution.Minute).Symbol
|
|
for i in (self.OptionChainProvider.GetOptionContractList(self.es19m20, self.Time) +
|
|
self.OptionChainProvider.GetOptionContractList(self.es20h20, self.Time))
|
|
if i.ID.StrikePrice == 3200.0 and i.ID.OptionRight == OptionRight.Call
|
|
]
|
|
|
|
self.expectedContracts = [
|
|
Symbol.CreateOption(self.es20h20, Market.CME, OptionStyle.American, OptionRight.Call, 3200.0, datetime(2020, 3, 20)),
|
|
Symbol.CreateOption(self.es19m20, Market.CME, OptionStyle.American, OptionRight.Call, 3200.0, datetime(2020, 6, 19))
|
|
]
|
|
|
|
for esOption in self.esOptions:
|
|
if esOption not in self.expectedContracts:
|
|
raise AssertionError(f"Contract {esOption} was not found in the chain")
|
|
|
|
self.Schedule.On(self.DateRules.Tomorrow, self.TimeRules.AfterMarketOpen(self.es19m20, 1), self.ScheduleCallbackBuy)
|
|
|
|
def ScheduleCallbackBuy(self):
|
|
self.MarketOrder(self.esOptions[0], 1)
|
|
self.MarketOrder(self.esOptions[1], -1)
|
|
|
|
def OnEndOfAlgorithm(self):
|
|
if self.Portfolio.Invested:
|
|
raise AssertionError(f"Expected no holdings at end of algorithm, but are invested in: {', '.join([str(i.ID) for i in self.Portfolio.Keys])}")
|