- `BacktestingBrokerage.Scan()` is now reentrant and was causing
duplicate processing and events. To solve this updateing the order
status keeped by the brokerage. Adding unit tests
The market fill warning introduced in #2869 was considering any price older than the fill time as stale (even if only a few seconds older), causing many false alerts.
This is being changed now by adding a new configurable algorithm setting: StalePriceTimeSpan (with a default value of one hour).
- Removing OrderFeeParameters.AccountCurrency. Where required replacing
for constructor parameter defaulting to USD.
- Updating IB fee model to use to correct fee currency
- `GetCashBalance()` will return a `List<CashAmount>`, will not need to
set conversion rates, which requires knowing what the account currency is.
- Removing `Global.Holding` conversion rate field. It wasn't being used
and required knowing what the account currency is.
- Adding equality operators for `CashAmount`. Adding unit tests.
- Removing `AccountCurrency` from `Cash` and `Brokerage` classes.
`ICurrencyConverter` will now provide the `AccountCurrency`
- Adding new static `OrderFee.Zero` which will return a 0 order fee in
`NullCurrency`
- Adding static `Currencies.USD` value, replacing all "USD".
- Addin new static `Currencies.NullCurrency`
- Updating Bitfinex `FeeModel` so it return fees in quote currency.
Adding unit tests
- Replacing `decimal` for `OrderFee` at the `OrderEvent`.
- Adding `FeeModelNotUsingAccountCurrency` regression test
- Adding unit tests for `CashBuyingPowerModel` and `SecurityMarginModel`
with non account currency fees
- 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.
- Refactoring `IFeeModel`. *This is a breaking change* for implementations
inheriting directly from the interface. Deleting old and adding a new method
`OrderFee GetOrderFee(OrderFeeParameters parameters)` that will use a parameter
and a result object.
- Refactoring `CashAmount` so it does not embed a `ICurrencyConverter`
instance.
- Updating unit tests
- The `Security.QuoteCurrency`, a `Cash` instance, will provide access
to the `AccountCurrency` as a property.
- Will maintain backwards compatibility with old python custom
FeeModels, Adding unit test.
> Note that for now, consumers will ignore the currency, as before, and
directly consume the amount
- Modifying `IFillModel` interface removing old methods and adding new
method `Fill Fill(FillModelParameters)`. This is a breaking change.
- Adding new `PythonWrapper` property for the `FillModel` base class.
This is required due to a limitation in PythonNet:
- Given C# class T has `virtual` methods A and B. Where method A
calls method B. And given custom python class L inherits class T.
And overrides method B. When class L calls
base method A (of class T). And when method A internally calls method B.
It will call C# implementation, not the python override. This issue
is solved going back to the `PythonWrapper`. Adding unit tests.
- Adding new `Parameters` property for the `FillModel` base class that will
be set by the call to `Fill()`. The `Parameters` property will be used by
the modified `XxxxFill()` implementations
- Adding new `Fill` result object for the `Fill(FillModelParameters)`
method
- Adding new check before removing a `SubscriptionDataConfig` due to the FillModels consuming the configuration collection when determining which Price to use. WIll now only remove the `SDC` if the symbol was removed from the selecting `universe`, this will avoid the case where the symbol is never deselected and the subscription ends, which happens at the end of all executions.
- Adding unit tests showcasing retro compatibility.
- Enabling C# `CustomModelsAlgorithm` as a regression test. Python
version returns a different result due to random number generation.
We recently disabled dividend application in live mode because
it was more accurate to rely on the brokerage's daily cash sync
to pick up when the distribution was actually made. Before that
change we were applying dividends on the ex-date, and then it was
un-applied via the cash sync and then re-applied when the funds
finally hit the brokerage account. By making that change we failed
to ensure that dividends were still applied in live paper mode.
Dividends are detected via the PaperBrokerage's Scan method which
is called at least once every time loop. IAlgorithm.CurrenctSlice
is used to check for dividends and then the total distribution is
computed and applied directly to the portfolio's cash book.
For years IFillModel has been responsibile for computing an order's fee. The
standard way of doing this has always been via invocation of security.FeeModel,
but there was no mechanism preventing an implementation from directly
computing the fee. As such, this check was added to prevent overwriting an order
fee that has already been computed.
This change aims to reduce the responsibilities of IFillModel implementations
by removing the requirement that they also compute the order fee. Order fees
are now computed by whomever invokes the fill model, namely the BacktestingBrokerage.
- removed IAlgorithm dependency from time in force handlers
- renamed GoodTilCancelled to GoodTilCanceled
- added GTC time in force in regression algorithms
- inlined initialization of time in force handler dictionary
The HasSufficientBuyingPowerForOrder method has been updated to return a result object including the reason the order cannot be executed.
The SetHoldings method has also been updated to display a message if CalculateOrderQuantity returns zero.
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/
The option assignment could fail for insufficient margin and the order status could be set to Invalid, updated the check to use OrderStatus.IsClosed().
The option assignment simulator used in backtesting was firing assignment events multiple times before expiration, but the actual assignment was not being performed until the expiration date.
The message for short option order events at expiration was "Automatic option assignment on expiration" for both ITM and OTM. It has now been corrected to "Option expiration" for OTM short options.
The same message is now also being reported in QCAlgorithm.OnAssignmentOrderEvent instead of the generic "Option Assignment" message.
- Moved provider implementations out of brokerages into their own classes
- Removed DefaultOptionChainProvider
- Added BacktestingOptionChainProvider and LiveOptionChainProvider
- Moved SetOptionChainProvider call from Engine to setup handlers
1. Made sure we treat properly option expiration dates before Feb 2015 and after. Added tests.
2. Refactored expiration delisting, assignments/option exercise to happen in the end of the date, not MOC orders in the beginning of the day. Regression test.
3. Refactored option exercise model to generate proper fills on assignments/option. Those fills are reflected correctly in margins, in stats and correspond to IB model. Still need to run IB real-life live tests.
4. Refactored option symbol related functions into separate module (OptionSymbol.cs)
5. Made sure OnAssignmentEvent arrived to the user algo in regression test. Do we need OnExercise event? Not sure.
6. Tested end-to-end Ray's current code (covered call strat) to see short option legs expire worthless, and stats updated.
- 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.