Commit Graph

46 Commits

Author SHA1 Message Date
Colton Sellers d8d8134437 Support Offset in DateRules MonthStart/End WeekStart/End (#4916)
* Add offset capabilities and related tests

* Add tests for Weekend Offsets on Symbol DateRules

* Unify Iterator Behavior

* Refactor and consolidate functions to reduce duplicate code

* Positive offset values only

* Address review

* Expand Month tests to include Forex and Crypto cases

* Ensure order of days in schedule

* Refactor and unify behavior

* More edge cases and tuning

* Address review + more tests
2020-11-13 15:38:34 -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 8d7585416b Fix ScheduleManager multiple enumeration
- Fix `ScheduleManager` multiple enumeration of the event times of a
scheduled event
2019-11-04 17:40:45 -03:00
Martin Molinero 98ae5cdd4e Fix TimeRules time zone issues
- `ITimeRules` are expected to yield time date in UTC, fixing `Noon`,
`Midnight` and `Every`
- `ScheduledUniverseSelectionModel` will use UTC time zone by default
since that is the default expected time zone `ITimeRule` provides
- Adding regression test
2019-11-04 15:34:57 -03:00
AlexCatarino c37b450a2e Adds Python Support
- Adds PyObject overload to `ScheduleManager.TrainingNow` and `ScheduleManager.Training`
- Adds `QCAlgorithm.Train` helper method
- Adds Python algorithm showing how to use the helper method.
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
Michael Handschuh 053a8ae55d Fix typo, move ScheduledEventException to its own file 2019-10-19 01:52:07 -04:00
Michael Handschuh 5db332a118 Add DateRules Today,Tomorrow and TimeRules Now, Midnight, Noon
These are simple, easy to use convenience properties for creating short-term
scheduled events and produces a cleaner, easier reading syntax than using the
other various methods to produce the same result, for example:
Schedule.On(DateRules.Tomorrow, TimeRules.Noon, MyScheduledEventMethod);

Also fixes typo in FuncDateRule constructor parameter.
2019-10-19 01:52:07 -04:00
Michael Handschuh 70048738d3 Don't skip ScheduledEvent at current time
When adding a new ScheduledEvent with exactly one event time set
to the algorithm's current time, the SkipEventsUntil function would
skip the only event. It appears that this bug was 'fixed' via commit:
33a4db4559

This 'fix' is more of a bandaid and I'm forgoing undoing the bandaid
applied in ScheduleManager and ScheduledEventBuilder where we start
calculating the event schedule a full day before the algorithm's
current time in an effort to reduce additional potential risks from
creeping into this PR focused on adding support for long-running
training functions.
2019-10-19 01:52:07 -04:00
Michael Handschuh d709d1c4e0 Update Common to respect CA1304 and CA1305
Updates all occurrences of parsing/ToString-ing to go through the new
StringExtensions methods that use CultureInfo.InvariantCulture

See #3045
2019-09-12 14:13:24 -04:00
Michael Handschuh 3e93158713 Use proper exception types
The `NullReferenceException` type is intended to only be thrown by the CLR.
In most cases, it should be converted to an `ArgumentException` or an
`InvalidOperationException`, depending on if the null value is a parameter
to the current method or not.

The `Exception` type should never really be thrown as it doesn't provide any
additional information or hints as to the issue. It also forces users that
would like to handle expected exceptions to catch all exceptions. These are
converted to an exception type that more accurately describes the reason for
raising the exception: `KeyNotFoundException`, `InvalidOperationException`
2019-08-16 18:07:30 -03:00
Martin Molinero e1482c50c2 Validate TimeRules.Every TimeSpan
- Will verify `TimeSpan` is not zero or less, adding unit tests.
2019-06-28 13:02:21 -07:00
AlexCatarino 1883bed1a7 Adds an Overload to DateRules.Every method that Accepts a Single DayOfWeek Object 2019-02-26 22:28:43 +00:00
Martin Molinero defe063647 Adding ToString for ScheduledEvent 2018-12-18 16:58:27 -03:00
AlexCatarino 88b97bd8e4 Adds overload to ScheduleManager.On method that accepts a PyObject parameter
Adding an overload to `ScheduleManager.On` method that accepts a `PyObject` parameter enables python algorithm to pass a method as parameter directly.
- Fixes `ScheduleEventsAlgorithm` to show the new feature in action.
2018-05-07 12:05:00 +01:00
Stefano Raggi 91ba63529b Remove Guid string from ScheduledEvent.Name
Fixes #1674
2018-03-07 21:33:33 +01:00
Michael Handschuh c8f20b7756 Add IExceptionProjection infrastructure
Provides a sample implementation of IExceptionProjection that
prepends the scheduld event name to the error message

 #1630
2018-03-01 12:36:00 -05: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 a8fc134c57 Support for scheduled events with same names or date/time rules
Fixes #1061
2018-02-05 11:53:09 +01:00
Stefano Raggi df925c4e3c Add new scheduler DateRules
- MonthEnd(): fires on the last day of each month
- MonthEnd(Symbol): fires on the last tradeable date for the specified symbol of each month
- WeekStart(): fires on Monday each week
- WeekStart(Symbol): fires on the first tradeable date for the specified symbol of each week
- WeekEnd(): fires on Friday each week
- WeekEnd(Symbol): fire on the last tradeable date for the specified symbol of each week
2017-12-12 12:32:06 +01: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
Andrew be986a5a8f End execution of Lean if an error in a scheduled event is thrown 2017-09-25 09:51:45 -04:00
Andrew eabd36966d Added ScheduledEventException
These changes fix a bug so that when an exception is thrown with the LiveTradingResultHandler, the error is handled and the next scheduled event can happen as scheduled.
2017-09-22 18:23:15 -04:00
jaredbroad 77a511f99c Remove associated tests for negative time rules 2017-02-10 11:29:34 -05:00
jaredbroad 6043d40ebd Revert negative only time difference values 2017-02-10 09:01:24 -05:00
Jared 04de92dae5 Merge pull request #736 from quant1729/master-scheduler-trace-feature
Added simple event acknowledgement trace lines to ScheduleManager cla…
2017-02-08 13:05:53 -05:00
quant1729 c7ff07d7d5 Added simple event acknowledgement trace lines to ScheduleManager class. Tested using ScheduledEventsAlgorithm code. 2017-02-08 23:15:06 +08:00
quant1729 ecb95bb59c Changed time rules to explicitly require a user to specify only positive numbers in offsets for both live and backtest modes. Tests. 2017-02-08 18:04:56 +08:00
Stefano Raggi 4152ddbe17 Fixed typo in TimeRules.BeforeMarketClose parameter name 2016-03-13 21:11:06 +01:00
Stefano Raggi 1e7d8f47ee Fixed XML comments compiler warnings 2015-12-06 16:26:48 +01:00
snugs 35ce0342f9 Tidy up some usages of Symbol.Value/ToString
Includes other small changes from review
2015-11-19 16:23:41 -05:00
snugs 9e660ffcbe Remove usages of Symbol implicits from non-algorithm projects 2015-11-18 18:15:31 -05:00
snugs 7b6c82841f Initial implementation of SecurityIdentifier 2015-11-12 13:55:42 -05:00
snugs c67ff638f4 Renames Symbol.SID to Symbol.Permtick
Coming soon we'll have a full SID system, so renames to make backwards compatibility easier
2015-09-20 23:14:53 -04:00
snugs e1938baafe Clean up using directives 2015-09-01 22:17:35 -04:00
snugs df79ce30c2 Adds the Symbol type
This includes updating all usages of symbol as a security identifier to use the new type.
The type includes a unique field, SID, as well as the current ticker's value. This allows
for consistent addressability while also allowing the ticker to evolve over time with the
mapping changes.

Effort was made to maintain compile and runtime backwards compatibility.
2015-09-01 22:17:10 -04:00
snugs 776a1e59a7 Adds more Date/Time rules 2015-08-20 18:43:37 -04:00
snugs 293fc1224a Improves ScheduledEvent usability
Adds Enabled flag to turn event on/off
Adds EventFired event for runtime binding
Schedule builder methods now return ScheduledEvent instance
2015-08-20 18:43:07 -04:00
snugs 66604a698c Change visibility of some members in ScheduledEvent
Preparation for adding user facing API methods/properties/events
2015-08-20 17:14:28 -04:00
snugs 3e665def67 Fixes bug in SkipEventsUntil, always skipped first event 2015-08-20 14:54:51 -04:00
snugs 33a4db4559 Fixes bug scheduling events on same day 2015-08-20 14:34:13 -04:00
snugs 74d6ab6822 Prevent null ref in ScheduleManager before init 2015-08-20 14:30:22 -04:00
snugs 8380da11cf Adds fluent interface for scheduled events
Algorithms can now use syntax like the following to define events:
Schedule.Event(name).{DateRuleMethod}.{TimeRuleMethod}.Run( lambda )

For example: Schedule.Event(tues).Every(DayOfWeek.Tuesday).AfterMarketOpen(SPY, 20).Run(MyTuesdayHandler);
2015-08-11 10:51:58 -04:00
snugs b68a8be848 Move Date and Time rules to ScheduleManager 2015-08-10 11:38:48 -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