Commit Graph

144 Commits

Author SHA1 Message Date
Gerardo Salazar be6ead75e9 Revert some changes and adds pandas memory allocator 2020-12-06 19:15:38 -08:00
Gerardo Salazar 25f7ccf0c2 Performance improvements 2020-12-06 19:15:38 -08:00
Gerardo Salazar afb0a86291 Faster double casting than CLR implementation 2020-12-06 19:14:48 -08:00
Gerardo Salazar c471d1ced0 Adds unit tests and fixes various bugs in PandasConverter 2020-12-06 19:14:48 -08:00
Gerardo Salazar 11bed1f0c3 Address self-review: Adds explanitory comments and cleans up code 2020-12-06 19:14:24 -08:00
Gerardo Salazar ec57799a5d Reverts changes and deletes unused classes 2020-12-06 19:14:24 -08:00
Gerardo Salazar 4c8aa638eb Fixes failing unit tests by converting filter mask to PyObject[] 2020-12-06 19:13:54 -08:00
Gerardo Salazar 45f71543bd Filters duplicates more efficiently, fixes warning on removal of dupes
* Commit includes behind the scenes testing and validation of the data
    and performance as a result of modifying the dupe removal process
2020-12-06 19:13:54 -08:00
Gerardo Salazar 13b9d91ecb Memory leak fixes for options and performance improvement for NA replace 2020-12-06 19:13:54 -08:00
Gerardo Salazar f239018e77 Tames the wild beast of memory leaks, for QuoteBar data 2020-12-06 19:13:54 -08:00
Gerardo Salazar f1c98b848a Partially fixes memory leak in PandasConverter 2020-12-06 19:13:54 -08:00
Gerardo Salazar 2c7bde422a Reuses MemoryStream to avoid having to reallocate consistently
* Cleans up .csproj and packages.config
  * Adds IDisposable to PandasConverter, PandasArrowMemoryAllocator
2020-12-06 19:13:54 -08:00
Gerardo Salazar 9e95bfea90 Fixes various bugs and matches previous version for backwards compat 2020-12-06 19:13:35 -08:00
Gerardo Salazar b820ff4de8 EOD commit; Attempts to implement alt. data support 2020-12-06 19:13:35 -08:00
Gerardo Salazar 8218a2be99 Fixes bug with options and refactors code
* Option index is now 1-1 with existing impl
  * Begin adding support for custom data
2020-12-06 19:13:35 -08:00
Gerardo Salazar 9e3031c562 Fixes options support
* 1 bug remaining: Get index to be ''
2020-12-06 19:13:35 -08:00
Gerardo Salazar 2cf9239b6e Improves performance by ~10% of Arrow implementation
* New allocator improves performance by reusing allocated buffers
2020-12-06 19:13:35 -08:00
Gerardo Salazar 4c63c60a89 Adds option expiry support 2020-12-06 19:13:35 -08:00
Gerardo Salazar 9a2e47b05c Adds support for future expiry and proper indexing 2020-12-06 19:13:35 -08:00
Gerardo Salazar 711d46d6e2 Fixes bugs with index and handling of no data 2020-12-06 19:13:35 -08:00
Gerardo Salazar 5d6625c1ea Adds support for Tick, OpenInterest
* Performance improvement for Symbol creation in TimeSliceFactory for
    futures
