Commit Graph

51 Commits

Author SHA1 Message Date
Martin-Molinero 9cdb4a91c5 Refactor live data feed (#4636)
* Live Coarse universe refactor

- Live trading will source Coarse and Fine fundamental data directly
  from disk. Updating unit tests.

* Adds ILiveDataProvider interface

  * Adds wrapper for IDataQueueHandler implementations

  * Replaces IDataQueueHandler with ILiveDataProvider in
    LiveTradingDataFeed

  * Edits IDataQueueHandler documentation

* Maintains aggregation for current IDQH impls and skips for ILDF impls

  * Note: No unit test was created for this method, go back and TODO

* Protobuf Market data

- Adding protobuf support for Ticks, TradeBars and QuoteBars. Adding
  unit tests.

* Adds unit tests for LiveDataAggregator changes

  * Fixes bug where custom data was not handled as it was before
  * Fixes race condition bug because of variable reuse in class

* Add protobuf extension serialization

* Fixes for protobuf serialization

* Refactor

* Fix OptionChainUniverse

* replace BaseDataExchange pumping ticks with consolidators

* AlpacaBrokerage

* BitfinexBrokerage

* GDAXBrokerage

* OandaBrokerage

* InteractiveBrokers

* TradierBrokerage

* FxcmBrokerage

* PaperBrokerage

* etc

* WIP fixes for existing LTDF unit tests

* Fixes more LTDF unit tests

* make IDataAggregator.Update recieving Generic BaseData rather than Tick

* Change IDataQueueHandler.Subscribe method

* Some fixes after adding new commits

* Adds protobuf (de)serialization support for Dividend and Split

* Serialize protobuf with length prefix

* Fix missing LTDF unit tests

* Adds TiingoNews protobuf definitions

* fix comments

* more fixes on IQFeedDataQueueHandler

* disallow putting ticks into enumerator directly

* ScannableEnumerator tests

* fix OandaBrokerage

* AggregationManager unit tests

* fix AlpacaBrokerage tests

* fix InteractiveBrokers

* fix FxcmBrokerage tests

* call AggregationManager.Remove method on unsubscribe

* fix GDAX existing tests

* Fixes, refactor adding more tests for AggregatorManager

* Adds BenzingaNews protobuf definitions and round trip unit test

* Adds missing TiingoNews unit test to Protobuf round trip tests

* Improve sleep sequence of LiveSynchronizer

* need start aggregating first, and then can subscribe

* More test fixes and refactor

- Refactoring AggregationManager and ScannableEnumerator so the last is
  the one that owns the consolidator
- Adding pulse on the main LiveSynchronizer

* Improve performance of LEquityDataSynchronizingEnu

* Add missing Set job packet method

* Minor performance improvements

* Improvements add test timeout

- Improvements adding test timeout to find blocking test in travis

* Improve aggregationManager performance

* Testing improvements for travis

* Remove test timeouts

* More test fixes

- Adding more missing dispose calls and improving determinism

* fix IEXDataQueueHandler and tests

* Final tweaks to LTDF tests

* more AggregationManager tests

* consume and log ticks

* fix test: couldn't subscribe to Forex tickers

* change Resolution for all bar configs

* Improve RealTimeScheduleEventServiceAccuracy

* refactoring: move common code to base class

* fixed bug; unsubscribe SubscriptionDataConfig

* Small performance improvement

* Minor fixes

* Avoid Symbol serialization

* Fixes coarse selection in live mode

* Fix for live coarse

* Adds protobuf (de)serialization support for Robintrack

  * Adds round-trip unit test

* Minor performance improvements

* More minor performance improvements

* pass LiveNodePacket through to OandaBrokerage

* Fixes empty list becoming null value when deserializing with protobuf

* Reverts BZ live trading exception removal and fixes tests

* Refactor WorkQueue making it abstract

* Add try catch for composer

* Adds optional data batching period to LiveFillForwardEnumerator

* Override data-queue-handler with config

* Improve PeriodCountConsolidator.Scan performance

* Move batching delay to main Synchornizer thread

* Reverts addition of Robintrack protobuf definitions

* Give priority to config history provider if set

* Add Estimize protobuffing

- Add Estimize protobuffing support. Adding unit tests

* Always dispose of data queue handler

Co-authored-by: Gerardo Salazar <gsalaz9800@gmail.com>
Co-authored-by: Adalyat Nazirov <aenazirov@gmail.com>
2020-08-18 20:21:10 -03:00
Martin Molinero 0027ab1e66 Regression test assert order list hash
- Regression tests assert order list hash value
- Normalizing some regression test behavior that had differences between
C# and Py
2020-02-19 20:26:12 -03:00
Martin Molinero 4584088a9e Address reviews
- Refactor to avoid calling rebalancing function twice in the same loop
- Refactor making portfolio rebalance setting instance based instead of
static
2020-02-13 16:10:52 -03:00
Martin Molinero e6d07d6305 Add new regression algorithms
- Adding new regression algorithms setting PCM.RebalanceOnSecurityChanges
and PCM.RebalanceOnInsightChanges to false
2020-02-11 17:36:27 -03:00
Gerardo Salazar 66e093babb Address review - Remove SampleAssetPrices from IResultHandlers
* Changed variable names of protected members in BaseResultHandler to
match existing variable naming convention
* Changed AlgorithmRunner return type
* Remove AlgorithmResults dictionary from AlgorithmRunner
* Create AlgorithmRunnerResults container class
* Modify Relative Sampling test to accept failure cases
* Misc. updates as a result of changing AlgorithmRunner return type
2020-01-16 14:03:55 -08:00
Gerardo Salazar dfee825ef6 Refactors sampling strategy in AlgorithmManager loop
* Refactors AlgorithmManager loop
* Refactors StatisticsBuilder methods and strategy for series alignment
* Move sampling logic to the corresponding IResultHandler
* Changes benchmark resolution to Resolution.Hour
* Modifies IResultHandler to enable external sampling
* Adds BacktestResultHandler unit tests
* Adds ResolutionSwitchingAlgorithm to test misalignment
* Adds support to AlgorithmRunner to store algorithm IResultHandler

Warning: this commit breaks accurate calculations for algorithms that
only make use of `Daily` resolution data. Previously, because
the benchmark was added in Daily resolution in backtesting, any
algorithm that only made use of daily data would have an accurate
calculation for beta and various other statistics.

These changes serve to fix the statistics calculations of non-daily
resolution algorithms, with daily resolution to be revisited at a later
time.
2020-01-16 14:03:54 -08:00
Martin Molinero cd9bf4cc77 Making WorkerThread static
- Making WorkerThread instance static
- Adding PythonInitialize.AddPythonPaths(), useful to add paths to
python after initialization
2020-01-14 11:31:58 -03:00
Martin Molinero 87bc03d71e Address reviews
- When BacktestNodePacket has the inital `CashAmount` set we will clear
all existing cash amounts and set the account currency
- Adding more unit tests
2019-12-31 13:25:58 -03:00
Prasad Somwanshi a1a2c494cb Modifed code for failing unit test 2019-12-31 13:13:05 -03:00
Martin Molinero 6da8eb7c66 AlgorithmManager exception fix
- `AlgorithmManager` will search for `SubscriptionDataConfigs` using the
`SubcriptionDataConfigService` versus directly checking active `Subscriptions`.
In the case of warmup, subscription have not been added yet. Also will
include internal subscriptions.
- Adding unit tests
2019-12-16 18:20:57 -03:00
Martin Molinero 9afe74a618 Fix rebase 2019-11-08 17:51:33 -03:00
Martin Molinero 2aeed3595d Algorithm will respect job dates if present
- Console and Backtesting setup handler will use job dates if present
(not the brokerage setup handler)
- Adding unit test
2019-11-08 17:51:33 -03: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 fbc0a22355 Provide detailed regression algorithm portfolio logging
I noticed some deltas in regression statistics after a change. Before this
change, we log all orders into an {AlgorithmName}.{Language}.orders.log.
This information turned out to be insufficient to identify the regression.
This change also adds daily logging of portfolio value and each security's
holding quantity/value, as well as the full cash book. This should help to
more quickly identify the root cause behind system regression test failures.
2019-09-30 12:30:26 -04:00
Martin Molinero 7cd1c18887 Benchmark Symbol will not be added to cache 2019-08-20 18:42:31 -03:00
Martin Molinero 2b07b0faf4 Fix test AlgorithmRunner 2019-05-28 11:49:08 -03: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 32ac3146b4 Merge Framework and Classic Algorithms
- Merging Framework and Bridge algorithms into classic QCAlgorithm
class.
- Removing Framework project, VS17 and VS15
2019-04-03 21:54:32 -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 ff5e888313 Fix for delisted subscription data being sent 2018-07-18 09:45:13 -03:00
Stefano Raggi dbb6561629 Add missing try...catch with logging in AlgorithmRunner task 2018-07-03 23:13:18 +02:00
Michael Handschuh 8c011640cb Properly set algorithm id in AlgorithmRunner
Many logs were showing the name of the first algorithm on the line:
SetUp Backtesting: User: <uid> ProjectId: <pid> AlgoId: AddRemoveSecurityRegressionAlgorithm

Instead of the name of the running algorithm.
2018-04-26 13:13:50 -04:00
Michael Handschuh a443be7e6e Add QCAlgorithmFramework.DebugMode
Setting this to true enables logging of model inputs and
outputs. Be careful about your universe size, it can generate
a LOT of data
2018-04-06 16:30:26 -04:00
Jared Broad c7f2e2cf21 Tweaked alpha value to be monthly instead of accumulating for ever 2018-03-22 18:33:52 -04:00
Michael 3fb429e5f4 Merge pull request #1685 from QuantConnect/feature-update-alpha-framework-for-consistency-with-api
Finalizes implementation of alpha framework, including alpha.spanner updates, many name changes, and harmonizes insight serialization with alpha streams API
2018-03-12 16:39:33 -04:00
Stefano Raggi 58a65bee97 Fix Forex data not received when reusing an existing internal feed
Fixes #1611
2018-03-09 23:28:23 +01:00
Michael Handschuh 6b239674e2 Renames Alpha -> Insight
The term 'alpha' is used to describe the entire algorithm. Therefore, 'alpha'
produces insights. From this we have things like IAlphaModel, which is the model
defining how insights are produced. We have IAlphaHandler, which defines how the
insights from a single 'alpha' (the algorithm) are managed, analyzed, and stored.
Types closer to the individual prediction level, such as InsightDirection, or
InsightScore relate directly to exactly 1 insight. The distinction between the
two became more clear as we developed the insights API, and from that effort it
was decided to harmonize alpha/insight terminology across the various QC systems.
2018-03-09 16:12:56 -05:00
Michael Handschuh 5ba44ed5ab Remove universe symbols from history requests
The engine defines securities for each universe to properly track them within
the data feed. These securities are not tradable and have no price data associated
with them, and as such, we should not be sending history requests for these symbols.
This change removes all universe symbols from history requests.
NOTE: Requests made directly to the history provider are not filtered out, as the
filtering happens within the QCAlgorithm implementation.
2018-03-05 14:18:33 -05: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 d38323b98c Add alpha statistics regression test functionality
When the algorithm finishes, the alpha statistics are merged with the backtest
result statistics. This keeps the regression testing pattern of alpha statistics
the same as the existing regular statistics.
2018-01-12 12:08:40 -05:00
Michael Handschuh 8263d15bdd Remove deletion of regression.log
This file is no longer written as part of the regresson test suit.
Regression logs files can now be found in the ./passed and ./regression
folders from the test's executing directory.
2017-12-04 15:45:44 +01:00
Michael Handschuh 1060b55899 Write regression logs to unique files
Often when implementing new features I find myself having to switch to master
in order to get a copy of a passing regression run log file. This change aims
to simplify that process by saving regression algorithm log files to their own
unique file and if they pass the regression test, copying that file to another
location to keep it while testing a potentially failing regression run.

The current run and most recent passed log files are placed in separate
directories to enable easy directory diffing to quickly find regression issues.

Current run:
  ./regression/<algorithm-name>.<language>.log

Most recent pass:
  ./passed/<algorithm-name>.<language>.log
2017-11-28 13:19:42 -05:00
AlexCatarino e7d08c1122 Fixes AlgorithmRunner to enable regression tests for python algos 2017-10-06 13:33:24 +01:00
Andrew 143e779bb8 Add Dispose method to ILeanManagement 2017-07-14 12:40:53 -04:00
Andrew e4ebcf6cf3 Created ILeanManagement
ILeanManagement is meant to be a wrapper on the entire Lean engine and allow
command to be sent from ILeanManagement to the rest of Lean.  In addition,
ILeanManagement can act as a hosting environment specific implementation for hosting Leaninstances.
2017-07-14 12:40:52 -04:00
Michael Handschuh 70b170358e Turn debug logging on for regression
Also removes some redundant/duplicate logging
2016-04-07 04:11:53 -04:00
Michael Handschuh 899ff7407e FileLogHandler: Add option to remove timestamp 2016-04-05 15:52:24 -04:00
Michael Handschuh 2689e6a976 Adds RegressionLogHandler to write log file w/out timestamps
This makes for cleaner diffs between runs in regression.log
2016-03-31 16:06:21 -04:00
AlexCatarino cc32d30c96 AlgorithmRunner admits language choice
AlgorithmRunner.RunLocalBacktest admits algorithm language choice
2016-02-22 20:10:09 -03:00
Michael Handschuh cf6b4aa57d Use BacktestingResultHandler instead of ConsoleResultHandler 2016-01-20 14:05:41 -05:00
Dmitri Pavlenkov 78d21b0d75 Fixes running multiple regression test algorithms
Properly dispose of all handlers
Reset Composer instance
2015-07-03 16:14:27 -04:00
snugs 941b0c5e51 Update test to be more config agnostic 2015-06-25 15:54:43 -04:00
snugs 9327ef09a2 Remove Engine as IDisposable, manage resources externally from the engine 2015-06-23 19:28:24 -04:00
snugs c8b4e6bdba Remove config 'local' value
This change includes addition of the 'tradier-save-tokens' config value used to write tradier access/refresh tokens to disk
2015-06-22 19:05:04 -04:00
snugs 470d51a6d0 Extract sourcing of job from Engine.Run
The engine itself shouldn't concern itself with where jobs come from, so we pull the next job and acknowledge job logic out of Engine.Run
Add RamAllocation to AlgorithmNodePacket
2015-06-22 18:28:23 -04:00
snugs 3636124c5e Misc edits from code review
Removed unused BaseDataFeed and IQFeedDataFeed
Add catch for NullReferenceException in stream store
ConsoleSetupHandler now throws on live jobs, use BrokerageSetupHandler
Renamed/moved FixedSizedQueue to Util\FixedSizeQueue
2015-06-18 17:19:36 -04: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 887faa24e7 Adds support for hourly/daily data to LEAN engine 2015-06-02 21:44:44 -04:00
snugs 49b398f8ff DataStream sync by end of bar
Adds EndTime to BaseData
Adds Period to TradeBar
Now filling data forward on days missing files/data
Some performance enhancements
Removed sorted dictonary in DataStream/AlgorithmManager

We round down fill forward data in the data stream since if we were to perform this in the data feed we would continually produce data at the same time and it would all go into the algorithm at once.
2015-05-01 19:23:57 -04:00
snugs 556bcb160d Add console write to algo runner 2015-04-24 19:47:10 -04:00