Commit Graph

84 Commits

Author SHA1 Message Date
Martin Molinero ec1d410907 Performance improvements
- `SecurityIdentifier` will calculate `StrikePrice` just once. Replacing
`!=` for a direct call to `Equals()` preventing unnecessary checks.
- Slightly improving Linq queries at `OptionFilterUniverse`
- Replace `OpenReader().CopyTo` for `Extract(stream)` avoids copying the
data twice.
- Replace `DateTime.Now` for `DateTime.UtcNow`
2019-06-10 22:40:19 -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 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 79d35333de Merge pull request #2720 from Martin-Molinero/refactor-2717-ifeelmodels
Refactor IFeeModel
2018-12-06 18:09:34 -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 c40415401d Fix non account currency Option settlement
- Option settlement for non account currency will not apply conversion
rate. Adding unit test.
2018-12-06 10:45:33 -03:00
Jared 299b467062 Merge pull request #2733 from Martin-Molinero/refactor-2728-buyingpowermodel-getinitialmarginrequiredfororder
BuyingPowerModel.GetInitialMarginRequiredForOrder will receive a Parameters object
2018-12-04 14:50:58 -08:00
Martin Molinero 6bbc8a304e BuyingPowerModel.GetInitialMarginRequiredForOrder
- `BuyingPowerModel.GetInitialMarginRequiredForOrder` will now receive
the new `InitialMarginRequiredForOrderParameters` object containing an
`ICurrencyConverter` instance.
2018-12-04 17:50:00 -03:00
Martin Molinero 95af5f8877 SecurityHolding has a ref to an ICurrencyConverter
- `SecurityHolding` will now have a reference to a `ICurrencyConverter`
instance, provided as a constructor argument, called by the owning `Security`.
2018-12-04 17:06:56 -03:00
Martin Molinero 251071ee73 Remove Security from Subscription
- Removing unneeded `CashBook` instance to create a new `TimeSlice`
- Adding new `TimeSliceFactory`, an instance base class that will
provide methods to create a new `TimeSlice`. Will own the `DateTimeZone`
property.
- Adding new `ISecurityPrice` and `IOptionPrice` that will provide a
reduced interface for accessing price properties and methods used when
creating a new `TimeSlice`
2018-11-14 18:28:18 -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 78742e5df6 Adding cash buffer for IB Cash Accounts 2018-08-10 17:21:50 -03:00
Juan José D'Ambrosio 84e0074350 Adding a control to avoid set the last trading date in a holiday
Move delisting date estimation to the constructor

Using `MarketHoursDatabase` for option delisting date estimation instead USHolidays
Adding file header.
Regression algorithm added.

Use of  `ExchangeHours.IsDateOpen` instead  `ExchangeHours.IsDateOpen.Holidays`.
Extract values from `symbol.ID` into a local variable.


Improved Regression test
2018-07-24 16:04:33 -03:00
AlexCatarino 6d721c897a Implements CallsOnly and PutsOnly methods in OptionFilterUniverse
These two helper methods makes it simpler to select options with a specific right. This selection could be done with a Linq expression, but there is no equivalent for python. It is more user friendly to add those helper than adding a `PyObject` overload to `Contracts` method.

