Commit Graph

256 Commits

Author SHA1 Message Date
Martin Molinero a92bee5bf1 Fix OnEndOfDay not fired
- Adding `IRealTimeHandler.OnSecurityChanged()` will be used to update
the `OnEndOfDay` security related scheduled events
- Adding `BaseRealTimeHandler.cs` to reduce code duplication in the
`Backtesting` and `LiveTrading` `RealTimeHandlers`
- Adding CSharp and Python regression tests
- Deprecating `OnEndOfDay()` callback because of two reasons, mainly
because Python does not support two methods with the same name, but also
because different assets have different market close times.
- `ScheduledEvents` set at the same time will now be deterministic
2019-06-20 17:35:28 -03:00
Martin Molinero 1c92986994 Calculate insight score 1 per time step 2019-06-11 19:06:39 -03:00
Martin Molinero 2c1cf0fa93 Address reviews
- Adding new regression test algorithm
- `SecurityPortfolioManager` will subscribe to the `CashBook.Updated`
event to invalidate the `TotalPortfolioValue
2019-06-07 17:51:30 -03:00
Martin Molinero 084353f182 Smart TotalPortfolioValue Calculation
- `SecurityPortfolioManager` will keep track of the current
`TotalPortfolioValue` and only re calculated when flagged as invalid.
2019-06-07 16:13:57 -03:00
Martin Molinero 14c779733b Address reviews 2019-06-04 17:16:52 -03:00
Martin Molinero ee4f8fee82 Overall performance improvements
- `TimeSliceFactory` will avoid creating empty collections
- `ExecutionModels` will check target collection count before trying to
enumerate
- Reduce calls to .`TotalPortfolioValue`
- `SecurityValues` will only be created when required
- `TimeKeeper` will use TimeZone unique Id as dictionary key. The
TimeZone hash is expensive.
- `AlgorithmManager` will avoid calling `DateTime.UtcNow`,
`ConvertFromUtc()` and `RoundDownInTimeZone()`
2019-06-03 15:09:02 -03:00
Jared 671adf545c Removed forced event handler for custom types.
Allow adding custom types in alpha models and consuming there.
2019-04-03 16:16:31 -07:00
AlexCatarino 4b722dfdfa Replaces Error for Debug
It is not an error, thus let's log it with the Debug method.
2019-04-03 21:09:59 +01:00
AlexCatarino dfe1d3f092 Replaces Exception for Error Logging when OnData for Custom Data is not Defined 2019-04-03 20:52:07 +01:00
Stefano Raggi 88d8b4c60c Remove unnecessary logging, throw if no configs found 2019-01-31 21:41:26 +01:00
Stefano Raggi ce2422b6a8 More split warning debugging info 2019-01-31 19:51:09 +01:00
Stefano Raggi 76bda53108 Improve logging for split warnings 2019-01-31 19:51:08 +01:00
Martin Molinero 0ad277a9af Remove invalid split warning 2019-01-25 12:53:17 -03:00
Martin Molinero 5d3d16a773 Fix exception caused by split for removed security
- Adding check at `AlgorithmManager.ProcessSplitSymbols()`, will skip
splits from removed securities.
- Adding regression test which reproduces original issue in master.
2019-01-25 10:55:00 -03:00
Martin Molinero af8e6bf85c Fix starting capital for non usd cash
- Moving `UniverseSelection.EnsureCurrencyDataFeeds` call into the
`IResultHandler` implementation through usage of the new `SetupHandlerHelper`
class, that will also set an initial conversion rate if none present.
- Adding regression test, that reproduces original issue
2018-12-19 16:15:28 -03:00
Martin Molinero 8817e683f7 Rename local start variable - format 2018-12-14 16:16:57 -03:00
Martin Molinero c9aba0c2db Fix warmup currency data feeds
- `AlgorithmManager` will call `EnsureCurrencyDataFeeds()` before the
history requests are created so the conversion rate securities are also
updated during warmup.
- `EnsureCurrencyDataFeeds()` will add new `SubscriptionDataConfigs` to
the `_addedCurrencySubscriptionDataConfigs` hash set. This hash set will
be used during `UniverseSelection()` to add the subscriptions.
- Wont trigger a `UniverseSelection()` before warmup. This was causing
the data to be fetched twice and for consolidators to be updated with
old data.
- Adding a new regression test and adding new checks to existing
regression tests.
2018-12-14 16:05:14 -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
Martin Molinero 8d5745319e Obsoleting Securities configurations properties
> This PR is a mechanical refactor, no behaviour changed

- Obsoleting `DataNormalizationMode`. Replacing the usaged by requesting
the `SubscriptionDataConfigs` to the new `SubscriptionDataConfigService`
> Note we still need to refresh the Security.DataNormalizationMode
property.
2018-12-05 10:41:21 -03:00
Martin Molinero 7d7ad17883 Obsoleting Securities configurations properties
> This PR is a mechanical refactor, no behaviour changed

- Obsoleting `IsFillDataForward`, `Resolution`, `IsExtendedMarketHours`
`Security` configuration properties. Replacing there usages by
requesting the `SubscriptionDataConfigs` to the new
`SubscriptionDataConfigService`
2018-12-05 10:05:53 -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
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