Commit Graph

132 Commits

Author SHA1 Message Date
Adalyat Nazirov a4f66628fd Lean Optimization interface in QCAlgorithm (#4923)
* initial commit

* run parametrized algorithm with command line parameters

* skeleton: top level structure

* OptimizationNodePacket scheme

* pass parameters as HashSet

* run Lean and read results

* call method on optimization completion

* refactor public interfaces

- close ParameterSet collection; allow only get operations
- explicit method to start LeanOptimizer

* synchronize RunLean method; the result could come in before the backtest id is set in the collections

* another portion of refactoring and interface changes

* comments

* comments & tests for Extremum, Minimization and Maximization classes

* unify optimization paramater values (min, max, step) & mode GridSearch tests

- swap min&max if necessary
- iterate left => right (negate step value if necessary) & provide default step value if step == 0
- no StackOverflow Exception
- parameterSet Id should be global for current generator and retain between steps
- test signle point boundary (min == max)

* BruteForceStrategy tests

* more comments

* Update Optimizer assembly information

- Update Optimizer projects assembly information to match behavior of
  the other projects

* Tweaks

- Adding comments
- Replace OnComplete for Ended event
- Replace Abort for Dispose
- ConsoleLeanOptimizer will keep track of running processes
- Each backtest will store results in a separated directory, so they
  don't fight for the log.txt file.
- Adding cmdline option for lean to close automatically
- Adding concurrent execution backtest limit
- Console optimizer will start Lean minimized
- Escape spaces in Json path

* remove parameter set generator abstraction layer

we don't need this flexibility now.

* refactor public methods; Step shouldn't be public

* constraints: wip

* define contract

* comparison operators and tests

* specify JsonProperty values

* Move SafeMultiply100 to extensions

* Throw exception on failed Optimizer.Start

* constraints: wip

* change finish & dispose process

* minor fixes

- handle force lean abort
- notify consumer if target has been reached

* target & constraints; adapt unit tests

* Minor Tweaks and fixes

- Some logging improvements
- Remove Public since not required

* Ignore empty ParameterValue

* simplify condition

* avoid reinitialization

* reduce type; force immutable

* unit tests for constraints  and target value

* parse & normalize percent values, i.e. 20% => 0.2

* fixup

* Target & Constraint & OptimizationNodePacket unit tests

* Add more json unit tests

- Adding more json conversion unit tests. Fix bug for Extremum which
  wasn't using the converter.

* LeanOptimizer tests

* Estimation results

* User thread safe counters

* LeanOptimizer unit tests; push OptimizationResult on Ended event

* more unit tests

* Minor tweaks

-Estimate ToString in a single line.
-Typos and missing header file

* Add base SendUpdate method

- Add base SendUpdate method for LeanOptimizer

* fix LeanOptimizer test; rely on internal Update rather than timer

* Add OptimizationStatus

- Add missing commments and OptimizationStatus

* EulerSearch implementation: wip

* OptimizationParameter custom converter

* change the type

* make step optional

* change folder structure

* enumerate optimization parameter using IEnumerable & IEnumerator

* unit tests: parameters & objectives

* unit tests: strategies

* remove redundant TODO

* change Euler search boundaries

* more Euler tests

* prevent race condition

* Add account/read endpoint

- Adding account/read endpoint. Adding unit test

* Add status check before running lean

* Minor self review

- Adding missing comments, minor changes

* remove array parameters

* minor changes

- tidy up config file, rename variable
- accept min less or equal than max

* move OptimizationParameter methods to strategies

* Minor improvements for BaseResultHandler derivates

* minor changes

- strict requirements for Step and MinStep values
- strategy specific settigs

* Add TotalRuntime to estimate

Co-authored-by: Martin Molinero <martin.molinero1@gmail.com>
2020-12-02 20:10:40 -03:00
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 bab635856d Create empty result packet for live trading 2020-07-08 11:47:28 -03:00
Martin Molinero aa0dfc7b3b Create empty result packet for failed inits
- Backtesting will create an empty packet for failed inits
2020-07-08 11:03:04 -03:00
Martin Molinero 452bf27bd9 Adding new DataPermissionManager
- Adding new DataPermissionManager that will own the existing
  datachannelProvider. Will assert configurations before added to the
  data feed. Adding unit tests
2020-06-12 12:34:10 -03:00
Martin Molinero e782ffa4c6 Reuse existing FileAccess permissions 2020-06-09 18:13:12 -03:00
Martin Molinero 5bd11ebd9d Add permission control for Storage
- Adding `Controls.StoragePermissions` to govern permissions for storing into
  the object store. Adding unit tests
2020-06-09 17:24:00 -03:00
Martin Molinero 8c0235617b Add CPU max allocation to Controls
- Add CPU max allocation to Controls
- Rename json field ram allocation from iRamAllocation to iMaxRamAllocation
2020-05-28 15:53:28 -03:00
Martin Molinero 57ea4683d4 Log fixes
- Revert change in Controls getting settings from log, moving to the
  QuantBook
- Adding a couple of logs to BRH exit
2020-05-21 20:08:51 -03:00
Martin Molinero f86af05227 Fix for ObjectStore for QuantBook 2020-04-29 21:03:35 -03:00
Martin Molinero 97f8f50230 Add server statistics for backtesting 2020-04-24 20:33:19 -03:00
Martin Molinero e76dcc4055 Add Order and OrderEvents to AlphaPacket 2020-03-31 20:53:19 -03:00
Martin Molinero bd862cff61 Live and backtest OrderEvent store and stream
- Live and backtesting will send delta order events updates
- Live will store order events every 10 minutes per day
- Backtesting will store last 100 order events on every update and will
store all order events in the end of the backtest
2020-03-30 11:07:18 -03:00
Stefano Raggi 9f75dbcdbb Fix Json property name format 2020-03-24 20:03:05 +01:00
Stefano Raggi 6aae5399b7 Rename and move StreamingDataPermissions to Controls 2020-03-24 18:20:01 +01:00
Stefano Raggi 69639b6d44 Add UserDataSubscriptions for streaming custom data 2020-03-24 12:00:33 +01:00
Martin Molinero 4d0d85ec16 Add Result parameter class
- Add BaseResultParameters and Live/BacktestResultParameters classes
2020-02-25 17:02:30 -03:00
Rohan Talip 66358ac798 Removed the RunMode enum that has been deprecated since the initial commit on 2015-01-12. 2020-02-17 12:50:16 -08: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 9649da3ee6 Added optional property to BacktestNodePacket 2019-12-31 13:13:05 -03:00
Michael Handschuh 999cc275b6 Add IObjectStore.ErrorRaised for persistence errors
Errors raised during persistence aren't able to be handled by user code,
and in fact, are swallowed by the implementation after being logged. By
exposing these errors as events we allow the algorithm to be notified of
such an error and take any step necessary to handle the persistence error.
2019-12-17 22:58:27 -05:00
Michael Handschuh a2b2f889ea Convert object store to in-memory w/ persistence interval
persistenceIntervalSeconds defines the number of seconds between
each save operation. For the local object store, this dictates
how often the contents of the object store is packaged and written
to disk. The PersistData virtual method is provided for subclasses
to provide a different implementation of how/where to persist the
data. The change to be in-memory aims at keeping the object store
performant with reasonable persistence guarantees.
2019-12-17 22:21:11 -05:00
Michael Handschuh 898e885e00 Implement storage limits via Controls
The job packet is now able to specify a maximum file count as well
as a maximum storage size limit. These controls are enforced in the
LocalObjectStorage implementation.
2019-12-17 22:21:11 -05:00
Martin Molinero 88e7645e0f Improve chart streaming
- Remove chart subscription logic. Will stream all chart updates if any
(wont stream empty updates)
- Only serialize properties which are not null
- Adding Chart and Series `IsEmtpy()` extension. Adding unit tests
2019-11-14 17:25:44 -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
Martin Molinero 118c1e49cc Add data channel provider
- Adding `IDataChannelProvider` that will be used to determine if
streaming should be used
- Adding `data-channel-provider` for `config.json`
- Adding unit tests
2019-11-01 14:53:56 -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
Martin Molinero 4010c0b815 QuantBook improvements
- Initialize API
- Set log handler from config
- Add default backtest id
2019-10-09 20:37:10 -03:00
Michael Handschuh b21bfe1731 Remove trailing space from SecurityTypesPacket.cs filename
See #3045
2019-09-12 15:30:46 -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 141eaa1fee Add missing license banner 2019-08-16 18:07:30 -03:00
Martin Molinero f5fa12203c Add Timeout in Controls 2019-08-13 18:25:31 -03:00
Martin Molinero f887c42638 Enable python and CSharp debugging
- Adding `DebuggerHelper` class, handles debugging initialization
- Setting the "PYTHONPATH" will be handled by the `JobQueue`
2019-08-12 22:03:13 -03:00
Jared Broad 6e5a73dc67 Move order controls to job packet 2019-08-07 17:50:45 -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
Stefano Raggi 6315970719 Make Packet.Channel virtual 2018-12-12 00:27:22 +01:00
Stefano Raggi 954515e204 Remove AlphaHeartbeat class 2018-12-12 00:11:18 +01:00
Stefano Raggi b3b1188d3a Add new AlphaHeartbeatPacket class 2018-12-10 23:08:13 +01: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
Michael Handschuh aa92403610 Add regression algorithm packet type 2018-06-05 12:10:50 -04:00
Michael Handschuh 662ae5a65b Limit total insights processed
Nominally set to 10k, similar to order limits
2018-03-22 11:37:34 -04:00
Michael Handschuh 50ae332062 Modify alpha result packet to use spine-case
This casing style is used in the insights API and the serialized form of
this type will also be consumable by the API.
2018-03-09 16:22:49 -05: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 0ab0c2cf76 Convert AlphaID to string 2018-03-05 15:33:10 -05:00
Michael Handschuh 989a2ed37c Handle AlphaNode in AlgorithmNodePacket.AlgorithmId 2018-01-05 11:59:50 -05:00
Michael Handschuh 2bcd355fd9 Add AlphaID to alpha node and result packets 2018-01-05 11:13:44 -05:00
Michael Handschuh 9174fd250d Add AlphaResultPacket.UserId
Very useful to have user information with the generated alphas
2018-01-04 19:21:38 -05:00
Michael Handschuh de66aa7aa7 Add AlphaNodePacket and PacketType.AlphaNode/AlphaWork
Defines a job to run an alpha stream
2018-01-04 19:21:38 -05:00
Michael Handschuh 363003815b Rename AlphaPacket -> AlphaResultPacket
Making room for the AlphaWorkPacket
2018-01-04 12:43:41 -05:00
Jared 8df7daa262 Merge pull request #1449 from QuantConnect/fix-cash-flashing
Default cashbook to null
2018-01-03 09:40:02 -05:00