Commit Graph

264 Commits

Author SHA1 Message Date
Stefano Raggi 9dc4ad17fc Add missing null check in LiveTradingResultHandler.Exit 2019-06-05 12:19:28 +02: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
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 5b04cfe202 Emiting Insights based on Fills
- Classic Algorithms will emight insights based on order fills.
   - To be able to update generated insights closed time, we will not
   clone emitted insights.
   - `InsightAnalysisContext` will update `AnalysisEndTimeUtc` when the
   Insight period is closed and the period is `EndOfTimeTimeSpan`
- Adding new regression algorithm asserting on the new emitted insights
- Adding unit tests
- `LiveTradingResultHandler` will store `AlphaRunTimeStatistics`
- Making `DefaultAlphaHandler.ProcessAsynchronousEvents` virtual to
facilitate cloud changes
2019-03-26 16:09:22 -03:00
Jared Broad 016e1f15f6 Made sample benchmark virtual 2019-02-27 17:25:27 -08:00
Jared 8c9c012478 Update LiveTradingResultHandler.cs 2019-02-27 16:01:51 -08: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 57d50c69c4 Fix XML documentation compiler warnings
- Fixed all warnings except for missing XML comments (CS1591)
2018-11-09 11:44:03 +01:00
Stefano Raggi 9b7fa0f226 Fix minor bug in LiveTradingResultHandler
- set next chart update time after StoreResult has finished
2018-11-06 18:52:46 +01: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 a896d2f448 Live Trading async algorithm status update
- `LiveTradingResulHandler` will launch a separate `Task` in charge of
calling the API to perform the algorithm status update every minute
2018-10-16 16:49:57 -03:00
Michael Handschuh a512f0a110 Merge pull request #2591 from Martin-Molinero/bug-2590-results-stored-multiple-times
Performance improvements LiveTradingResultHandler for algorithms with many symbols (up to 3,000 tested)
2018-10-09 10:08:35 -04:00
Martin Molinero 716f7f5fb1 Performance improvements LiveTradingResultHandler
- Reducing the amount of calls to DateTime.UtcNow.
- Adding new `_nextChartTrimming` check
- Increasing sleep of result thread from 10ms to 100ms
- Modifying exit behavior to avoid multiple (2 or 3) complete storing of results, at algorithm exit.
- Moving update to _nextUpdate outside try catch to avoid multiple
executions in case of error
2018-10-08 15:27:57 -03:00
AlexCatarino a96d6725aa Fixes SecurityCache tick update
Trade ticks are not allowed to update quote variables and vice-versa.
Explicitly define the `TickType` of the tick with the subscription type.
2018-10-05 21:59:54 +01:00
Martin Molinero e8ded1c6d4 Adding checks for .Add operations on dictionaries 2018-08-24 16:38:08 -03: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
Stefano Raggi 33e82919e7 Fix Python regression orders file name
Previously it was reusing the same file name for all algorithms: AlgorithmPythonWrapper.python.orders.log
2018-07-03 20:45:31 +02:00
Stefano Raggi 211dae73f0 Fix duplicate order event logging in LiveTradingResultHandler
Closes #1992
2018-05-10 15:46:40 +02: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