Commit Graph

285 Commits

Author SHA1 Message Date
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
Stefano Raggi 57d50c69c4 Fix XML documentation compiler warnings
- Fixed all warnings except for missing XML comments (CS1591)
2018-11-09 11:44:03 +01:00
Martin Molinero 6f13edce2d Addressing reviews 2018-10-29 16:57:23 -03:00
Martin Molinero 239664277f Refactor Volatility Models
- Removing usages of Security.Configuration properties from existing
Volatility Models, without modifying existing interfaces. Adding unit
tests for existing behavior
- Adding new BaseVolatilityModel, which will have a setter for a
ISubscriptionDataConfigProvider which will be called by the system.
Adding unit tests for this behavior.
- Adding new `SubscriptionDataConfigExtensions` static class which will
provide methods used to determine different configuration properties for
a given set of `SubscriptionDataConfigs`. The behavior was extracted
from current `Security` class behavior regarding the `SubscriptionBag`.
Adding unit tests covering exepected behavior here.
2018-10-29 16:57:23 -03:00
Martin Molinero 9bdf702c41 Creating new Synchronizer - TimeSlice streamer
- Creating new `Synchronizer` which will consolidate and combine `TimeSlice`
streaming for both live and backtests modes. Will live in front of the
`DataManager`
- `SubscriptionSynchronizer` will be the `FrontierTimeProvider` exposed,
and owned, by the new `Synchronizer`
- Updating existing tests
2018-10-19 15:36:08 -03:00
Stefano Raggi c077689e50 Add CurrentTimeStepElapsed to Isolator logging 2018-10-04 00:11:12 +02:00
Michael Handschuh a555d455ed Never apply dividends in live mode
LEAN currently lacks support for dividend payable dates, and as such
it's incorrect to apply the dividend on the ex-date (backtesting behavior).
We'll pick up the additional cash in the account by means of the daily
cash sync performed by the BrokerageTransactionHandler
2018-09-25 14:04:03 -04:00
Michael Handschuh 34584d1f81 Always apply splits in live mode
Regardless of the chosen data normalization mode, splits must be
applied in live mode to ensure proper portfolio modelling.
2018-09-25 14:02:27 -04:00
Michael Handschuh 49117137f0 Improve split/dividend application logging in live mode
It's important we see the before/after and the data used to make the change.
This will aid in debugging potential misapplications of split/dividend events.
2018-09-20 17:20:02 -04:00
Martin Molinero 1997197f47 Fix failing unit tests 2018-09-18 12:10:42 -03:00
Martin Molinero 0a82d16829 DataManager wraps IDataFeed. DataManager owns UniverseSelection instance 2018-09-17 20:45:16 -03:00
Martin Molinero 2410726b92 Fix exception being thrown when using SetWarmup with an option contract 2018-07-25 18:45:19 -03:00
Stefano Raggi 9040f2b5fa Fix MapFileResolver with remapped and delisted symbol 2018-07-24 12:06:19 +02:00
Stefano Raggi fde0239930 Fix failing internal feed regression algorithms 2018-07-23 14:25:28 +02:00
Stefano Raggi bd3c48e05e Fix internal feed subscription end time in AlgorithmManager 2018-07-19 00:32:20 +02:00
Martin Molinero ff5e888313 Fix for delisted subscription data being sent 2018-07-18 09:45:13 -03:00
Martin Molinero 82c2532a31 Improve performance for backtests with a large amount of trades 2018-06-21 16:59:29 -03:00
Stefano Raggi bbfe7a9beb Rename LatestSlice to CurrentSlice 2018-06-05 19:05:40 +02:00
Stefano Raggi 08f28a55cf Make the latest Slice received in OnData available to the algorithm 2018-06-01 18:24:09 +02:00
Michael Handschuh ad331118ab Add refresh to IUniverseSelectionModel to support dynamic universes
This change allows the universe selection model to select different universe
definitions as time proceeds. This enables the definition of a universe model
that, for example, could add option chains for securities selected by a different
universe model.

