Commit Graph

126 Commits

Author SHA1 Message Date
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
Martin Molinero 4382aa1886 Add algorithm thread
- Adding `WorkerThread` class, wrapper for a worker thread that will
execute given `Actions`.
    - Algorithm related code (`Construction`, `Initialization`,
    `Execution` will be executed by the same `WorkerThread` instance,
    this is required for `Python` debugging.
2019-05-09 11:23:28 -03:00
Martin Molinero 3d52343799 Optimize stored result json
- `Alpha Assets` chart will only store last data point
- Adding new `JsonRoundingConverter` that will round to 4 (number of
digits currently used for comparing alpha statistics) fractional
digits.
   - Will be used for `Insights` and `ChartPoint`
2019-04-29 19:17:00 -03:00
Martin Molinero c13a2817a2 Reducing initial BacktestingResultHandler latency 2019-04-16 15:27:53 -03:00
Martin Molinero b7930aff67 Performance improvements
- Using `Aggregate(lambda)` vs `Sum(lambda)` since the later is slower
due to performing an extra `Select`
- For `QCAlgorithm.Framework.OnFrameworkData()` will avoid calling
`ToArray()` on empty `Enumerables` due to its cost * the number of
calls. If the `Enumerable` is the empty instance, which is static,
will create a new empty array and return it instead.
- Replacing `SecurityIdentifier` `SecurityType` and `GetHashCode`
implementations for `Lazy` versions, that are performed just once, since
these values do not change and are used multiple times.
- For the different `DataDictionary<T>` implementations adding `this[
Symbol] get; set` since existing overload `this [string]` produces an
extra round operations `Symbol->string->Symbol` with a significant
impact.
- Adding `PortfolioTargetCollection.AddRange()` overload using an array
to avoid unnecessary convertions.
2019-04-11 19:01:27 -03:00
Jared d9ee31c979 Merge pull request #3055 from QuantConnect/feature-3041-merge-framework-classic-algorithm
Merge Framework, Bridge and Classic Algorithms
2019-04-05 14:54:31 -07:00
Martin Molinero cfa08a11fb Address reviews
- Removing `using QCAlgorithmFramework = QuantConnect.Algorithm.QCAlgorithm`
- Removing `QCAlgorithmFrameworkBridge`
- Removing `IsFrameworkAlgorithm`
- Making `EmitInsightBasedOnFill` private. Adding new
`IOrderEventProvider` exposing an `event` to which `QCAlgorithm` will
subscribe.
- `AccountType.Cash` algorithms will be allowed to manually trade and
emight insights manually or with alpha model.
2019-04-03 21:55:44 -03:00
Martin Molinero 9f70a962dc Address review 2019-04-03 20:22:32 -03:00
Martin Molinero 9e6f8194fb Send exceeded data points message once 2019-04-03 19:13:33 -03:00
Martin Molinero ecd7242ac5 Store the AlphaRuntimeStatistics for backtest
- `BacktestingResultHandler` will now store the `AlphaRuntimeStatistics`
in the result json file.
2019-01-10 15:20:23 -03:00
Martin Molinero aba9da44c0 Fix intense logging race condition
- Will now use a new container instance for storing the logs outside of
the lock. Else the `_logStore` could be modified while we are looping
over it causing an exception.
2018-11-14 11:15:15 -03:00
Stefano Raggi 5c051c2135 BacktestingResultHandler speed improvement with many orders
- only the last 100 orders will be stored for intermediate backtesting results. The final result packet will always include all orders.
2018-11-06 18:46:45 +01:00
Martin Molinero f1ecfd5784 Move DataManager in front of DataFeed
- Completly move `DataManager` in front of `DataFeed`. Specifically
`AddSubscription()` and `RemoveSubscription()` implementations. Also
removing IDataFeed.Subscriptions
2018-10-29 16:13:27 -03:00
Stefano Raggi ee7877d657 Increase time between updates to 2 sec in BacktestingResultHandler 2018-10-26 10:06:43 +02:00
Stefano Raggi ef5d57ef61 Remove locking during SaveResults in BacktestingResultHandler
We now only lock for the time needed to create a copy of the charts.
2018-10-25 20:58:32 +02:00
Stefano Raggi 5a3b2fd56f Fix delay between result storage updates in BacktestingResultHandler
The 30-second delay for the next update was set before (instead of after) calling StoreResult, which could potentially take a while (if the algorithm submits many orders).
2018-10-25 20:58:32 +02:00
Martin Molinero 5f3fc59c72 Fix insight sum pie chart 2018-08-22 10:44:41 -03:00
Jared 82edfcef2e Merge pull request #2418 from QuantConnect/bug-466-refactor-chart-data-point-limit-lean
Adding a configuration for maximum data points per chart series
2018-08-20 09:22:27 -04:00
Stefano Raggi bba33ff63e Fix time zone bug in BacktestingResultHandler
Also replaced usages of DateTime.Now with DateTime.UtcNow in all result handlers.
2018-08-20 12:07:00 +02:00
Martin Molinero 17995f4c86 Adding a configuration for maximum data points per chart series. Limit will only apply for backtesting result handler 2018-08-17 18:14:33 -03:00
Stefano Raggi 0f49e093e5 Remove debug message variables from BacktestingResultHandler 2018-08-17 20:16:34 +02:00
Stefano Raggi 5629b9d456 Clean up result handlers 2018-08-17 18:48:39 +02:00
Stefano Raggi 5d4639ec68 Delay first packet upload in BacktestingResultHandler 2018-08-08 22:23:16 +02:00
AlexCatarino 9e92c878bd Exclude warmup period from sampling data 2018-08-01 18:49:49 +01:00
Michael Handschuh e6e4e58eb9 Log all order events to dedicate file in regression
When inspecting regression differences, the first thing that should be looked at
are the fills. Some of the regression algorithms log this data making it possible
to inspect whie others do not. In addition, for algorithms with many securities the
log can quickly become fills with noise from scheduled event logging.

This change aims to make it very easy to compare any regressions in orders/fills
against the most recent successful run of the specified regression algorithm.
2018-02-19 13:01:27 -05:00
Michael Handschuh af71a1389b Fixes stack overflow ex when running multiple regression algos 2018-02-09 14:28:21 -05:00
Michael Handschuh 56b99777f7 Force synchronous logs during regression tests
Debugging using the log files is further complicated by the asynchronous write
of the algorithm's Debug and Log methods. This change allows writing via the
Console to happen synchronously, which makes it much easier to spot meaningful
differences between log files.
2018-02-06 19:52:31 -05:00
Stefano Raggi 97f529e30f Replace Stopwatch with DateTime.UtcNow in BacktestingResultHandler
Tight loops like these seem to be consuming more CPU when using Stopwatch.
2017-12-29 01:04:59 +01:00
Jared Broad b64365f7c3 Bug fix missing progress setting 2017-12-27 17:59:46 -05:00
Jared Broad a02e9a378c null ref exception 2017-12-27 17:28:29 -05:00
Jared Broad 120b807d66 Rework to use algorithm dates rather than job 2017-12-27 17:10:06 -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 Handschuh 7be45ec0eb Only save most recent chart point for pie series 2017-12-19 18:18:33 -05:00
Michael Handschuh aeab15b57e Fixes typo in BacktestResult.IsFrameworkAlgorithm field name 2017-12-18 16:04:06 -05:00
Michael Handschuh d8ef289c9b Add IAlgorithm.IsFrameworkAlgorithm and BacktestingResut.IsFrameworkAlgorithm
Flag indicates whether or not the algorithm is a framework algorithm.
2017-12-14 19:43:26 -05:00
Michael Handschuh 60ddbca0e4 Update signal handler to persist signals
Revert changes to result handlers from previously persisting signals in there.
Minor changes to the signal analysis result class.
2017-12-12 09:18:32 -05:00
Michael Handschuh ee4161ae4a Make SetAlgorithm, StoreResult, and Truncate virtual
It's reasonable to think that a user defined implementation of these methods would
benefit from being able to override.
2017-12-08 10:07:54 -05:00
Stefano Raggi ec320fd27b Fix potential division by zero in BacktestingResultHandler
This can happen with algorithms that do not call AddSecurity and have a non-security benchmark such as SetBenchmark(x => 0)
2017-12-05 20:12:54 +01:00
Michael a72f30925c Merge pull request #1328 from QuantConnect/cashbook-result
Cashbook result
2017-11-17 16:11:12 -05:00
Andrew 238d4772d2 Implement SendStatusUpdate for BacktestingResultHandler 2017-11-02 15:01:29 -04:00
Jared Broad aefdfcc411 Add the cashbook to the result packet 2017-10-23 17:00:28 -04:00
Andrew 1ec86d2c6c Mark BRH.SendStatusUpdate as virtual 2017-10-13 11:40:50 -04:00
Andrew 9855794e95 Add null check in BRH.ProcessSynchronousEvents()
There are cases were creating the instance of the algorithm or setting up the algorithm will throw an error. In those cases, the backtesting result handler - who has already been initiaized - will attempt to call ProcessSynchronousEvents() when it's instance of IAlgorithm is still null. This will then throw an error when BRH.ProcessSynchronousEvents() attempts to access the properties on IAlgorithm
2017-09-15 10:27:53 -04:00
Andrew 3370a9b7fd Call ProcessSynchronousEvents() in BRH.Exit()
Debug messages can be lost if an exception is thrown in the algorithm before IResultsHandler.ProcessSynchronousEvents() is called in AlgorithmManager. Calling ProcessSynchronousEvents() in the Exit method of the BacktestingResultsHandler should help ensure that Debug messages make it back to the user even if there is an exception thrown in the algorithm. This is the pattern used by the LiveTradingResultsHandler
2017-09-13 10:53:57 -04:00
Stefano Raggi 13718b143c Merge pull request #1056 from QuantConnect/net-profit-fix
Net profit fix
2017-08-09 11:00:46 +02:00
Jared Broad dcc4f2f7c7 Updated result handlers to display net profit 2017-08-08 19:46:37 -04:00