Commit Graph

220 Commits

Author SHA1 Message Date
AlexCatarino 83d9d6d850 Fix Equity Fee Logic for AlphaStreamsFeeModel
Since cashbook receives a fee for a short equity positions, the fee is negative.
2019-07-25 17:06:15 +01:00
AlexCatarino 6b3993f4aa Improve Unsupported SecurityType Message 2019-07-10 22:55:33 +01:00
AlexCatarino aa85c7028e Remove LIBOR dependency
Borrowing costs will be modelled separately.
2019-07-10 21:46:46 +01:00
AlexCatarino 8a479e07c2 Refactors AlphaStreamsFeeModel
- Refactors and symplifies `AlphaStreamsFeeModel`.
- LIBOR is represented by `Security` since it can be updated
- Improve unit tests.
2019-07-10 17:01:33 +01:00
Jack Simonson 27f183fcd3 Create AlphaStreams Fee Model 2019-07-10 17:01:33 +01:00
Stefano Raggi 9d3c1df5f3 Fix execution models to handle partially filled orders 2019-05-24 11:50:31 +02:00
Stefano Raggi f113c60d68 IB FeeModel throws ArgumentException for unsupported security type 2019-05-21 23:38:44 +02:00
Stefano Raggi 12b3658622 Fix Invalid Currency exception in IB FeeModel 2019-05-21 18:41:46 +02:00
Martin Molinero 412eccebc9 Address reviews
- Revert charting rouding
- Add statistics rouding
- Json converter will ignore null order values
- Remove `type` field in `Symbol` json
- Add default type value for the `TimeInForceJsonConverter`
2019-04-30 11:45:07 -03:00
Martin Molinero b7930aff67 Performance improvements
- Using `Aggregate(lambda)` vs `Sum(lambda)` since the later is slower
due to performing an extra `Select`
- For `QCAlgorithm.Framework.OnFrameworkData()` will avoid calling
`ToArray()` on empty `Enumerables` due to its cost * the number of
calls. If the `Enumerable` is the empty instance, which is static,
will create a new empty array and return it instead.
- Replacing `SecurityIdentifier` `SecurityType` and `GetHashCode`
implementations for `Lazy` versions, that are performed just once, since
these values do not change and are used multiple times.
- For the different `DataDictionary<T>` implementations adding `this[
Symbol] get; set` since existing overload `this [string]` produces an
extra round operations `Symbol->string->Symbol` with a significant
impact.
- Adding `PortfolioTargetCollection.AddRange()` overload using an array
to avoid unnecessary convertions.
2019-04-11 19:01:27 -03:00
Jack Simonson 349ce68006 Merge branch 'master' of https://github.com/QuantConnect/Lean 2019-03-28 09:47:43 -07:00
Jack Simonson e4d9a176d0 Update FillModel.cs 2019-03-28 09:45:03 -07:00
Stefano Raggi f4f35913d8 Simplify GDAXFeeModel 2019-03-21 11:34:52 +01:00
Stefano Raggi 3cbc4a227a Update GDAXFeeModel to new fee structure 2019-03-18 14:33:49 +01:00
Stefano Raggi a616bdbea2 Add StalePriceTimeSpan setting for market fill warnings
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).
2019-03-14 22:03:23 +01:00
Stefano Raggi 55b173995e Add warning message to market order fills on stale prices 2019-03-12 20:34:29 +01:00
Stefano Raggi 99d96d681a Update BrokerageTransactionHandler.AddOrder to wait for order to be processed 2019-02-18 23:28:28 +01:00
Martin Molinero 40ac9c5033 Fix IB FeeModel Option fees
- Fixing IB FeeModel options fees. Adding unit tests
- Updating regression algorithms
2019-01-02 15:50:00 -03:00
Martin Molinero 3717fe4651 IB FeeModel will be based on Market
- The `InteractiveBrokersFeeModel` will determine commissions based on
the `Market` of the security
2019-01-02 14:10:32 -03:00
Martin Molinero c9e6268cbd Remove OrderFeeParameters.AccountCurrency
- Removing OrderFeeParameters.AccountCurrency. Where required replacing
for constructor parameter defaulting to USD.
- Updating IB fee model to use to correct fee currency
2018-12-28 15:57:53 -03:00
Martin Molinero 0af7ba14f5 Address reviews
- `CashBook[NullCurrency] { get; }` will throw an exception
- Revert `Currencies.USD` changes in user facing algorithms
- Improve some documentation
- Revert some format changes
- Adding more asserts for regression test
- Adding new regression tests using a custom fee model which returns
`OrderFee.Zero`
- Adding a non-usd account currency test to the cash book tests
- Adding some unit tests for `NullCurrency` and `OrderFee.Zero`
2018-12-14 12:38:55 -03:00
Martin Molinero 0933da9303 Refactor previous commits
- 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
2018-12-13 11:30:40 -03:00
Martin Molinero e85942f4f0 GDAX FeeModel will use QuoteCurrency
- GDAX FeeModel will now use QuoteCurrency as fee currency. Adding unit
test.
2018-12-10 14:59:55 -03:00
Martin Molinero b7bcdbef04 Adding OrderFee to OrderEvent
- Replacing `decimal` for `OrderFee` at the `OrderEvent`.
- Adding `FeeModelNotUsingAccountCurrency` regression test
- Adding unit tests for `CashBuyingPowerModel` and `SecurityMarginModel`
with non account currency fees
2018-12-10 13:18:41 -03:00
Martin Molinero 75ffa300f1 Adding new IAlgorithm.AccountCurrency
- 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.
2018-12-10 11:59:02 -03:00
Martin Molinero c5daf9ac9a Refactor IFeeModel
- 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
2018-12-06 16:20:36 -03:00
Martin Molinero 46baedf858 Refactor FillModels
- 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.
2018-11-29 15:38:46 -03:00
Michael Handschuh 137730a214 Move fee computation outside of fill models
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.
2018-10-02 15:11:33 -04:00
Michael Handschuh 07f2158dc6 Extract ImmediateFillModel into new base FillModel class
The new FillModel class will serve as a base for all fill models.
This provides benefits in backwards compatibility by providing a common
place for 'shim' code. The ImmediateFillModel class remains but is now
empty as it's entire implementation has been moved to the new FillModel
class.
2018-10-02 15:11:33 -04:00
Stefano Raggi 7a7b0dcb2f Update fill models to not fill Limit/StopMarket/StopLimit orders on stale data 2018-09-28 00:17:21 +02:00
Adalyat Nazirov 0bce179a89 Requested changes: comments
- remove 0% from BitfinexFeeModel comments
- fix restore candles comment
- add comment to public methods
- change access modifiers of bitfinex specific  methods
- market price must be positive too
- comment number of requests limits
2018-08-27 22:01:06 +03:00
Adalyat Nazirov 15b41f1113 Manage orders 2018-08-27 21:59:15 +03:00
Stefano Raggi bba33ff63e Fix time zone bug in BacktestingResultHandler
Also replaced usages of DateTime.Now with DateTime.UtcNow in all result handlers.
2018-08-20 12:07:00 +02:00
Martin Molinero c73b7bb62f Adding smarter methods for PortfolioTargetCollection 2018-07-27 10:48:55 -03:00
Martin Molinero f26145539c Fix exception throwing at OrderTicket.InvalidUpdateOrderId 2018-07-11 11:50:39 -03:00
Stefano Raggi ce51fcb08a Remove unnecessary binding flags in TimeInForceJsonConverter 2018-05-30 18:45:38 +02:00
Stefano Raggi 8613deb3ef Minor refactor
- Added TimeInForce.GoodTilDate static method
- Made GoodTilDateTimeInForce.Expiry readonly
2018-05-30 18:25:52 +02:00
Stefano Raggi 7a76b07174 Post review updates
- removed TimeInForceType enum
- updated comments in InteractiveBrokersBrokerage.ParseExpiryDateTime
- removed equality methods and operators from TimeInForce class
- fixed TimeInForce JSON serialization/deserialization with custom converter
2018-05-30 10:00:13 +02:00
Stefano Raggi bbf3e32e70 Fix IB issues with GTD orders 2018-05-30 10:00:12 +02:00
Stefano Raggi 59ee1d219a Remove Order.DurationValue property
This property has been moved to GoodTilDateTimeInForce.Expiry
2018-05-30 10:00:11 +02:00
Stefano Raggi 9116531e1d Add Good Til Date (GTD) time in force 2018-05-30 10:00:11 +02:00
Stefano Raggi 4406332046 Make TimeInForce class abstract 2018-05-30 10:00:11 +02:00
Stefano Raggi 9ae346b251 Refactor TimeInForce enum to class 2018-05-30 10:00:10 +02:00
Stefano Raggi 5d0aa431ed Update fee percentages in GDAXFeeModel
The GDAX fee model has been updated to the new GDAX fee structure:
https://www.gdax.com/fees
2018-05-28 10:07:03 +02:00
Michael d878857e50 Merge pull request #1938 from StefanoRaggi/feature-1093-ib-time-in-force-day
Add TimeInForce.Day support in backtesting and IB brokerage
2018-05-03 14:33:40 -04:00
Stefano Raggi 62e1c2e32c Update DayTimeInForceHandler to use GetNextMarketClose 2018-05-02 22:37:57 +02:00
Stefano Raggi a85ebe42d5 Rename HasOrderExpired to IsOrderExpired 2018-05-02 21:00:56 +02:00
Michael Handschuh c25afbad29 Add fill/update/cancel times to order object
LastFillTime is updated on each partial/fill order event
LastUpdateTime is updated on each submitted order event w/ update count > 0
CancelTime is updated on canceled order events

Also fixes bug in regression algorithm where it used Time instead of UtcTime
for creating the SubmitOrderRequest object.
2018-05-02 14:16:33 -04:00
Stefano Raggi bfe5a8b005 Fix time zone bug with Forex orders in DayTimeInForceHandler 2018-05-01 23:53:18 +02:00
Stefano Raggi 2d19ab7ead Review TimeInForce handler interface
- 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
2018-05-01 20:53:43 +02:00