Commit Graph

84 Commits

Author SHA1 Message Date
Jared 3efb39e313 Increase the load time of the algorithm slightly.
Reduce the probability of timeouts loading the algorithm.
2020-07-08 16:55:51 -07:00
Martin Molinero e73e927c0f Enable parallel unit testing 2020-04-27 17:45:53 -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 9649da3ee6 Added optional property to BacktestNodePacket 2019-12-31 13:13:05 -03:00
Stefano Raggi d407307566 Add IObjectStore interface with LocalObjectStore implementation
This commit is squashed from iterative development:

- More consistent method naming
- Storage root path updated to be absolute and include algorithm name
- Storage root path created only if object store is actually used
- Implemented XML save/load
- Added missing unit tests
- Replaced Log.Trace with Log.Error calls
- Added the object store name logging in Engine.Main
- Read storage root from config
- Create algorithm storage root folder in Initialize
- Remove empty folder in Dispose
- Added null checks in all methods
- Added missing XML parameter docs
- make Initialize and Dispose virtual
- make AlgorithmStorageRoot protected

The IObjectStore abstraction provides algorithms with a persistent
storage mechanism. While the algorithm is running, data is maintained
in memory as a dictionary of raw bytes (string -> byte[]). This ensures
we avoid any reference type shenanigans. Periodically, the data in the
object store is persisted and additionally, when the algorithm shuts
down, the object store's data will again be persisted. This ensures that
when the algorithm starts up again, it will have access to any state
that has been saved into the object store.

A great use case for IObjectStore is saving a compute heavy model.
For example, computing the weights of a deep neural network is very
CPU intensive, but after the weights are computed, evaluation is fairly
quick. An initial backtest can be used to solved for the network's weights
and then subsequent backtests or even in live mode, the weights will be
available to the algorithm provided they were saved into the object store.

Also, some libraries require a file path to load model data. The object
store provides a `GetFilePath(key)` method which will copy the data for
the provided key to the disk and return that path so the library can load
the model data.
2019-12-17 22:21:11 -05: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 0e7c035329 Adding FreePortfolioValue
- Adding `FreePortfolioValue` to be set after algorithm initialize based
on the `TotalPortfolioValue` and the `FreePortfolioValuePercentage`
- Updating regression tests
- Adding new regression test
- Adding check for minimum order value at `BuyingPowerModel`
2019-10-23 13:56:35 -03:00
Michael Handschuh e4d1005c4a Update Lean.Engine 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 15:30:45 -04:00
Martin Molinero eb9fe73ebc Engine code clean up 2019-08-16 19:09:45 -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 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 a26b3542bb Address reviews
- `ISetupHandler.Setup()` will now receive a parameters object
- Removing `SetupHandlerHelper` and adding new `BaseSetupHandler`
2018-12-19 16:15:28 -03:00
Martin Molinero af8e6bf85c Fix starting capital for non usd cash
- Moving `UniverseSelection.EnsureCurrencyDataFeeds` call into the
`IResultHandler` implementation through usage of the new `SetupHandlerHelper`
class, that will also set an initial conversion rate if none present.
- Adding regression test, that reproduces original issue
2018-12-19 16:15:28 -03:00
Martin Molinero 4d7dfe1c89 Initialize algorithm faster
- ISetupHandler implementations will now use 50ms as sleep interval
while initializing the algorithm
- If the sleep interval is >= to 1s (default value) it will divide the
sleep operations into 5
2018-10-31 18:05:12 -03:00
AlexCatarino e9899e357d Improves Exception Messaging For Loader
Improves the message when the Loader cannot resolve the algorithm to load. It happens when the assemblies don't have a QCAlgorithm class that match the algorithm name or you have 2-of them so Lean doesn't know which one to backtest.

The possible Loader exceptions are thrown as `AlgorithmSetupException` to mach the pattern for exceptions during initialization.
2018-06-28 13:27:08 +01:00
Michael Handschuh 301ab1cb93 Invoke PostInitialize immediately following Initialize
This is performed w/in a try/catch which esures that we won't call PostInitialize
if Initialize throws an error, thereby preventing potential confusing in the reported
error message

Fixes #1778
2018-03-26 13:49:35 -04:00
AlexCatarino 1cf26efa73 Applies exception interpreters to errors thrown in ISetupHandler.Setup
Change the logic in Engine.Run to interpret each exception thrown during initialization that is saved in ISetupHandler.Errors.
2018-03-15 22:12:48 +00: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 60fd7eb304 Refactor ISetupHandler.Errors to List<Exception>
This will prevent loss of information by translating the exception to a
string message too early
2018-02-27 22:17:46 -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
AlexCatarino dfffbd6953 Adds IFutureChainProvider interface with base implementations
- Move BacktestingFutureChainProvider provider to Lean.Engine.DataFeeds along with its options equivalent.

