Commit Graph

10 Commits

Author SHA1 Message Date
Martin Molinero a2e818b1d7 Improve subscription sorting mechanism to improve performance 2018-07-17 09:59:31 -03:00
Stefano Raggi 749737583f Fix non-deterministic enumeration in SubscriptionCollection 2018-06-18 21:23:36 +02:00
Michael Handschuh 163dc6c5c1 Move security type ordering to SubscriptionCollection
This will change the order in which we enumerate subscriptions so we don't need
to re-sort inside of TimeSlice.Create.

The way we currently build time slices requires that we receive the underlying data
before any derivative data. This change ensures that we enumerate the underlying equity
data before we process any derivative data, such as options.
2018-02-12 14:31:06 -05:00
Stefano Raggi ed44830391 Performance speedup in SubscriptionCollection
The list of subscriptions needs to be sorted by TickType when enumerating, but this sorting was previously done in GetEnumerator (called for each data point).
This has been fixed by sorting only when adding or removing subscriptions, gaining a significant backtest speed improvement.

In addition, the storage for subscriptions was simplified to a single ConcurrentDictionary, instead of nested dictionaries.
2018-01-02 15:07:03 +01:00
Stefano Raggi 16a0441ca7 Fix SubscriptionCollection.TryRemove return value 2017-12-22 10:50:01 +01:00
Stefano Raggi fc77b886a6 Fix subscription removal in SubscriptionCollection.TryRemove
This method was not removing the symbol dictionary entry when removing the last subscription, allowing the collection to grow excessively over time (especially with universe selection algorithms).

This PR also includes a few minor performance fixes.
2017-12-22 00:03:35 +01:00
Stefano Raggi de38b61fd3 Fix race condition in SubscriptionCollection.GetEnumerator
An occasional NullReferenceException was thrown when enumerating and concurrently adding or removing items.

A new unit test that always throws this exception was also added.
2017-12-18 17:12:39 +01:00
Stefano Raggi e60a49093f Make subscription enumeration order deterministic
In the SubscriptionCollection class, subscriptions are stored in nested dictionaries, keyed by Symbol and by SubscriptionDataConfig.
According to MSDN when enumerating: The order in which the items are returned is undefined.
https://msdn.microsoft.com/en-us/library/xfhwa508.aspx

The enumeration ordering for different symbols is not an issue, but the order of configs for the same symbol can cause non-deterministic backtest results (only security types with multiple data types per subscription are affected such as Crypto, Futures, Options). This random behavior was observed with the FractionalQuantityRegressionAlgorithm, so the regression statistics have also been updated.

In this PR we force a fixed priority for data types, which will guarantee that different data points for the same symbol at the same time step will always be emitted in the same order (TradeBar before QuoteBar).
2017-12-01 20:26:57 +01:00
Stefano Raggi 213f428197 Fix bug in SubscriptionCollection.TryRemove 2016-08-06 22:34:59 +02:00
Michael Handschuh 3373069857 Adds SubscriptionCollection 2016-04-12 19:12:39 -04:00