Commit Graph

90 Commits

Author SHA1 Message Date
Adalyat Nazirov 7bb143b215 Bug 4031 Change data depending on configuration (#4650)
* Calculate both raw and adjuasted prices for backtesting

* disable second price factoring

* move and reuse method

* test coverage for new methods

* reuse scaling method

* reuse subscriptionData.Create method

* removed unused code

* regression test

* switch to aapl

* fix regression test output

* more asserts

* fix comments - reduce shortcuts and abbrevation

* more comments

* merge parameters

* reduce number of getting price factors

* fix tests

* fix tests

* fix regression tests

* calculate TotalReturn on demand

* include TotalReturn calculations

* perf tuning

* more unit tests for SubscriptionData.Create

* simplify things - store and return only raw and precalculated data

* fix regression tests; change it back

* factor equals 1 for Raw data

* small changes

* follow code style

* implement backward compatibility
2020-09-09 18:40:19 -03:00
Martin-Molinero 3609340281 Add internal subscriptions always (#4690)
* Add set market price during extended market hours

- Set market prices during extended market hours for live trading.
  Adding unit test

* Add assert on internal data count
2020-09-03 18:15:21 -07:00
Martin Molinero bcc67d2457 DataPermissionManager is used by history provider
- DataPermissionManager will be used by the history provider
- Moving interfaces from Engine to Common
2020-06-12 12:51:14 -03:00
AlexCatarino 7a9778f9fd Addresses Peer-Review
- Do not reuse parameter variables `start` and `end`. Create new variables with meaningful names and rename them to `startUtc` and `endUtc`.
- Use `EachTradeableDayInTimeZone` to calculate `tradableDates`.
- Adds another test/assertion in the regression algorithms to ensure tests in the scheduled event were performed.
2020-05-29 14:56:10 +01:00
AlexCatarino 8b1afdb083 Fixes History Request Data Time Zone
The tradable days of the history request should respect the data time zone since the data source files also do.

Upgrade `BasicTemplateFuturesHistoryAlgorithm` to a regression algorithm and add a schedule event to test history requests every hour.
2020-05-29 00:31:12 +01:00
Martin Molinero 793cc15cd3 Add optional intraday historical enumerator
- Adding new ConcatEnumerator that will join enumerators together
  secuentially. Adding unit tests
- SubscriptionDataReaderHistoryProvider will consume an optional
  intraday enumerator that will be concatenated with the existing
  SubscriptionDataReader
2020-04-15 10:48:04 -03:00
Martin Molinero 010c6ab799 Address reviews
- Rename history provider parameters `LiveMode` to `ParallelHistoryRequestsEnabled`
- Reduce code duplication
2019-11-29 17:31:19 -03:00
Martin Molinero 9f87ee5391 Disable live parallel history request
- Some IDataCacheProviders are not compatible with parallel history requests,
so disabling for live trading.
2019-11-29 15:55:13 -03:00
Martin Molinero 0d4aecaac5 Limit LiveTrading parallel history
- Limit workers queue size for parallel history requests
- Small performance fix, use `queue.count` instead of `any`
2019-11-15 13:46:11 -03:00
Jared c4287eaa22 Merge pull request #3809 from QuantConnect/performance-3724-parallel-history-request
Parallel history requests
2019-11-08 08:16:22 -08:00
Martin Molinero 3f8a751cef Parallel history request
- Enable parallel workers for history requests, improving performance.
- Adding SubscriptionUtils to be used by backtesting through the FileSystemDataFeed and
SubscriptionHistoryProvider and live deployments which use the
SubscriptionHistoryProvider in the core
- Fix some timezone issues when using local
start/end time instead of UTC
- Adding missing `Enumerator.Dispose()` to be called by the worker
2019-11-07 18:10:30 -03:00
Martin Molinero 86ffbcb3f9 Fix invalid initial SymbolChanged event
- EventProvider will receive start date during initialization, this will
be used by the `MappingEventProvider` to correctly set current mapped
symbol
- Adding unit test, updating existing regression test
2019-11-06 14:41:12 -03:00
Stefano Raggi 55880d79bd Refactor SynchronizingHistoryProvider
The CreateSubscription method has been moved from the BrokerageHistoryProvider to the SynchronizingHistoryProvider base class, to enable reuse and avoid code duplication.
2019-11-05 16:46:33 +01:00
Martin Molinero 0783a50dcc Fix data emitted before first date
- `SubscriptionDataReader` will check map file first data and adjust
start date based on it
- Adding unit test
- Reducing code duplication
- Setting up `HistoryProvider` event handling
2019-10-25 14:09:02 -03:00
Martin Molinero a5dc1774a7 Add SecurityCacheProvider
- Adding `SecurityCacheProvider` this class allows for two different
`Security` to share the same data type cache through different instance
of `SecurityCache`. This is used to directly access custom data types
through their underlying in a peformant maner
- Some small improvements
2019-10-22 13:46:57 -03:00
Martin Molinero 404533eb39 Address reviews - Use TimeZoneOffsetProvider 2019-10-14 14:39:26 -03:00
Michael Handschuh 362826988f Improve DynamicSecurityData usability
Adds IRegisteredSecurityDataTypesProvider to track all the data types
registered in the algorithm. Using this data, we can detect if it's
possible that we'll eventually have a property of a certain type name.
For example, consider I wish to use security.Data.TradeBar but we haven't
received any trade bars yet. Before this change a KeyNotFoundException
would be raised, but since we can determine that we expect to have trade
bars, we can detect this and return an empty list when we haven't received
any data yet. This also removes the need to constantly do a HasData<T>()
check before accessing the dynamic members.

Closes #3620
2019-09-30 19:06:21 -04:00
Jared 4f752973d7 Merge pull request #3526 from Martin-Molinero/bug-3516-handle-coarse-data-unit-test
Fix enumerator Dispose chain
2019-08-22 14:34:39 -07:00
Martin Molinero 0938e9f984 Fix Dispose enumerator chain
- Adding new `SubscriptionDataEnumerator` to fix broken enumerator Dipose chain
- Adding `Dispose` calls on enumerators in unit tests
- Fix unit test HandlesCoarseFundamentalData
2019-08-22 17:25:02 -03:00
Martin Molinero 24527e0cc2 Address reviews - Renaming 2019-08-21 16:30:03 -03:00
Martin Molinero 73d780daae Moving UsesMapFiles to DataType
- Custom data types will know whether or not Lean should use map files
- Updating regression test with sample custom data using map files,
which can run locally
- Adding unit tests for the `SubscriptionDataReaderHistoryProvider`,
checking it mappes equities and options correctly
2019-08-20 17:33:41 -03:00
Gerardo Salazar e6a510d803 Add Mapfile support for custom data sources 2019-08-20 16:56:02 -03:00
Martin Molinero ed5f7ab58c Moving price scale factoring to new enumerator
- Adding new `PriceScaleFactorEnumerator` that will scale raw prices
based on a provided `SubscriptionDataConfig` and update the
`SubscriptionDataConfig.PriceScaleFactor`. Adding unit tests.
- `BaseData` factories (`TradeBar.cs`, `QuoteBar.cs`, `Tick.cs`) will
no longer scale factor prices, they will generate data points in raw
mode.
- `SubscriptionDataReader` will no longer update the
`SuscriptionDataConfig.PriceScaleFactor`
- Fix `BrokerageTransactionHandlerTests` unit test that was having a
race condition.
2019-02-27 15:11:34 -03:00
Stefano Raggi 4e241dec52 Add missing list materialization in AuxiliaryDataEnumerator
- restored includeAuxiliaryData to false in SubscriptionDataReaderHistoryProvider
2019-01-17 20:22:49 +01:00
Stefano Raggi 24ccda8b9a Update SubscriptionDataReaderHistoryProvider to handle symbol changes 2019-01-17 12:49:16 +01:00
Martin Molinero 0933da9303 Refactor previous commits
- Removing `AccountCurrency` from `Cash` and `Brokerage` classes.
`ICurrencyConverter` will now provide the `AccountCurrency`
- Adding new static `OrderFee.Zero` which will return a 0 order fee in
`NullCurrency`
- Adding static `Currencies.USD` value, replacing all "USD".
- Addin new static `Currencies.NullCurrency`
- Updating Bitfinex `FeeModel` so it return fees in quote currency.
Adding unit tests
2018-12-13 11:30:40 -03:00
Martin Molinero 75ffa300f1 Adding new IAlgorithm.AccountCurrency
- Adding new `IAlgorithm.AccountCurrency { get; }` that will point to the
`Portfolio.CashBook.AccountCurrency`. Setter will be added in a
following PR.
- Base `Brokerage` class will now have a `AccountCurrency { get }`
pointing to the `IAccountCurrencyProvider`. Will be used by the different
brokerages implementations.
2018-12-10 11:59:02 -03:00
Jared 54fbf36be8 Merge pull request #2671 from Martin-Molinero/refactor-2429-corporate-events-own-enumerator
Move corporate events to new enumerators
2018-12-03 10:45:44 -08:00
Martin Molinero dea0fe2674 Implementing composition over inheritance
- Mappings, splits, delisting and dividends will be
`ITradableDateEventProvider` that will be handled by
the `AuxiliaryDataEnumerator`.
2018-11-20 16:17:44 -03:00
Martin Molinero 6db7f13dca Addressing reviews
- Will now use the `SynchronizingEnumerator` and avoid the duplicated
synchronization logic.
- Slightly modified the `SynchronizingEnumerator` implementation to
avoid removing enumerators with current `null` returning `true`. Adding unit tests
- Adding unit tests for `DelistingEnumerator`
- Fixing issue where price was not correctly set. Adding new check for
`HourSplitRegressionAlgorithm`
2018-11-20 15:50:19 -03:00
Martin Molinero a746dd0137 Move corporate events to enumerators
- Moving `Splits`, `Dividends`, `Mappings`, `Delistings`, from the
`SubscriptionDataReader` into there own enumerator, inheriting from
new `CorporateEventBaseEnumerator`
- Adding new helper `static class CorporateEventEnumeratorFactory` to
create the new enumerators
- Adding unit tests for new `CorporateEventBaseEnumerator`
- Adding some extra checks to `HourSplitRegressionAlgorithm` and
`DelistingEventsAlgorithm`
2018-11-20 15:50:19 -03:00
Martin Molinero 7ab6a374cf Addressing reviews
- `TimeSliceFactory` `TimeZone` will now be a constructor parameter
2018-11-14 19:12:45 -03:00
Martin Molinero 251071ee73 Remove Security from Subscription
- Removing unneeded `CashBook` instance to create a new `TimeSlice`
- Adding new `TimeSliceFactory`, an instance base class that will
provide methods to create a new `TimeSlice`. Will own the `DateTimeZone`
property.
- Adding new `ISecurityPrice` and `IOptionPrice` that will provide a
reduced interface for accessing price properties and methods used when
creating a new `TimeSlice`
2018-11-14 18:28:18 -03:00
Martin Molinero ee2dc32710 Subscriptions will track Universe requests
- The class `Subscription` will internally track each `Universe`
`SubscriptionRequest` added or removed
- Adding regression test in which two different `Universe` request the
same `SubscriptionDataConfig` and one of them removes/adds it in a
toggle fashion (fails on current master)
- `UniverseSelection` pending removals will also be tracked by
`Universe`
- `UniverseDecorator` will overwrite the `Universe` member of
`SubscriptionsRequests` at `GetSubscriptionRequests()`. This is due to
`this != this,Universe`
- Adding `Subscription` unit tests covering expected behavior
- Extracting pending removals logic from `UniverseSelection` class into
a new helper class `PendingRemovalsManager`. This new class will keep
track of the `universes` requesting to remove a security. Adding unit tests
2018-11-08 13:02:11 -03:00
Stefano Raggi 44412f2273 Move HistoryProviderBase to QuantConnect.Common project 2018-10-14 23:07:09 +02:00
Stefano Raggi dbaf109c78 Post-review updates
- Renamed events in SubscriptionDataReader and IHistoryProvider
- Added HistoryProvider base class with events and event invocators
2018-10-14 22:29:06 +02:00
Stefano Raggi 9fad26bc8f Add events to IHistoryProvider and SubscriptionDataReader
The SubscriptionDataReaderHistoryProvider was using StubResultHandler, so no error messages were being shown or logged. By adding events to IHistoryProvider and SubscriptionDataReader, the dependency on IResultHandler could be removed completely and error messages are now pushed up the stack.
2018-10-14 22:29:04 +02:00
Stefano Raggi 77b37f4dfd Update IHistoryProvider.Initialize to use HistoryProviderInitializeParameters
This is only a mechanical refactor for the updated IHistoryProvider.Initialize method in all IHistoryProvider implementations, call sites and unit tests.
2018-10-14 22:29:02 +02:00
Martin Molinero 60a36b58d4 SineHistoryProvider wont use Security Config Prop
- Modifying `SineHistoryProvider` so it does not use `Security`
configurations properties, including `Security.Subscriptions`.
   - `SineHistoryProvider` will create SDC based on the `HistoryRequests`,
   as done in other HistoryProviders
2018-10-11 18:00:45 -03:00
Michael Handschuh 20133d40d1 Add ICurrencyConverter to Security constructors
Security instances will require private access to this value in order to
compute close profit.

NOTE: The extent of these changes for simply adding a constructor argument
insinuates that we're missing an abstraction to manage the construction of
these objects, such as a factor object for Security. This will need some
careful TLC in the near future.
2018-10-10 11:17:12 -04:00
Michael Handschuh a5179bc6ab Add universe data to TimeSlice
Pipes universe data from the data feed, through TimeSlice.Create and adds
TimeSlice.UniverseData dictionary property for read access from the algo
manager, where the data will be placed onto the correct security object.
2018-04-24 18:23:00 -04:00
AlexCatarino 6799558d0d Adds SineHistoryProvider
This toy HistoryProvider implements a history provider that always return a IEnumerable of Slice with prices following a sine function.
2018-04-11 11:11:32 +01:00
Michael Handschuh cee7ff7766 Move clone and tz conversion operations to DF thread
A large percentage of synchronization time is spent performing time zone conversions.
Previously, it was possible that we may compute the same tz conversion multiple times
on the same piece of data until it's emitted. This change moves the time zone conversion
logic onto the data feed thread right before it puts the data into enqueueable enumerator.
In addition, we're not performing the clone operation at the same moment. This removes
unnecessary computation while moving the necessary computation to the data feed thread to
lighten the load on the synchronization/algorithm thread.
2018-02-13 15:59:56 -05:00
Jared Broad aefdfcc411 Add the cashbook to the result packet 2017-10-23 17:00:28 -04:00
Michael Handschuh 6f1c07d488 Add dataTimeZone to FillForwardEnumerator 2017-10-02 12:16:06 -04:00
Michael Handschuh 6292f1e286 Clean white space 2017-10-02 12:16:05 -04:00
Andrew 08bb34a1eb Add TickType field to the HistoryRequest class 2017-08-22 09:42:42 -04:00
Andrew a855a7c545 Renamed HistoryRequest.TimeZone to DataTimeZone 2017-08-21 15:06:29 -04:00
Stefano Raggi e4509d1a5c Add QuoteBarFillForwardEnumerator 2017-08-15 12:22:41 +02:00
Andrew b77502f35b All Results handler inherit from the BaseResultsHandler 2017-08-08 12:52:12 -04:00