- EmptyFutureChainProvider: provider that returns an empty list of symbols
- CachingFutureChainProvider: implements caching by date
- BacktestingFutureChainProvider: provider that gets chain from local files
- LiveFutureChainProvider: provider that gets chain from external source (empty list of symbols for now)
2017-12-04 14:16:59 +00:00
Andrew a035c05510 Send Initializing status packet in BacktestingSetupHandler 2017-11-02 15:01:29 -04:00
Michael Handschuh d92f161f8c Update max run time to check for universes
The max run time calculation wasn't considering whether or not the user had
any universe subscriptions
2017-10-20 09:27:13 -04:00
Michael Handschuh 7c0a0c4698 Set algorithm name in setup handler
When using the console setup handler, the algorithm's type name
will be used as an identifier.
2017-10-06 16:23:38 -04:00
Michael Handschuh ecd92462da Clean white space 2017-10-06 16:23:37 -04:00
Andrew 245a2e1580 Added Linq extension method to find the algorithm name
This extension method is meant to standardize the finding of the class to run between the Brokerage and Backtesting setup handlers
2017-08-24 12:18:26 -04:00
Stefano Raggi e379457757 Refactor option chain providers
- Moved provider implementations out of brokerages into their own classes
- Removed DefaultOptionChainProvider
- Added BacktestingOptionChainProvider and LiveOptionChainProvider
- Moved SetOptionChainProvider call from Engine to setup handlers
2017-08-02 22:43:15 +02:00
Andrew acb56cb985 Fix comment 2017-06-28 11:01:32 -04:00
Andrew 416c79de04 Let Lean set start/end date during backtesting
Lean will not set the start and end date in the BacktestingSetupHandler.
The start and end dates are specified in the user code in
IAlgorithm.Initialize.
2017-06-28 11:01:01 -04:00
jaredbroad 57456e12f5 Update python runtime to be 10x longer to account for pythonnet 2017-04-30 21:19:01 -04:00
Stefano Raggi 374c8a1959 Fix SetOrderProcessor called too late
When using BrokerageHistoryProvider with InteractiveBrokers, GetOrderByBrokerageId calls on open orders were logging NullReferenceExceptions because SetOrderProcessor is called later, in BrokerageSetupHandler.Setup.
2017-04-14 23:43:36 +02:00
jaredbroad fe9a9cc44e Refactor TryCreateAlgorithmInstanceWithIsolator to take job and set ram limit 2017-02-17 09:34:34 -05:00
jaredbroad b22b85d186 Use controls limit in backtest initialization 2017-02-16 18:13:08 -05:00
Andrew Hart 077c2256b6 Increase loaderTimeLimit of Loader in BacktestingSetupHandler 2017-01-16 17:32:02 -05:00
quant1729 6ba1ae899a Removed UnzipCached() method and its usages. Updated Zip() method. 2017-01-11 12:57:03 +08:00
quant1729 48721125dc Revert "Fixed bug with static zip archive caching. Added new caching data file provider. Refactored IDataFileProvider interface."
This reverts commit c59743dc42.
2017-01-11 11:27:28 +08:00
quant1729 c59743dc42 Fixed bug with static zip archive caching. Added new caching data file provider. Refactored IDataFileProvider interface. 2017-01-08 09:25:26 +08:00
quant1729 5a6176df30 Adjusted maximum runtime limits to account for derivatives 2016-12-27 17:01:39 +01:00
quant1729 f2f93ef85c Better cache for ZipArchive 2016-12-27 15:18:39 +01:00
quant1729 27dd334ca5 Debug commit: removing temporarily time limits for backtests 2016-12-22 18:08:20 +01:00
quant1729 705024cd89 Merge branch 'futures'
Conflicts:
	Common/QuantConnect.csproj
2016-12-20 15:53:24 +01:00
Stefano Raggi 4a2b6c36e4 Improve logging and error reporting for runtime errors 2016-12-17 13:14:30 +01:00
quant1729 2dce74e26d - Extended Option security and Option holding classes
- Updated IB fee model to support option exercise
- Added support for splits for options. Not tested on real data yet.
- Added option exercise functionality for long positions. Unit Tests. Not tested on real data yet.
- Added option assignment functionality for short positions. Assignment event. Unit Tests.
- Added basic option assignment simulator for backtesting brokerage. Simulates assignments for deep ITM short positions close to expiration. Unit Tests.
2016-08-31 18:00:00 +02:00
devalkeralia f8fa37fa92 changed the Engine to use the new CreateBrokerageMessageHandler using the brokerage factory 2016-07-21 15:54:53 -04:00
Michael Handschuh 1d07e5d31a Move IBrokerageFactory.DefaultMarkets to IBrokerageModel 2016-02-04 13:27:53 -05:00
Michael Handschuh 7fb2073fab Invoke ISecurityInitializer in Security.CreateSecurity
This removes the SetupHandler.UpdateModels(...) method which used the brokerage
model to set fill/fee/slippage/settlement models. This will also allow the
removal of flags indicating that the user has set certain Security properties
2016-01-19 13:13:00 -05:00
snugs 3a787c1fec Update models using IAlgorithm.BrokerageModel in universe selection 2015-12-28 14:44:39 -05:00
Stefano Raggi a29b78cc0a Fixed universe subscriptions with Forex 2015-12-28 13:38:52 -05:00