The BasicTemplateOptionsFrameworkAlgorithm was added to showcase and provide
regression for a universe model that selects different universes.
2018-05-31 11:48:23 -04:00
Michael Handschuh 5879e477b7 Mark delisted securities as not tradable
Add regression test for delisted/tradable flags.
Add Security.IsDelisted to flag.
2018-05-07 11:41:24 -04:00
Michael Handschuh 351ac55f7f Rework implementation of maintaining tradable flag
The previous implementation had some issues and introduced undue
complexity. This implementation follows established patterns of
having the algorithm manager apply changes to the algorithm that
result from universe selection.
2018-05-02 20:00:37 -04:00
Michael Handschuh ddcbc66cf8 Add SecurityCache.StoreData and use to store universe data
We never want universe data to impact a security's price or other cache
properties. To that end, this change adds another way of adding data to
the cache that simply stores the data for retrieval and does NOT update
any of the security cache properties. The check for aux data was left in
to prevent aux data from setting security prices as well.
2018-04-26 14:18:34 -04:00
Michael Handschuh 58efd4ae6a Store universe data in security cache
Universe data is piped through the TimeSlice and saved in the
security cache in the algorithm manager for consumption by the
algorithm.

This change includes an update to SecurityCache.AddData to preclude
us from setting the security price using auxiliary data. Tests were
updated accordingly.
2018-04-24 18:23:01 -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
Michael Handschuh e090eed5b0 Use UniverseSettings.Resolution instead of Universe.Configuration.Resolution
Universe.Configuration.Resoluton is intended to describe the resolution of the universe data
and NOT the resolution of any subscriptions added by the universe. Universe subscription
resolutions are defined by either Universe.UniverseSettings.Resolution or if null,
IAlgorithm.UniverseSettings.Resolution
2018-04-10 19:24:36 -04:00
Stefano Raggi 5da176588a Fix Forex/Crypto zero conversion rates during warm up
Fixes #1833
2018-04-05 01:15:05 +02:00
Michael d655f31597 Merge pull request #1725 from StefanoRaggi/bug-1724-warmup-tick-consolidators-not-updated
Fix consolidators not updating during warmup with tick resolution
2018-03-21 10:02:27 -04:00
Michael Handschuh 27b34a4274 Add IAlgorithm.OnEndOfTimeStep to batch universe changes
We had an issue with the data feed picking up universe/security changes
too quickly, thereby preventing user code from being able to configure the
security object properly. Specifically, users were having an issue setting
the data normalization mode of options and underlying equity securities. By
the time the user code had set the data mode, the data feed had already
created a subscription and began processing it, so the changes were never
seen in the data feed.

This change moves all security/universe changes into pending lists and at
the end of the time step applies those changes. Security objects are still
added directly to the SecurityManager for instance access, but we delay in
adding the security to the universe and the universe to the UniverseManager.
Once added to the universe manager, an event is fired and the data feed will
process the new subscriptions.
2018-03-20 10:10:29 -04:00
Stefano Raggi dd1ba650a2 Fix consolidators not updating during warmup with tick resolution
Fixes #1724
2018-03-20 11:46:33 +01:00
Stefano Raggi d87fc1f264 Fix error when using SetWarmup with Tick resolution
Fixes #1716
2018-03-19 16:15:30 +01:00
Michael Handschuh 6b239674e2 Renames Alpha -> Insight
The term 'alpha' is used to describe the entire algorithm. Therefore, 'alpha'
produces insights. From this we have things like IAlphaModel, which is the model
defining how insights are produced. We have IAlphaHandler, which defines how the
insights from a single 'alpha' (the algorithm) are managed, analyzed, and stored.
Types closer to the individual prediction level, such as InsightDirection, or
InsightScore relate directly to exactly 1 insight. The distinction between the
two became more clear as we developed the insights API, and from that effort it
was decided to harmonize alpha/insight terminology across the various QC systems.
2018-03-09 16:12:56 -05:00
AlexCatarino 9f691113e6 Fixes subscription not found due to PythonData warm up history request 2018-02-14 17:02:12 +00:00
Stefano Raggi 1bf6ffd85b Fix consolidator updating during warmup
When creating time slices for warmup history requests, data for security types with multiple tick types (Crypto, Futures, Options) were being matched to the configuration for the first subscription, instead of using the correct data type.

