Commit Graph

201 Commits

Author SHA1 Message Date
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 1b0bdd9b0b Adding SetAccountCurrency for backtesting
- Adding new `SetAccountCurrency()` for backtesting. Has to be called
before adding any `Security` or calling `SetCash()`, else will throw.
- Adding new Non account currency unit tests for `CashBuyingPower`,
`SecurityPortfolioModel`, `SecurityMarginModel`,
`SecurityPortfolioManager`, `Future/OptionMarginBuyingPowerModels`
- Adding new C# regression test using `SetAccountCurrency()`, one for
`CashBuyingPowerModel` and one for `SecurityMarginModel`
- Adding new Py and C# basic regression algorithms using
`SetAccountCurrency()`
- `Options` and `Futures` will use not use `AccountCurrency` as quote
Cash.
- `SecurityBenchmark` value will be in account currency
2019-01-25 14:54:43 -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 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 9a2bc5c33e Fix undeterministic conversion rates
- `BaseSetupHandler.SetupCurrencyConversions` will order configurations
based on their type, selecting (`Trade` over `Quote`) and just perform
one history request per security.
2018-12-24 17:03:02 -03:00
Martin Molinero 65ea963a26 Using new HistoryRequestFactory
- BaseSetupHandler will use new `HistoryRequestProvider` class
2018-12-19 16:15:29 -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 3638f19ba5 Fix incorrect symbol market used when loading holdings/open orders from brokerage 2018-11-09 16:55:55 +01:00
Martin Molinero 4d7dfe1c89 Initialize algorithm faster
- ISetupHandler implementations will now use 50ms as sleep interval
while initializing the algorithm
- If the sleep interval is >= to 1s (default value) it will divide the
sleep operations into 5
2018-10-31 18:05:12 -03:00
Stefano Raggi d7160852f9 Fix ConsoleSetupHandler overwriting Job.BacktestId 2018-09-28 10:13:43 +02:00
Stefano Raggi 654f315480 Fix PostInitialize called too early in BrokerageSetupHandler.Setup 2018-09-17 18:43:54 +02:00
Stefano Raggi b638898948 Optimize loops over holdings and open orders 2018-08-29 15:15:29 +02:00
Stefano Raggi 73be28ed39 Fix BrokerageSetupHandler error when loading option/equity holdings/orders 2018-08-29 11:40:39 +02:00
Stefano Raggi 7c9b40ded4 Update BrokerageSetupHandler to call AddSecurity for open orders 2018-08-28 17:27:30 +02:00
Jared 1f080436a4 Increase time to handle loading edge cases. 2018-08-09 10:01:16 -04: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
Martin Molinero f38431446d Fixing null pointer exception at brokeragetransactionhelper 2018-06-27 18:10:04 -03:00
Michael 8c763ee314 Merge pull request #2112 from StefanoRaggi/feature-2103-gdax-paper-trading
Add live brokerage DataQueueHandler support to PaperBrokerage
2018-06-22 16:53:48 -04:00
Stefano Raggi 25c7c61099 Post review fixes
- Added class attribute to BrokerageFactoryAttribute
- Extracted PreloadDataQueueHandler method in BrokerageSetupHandler
- Added BrokerageFactory attribute to IB, Oanda, FXCM brokerages
2018-06-22 21:43:55 +02:00
Martin Molinero 82c2532a31 Improve performance for backtests with a large amount of trades 2018-06-21 16:59:29 -03:00
Stefano Raggi 90f00351c2 Add live brokerage DataQueueHandler support to PaperBrokerage 2018-06-20 14:54:06 +02: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 5ba44ed5ab Remove universe symbols from history requests
The engine defines securities for each universe to properly track them within
the data feed. These securities are not tradable and have no price data associated
with them, and as such, we should not be sending history requests for these symbols.
This change removes all universe symbols from history requests.
NOTE: Requests made directly to the history provider are not filtered out, as the
filtering happens within the QCAlgorithm implementation.
2018-03-05 14:18:33 -05: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
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
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
Andrew a035c05510 Send Initializing status packet in BacktestingSetupHandler 2017-11-02 15:01:29 -04:00
Michael Handschuh d92f161f8c Update max run time to check for universes
The max run time calculation wasn't considering whether or not the user had
any universe subscriptions
2017-10-20 09:27:13 -04:00
Michael Handschuh 7c0a0c4698 Set algorithm name in setup handler
When using the console setup handler, the algorithm's type name
will be used as an identifier.
2017-10-06 16:23:38 -04:00
Michael Handschuh ecd92462da Clean white space 2017-10-06 16:23:37 -04:00
Jared 72b66501eb Merge pull request #1131 from QuantConnect/crypto-security
Crypto security
2017-09-14 10:48:31 -04:00
jameschch@outlook.com ca4cd13476 Merge branch 'master' of https://github.com/QuantConnect/Lean 2017-08-29 11:11:04 +01:00
Andrew 8baf058dc3 Refactored BrokerageSetupHandler.GetOpenOrders into smaller, testable method 2017-08-28 16:27:19 -04:00
Andrew a19dd2ab45 Add message to result handler if open order is detected 2017-08-28 14:19:38 -04: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
Andrew 245a2e1580 Added Linq extension method to find the algorithm name
This extension method is meant to standardize the finding of the class to run between the Brokerage and Backtesting setup handlers
2017-08-24 12:18:26 -04:00
12112 921ec8f983 merge from upstream 2017-08-22 16:56:35 +01: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
Andrew 834d0ae802 Add stackTrace when Exceptions are thrown Initialize() 2017-07-24 13:05:52 -04:00
12112 83fdf9c386 crypto wip 2017-07-14 16:53:42 +01:00
Andrew acb56cb985 Fix comment 2017-06-28 11:01:32 -04:00
Andrew 416c79de04 Let Lean set start/end date during backtesting
Lean will not set the start and end date in the BacktestingSetupHandler.
The start and end dates are specified in the user code in
IAlgorithm.Initialize.
2017-06-28 11:01:01 -04:00
Stefano Raggi 9139ca7c40 Merge master into issue-330/decimal-quantity 2017-06-19 23:50:26 +02:00
Stefano Raggi 6f3d7f011c Fix default algorithm DataSubscriptionLimit for IB brokerage
In BrokerageSetupHandler.Setup, the default value for the algorithm Settings.DataSubscriptionLimit is set to 100 only when using IB as a DataQueueHandler.
2017-06-16 20:52:01 +02:00
Stefano Raggi eb8bbcb027 Move default IB subscription limit to BrokerageSetupHandler 2017-05-24 00:24:44 +02:00
Stefano Raggi 5c4bd9a684 Add new methods to IAlgorithm for Python usage 2017-05-19 20:50:57 +02:00
Stefano Raggi 2fb4847b41 Handle subscriptions for existing brokerage Option holdings 2017-05-19 15:50:45 +02:00