45 Commits

Author SHA1 Message Date
Martin-Molinero e0b9a2735f Warmup fixes (#6293)
Regression Tests / build (push) Has been cancelled
Build & Test Lean / build (push) Has been cancelled
Research Regression Tests / build (push) Has been cancelled
* Add regression test reproducing issue

* WIP

* Update regression algorithms

* Improvements

* Cleanup and more fixes

- Clean up BaseDataExchange

* RealTimeHandler fixes

* Address reviews

* More comments, tests and minor tweaks

* Avoid false test failures

* Fixes

* Minor improvements

* Scheduled Event start time fix

* Add warmup option regression algorithm and fix

* Add WarmupFutureRegressionAlgorithm

* Normalize backtesting and live future selection
2022-05-31 10:03:56 -03:00
Martin-Molinero b77f0122b2 Improve python exception parsing (#5831)
Regression Tests / build (push) Has been cancelled
Build & Test Lean / build (push) Has been cancelled
* Improve python exception parsing

- Improve python exception parsing adding support for line shift. Adding
  unit tests

* PythonException revert change

* Centralized and normalize algorithm runtime handling

* Adding support for C# line and file exception report
2021-08-06 20:11:54 -03:00
Martin Molinero 1dc6ed06f7 Address reviews
- Dispose of TimeMonitor on RealTimeHandler exit
2020-03-03 18:45:43 -03:00
Martin Molinero 8e1d0f7e4f Remove RealTime thread from engine
- Remove RealTime thread from the engine
- Engine will call DataFeed.Exit() even if algorithm initialization
failed, to avoid 30 sec delay
2020-03-03 16:50:25 -03:00
Martin Molinero 7ea241b735 Fix backtesting event bug
- After skipping scheduled events it will re order them
- Fix bug where when only a single scheduled event was present it
wouldn't fire
2020-03-03 12:56:50 -03:00
Martin Molinero b45b7e427f Address reviews
- Address review improve regression and unit test
- Fix same time scheduled event order
- Adding comments in unit test
- Increasing unit test sleep time
2020-03-03 10:45:37 -03:00
Martin Molinero b3feea86a1 Refactor IsolatorLimitResultProvider
- Replace `new Task` at `IsolatorLimitResultProvider.Consume()` for
single instance base timer.
- Adding unit test
2020-03-02 18:23:20 -03:00
Martin Molinero 2f4f7dc2cb ScheduledEvents fire in order
- Scheduled events will fire in order even after market hours
- Improving scheduled events performance
- Adding regression and unit test
2020-03-02 11:05:54 -03:00
Martin Molinero 3a5a2c582f Lazy OnEndOfDay ScheduledEvent
- Only add OnEndOfDay ScheduledEvent if the algorithm implements the
method. Adding unit tests
- Avoid creating a new baseData instance at
`SubscriptionDataSourceReader`
- Adding static `FineFundamental` instance since creating new ones is
expensive
2019-12-19 19:07:16 -03:00
Martin Molinero 891f94fbeb Address reviews
- Set `CanRunLocally => false` for training regression algorithms
- Reverting sorting changes at `BacktestingRealTimeHandler` due to
performance degradation of current scheduled event benchmark algorithm
2019-10-21 21:18:06 -03:00
Michael Handschuh b371847a19 Usings cleanup, doc, unused parms, etc
Per review comments provided in #3743 regarding the
training/long-running scheduled events and the leaky
bucket algorithm. See the PR for more information.
2019-10-19 14:52:34 -04:00
Michael Handschuh 28be3bbe3d Refactors scheduled events to execute on main thread
In order to continue to provide debugging support in the QC cloud, the
scheduled events were moved from inside of a task to the algorithm's
main execution thread. This necesitated a different methodology for
managing timeouts. Instead of raising an exception when attempting to
request additional time when none is remaining, we're now simply allowing
the isolator's limit to be reached by virtue of not incrementing the
additional minutes in the time manager. This uncovered a bug in LEAN
engine where if the isolator terminates an algorithm, then the status
of the algorithm (on the algorithm manager instance) isn't properly
updated to indicate RuntimeError. This is in direct conflict with the
status update that is provided to the api, which is RuntimeError, so
this change remedies that issue as well. One of the regression algorithms
depends on this status value being properly flipped to RuntimeError in
the event that the isolator limit is reached.

See #3319
2019-10-19 14:52:34 -04:00
Michael Handschuh 22d56e5ffb Properly handle events raised in ScheduledEvents
Adds logic to intercept exceptions raised by user code in the
task used to wrap the scheduled event execution.
2019-10-19 14:52:34 -04:00
Michael Handschuh 09cc78599a Add mechanism for scheduled events to use 'additional time'
We restrict each algorithm time loop to a pre-determined amount of time.
Exceeding this limit will cause the algorithm to immediately terminate.
This quickly becomes an issue when considering users running trainable
models that have a long initialization period that exceeds the time loop
maximum.

This change provides a mechanism through which a long-running scheduled
event is permitted to keep running and is permitted to avoid the time loop
permitted by requesting additional time. Requests for additional time are
limited according to a leaky bucket implementation whose parameters are
set via the job's controls structure. The fundamental time unit for the
algorithm is a single minute.

Here's how it works. If a scheduled event takes longer than one full wall
clock second then a request is made to the leaky bucket for one more minute.
If the scheduled event continues to take more time, it will continue to
request additional minutes. Each requested minute will prevent the algorithm's
time loop check from terminating the algorithm. When the bucket is empty and
no more minutes are available to be requested, a TimeoutException is thrown
causing a cascade that ends in the algorithm's termination and status being
flipped to RuntimeError.

Additionally, this applies equally to ALL scheduled events. While some helpers
were added with the naming of Train and TrainNow to the ScheduleManager, these
methods don't do anything special and the infrastructure doesn't otherwise
flag them as different, so this feature becomes part of the core Scheduled
Event feature set.

Further, the live scheduled events were not touched and are still pending
further discussion regarding the value added by enforcing a time restriction
when simulation time and wall clock time are equivalent.

Fixes #3319
2019-10-19 14:52:34 -04:00
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
AlexCatarino 27d14d047f Fixes missing inner exception information in ScheduledEventException
When a `ScheduledEventException` was thrown, `IAlgorithm.RunTimeError` was not set as `ScheduledEventException` , but as `Exception` with the orginal exception message and no inner exception.
2018-04-13 19:23:45 +01:00
Stefano Raggi 91ba63529b Remove Guid string from ScheduledEvent.Name
Fixes #1674
2018-03-07 21:33:33 +01:00
AlexCatarino 136ca90f6c Fixes message input in ScheduledEventException instance creation
Passes exception to Log.Error in RealTimeHandlers in order to include stack information
2018-02-20 17:39:03 +00:00
AlexCatarino af7b592dda Passes inner exception to ScheduleEvent exception
Without the inner exception, information on the user exception is lost. In python algorithm, the stack trace is completely lost.
Removes ScheduledEventExceptionMessage property as it is redundant to Message property inherited from parent class.
2018-02-19 19:11:55 +00:00
Stefano Raggi 20a325276e Fix scheduled event firing order in backtesting
When backtesting with multiple scheduled events, these were fired in unpredictable order, not respecting the expected sequence sorted by time.
2018-01-03 14:27:08 +01: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 7068a5aeba Fix scheduled event scheduling
Scheduled events were seemingly only being submitted for internal feed
securities -- the opposite of what we're looking for.
2017-10-20 13:49:56 -04:00
Andrew 2c156ce04a Add schedule event exception logic to BacktestingRealTimeHandler
Catching the exception in BacktestingRealTimeHandler prevents unhandled errors in backtesting and provides more specific logging to make debugging easier for users
2017-09-25 11:04:13 -04:00
Stefano Raggi 4149aba9d7 Fixed scheduled event firing time in backtesting
If backtesting, we need to check if there are realtime events in the past
which didn't fire because at the scheduled times there was no data (i.e. markets closed) and fire them with the correct date/time.
In live mode, no changes are needed.
2017-02-23 20:25:49 +01:00
Michael Handschuh 42465ffd52 Clean up IsInternalFeed usages 2016-04-12 19:06:49 -04:00
snugs 8374b99e18 Don't fire EOD events for internal feeds 2015-09-28 13:28:09 -04:00
snugs e1938baafe Clean up using directives 2015-09-01 22:17:35 -04:00
snugs 730430b1bb Adds scheduling feature
Adds the ScheduleManager which allows an algorithm to add/remove scheduled events
Check out the ScheduledEventsAlgorithm for syntax
ScheduledEvents are at their core an IEnumerator<DateTime> that defines the event times coupled with a callback
IDateRule defines dates for events
ITimeRule defines time(s) on a given date for events
2015-08-10 10:56:14 -04:00
snugs 844a040be5 Initial impl of coarse universe selection
Adds concept of Subscription to contain everything a data feed needs in order to process  single data feed item
Moves preparation of all data to data feed thread, algo thread receives data in format it needs
QCAlgorithm.SetUniverse( func ) allows selection based on market/symbol/dollar volume/price
Remove laziness from Slice as optimization, no order by in real time handler
2015-08-06 17:52:23 -04:00
snugs 7fa9a4b1be Implements self re-scheduling events
A ScheduledEvent can be defined using an enumerator of event times and a callback
2015-08-05 13:13:08 -04:00
QuantConnect cc3f0c76e1 Reduced logging from backtesting realtime handler 2015-06-29 11:55:25 -04:00
Jared 7e71f24f33 Merge pull request #124 from AnObfuscator/master
Fix time issue preventing OnEndOfDay() event from firing.
2015-06-25 18:57:38 -04:00
Jonathan Evans 84bfaf129c Fix time issue preventing OnEndOfDay() event from firing. Remove redundant ScanEvents() call. 2015-06-25 17:44:54 -05:00
snugs 4de2ec4070 Make Engine an instance
Updated all interfaces to accept dependencies via Initialize methods
2015-06-18 13:50:11 -04:00
snugs c1736571cc Load real time handlers via MEF configuration 2015-06-17 22:34:01 -04:00
QuantConnect fde0cbed3a Strip out block quote section header comments 2015-06-13 16:04:27 -04:00
snugs 89b6e98af8 Fixes warnings mostly relating to xml comments
Also cleans up some block comments

Via PR#72 - thanks @ammachado!
2015-05-13 10:56:47 -04:00
snugs 33f4046fb9 Several random fixes
Made ObjectActivator.Clone 4x faster
Updated deltaCharts in live trading results using order events
2015-04-30 15:31:57 -04:00
snugs d80b1733a9 Pre ib launch review 2015-04-24 19:12:16 -04:00
Adriano Marcondes Machado b2229e8968 Fixed a few compilation warnings 2015-03-09 16:28:17 -03:00
QuantConnect 5be77cbaaf Large shuffle to move MarketToday clock into RealTime handler and out of DataFeed. Added public accessor for market today hours. Simplify and tidy live real time handler 2015-02-25 15:33:10 -03:00
Jared Broad df00cc1f3a Fixed access to modified closure bug with wrong EOD event symbol 2015-02-19 00:40:10 -03:00
Jared Broad 90b162b85d Rework RealtimeEvent class to use datetime - fix #11, simplified live realtime event handler, eliminate backtest realtime thread 2015-02-18 16:49:42 -03:00
Jared Broad b3de520915 Initial commit 2015-01-12 12:03:33 -03:00