- When BacktestNodePacket has the inital `CashAmount` set we will clear
all existing cash amounts and set the account currency
- Adding more unit tests
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.
- 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`
- 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.
- 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
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.
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
- 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)
- Moved provider implementations out of brokerages into their own classes
- Removed DefaultOptionChainProvider
- Added BacktestingOptionChainProvider and LiveOptionChainProvider
- Moved SetOptionChainProvider call from Engine to setup handlers
When using BrokerageHistoryProvider with InteractiveBrokers, GetOrderByBrokerageId calls on open orders were logging NullReferenceExceptions because SetOrderProcessor is called later, in BrokerageSetupHandler.Setup.
- 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.
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
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
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
Removed ISetupHandler.SetErrorHandler, this is replaced by
brokerage.Message += (sender, message) => algorithm.BrokerageMessageHandler.Handle(message)
allowing algorithm direct access to managing the brokerage messages
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