Use `PutsOnly` method in `BasicTemplateOptionsFrameworkAlgorithm`.
2018-07-05 20:59:08 +01:00
Michael Handschuh 1c2fd66027 Add OnlyApplyFilterAtMarketOpen to option/future filters
Sometimes we want to make decisions based on strike prices but still only
want the filter to be executed at market open and run once per day. Without
this change there was no way to force this behavior. Also, using this
method can greatly improve system performance by not running the contract
filter on every time step.
2018-05-07 15:52:31 -04:00
Michael Handschuh 47dd6fae1e Add OptionFilterUniverse.SetFilter overload for only expirations
Without this helpers users would need to call .
We provide a helper for strikes only but not expirations only. This change adds the
missing helper. A similar method is also available for futures.
2018-05-07 15:52:30 -04:00
Michael Handschuh 195231b9e0 Add Contracts function to OptionFilterUniverse
OptionFilterUniverse was lacking a means of explicitly setting the set of
contract symbols to be selected, which means algorithms had to use the
various helper methods but were unable to define their own selection function
for the contract universe. This change adds two methods, one to epxlicitly
set the contracts to be selected and another that mirrors the way universe
selection works, by providing a function that accepts the full set of contract
symbols and returns the filtered set of contract symbols. This enables LINQ
filtering of the contract universe.
2018-05-07 15:52:30 -04:00
Michael Handschuh 38ec70d087 Add Option.IsOptionChain and Option.IsOptionContract flags
These flags allow algorithms to test an option security object to see if it
represents an actual options contract or the entire option chain.
2018-05-07 15:52:29 -04:00
Stefano Raggi 4784f9b206 Remove unnecessary check in OptionFilterUniverse.Strikes
According to the MSDN documentation for Array.BinarySearch, the value of our index variable after taking the bitwise complement should be between zero and count-1.
2018-04-18 23:09:48 +02:00
Stefano Raggi cfa5a290a6 Fix ArgumentOutOfRangeException in Option strike filtering
Fixes #1875
2018-04-18 23:09:47 +02:00
Michael Handschuh 5ef9401fda Remove unnecessary cast, use abstraction
The interface properly declares the required properties, so no
need to down cast to the concretion.
2018-03-19 12:40:54 -04:00
Michael Handschuh 1c9671f495 Add IDerivativeSecurity and implement in Option/Future
Provides an abstraction for securities w/ an underlying security.
This is intended to pair with IDerivativeSecurityFilter.

This enables othe code to not need to bind and look for specific
security types in order to access the Underlying property.
2018-03-19 12:40:54 -04:00
Michael Handschuh f08184c0ae Revert class name changes from #1506
This caused several user algorithms to break. Also, its still correct to
call these margin models.
2018-02-04 14:20:38 -05:00
Michael 99327d106c Merge pull request #1506 from QuantConnect/refactor-margin-models
Refactor margin model interface
2018-02-02 11:31:00 -05:00
Stefano Raggi 5b5a56102b Remove IBuyingPowerModel.GetMarginRemaining, add GetBuyingPower
The GetMarginRemaining method in SecurityMarginBuyingPowerModel class is made protected as it can still be overridden in derived classes.
2018-01-31 11:47:35 +01:00
Stefano Raggi c6fd9bb904 Remove IBuyingPowerModel.GetMaintenanceMargin, add GetReservedBuyingPowerForPosition
The GetMaintenanceMargin method in SecurityMarginBuyingPowerModel class is made protected as it can still be overridden in derived classes.
2018-01-31 11:47:35 +01:00
Stefano Raggi baced83ac4 Rename interface ISecurityMarginModel to IBuyingPowerModel
Also renamed all existing margin models to buying power models:
- SecurityMarginModel -> SecurityMarginBuyingPowerModel
- FutureMarginModel -> FutureMarginBuyingPowerModel
- OptionMarginModel -> OptionMarginBuyingPowerModel
2018-01-31 11:47:34 +01:00
Stefano Raggi 2952e30f15 Remove GetInitialMarginRequiredForOrder and GetInitialMarginRequirement from ISecurityMarginModel interface
GetInitialMarginRequiredForOrder and GetInitialMarginRequirement methods in the SecurityMarginModel class are made protected as they can still be overridden in derived classes.
2018-01-31 11:47:33 +01:00
Stefano Raggi e01d0ff670 Derive all margin models from SecurityMarginModel
This is a preliminary step before adding new methods to the ISecurityMarginModel interface and the SecurityMarginModel class.
2018-01-31 11:47:32 +01:00
Michael Handschuh e712c75b23 Remove unused option split code
This code was an attempt at modeling option splits. The reality of the situation
is far more complicated and requires an external data source to be properly modeled.
Some things to consider are handling a split event before all the contracts from the
previous split event have expired.

