Commit Graph

85 Commits

Author SHA1 Message Date
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
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
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
Stefano Raggi d7160852f9 Fix ConsoleSetupHandler overwriting Job.BacktestId 2018-09-28 10:13:43 +02: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 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
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
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
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
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 f2f93ef85c Better cache for ZipArchive 2016-12-27 15:18:39 +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
Andrew Hart c71a55f7a9 AvailableDataTypes is now part of SubscriptionManager 2016-11-23 13:42:55 -05:00
Andrew Hart 81fe2a94cb Data formats (Trade/Quote) are configurable for each security 2016-11-18 15:30:54 -05: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
Jared 59574d96e8 Merge pull request #495 from devalkeralia/BrokerageMessageHandler-fix
Brokerage Specific Default BrokerageMessagingHandler + FXCM BrokerageMessagingHandler Bug Fix
2016-07-22 12:07:14 -04:00
devalkeralia f8fa37fa92 changed the Engine to use the new CreateBrokerageMessageHandler using the brokerage factory 2016-07-21 15:54:53 -04:00
AlexCatarino 648e4b1c7d User-frieldly warning misspecification of algorithm name
Defines a new resolver function to return null instead of throwing so that Loader can return a user-friedly error message.
2016-07-11 10:56:32 -03:00
jaredbroad 2670b41be6 Bug fixes and event onload for when embed url is loaded 2016-04-11 20:06:25 -04:00
jaredbroad 632c21c99c New UX for LEAN, launched from Launcher using embedded HTML browser 2016-04-11 18:29:50 -04:00
David Hsieh 4f500c04aa Updated launcher to run new desktop configuration 'backtesting-desktop'. 2016-04-04 05:28:25 +10: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
snugs f33cffe77f Moves asset count limit logic out of Algorithm namespace
Since we now support universe selection and by convention never remove a security
object, we can't rely on the counts of the security manager to perform limits on
data subscriptions, this logic was moved deeper into the engine, where we perform
UniverseSelection, which is the path taken to add new data subscriptions
2015-12-21 16:13:23 -05:00
snugs 07ea7958c6 Adds ISetupHandler.CreateBrokerage 2015-12-14 13:18:22 -05:00
snugs 809a1ec9bb Set algorithm default markets in setup handlers 2015-12-10 15:22:56 -05:00
snugs bc6ffbce0c Set algorithm parameters from job packet 2015-12-10 13:45:40 -05:00
snugs be950e756a Log full errors/stack traces
Many places in the code used Log.Error(err.Message) or equivalent which
strips out all the really useful information, such as the stack trace
and inner exceptions. Using Log.Error(exception) is the correct way to
log an error as it will correctly write all the message details, also,
by passing the full Exception object we can improve the logging in this
one place and all call sites will automatically benefit from the improvements
2015-12-02 12:35:33 -05:00
snugs 75a81f581e Rename SecurityExchangeHoursProvider to MarketHoursDatabase 2015-11-30 16:50:09 -05:00
Stefano Raggi 01afc560f4 Added Settlement models
- New ISettlementModel interface with implementations:  ImmediateSettlementModel + DelayedSettlementModel
- SecurityPortfolioManager: UnsettledCashBook + ScanForCashSettlement
- Added tests for settlement models
- Added GetSettlementModel to IBrokerageModel
- Added AccountType argument to SetBrokerageModel()
- Added SetBrokerageModel(IBrokerageModel) overload
- Made BrokerageModel setter private
2015-11-11 22:18:34 -05:00
snugs 93fb8a1f59 Adds IBrokerageMessageHandler and DefaultBrokerageMessageHandler
Removed ISetupHandler.SetErrorHandler, this is replaced by

brokerage.Message += (sender, message) => algorithm.BrokerageMessageHandler.Handle(message)

allowing algorithm direct access to managing the brokerage messages
2015-10-29 20:14:31 -04:00
snugs 071d679f1e Send user emails on brokerage warnings 2015-10-29 14:03:53 -04:00
snugs 9c5a6aa254 Fixes bug in sending Notifications in Initialize 2015-10-28 22:48:15 -04:00
snugs 730430b1bb Adds scheduling feature
Adds the ScheduleManager which allows an algorithm to add/remove scheduled events
Check out the ScheduledEventsAlgorithm for syntax
ScheduledEvents are at their core an IEnumerator<DateTime> that defines the event times coupled with a callback
IDateRule defines dates for events
ITimeRule defines time(s) on a given date for events
2015-08-10 10:56:14 -04:00
snugs e16c82a856 Adds IAlgorithm.PostInitialize
Resolve benchmark in PostInitialize method
2015-08-06 13:05:05 -04:00