Commit Graph

93 Commits

Author SHA1 Message Date
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
Martin Molinero 2c2612aa71 Addressing reviews
- SecurityManager will no longer inherit ISecurityService
- Rebase from master
2018-10-18 16:45:16 -03:00
Martin Molinero a288648929 Creating new ISecurityService
- Adding new ISecurityService and its implementation SecurityService.
Expose by SecurityManager.
This class will expose a method for creating new securities. The
SecurityManager is exposing this new interface, calling _securityService
internally, so Future/OptionUniverseSelectionModel.cs can use it
- Replacing all usages of SecurityManager.CreateSecurity for new
ISecurityService
- Modifying `Cash.cs` and `CashBook.cs` `EnsureCurrencyDataFeeds()` to
return newly added `SubscriptionDataConfig` instead of `Security`. This
will avoid using `Security.Subscriptions` at call site.
- Moving old SecurityManager.CreateSecurity into new
SecurityServiceTests.cs
2018-10-18 16:25:32 -03:00
Michael Handschuh 20133d40d1 Add ICurrencyConverter to Security constructors
Security instances will require private access to this value in order to
compute close profit.

NOTE: The extent of these changes for simply adding a constructor argument
insinuates that we're missing an abstraction to manage the construction of
these objects, such as a factor object for Security. This will need some
careful TLC in the near future.
2018-10-10 11:17:12 -04:00
Martin Molinero 2e8707fbff Refactor ITimeKeeper
Addressing reviews, expanding ITimeKeeper, and making SecurityManager
use the new interface.
2018-10-01 13:52:41 -03:00
Martin Molinero d6f958b94a Rename to I...Service - Merge Create and Add 2018-09-28 14:48:21 -03:00
Martin Molinero 9d5351152d Adding new ISubscriptionDataConfigBuilder
- Adding new ISubscriptionDataConfigBuilder implemented by DataManager, exposed by
SubscriptionManager
- SecurityManager and SubscriptionManager will use new interface.
In a next PR, its intended for it to also be consumed by Universe.GetSubscriptionRequests().
- Moving LookupSubscriptionConfigDataTypes implementation into
DataManager
2018-09-27 18:09:08 -03:00
Stefano Raggi c6693cb237 Disable automatic security seeding
In this PR we are disabling the default security seeding (automatically getting the last price for a security when added to the algorithm) for a couple reasons, both when using large universes:
- In live trading, these history requests are sent to a history server, potentially causing timeouts
- In backtesting, depending on the algorithm this could also cause slowdowns up to 30%
2017-12-22 21:49:14 +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
jameschch@outlook.com ca4cd13476 Merge branch 'master' of https://github.com/QuantConnect/Lean 2017-08-29 11:11:04 +01:00
Stefano Raggi 492bc70229 Fix Options and Futures subscriptions at Tick resolution
Previously Tick resolution subscriptions only received ticks with TickType.Trade, now TickType.Quote and TickType.OpenInterest are received as well.

This PR replaces PR #1065
2017-08-22 02:20:36 +02:00
12112 83fdf9c386 crypto wip 2017-07-14 16:53:42 +01:00
Stefano Raggi a62fab742c Fix SetBrokerageModel when called after AddSecurity and friends
Currently, calling SetBrokerageModel after AddSecurity, AddForex, etc. has no effect, the security initializer has already been initialized and its models have been set to their default implementations.

For example, Forex backtests using OandaBrokerageModel will report fees calculated with the default fee model (Oanda fees are spread-based, so they should always be reported as zero).

In this PR, SetBrokerageModel now calls SecurityInitializer.Initialize on all securities added before SetBrokerageModel is called.

Fees will be calculated using the correct fee models and the order of the calls in algorithm Initialize is now irrelevant.
2017-04-07 15:40:24 +02:00
Andrew Hart e035ed7d37 Remove SecurityManager.GetDataFeedType() method 2017-01-12 15:56:28 -05:00
Andrew Hart 709d5aef2c Lookup types in SecurityManager.CreateSecurity() when none provided 2017-01-12 15:56:00 -05:00
Andrew Hart 2523750704 SecurityManager adds Forex with Subscription type of QuoteBar 2017-01-12 14:58:42 -05:00
Andrew Hart d3d5baf3ad Changed signerature of SecurityManager.CreateSecurity() 2017-01-12 14:55:06 -05:00
Andrew Hart b49319bfdb Added IsCommonLeanDataType
This method is helpful in determining if a Type is a common data type, which are TradeBar, QuoteBar and OpenInterest.
2017-01-06 12:09:15 -05:00
quant1729 145ba7bd83 Updated code as per PR 2017-01-02 19:47:23 +01:00
quant1729 334ea4bdeb Removed duplicate derivative subscription in SecurityManager. Test. 2016-12-27 16:57:39 +01:00
quant1729 586c2b4006 Fixing issue with invalid data in portfolio holdings for futures 2016-12-09 14:40:53 +01:00
quant1729 92a3be5ea5 Merge branch 'futures-quotebar-easy' into futures
Conflicts:
	Common/Securities/SecurityManager.cs
