Commit Graph

147 Commits

Author SHA1 Message Date
Martin Molinero 7f12cbb901 Addressing reviews 2019-05-15 18:56:08 -03:00
Martin Molinero f976ffa099 Removing BacktestingTransactionHandler thread
- For backtesting the algorithm thread will sequentially process pending
order requests
   - Adding new non blocking `BusyCollection`
- Updating `UpdateOrderRegressionAlgorithm` that suffered of a race
condition: it supposed `OnOrderEvent` would be called after the call to
`Transactions.AddOrder()` was finished
2019-05-10 16:15:24 -03:00
Martin Molinero cfa08a11fb Address reviews
- Removing `using QCAlgorithmFramework = QuantConnect.Algorithm.QCAlgorithm`
- Removing `QCAlgorithmFrameworkBridge`
- Removing `IsFrameworkAlgorithm`
- Making `EmitInsightBasedOnFill` private. Adding new
`IOrderEventProvider` exposing an `event` to which `QCAlgorithm` will
subscribe.
- `AccountType.Cash` algorithms will be allowed to manually trade and
emight insights manually or with alpha model.
2019-04-03 21:55:44 -03:00
Martin Molinero 5b04cfe202 Emiting Insights based on Fills
- Classic Algorithms will emight insights based on order fills.
   - To be able to update generated insights closed time, we will not
   clone emitted insights.
   - `InsightAnalysisContext` will update `AnalysisEndTimeUtc` when the
   Insight period is closed and the period is `EndOfTimeTimeSpan`