2020-12-06 19:13:34 -08:00
Gerardo Salazar 0a70611d81 MVP of Apache Arrow in-memory pandas DataFrame construction 2020-12-06 19:13:16 -08:00
Gerardo Salazar eb1181f5f7 Adds Futures Options Asset Class w/ IB Support (#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
2020-12-02 21:49:59 -03:00
Alexandre Catarino 6efeee07dc Implements Equity Fill Model (#4913)
* Implements Equity Fill Model

This commit sets the base to create a new equity fill model and the `EquityFillModel` is just a copy of `FillModel`.

* Adds Summary to FillModelPythonWrapper.GetPricesInternal

Adds summary to FillModelPythonWrapper.GetPricesInternal with remarks that it's a temporarily method to help the refactoring of fill models.
2020-11-04 15:51:41 -03:00
Colton Sellers 34676f0c46 Bug 4668 python register indicator (#4670)
* Convert to timespan if possible

* Fix to support both timespans and custom consolidators

* Adjust tests for new wrapper requirements

* Cleanup
2020-08-29 02:53:32 -03:00
Colton Sellers b8674731a5 Feature 2456 custom Python consolidator support (#4637)
* DataConsolidator Wrapper for Python Consolidators

* Regression Unit Test

* Refactor Regression test

* Bad test fix

* pre review

* self review

* Add RegisterIndicator for Python Consolidator

* Python base class for consolidators

* Modify regression algo to register indicator

* unit test - attach event

* Test fix

* Fix test python imports

* Add license header file and null check

Co-authored-by: Martin Molinero <martin.molinero1@gmail.com>
2020-08-25 17:26:55 -03:00
Alexandre Catarino 75a5f267f1 Adds Support to List of Symbol and String (Ticker)
Adds case in the mapper method to handled list type.
2020-07-04 00:11:19 +01:00
Jared f9cad3dc0c Merge pull request #4451 from QuantConnect/bug-pandasdata-misaligned-series-indexes-crash
Fixes alignment of Series objects created in PandasData causing crash
2020-05-26 14:02:17 -07:00
Gerardo Salazar 833c0540e0 Address review - short circuit the PandasData field/property type check 2020-05-25 09:46:58 -07:00
AlexCatarino 7bb7d6487f Fixes PandasData Wrapper Support for Query Method
query/eval methods needs to look for a scope variable at a higher level since the wrapper classes are children of pandas classes.
2020-05-23 02:19:52 +01:00
Gerardo Salazar bb2947d941 Fixes alignment of Series objects created in PandasData causing crash
* When a BaseData instance has Nullable fields, the number of data
    points per Series is inconsistent, and results in a Series with
    a length different from the other Series we produce, resulting
    in an error "ValueError: cannot handle a non-unique multi-index!"
    when we were constructing the final DataFrame.
2020-05-22 15:57:16 -07:00
AlexCatarino 2ab7eefd63 PandasData Speed Improvement
Use the original `pandas.Series` to create `Series` objects before `DataFrame` (wrapper version) creation.
It improves the speed because it avoids unnecessary and expensive index wrapping operations of the `DataFrame` creation.
2020-05-21 15:55:00 +01:00
AlexCatarino 34c337e766 Addresses Peer-Review 2020-05-18 16:28:19 +01:00
AlexCatarino e9eba27e6e Implements New PandasData.Remapper
In this implementation, we dynamically create new classes that wraps key functions and properties. The wrappers will map/convert any parameter that are convertible to the string representation of Symbol.ID before they are used by the original function/property.
2020-05-15 23:30:19 +01:00
Martin-Molinero 85cc7b13dc Revert "Adds pandas Methods (Part I)" 2020-05-06 20:16:04 -03:00
Martin-Molinero 31ed6e349b Revert "Adds pandas Methods (Part II)" 2020-05-06 20:15:41 -03:00
Martin-Molinero 3d9a24ff5c Revert "Adds pandas Methods (Part III)" 2020-05-06 20:15:17 -03:00
Martin-Molinero 07ef201f01 Revert "Adds pandas Methods (Part IV)" 2020-05-06 20:14:57 -03:00
Martin-Molinero 07bf7f48e4 Revert "Adds pandas Methods (Part V)" 2020-05-06 20:14:17 -03:00
AlexCatarino c1baf7da1a Addresses Peer-Review
`first_valid_index´ has been removed for now as it doesn't have a satifactory init test. It will be added in a future commit.
2020-05-06 14:28:59 +01:00
AlexCatarino 1538d0f134 Adds pandas Methods (Part V)
Methods: 'eq', 'eval', 'explode', 'ffill', 'fillna', 'filter', 'first', 'floordiv', 'ftypes', 'ge'
2020-05-06 02:05:20 +01:00
AlexCatarino b7b54ffa0b Adds pandas Methods (Part IV)
Methods: 'diff', 'div', 'divide', 'drop', 'drop_duplicates', 'droplevel', 'dropna', 'dtypes', 'duplicated'

`BackwardsCompatibilityDataFrame_binary_operator` replaces `BackwardsCompatibilityDataFrame_add` to handle all operations (more to be added in future commits)
2020-05-05 21:43:12 +01:00
AlexCatarino 02d90c4fb0 Adds pandas Methods (Part III)
Methods: 'columns', 'combine', 'combine_first', 'compound', 'copy', 'corr', 'corrwith', 'count', 'cov', 'cummax', 'cummin', 'cumprod', 'cumsum'
2020-05-05 17:15:30 +01:00
AlexCatarino a14c41bb97 Addresses Peer-Review
Removes `bool` because it doesn't return a pandas object with an index.
2020-05-05 15:24:34 +01:00
AlexCatarino 321603926a Adds pandas Methods (Part II)
Methods: 'asfreq', 'asof', 'assign', 'astype', 'at', 'at_time', 'axes', 'between_time', 'bfill', 'bool', 'clip', 'clip_lower', 'clip_upper'.
2020-05-05 12:40:14 +01:00
AlexCatarino ff32b8e15e Adds pandas Methods (Part I)
Methods: 'abs', 'add', 'add_prefix', 'add_suffix', 'agg', 'aggregate', 'align', 'all', 'any', 'append', 'apply', 'applymap'.
2020-05-05 01:32:49 +01:00
AlexCatarino a892173710 Fixes Not Wrapped pandas.Dataframe
`Remapper.__getitem__`  was not returns a `Remapper` object when the result was `pandas.DataFrame`. It is needed for a sequence of `.loc.` calls.
Refactors `Remapper._self_mapper` to handle tuples where the key can be found in both first and second position.

Update unit tests that should test `Symbol` object as key, but were using `str(Symbol)`.
2020-05-01 00:25:46 +01:00
Martin Molinero 8e71e48c07 PythonSlice
- AlgorithmPythonWrapper will directly call base OnFrameworkData()
  implementation skipping going through python and it's overhead
- Small performance improvement for adding Tick data points into a Ticks
  collection
- For python always wrap slice with PythonSlice, so that slice.Get()
  works even when no custom data is present, adding test.
2020-04-27 19:03:03 -03:00
AlexCatarino c1e18f82bb WIP 2020-04-01 16:15:04 +01:00
AlexCatarino 5e37a8b259 Implements IExtendedDictionary
`PythonSlice` implements `IExtendedDictionary`
2020-04-01 16:15:04 +01:00