2016-11-28 14:46:46 +01:00
quant1729 55299e60fb Added new constructors to IBMapper class
Added support for history requirements, exposed by vol models. AM processes requirements.
Added new volatility model - standard deviation of returns - default vol model. Compared its results with publicly available.
Refactored option pricing engine to support optimal approximation calculations.
Added basic greeks approximation in case they are not available in QL. Tests.
Updated BasicTemplateOptionHistoryAlgorithm to print greeks.
2016-11-25 15:11:01 +01:00
Andrew Hart c71a55f7a9 AvailableDataTypes is now part of SubscriptionManager 2016-11-23 13:42:55 -05:00
Andrew Hart ed3603e344 Fixed bug where custom BaseData types were not added to subscriptions 2016-11-21 10:11:42 -05:00
Andrew Hart 81fe2a94cb Data formats (Trade/Quote) are configurable for each security 2016-11-18 15:30:54 -05:00
quant1729 1141cd21e6 Merge branch 'futures' into master
Conflicts:
	Algorithm.CSharp/QuantConnect.Algorithm.CSharp.csproj
	Algorithm/QCAlgorithm.cs
	Brokerages/InteractiveBrokers/InteractiveBrokersBrokerage.cs
	Common/QuantConnect.csproj
	Common/Securities/Option/Option.cs
	Data/equity/usa/factor_files/aapl.csv
	Data/symbol-properties/symbol-properties-database.csv
	Engine/DataFeeds/Enumerators/Factories/BaseDataSubscriptionEnumeratorFactory.cs
	Engine/DataFeeds/Enumerators/Factories/OptionChainUniverseSubscriptionEnumeratorFactory.cs
	Engine/DataFeeds/SubscriptionDataReader.cs
	ToolBox/QuantConnect.ToolBox.csproj
2016-11-07 16:18:11 +01:00
quant1729 5803115548 Option splits and renames in backtesting. Added regression tests. 2016-10-26 21:20:03 +02:00
quant1729 cee38707db Added support for futures expiration dates in IQFeed/IB, that makes possible the delivery of options/futures calendars and continuous contracts
Added futures market hours with help of Deval. This needs more tests in the future.
Added several futures exchanges. Some groundwork for future use of exchanges in the future symbols.
Removed IQFeed futures symbols map. Map is now generated and saved automatically, effectively removing the issue of IQFeed arbitrary renaming futures symbols
Changed IQFeed universe file downloading intervals from daily to weekly.
2016-10-07 19:10:53 +02:00
quant1729 dd72878d2c Implementing futures support. Future, FutureCache, Futures Chain, Futures Universe classes and more 2016-09-26 13:56:02 +02:00
AlexCatarino 82d81108ad Implements price variation models
Implements IPriceVariationModel interface which takes the security object and returns a decimal variation
Implemets SecurityVariationModel class: default implementation of IPriceVariationModel that returns a fixed value (read from symbol-properties-database) for decimal variation
Implemets EquityVariationModel class: implementaion of IPriceVariationModel that returns a decimal variation as a function of equity price
Implemets AdjustedPriceVariationModel class: implementaion of IPriceVariationModel that returns zero
Adds unit test
2016-09-20 15:36:04 -03:00
quant1729 2dce74e26d - Extended Option security and Option holding classes
- 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.
2016-08-31 18:00:00 +02:00
Stefano Raggi c5333f4e6f Fixed compile error in SecurityManager.CreateSecurity 2016-05-11 17:31:33 +02:00
Michael Handschuh c1c3ff252b Merge branch 'multi-subscriptions' into options-new 2016-04-20 12:14:42 -04:00
Michael Handschuh e933306ed1 Allow constructing Security without subscription config 2016-04-14 17:28:54 -04:00
Michael Handschuh 93357094c9 Reshuffle method in preparation for changes 2016-04-13 21:53:55 -04:00
Michael Handschuh ce7fef5cce SecurityManager.CreateSecurity supports option securities 2016-04-07 14:18:05 -04:00
Michael Handschuh 9cf86614cd Properly set option subscription data type/tick type 2016-04-07 06:46:23 -04:00
Michael Handschuh cc25950e10 Adds SubscriptionDataConfig.IsFilteredSubscription
Subscriptions can now be explicit as to whether or not a SubscriptionFilterEnumerator is to be applied.
Regular security price data subscriptions get filtered (user/market-hours)
Universe subscriptions don't get filtered (even if a subscription of equity price data, such as options underlying feeds)
2016-04-05 15:51:45 -04:00
Michael Handschuh 262900a5dd Fixes bug in forex symbol properties quote currency 2016-03-02 23:27:12 -05:00
Michael Handschuh 38248d641e Adds symbol properties to Security ctor 2016-02-16 13:26:02 -05:00
Michael Handschuh 0042586b6a Adds quote currency to Security ctor 2016-02-16 13:26:00 -05:00
Stefano Raggi f7f4e961e4 Update SecurityManager.CreateSecurity overload to take a SymbolProperties argument 2016-02-01 23:33:55 +01:00
Stefano Raggi 932b757a1b Remove Cfd.GetQuoteCurrency(Symbol) 2016-01-24 16:29:52 +01:00
Stefano Raggi 93b2d50a4e Adds SymbolProperties argument to Cfd constructor 2016-01-24 16:02:45 +01:00
Stefano Raggi f28c02ff87 Gets symbol properties in SecurityManager.CreateSecurity 2016-01-23 00:30:05 +01:00
Stefano Raggi 6a381a990e Adds SymbolPropertiesDatabase argument to SecurityManager.CreateSecurity 2016-01-23 00:03:50 +01:00
Stefano Raggi b18042c4a4 Adds CFD support to SecurityManager.CreateSecurity 2016-01-20 21:57:38 +01:00
Michael Handschuh 96a5e76729 Adds IBrokerageModel.GetLeverage(Security)
Also removes leverage as Security ctor parameter
2016-01-19 14:20:23 -05:00
Michael Handschuh 7fb2073fab Invoke ISecurityInitializer in Security.CreateSecurity
This removes the SetupHandler.UpdateModels(...) method which used the brokerage
model to set fill/fee/slippage/settlement models. This will also allow the
removal of flags indicating that the user has set certain Security properties
2016-01-19 13:13:00 -05:00