Tags: kabua/Lean
Tags
Adds Futures Options Asset Class w/ IB Support (QuantConnect#4928) * Adds preliminary universe selection for Future Options * Fixes scaling issues with Future Options * Fixes scaling multiplying by 10000x instead of using _scaleFactor * Fixes scaling for Tick * Revert changes to Tick since it divides the scaling factor * Changes stale method name to new method name after rebase * Fixes selection bugs, adds new methods, and adds unit tests * Fixes bug where Equity Symbol was created for an underlying non-equity Symbol, resulting in equity data trying to be loaded * Adds unit tests covering changes to Tick, QuoteBar, TradeBar and LeanData * Adds regression test for AddUniverseOption filter contract selection for Future Options * Addresses review - modifies the AddFutureOption signature * Adds new AddUniverseOptions method overload * Removes and adds a new unit test * Misc. modifications to account for new changes * Fixes bug where futures were loaded using default SID Date * Refactors and removes unnecessary work * Fixes regression algorithm, which previously made no trades * Adds future option data * Adds the corresponding underlying data, in this case, futures data to enable usage of future options data * Replaces data with new data (ES18Z20) * Improves Future chain filtering and updates regression stats * Add AddFutureOptionContract API * Expands regression and unit tests to test in finer detail * Adds Python regression algorithms for AddFutureOption[Contract] methods * Adds new unit test for BacktestingOptionChainProvider * Fixes bug with BacktesingOptionChainProvider where we attempted to load the Trades option chain first, resulting in breakage of backwards compatibility and limitation of the option chain. * Adds new regression algorithms (Py) to Algorithm.Python project * Adds FutureOptionMarginBuyingPowerModel * Modifies code paths used to select margin model * Adds related unit tests for margin model * Fixes issue with unit test and MHDB/SPDB lookup for Future Options * Preliminary regression algorithm testing ITM call/put option buying * Fixes bug where fee model used did not find non-US market options fee model. We now use the futures fee model for future options because IB charges the same commissions per contract between futures and futures options * Adds proper regression algorithm for ITM future options expiration * Pushing broken algorithm for review * Currently, algorithm does not fill forward, causing a single future option to not get exercised when it is delisted. * Adds FutureOptionPutITMExpiryRegressionAlgorithm * Improves existing regression algorithm for call side * Fixes bug in existing regression algorithm * Adds AAPL daily data to advance enumerator for ^^^ fix * Adds additional future option regression algorithms * Adds Buy OTM expiration regression algorithms * Adds Sell ITM/OTM expiration regression algorithms * Adds missing Python regression algorithms * Adds remaining Python regression algorithms and fixes issues * Fixes naming issues and statistics * Adds short option OTM regression algorithms (Py) * Add license header and class comments to python algorithms * Cleans up comments and docstrings * Create Buy/Sell call intraday regression algo * Redirects future options symbol properties to futures symbol properties * Asserts exercise/assignment price and updates stats in regression algos * Adds new unit test covering changes to SecurityService * Adds comments and fixes failing test * Partially fixes future option mis-calculated profit/loss * Adjusts portfolio model to calculate FOP as a no upfront pay asset class * Updates regression algorithm statistics * Begin IB FOP support * Initial support for FOP IB data streaming, live � * Adds additional functionality to LiveOptionChainProvider - Allows querying CME API to retrieve option chains for CME products - Ultimately, it's also the groundwork for the CME LiveFutureChainProvider * Edits IDataQueueUniverseProvider interface to provide greater control to implementors of it * Misc. bug fixes required to get FOP data streaming through IB * Adds comments, adds missing rategate call, and cleans up code * Force exchange for FOP and Futures when no exchange is provided * Fixes bug with Portfolio modeling across all asset classes * Adds LiveOptionChainProvider tests for Future Options * IB brokerage option symbol bug fixes and improvements * Fixes contract multiplier lookup bug * Fixes issue where we attempted to subscribe to IB data feed with canonical security * Adds ES MHDB entry * Reverts portfolio modeling changes for Futures Options * Since IB eats into our account's cash balance when a new FOP contract is purchased, we must model by applying funds to our cash whenever a new purchase/sell occurs. If we choose to model FOPs exactly as we do with futures, we will end up with an invalid TotalPortfolioValue on algorithm restart. By all means and purposes, FOPs are modeled exactly the same as equity options with respect to the portfolio. * Adds comments clarifying portfolio modeling and clarifies existing portfolio modeling comments with additional context. * Fixes IB symbol lookup for future options * Fixes LiveOptionChainProvider looping 5 times per option chain request, even on success * Sets OptionChainedUniverseSelectionModel to produce a canonical future/future option/option Symbol to avoid creating two Symbols * Adds GLOBEX future option symbol mapping from future -> fop * Fixes LiveOptionChainProvider loading wrong contract option chains * Fixes loading of futures options ZIP files when backtesting * Adds a string -> decimal JSON converter * Additional fixes/refactoring to the LiveOptionChainProvider * Adds tests for changes to Symbol and LeanData * Reverts changes to IB-symbol-map * Fixes Value for mapped future options tickers * Fixes Symbol test * Changes path of future options to future's expiry date * Extra changes made to remove scaling from writing CSV * Added method to map from FOP Globex -> FUT Globex * Fixes MOO and MOC orders for future options * Note: this order type might not be supported by IB or CME. * Bug fixes and updates unit tests * Update regression tests and data format * Rebase changes * 1. Multiple bug fixes for LiveOptionChainProvider, reverts IQFeed changes 2. Address review (partial): Code reuse and cleanup 1. * Modifies check in `AddFutureOptionShort(Call|Put)ITMExpiryRegressionAlgorithm` to ensure no buys have negative quantity * Code reuse changes in IB brokerage * Bug fix in IB brokerage where we assigned the FOP expiry as the futures expiry (requires verification) * Doc changes and adds missing summaries/license banners * Disposes of HTTP client resources in LiveOptionChainProvider * Renames classes and adds FutureOption folder in Common/Securities 2. * We revert back to the quotes API for the option chain, since the settlement API sometimes had missing strikes. * Fixes future option expiry being set as future's expiry in LiveOptionChainProvider * Fixes bug where wrong option chain was selected because of bad expiry lookup in the futures expiries returned from CME * Fixes multiple looping bug in LiveOptionChainProvider * Adds strike price scaling for LiveOptionChainProvider * Reverts IQFeed changes and simplifies interface upgrade changes Some additional challenges we'll have to solve as part of FOPs: - The `OptionSymbol.IsStandard` method makes the assumption that weeklies contracts follow the pattern equities follows, which does not apply to Futures Options - The Subscription created in: `OptionChainUniverseSubscriptionEnumeratorFactory` ...adds a Trade config. For illiquid contracts, this will delay universe selection for the option symbol until we get a trade. However, if we add a quote config, the data would instead be loaded based on the first quote we received from the brokerage. But since we're currently using a trade config, illiquid contracts won't start streaming data until it receives a trade. NOTE: this commit is a WIP to addressing the reviews received in the PR, but has been committed early for efficiency in the review process * Fixes regression algorithms and misc. bugs * Fixes map file lookup for non-equity options * Adds extra assertion at end of algorithm to ensure no holdings are left when the algorithm ends. * Adds FutureOptionSymbol, allowing all contracts through as standard * Changes SPDB to allow defaulting to underlying future symbol properties if no entry is found for the given FOP * Fixes calls to SPDB in SecurityService, IBBrokerage * Reverts AAPL daily ZIP file to fix majority of regression algorithms * Adds FOPs symbol properties * Fixes existing symbol properties for a few futures * Adds tests for changes to Symbol Properties Database * Removes string SPDB lookup method * Updates tests and misc callees of previous method * Updates all regression tests to use data of already expired contracts * Adds Futures Options Expiry Functions tests * Adds required futures data for 2020-01-05 * Address review (partial): Expands test coverage and fixes tests * Set option chain tests parallelism to fixture only * Fixes broken test for contract month delta for FuturesOptionsExpiryFunctions * Changes delisting date logic for Futures Options * Address review: removes duplicate code, misc code fixes * Bug fix in MarketHoursDatabase.GetDatabaseSymbolKey() where we would use the underlying's Symbol for lookup in the MHDB * Adds missing license banner * Removes Futures Options entries from MHDB * Adds new tests * Adds SecurityType.FutureOption * Converts any underlying comparisons and uses SecurityType directly instead for FOP specific behavior * Extra code modifications to acommodate new SecurityType * Addresses review: fixes order fee bug on exercise * Additional bug fixes and adding of SecurityType.FutureOption * Updates regression algorithms OrderListHash * Fixes various bugs in IB live implementation * Fixes bug setting the right contract expiration date for FOP generated by LiveOptionChainProvider * Adds new function to FuturesOptionsExpiryFunctions * Clarifies parameter names better in some functions/methods * Fixes bugs in IB brokerage for FOPs * Address review - code cleanup and refactor * Remove MappingEventProvider, SplitEventProvider, and DividendEventProvider for Futures Options in CorporateEventEnumeratorFactory * Address review: Use MHDB key resolver in SPDB * Makes regression tests pass and adds comment for expiry issue * Fixes MHDB lookup on string symbol method * Adds Futures Options greeks regression algorithm (C# only) * Adds explanitory comment on MHDB FOP lookup * Remove python from FutureOptionCallITMGreeksExpiryRegressionAlgorithm
Bug 4757 Synchronize Security Additions (QuantConnect#4879) * Bump time by one tick in adding subscription * Adjust regressions * Change removal to immediate * Use series.AddPoint instead of directly adding it * Adjust regression * Add checks for fixed behavior in regressions * Address review
Lean Optimization interface in QCAlgorithm (QuantConnect#4923) * initial commit * run parametrized algorithm with command line parameters * skeleton: top level structure * OptimizationNodePacket scheme * pass parameters as HashSet * run Lean and read results * call method on optimization completion * refactor public interfaces - close ParameterSet collection; allow only get operations - explicit method to start LeanOptimizer * synchronize RunLean method; the result could come in before the backtest id is set in the collections * another portion of refactoring and interface changes * comments * comments & tests for Extremum, Minimization and Maximization classes * unify optimization paramater values (min, max, step) & mode GridSearch tests - swap min&max if necessary - iterate left => right (negate step value if necessary) & provide default step value if step == 0 - no StackOverflow Exception - parameterSet Id should be global for current generator and retain between steps - test signle point boundary (min == max) * BruteForceStrategy tests * more comments * Update Optimizer assembly information - Update Optimizer projects assembly information to match behavior of the other projects * Tweaks - Adding comments - Replace OnComplete for Ended event - Replace Abort for Dispose - ConsoleLeanOptimizer will keep track of running processes - Each backtest will store results in a separated directory, so they don't fight for the log.txt file. - Adding cmdline option for lean to close automatically - Adding concurrent execution backtest limit - Console optimizer will start Lean minimized - Escape spaces in Json path * remove parameter set generator abstraction layer we don't need this flexibility now. * refactor public methods; Step shouldn't be public * constraints: wip * define contract * comparison operators and tests * specify JsonProperty values * Move SafeMultiply100 to extensions * Throw exception on failed Optimizer.Start * constraints: wip * change finish & dispose process * minor fixes - handle force lean abort - notify consumer if target has been reached * target & constraints; adapt unit tests * Minor Tweaks and fixes - Some logging improvements - Remove Public since not required * Ignore empty ParameterValue * simplify condition * avoid reinitialization * reduce type; force immutable * unit tests for constraints and target value * parse & normalize percent values, i.e. 20% => 0.2 * fixup * Target & Constraint & OptimizationNodePacket unit tests * Add more json unit tests - Adding more json conversion unit tests. Fix bug for Extremum which wasn't using the converter. * LeanOptimizer tests * Estimation results * User thread safe counters * LeanOptimizer unit tests; push OptimizationResult on Ended event * more unit tests * Minor tweaks -Estimate ToString in a single line. -Typos and missing header file * Add base SendUpdate method - Add base SendUpdate method for LeanOptimizer * fix LeanOptimizer test; rely on internal Update rather than timer * Add OptimizationStatus - Add missing commments and OptimizationStatus * EulerSearch implementation: wip * OptimizationParameter custom converter * change the type * make step optional * change folder structure * enumerate optimization parameter using IEnumerable & IEnumerator * unit tests: parameters & objectives * unit tests: strategies * remove redundant TODO * change Euler search boundaries * more Euler tests * prevent race condition * Add account/read endpoint - Adding account/read endpoint. Adding unit test * Add status check before running lean * Minor self review - Adding missing comments, minor changes * remove array parameters * minor changes - tidy up config file, rename variable - accept min less or equal than max * move OptimizationParameter methods to strategies * Minor improvements for BaseResultHandler derivates * minor changes - strict requirements for Step and MinStep values - strategy specific settigs * Add TotalRuntime to estimate Co-authored-by: Martin Molinero <martin.molinero1@gmail.com>
Add OptionStrategyMatcher (QuantConnect#4924) * Reformat/cleanup OptionStrategies This file was breaking pretty much every style convention in LEAN. There are other things that should be addressed in here that weren't, such as passing non-argument names as argument names for ArgumentException, as well as preferring constructors over property initializer syntax, but such changes aren't being made to keep this commit strictly reformatting instead of refactoring. Added braces and reformatted long lines to make code more legible. * Add abstract base class for OptionStrategy Option/UnderlyingLegData This allows us to create either or and later use the Invoke method to push it into the appropriate list on OptionStrategy. * Replace O(n) option contract search with 2 O(1) TryGetValue calls A better improvement would be resolving the correct symbol in the strategy, but this immediate change is instead just focused on removing the O(n) search inside a loop. * Add BinaryComparison and supporting methods in ExpressionBuilder We're going to use these binary comparisons to make it possible to create ad-hoc queries against a collection of symbols. Using these expressions, along with type supporting composition of these expression, we'll be able to define predicates that can declaratively define how to match an option strategy with an algorithms current holdings. * Make GetValueOrDefault defaultValue optional Was receiving ambiguous invocations leading to neading to invoke this method explicitly (LinqExtensions.GetValueOrDefault) instead of being able to use it as an extension method. Making the default value optional seems to have resolved this ambiguity, leading to cleaner code in the OptionPositionCollection (forthcoming) * Add OptionPosition and OptionPositionCollection OptionPositionCollection aims to provide a single coherent interface for querying an algorithm's option contract positions and the underlying equity's position in a performant, immutable way. The immutability of the type is necessary for how the options matcher will operate. We need to recursively evaluate potential matches, each step down the stack removing positions from the collection consumed by each leg matched. This will enable parallelism of the solution as well as simplifying the mental model for understanding due to not needing to track mutations to the collection instance. * Add Option test class for easily creating option symbol objects * Add OptionStrategyLegPredicate and OptionStrategyLegDefinition The definition is a composition of predicates, and each predicate supports matching against a set of pre-existing legs and a current position being checked for the next leg (this leg). In addition to the matching functionality, it also supports filtering the OptionPositionCollection, which is where much of the work for resolving potential option strategies is done. By successively filtering the OptionPositionCollection through successive application of predicates, we wil end up with a small set of remaining positions that can be individually evaluated for best margin impacts. All of this effectively unrolls into a giant evaluation tree. Because of this inherent structure, common in combinatorial optimization, the OptionPositionCollection is an immutable type to support concurrent evaluations of different branches of the tree. For large position collections this will dramatically improve strategy resolution times. Finally, the interface between the predicate and the positions collection is purposefully thin and provides a target for future optimizations. * Add OptionStrategyDefinition and OptionStrategyDefinitions pre-defined definitions The OptionStrategyDefinition is a definitional object provided a template and functions used to match algorithm holdings (via OptionPositionCollection) to this definition. The definition defines a particular way in which option positions can be combined in order to achieve a more favorable margin requirement, thereby allowing the algorithm to hold more positions than otherwise possible. This ties into the existing OptionStrategy classes and the end result of the matching process will be OptionStrategy instances definiing all strategies matched according to the provided definitions. * Add OptionStrategyMatcher and Options class, w/ supporting types OptionStrategyMatcherOptions aims to provide some knobs and dials to control how the matcher behaves, and more importantly, which positions get prioritized when matching. Prioritization is controlled via two different enumerators, one controller which definitions are matched first and the other controller which positions are matched first. Still unimplemented, is computing multiple solutions and running the provided objective function to determine the best match. When this gets implemented, we'll also want to implement the timer. For anyone looking to implement these features, please talk with Michael Handschuh as there's a particular way of representing these types of combinatorial solutions (a 3D tree) that can be used as a variation of the linear simplex method for optimizing combinatorial problems. * OptionStrategyMatcher: Address PR review comments * Ensure created OptionStrategy legs all have the same multiplier Each leg definition match gets it's own multiplier which indicates the maximum number of times we matched that particular leg. When we finish matching all legs, we pick the smallest multiplier from all the legs in the definition and use that as the definition's multiplier. When we go to create the OptionStrategy object we MUST make sure we're using the multiplier from the definition and not from the individual legs. This change fixes this issue and also provides a guard clause to ensure that we're not trying to use a multiplier larger than what was matched. * Add XML docs for OptionStrategyDefinitions from OptionStrategies
Lean shutdown improvements (QuantConnect#4982) - Use DisposeSafely instead of dipose. - Adding some logs to know when handlers are getting disposed. - Normalize exit procedure
Block SetWarmUp after Algorithm has compeleted initialization (QuantC… …onnect#4975) * Fix for QuantConnect#4939 * Address review * Logic fix
Fixes issue parsing SI data w/ unknown enum value (QuantConnect#4961) * Extends tests to cover new additions
Bug 4947 OnOrderEvent exceptions (QuantConnect#4974) * Force algorithm to fail on runtime error * add comment * Remove unneeded change * Update algorithm summary * Address review
Fixes inability to parse negative strike prices in SecurityIdentifier (… …QuantConnect#4953) * Fixes inability to parse negative strike prices in SecurityIdentifier * Adds new tests ensuring backwards compat and no throwing w/ negative strike prices * Changes strategy used to support negative strike prices * We add support for negative strike prices at the cost of reducing the maximum allowed precision for the strike price. We encode a negative sign into the 20th bit of the strike price and set our bounds for precision to a max (exclusive) of 475712. This in turn is then used to form a negative strike when rebuilding the SID. * Adds tests covering changes * Address review: adds additional tests and refactors code * Address self-review: remove unused import in SymbolTests * Address review: adds additional test cases for OptionStyle and OptionRight * These tests are to ensure that backwards compatibility is maintained * Addresses review: Adds option chain <-> master SID hash test * Refactors previous tests to reduce on code duplication * Reduce test duplication Co-authored-by: Martin Molinero <martin.molinero1@gmail.com>
PreviousNext