With respect to the holdings, I think a more generic method to rewrite the holdings
would be beneficial when we have the data, but it isn't as simple as applying a split
factor. During splits and other corporate events, the OCC will rewrite the options
conract such that you are 'made whole'. Sometimes this involves adjusting the contract
multiplier away from the default 100 (or 10 for minis). Another fairly common case
(especially with M&A's) is to have part of the contract paid out in cash. So it's
possible for pretty much every value in the contract/holdings to change:

	1. Multipler
	2. Strike Price
	3. Number of contracts held
	4. Cash payout in leiu of fractional stock
	5. Constant cash payout
2018-01-23 15:04:58 -05:00
Stefano Raggi 32350739aa Fix short option margin calculation
The OptionMarginModel.GetMaintenanceMargin method was returning very large margin requirements for short options held until near expiration, causing "Insufficient funds" errors.
2017-12-08 22:34:35 +01:00
AlexCatarino d2e352cf58 Extends Option.SetFilter with an overload that accepts PyObject
This feature enables users to write complex filters for option universes.
Fixes OptionExerciseAssignRegressionAlgorithm
Adds regression test for OptionExerciseAssignRegressionAlgorithm
2017-10-06 16:55:18 +01:00
Stefano Raggi 9c1af722d2 Fix bug in Update Option.GetExerciseQuantity
Previously this method was returning the number of option contracts instead of the underlying shares
2017-08-30 16:57:50 +02:00
Stefano Raggi a0653820e4 Fix quantity bug in option exercise/assignment
When assigning shares of the underlying equity for an option at expiration, the equity quantity was incorrectly set equal to the option quantity. Now this quantity is multiplied by option.ContractUnitOfTrade (usually 100 for US options).

This bug was hidden by the option assignment tests in SecurityPortfolioManagerTests, which have also been corrected.
The regression stats for OptionExerciseAssignRegressionAlgorithm have also been updated.

In some cases this bug was also causing division by zero exceptions in OnOrderEvent, which seem to be fixed with this PR.
2017-08-30 14:25:02 +02:00
Stefano Raggi f934322dbc Fix indentation in QLOptionPriceModel 2017-08-23 22:45:36 +02:00
Stefano Raggi 79a85537f5 EnableGreekApproximation is now enabled by default on QL option price models
This bool property has been moved to the QLOptionPriceModel class and
the same property in the Option class has been obsoleted.
2017-08-23 22:41:06 +02: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
Stefano Raggi 1ae5141c61 Add EmptyOptionChainProvider class
used for back-end operations
2017-08-02 22:43:13 +02:00
Stefano Raggi aa1611d55a Add IOptionChainProvider interface with base implementations
- DefaultOptionChainProvider: provider that only throws an exception
- CachingOptionChainProvider: implements caching by date
2017-08-02 22:43:11 +02:00
Jared b10222a83c Merge pull request #990 from andrewhart098/data-norm-options
DataNormalizationMode or options must be Raw
2017-06-27 20:16:20 -04:00
Andrew 5442b23b04 Add Equity.SetDataNormalizationMode override 2017-06-26 17:14:35 -04:00
Andrew 83e0ea1518 Make SetDataNormalization mode a virtual method
Option class now overwrites the Security.SetDataNormalizationMode and checks for the proper DataNormalizationMode
2017-06-26 13:52:19 -04:00
Andrew 646aca7f92 Throw if any other DataNormalization mode other than Raw is used with Options 2017-06-26 10:15:29 -04:00
Stefano Raggi 6bfea3d216 Post merge fixes
- Update quantity to decimal in OptionExerciseOrder
- Update FractionalQuantityRegressionAlgorithm to use QuoteBarConsolidator
- Update FractionalQuantityRegressionAlgorithm stats
- Truncate order quantity to int in IB exerciseOptions
- Truncate order quantity to int in FuzzyInferenceAlgorithm
2017-06-20 01:00:36 +02:00
Anshul ac2f20de70 Fixes three warnings with code CS0168 2017-06-12 17:59:24 +05:30
Stefano Raggi 9e9e246f38 Fix bug in option filtering by range of strikes
The previous code was not taking into account varying distance between strike prices.
2017-05-23 22:37:53 +02:00
Anshul e7a3a2f3bd Fixes 5 warnings with code CS1574 2017-05-18 17:05:09 +05:30
AnshulYADAV, Computer Artist (CoArsey) 350e58567f Fixes 18 warnings with code CS1572 (#908)
* Fixes 5 warnings with code CD1572

* Adds the Xml Comment parameter and implements the missing selector parameter

* Fixes rest of the 13 warnings with code CS1572
2017-05-12 09:28:46 -04:00