For example, with the Crypto security type, historical data of type TradeBar was passed to TimeSlice.Create with a SubscriptionDataConfig object for the QuoteBar data type.
2018-02-12 21:09:41 +01:00
Michael Handschuh f490fd4400 Remove cash updates from time slice
Instead of tracking just the security's symbol in the cash object we're now
maintaining a reference to the actual security object. This removes the need
to worry about cash update data in the time slice create method.
2018-02-09 14:51:47 -05:00
Michael Handschuh 10dfabfe91 Remove unused parameter from AlgorithmManager.Stream 2018-02-06 18:44:01 -05:00
Michael Handschuh 0c06f39cd3 Don't apply split warning events 2018-02-05 11:58:44 -05:00
Michael 99327d106c Merge pull request #1506 from QuantConnect/refactor-margin-models
Refactor margin model interface
2018-02-02 11:31:00 -05:00
Jared 2c7c5204c6 Merge pull request #1503 from QuantConnect/liquidate-options-on-split-warning
Liquidate options on split warning
2018-02-01 14:52:44 +00:00
Stefano Raggi 3d1ab08b44 Move Portfolio.ScanForMarginCall to IMarginCallModel.GetMarginCallOrders
The logic for margin calls was previously split between SecurityPortfolioManager.ScanForMarginCall and IMarginCallModel methods, now it is entirely contained within margin call model implementations.

One of the margin call model tests was also testing against the Null model, it has been updated to use the DefaultMarginCallModel.
2018-01-31 11:47:35 +01:00
Michael Handschuh ac23c6b889 Liquidate option contract holdings before split events
Using the newly added split warnings, submit market on close order at the last
possible moment to liquidate option contract holdings. After the liquidate order
has been submitted, we now mark the option contract as non-tradable, thereby
preventing any further trading in post-split option contracts.

This is added because we currently do not properly support option contract splits.
To properly support, we'll need some extra data sources defining how the contracts
are rewritten due to the split event. This data is freely available via the OCC in
pdf format.
2018-01-23 15:03:48 -05:00
Ben Sauerwine bb9c11c4ba Re-use _timeLoopMaximum in error message. 2018-01-22 11:32:32 -06:00
Ben Sauerwine 2a4c567aaf Fix misleading error message in AlgorithmManager. 2018-01-22 11:20:42 -06:00
Michael Handschuh dfce99f575 Sample alpha scores on next time step, ignore mag scores if mag=null 2017-12-28 11:27:40 -05: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
Jared 5f64665598 Merge pull request #1425 from QuantConnect/concurrency-fix
Reduce full locking on ConcurrentDictionary objects
2017-12-20 18:56:30 -05:00
Stefano Raggi f37d0cc962 Optimize loops for performance on cashbook and securities 2017-12-20 21:58:59 +01:00
Stefano Raggi c6aba7bfec Reduce full locking on ConcurrentDictionary objects
This PR is an attempt to reduce contention in concurrent dictionaries, replacing method calls using full locks with lock-free equivalents:

- dictionary.Count -> dictionary.Skip(0).Count()
- dictionary.Keys -> dictionary.Select(x => x.Key)
- dictionary.Values -> dictionary.Select(x => x.Value)

The most frequent usages of these methods are: CashBook, SecurityManager, UniverseManager and indirectly, SecurityPortfolioManager.

The reasons for this update are explained very clearly in this article:
https://arbel.net/2013/02/03/best-practices-for-using-concurrentdictionary/
2017-12-20 17:18:54 +01:00
Michael Handschuh 2295e524f4 Add IAlphaRuntimeStatisticsGenerator and send to result handler
Provides estimates of alpha value as well as performs online computations of
alpha scores and other KPIs.

Sends alpha stats to result handler
Update live result with framework flag
2017-12-20 08:33:30 -05:00
Michael 9997abec89 Merge pull request #1372 from QuantConnect/feature-algorithm-framework
Initial release of the QuantConnect ALPHA streams feature.
2017-12-15 20:18:40 -05:00