- Adding new regression algorithm asserting on the new emitted insights
- Adding unit tests
- `LiveTradingResultHandler` will store `AlphaRunTimeStatistics`
- Making `DefaultAlphaHandler.ProcessAsynchronousEvents` virtual to
facilitate cloud changes
2019-03-26 16:09:22 -03:00
Stefano Raggi 576e91f593 Append fill order event message to order tag 2019-03-12 20:34:30 +01:00
Stefano Raggi e14d520517 Update OandaBrokerage.GetCashBalance to include currencies for open positions 2019-02-21 11:19:48 +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 8e41371e19 Non-Usd brokerage support
- `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.
2018-12-27 12:13:43 -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 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
Stefano Raggi bd4c799d2b Rename parameter classes from Context to Parameters 2018-11-29 22:05:49 +01:00
Stefano Raggi 78f3b4b099 Refactor additional IBuyingPowerModel methods to use context objects 2018-11-27 22:50:15 +01:00
Stefano Raggi bd6485e1e1 Fix potential endless loop in BrokerageSetupHandler daily cash sync
- added tracking of failed cash sync attempts and throw if maximum reached
- added extra log traces in IB GetCashBalance and in BrokerageTransactionHandler
- added endless loop unit tests for both BrokerageTransactionHandler and InteractiveBrokersBrokerage
2018-11-02 14:45:38 +01:00
Martin Molinero f5d7ee5476 Fix so we perform cash sync only once 2018-09-17 16:09:41 -03:00
Stefano Raggi bcd4223405 Add additional logging of margin info for submit order requests 2018-09-12 20:48:21 +02:00
Stefano Raggi 74bc5d7689 Add logging of margin information in Live mode 2018-09-12 18:42:17 +02:00
Martin Molinero 8cd4d4d6e1 Adding lock for HandleOrderEvent 2018-07-23 09:28:40 -03:00
Martin Molinero 2c7a0b0510 Fix cancelled order status setting location 2018-07-12 14:08:21 -03:00
Martin Molinero f38431446d Fixing null pointer exception at brokeragetransactionhelper 2018-06-27 18:10:04 -03:00
Martin Molinero 82c2532a31 Improve performance for backtests with a large amount of trades 2018-06-21 16:59:29 -03: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 0310b2945a Fix GDAX fees for limit orders in backtesting
Fixes #1852
2018-04-13 20:57:21 +02:00
Stefano Raggi 11d4c0ea58 Prevent order status overwriting in BrokerageTransactionHandler.HandleSubmitOrderRequest
Fixes #1799
The order status should be set to Submitted only in PlaceOrder (for all brokerage implementations).
2018-03-28 18:45:10 +02:00
Stefano Raggi 4318c17974 Update buying power model interface for better messaging
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.
2018-02-27 11:24:15 +01:00
Stefano Raggi acb5db6cf5 Rename Security.MarginModel to BuyingPowerModel 2018-01-31 11:47:34 +01:00
Stefano Raggi c9542abc42 Rename ISecurityMarginModel.CanExecuteOrder to HasSufficientBuyingPowerForOrder 2018-01-31 11:47:33 +01:00
Stefano Raggi 66b265d890 Move GetSufficientCapitalForOrder to SecurityMarginModel.CanExecuteOrder 2018-01-31 11:47:33 +01: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
Stefano Raggi 1295c91551 Update order event messages for option expiration
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.
2017-12-05 00:49:41 +01:00
Andrew 7325b52e51 OrderTickets are initialized in BrokerageSetupHandler
- Created public property on ITransactionHandler that wraps the private OrderTicket dictionary. Allows BrokerageSetupHandler to add the order tickets

Refactored ToOrderTicket extension method to handle several types of order
2017-08-28 14:19:04 -04:00
Stefano Raggi 9139ca7c40 Merge master into issue-330/decimal-quantity 2017-06-19 23:50:26 +02:00
Stefano Raggi 4b59634a14 Fix time zone bug in cash sync
PR #861 didn't fix the issue properly, this one should do it
2017-04-24 16:08:58 +02:00
Stefano Raggi c78b9579bb Fix time zone bug in cash sync
With the update in the PR, cash synchronization in BrokerageTransactionHandler will now always be performed at 7:45 AM NewYork time, even if Lean is running in a different time zone.
2017-04-22 16:57:16 +02:00
quant1729 ab39c2da34 Added IsAssignment attribute to Order Event 2017-02-03 22:37:31 +08:00
quant1729 cb9dfcbd8d Picking the right event for propagation to user algo 2017-02-02 22:58:11 +08:00
quant1729 c416df6241 Refactored option assignment/exercise:
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.
2017-02-02 19:35:37 +08:00
Jared d5cc022867 Merge pull request #675 from QuantConnect/master
Merge with master
2017-01-05 12:12:40 -05:00
Stefano Raggi 23d7812804 Add new CancelPending order status
This new status is being added to solve the following problem with order cancellations:

Working orders (limit or stop) are usually cancelled by calling the OrderTicket.Cancel() method. This method is asynchronous in both backtesting and live, so reading the OrderStatus immediately after the Cancel call, can result in different values seen over different runs.

The solution introduces a new CancelPending value to the OrderStatus enum and guarantees that the order will have this status when the Cancel method returns (unless there was an error earlier, such as invalid order id). This status is meant to be temporary and will be overwritten/replaced by the Canceled value after the brokerage has completed the cancel operation.
2017-01-02 21:00:35 +01:00
quant1729 8af29aca3c Updated trade builder to support derivatives (multiplier > 1). Tests. 2016-11-28 15:16:15 +01:00
AlexCatarino 0b943c4223 Fixes OrderType cast in BrokerageTransationHandler.RoundOrderPrices 2016-09-28 19:17:26 -03:00
AlexCatarino ed70d85c5b Adds a function to round order prices
Adds a function to round order prices to the minimum price variation. This procedure is needed to meet brokerage precision requirements.
In backtest mode when price is adjusted, there is no rounding.
2016-09-20 15:36:45 -03:00
Jared 77e9001558 Merge pull request #541 from devalkeralia/tradier-orders-fix
Tradier orders fix
2016-08-24 18:05:04 -04:00
devalkeralia a28d687731 removed check for live mode 2016-08-24 16:59:14 -04:00
jameschch@outlook.com befbfc20ca merge latest upstream 2016-07-26 20:03:03 +01:00
Jared b4402a42b6 Merge pull request #483 from Phoenix1271/bugfix/LotRoundedToZero
Lot size rounding to zero causes Order to timeout
2016-07-13 10:50:23 -04:00
Petr Drastil 003e490ec2 HandleOrderEvent() should be called when quantity is zero 2016-07-13 02:44:34 +02:00
Jared 8fd733f7c1 Merge pull request #473 from devalkeralia/master
Updated the GetCashBalance to reflect the correct cash in the cashbook and Updated the PerformCashSync
2016-07-12 15:48:38 -04:00
devalkeralia 59bacc0662 Adds the currenies to the cashbook the user might have deposited 2016-07-12 15:31:07 -04:00
devalkeralia b983f44445 Revert "Adds the currenies to the cashbook the user might have deposited"
This reverts commit 7f05f1e51f.
2016-07-12 15:14:37 -04:00