Commit Graph

128 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 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 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 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 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
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
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
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
Stefano Raggi 0fc2af8025 Handle existing brokerage holdings in Futures universe selection filters 2017-05-17 22:11:43 +02:00
Stefano Raggi dbdcc9b8b4 Fix NullReferenceException with Futures existing holdings 2017-05-16 15:17:50 +02:00
Stefano Raggi 374c8a1959 Fix SetOrderProcessor called too late
When using BrokerageHistoryProvider with InteractiveBrokers, GetOrderByBrokerageId calls on open orders were logging NullReferenceExceptions because SetOrderProcessor is called later, in BrokerageSetupHandler.Setup.
2017-04-14 23:43:36 +02:00
jaredbroad fe9a9cc44e Refactor TryCreateAlgorithmInstanceWithIsolator to take job and set ram limit 2017-02-17 09:34:34 -05:00
jaredbroad dc0aba38c6 Packet controls limit on live initialization instead of stock 1024mb 2017-02-16 18:16:07 -05:00
quant1729 c721a15af5 Merge branch 'futures'
Conflicts:
	Common/QuantConnect.csproj
2017-01-12 16:22:24 +08:00
Stefano Raggi 89357ef7aa Disable margin calls in live mode and refactor margin call models
This PR reverts and replaces PR #674 because it caused issue #678.
The margin call model has been refactored and now contains both methods for margin call order handling (generation and execution).

Disabling margin calls is now much simpler:
Portfolio.MarginCallModel = MarginCallModel.Null;

List of changes:
- Added a new IMarginCallModel interface
- Renamed MarginCallModel to DefaultMarginCallModel
- Refactored margin call models by moving the GenerateMarginCallOrder method from ISecurityMarginModel to IMarginCallModel
- Disabled margin calls by default for live trading in BrokerageSetupHandler initialization
2017-01-06 17:50:38 +01:00
Stefano Raggi a0dac817ef Revert commit cb8f451 2017-01-06 15:41:52 +01:00
Stefano Raggi adc50af3c8 Revert commit 517ba7d 2017-01-06 15:39:38 +01:00
Stefano Raggi 517ba7db90 Added IMarginCallModel interface
- Renamed MarginCallModel to DefaultMarginCallModel
- Private null implementation exposed as MarginCallModel.Null
2017-01-05 19:03:08 +01:00
Stefano Raggi cb8f451ebb Disable margin calls by default in live mode 2017-01-05 15:09:32 +01:00