Commit Graph

125 Commits

Author SHA1 Message Date
Alexandre Catarino dd8dc473b3 Improve Error Message For Arithmetic Overflow In Decimal Cast of Double (#4728)
* SafeDecimalCast Throws Exception For Non-Finite Numbers

* Fixes Arithmetic Overflow Exception in QCAlgorithm.Trading Methods

Replace decimal cast for `SafeDecimalCast()`.

If the algorithm uses a non-finite number in QCAlgorithm trading methods, it will throw with an user-frieldly exception message.

* Fixes KellyCriterionProbabilityValue Calculation
2020-09-18 09:17:09 -03:00
Martin Molinero 49abcd08b3 Normalize and improve Zero security price message 2020-05-13 21:19:37 -03:00
Martin Molinero 2812ad6f8e Address reviews. Improvement
- Improve mechanism to fetch open orders quantity, based on method used
by the `ImmediateExecutionModel`
- Adding unit test
2019-11-06 12:14:10 -03:00
Martin Molinero 9b507bbf34 Fix SetHoldings OnMarketOpen orders
- `SetHoldings` will take `OnMarketOpen` ordes into account when
determining order quantity
- Adding new regression test. Updating existing algorithms which
suffered of the issue
- Adding a performance improvement, will avoid margin and portfolio
calculations for MarketOnOpen orders that wont be able to fill
2019-11-05 21:05:49 -03:00
Martin Molinero 2f9814f2f9 Add SetHoldings for collection of targets
- Adding `SetHoldings` implemenetation for a collection of portfolio
targets
- Adding regression test
- Some performance improvements
2019-11-05 13:47:42 -03:00
Michael Handschuh d8db9f9fce Update Algorithm to respect CA1304 and CA1305
Updates all occurrences of parsing/ToString-ing to go through the new
StringExtensions methods that use CultureInfo.InvariantCulture

See #3045
2019-09-12 15:30:44 -04:00
Martin Molinero c39638668c Overall performance improvements
- `FactorFile` will keep an ordered reversed list with the dates.
Calling `Reverse()` on the `SortedList` is expensive.
- `MapFiles` will keep first and last date, so we don't need to call
`First()` and `Last()` multiple times.
- `Liquidate` will go through all the algorithms securities only if
necessary
- `TradeBar` parsing will not call `new T` for pure `TradeBar` which is
expensive
- Removing `Lazy` hash code and security type for the
`SecurityIdentifier`, replacing for direct initialization. Accessing the
`Lazy` value adds an overhead.
- Replacing `Enum` to string for hardcoded switch statement. `Enum.ToString` is expensive.
- `DataManager` will be lazy for counting the subscriptions for
determining if its above the limit
- Adding `AlgorithmSecurityValuesProvider.GetAllValues()`, removes the
need to fetch all the security keys twice.
- During universe selection, will not try to re add already added symbol
2019-04-22 10:47:27 -03:00
AlexCatarino 1c9b545ecd Prevents Multiple Warning from Market to MarketOnOpenOrder
Adds a flag that prevents multiple warning from market to `MarketOnOpenOrder`.
2019-04-03 22:39:18 +01:00
Stefano Raggi 57d50c69c4 Fix XML documentation compiler warnings
- Fixed all warnings except for missing XML comments (CS1591)
2018-11-09 11:44:03 +01:00
Martin Molinero 83897a7b88 Portfolio target percent respects FreePortfolioValuePercentage 2018-08-28 12:03:56 -03:00
Martin Molinero 6da57a1e12 Improving GetMaximumOrderQuantityForTargetValue 2018-08-03 16:26:14 -03:00
AlexCatarino 4a1307d69f Revert logic removal in MarketOrder method. 2018-07-18 23:00:59 +01:00
AlexCatarino b6c6479b20 Refactors SetHolding to use MarketOnOpen for daily data
The logic to select the right market order type is moved to `SetHoldings`. If the market is closed or there is only daily data, a market on open order is placed.
2018-07-18 17:31:55 +01:00
Stefano Raggi 7806466a24 Fix SetHoldings not taking into account pending market orders 2018-06-29 15:02:27 +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 86df0a20ff Add IsError flag to GetMaximumOrderQuantityForTargetValueResult
When buying power models return a zero quantity for an order, a flag can be set to indicate if it's an error condition, so CalculateOrderQuantity will show the error to the user.
2018-02-28 01:39:49 +01:00
Stefano Raggi 4d735756b2 Add error messages in CalculateOrderQuantity 2018-02-27 13:05:26 +01:00
Stefano Raggi 92b7b3ecc0 Normalize decimal value in SetHoldings message 2018-02-27 11:24:16 +01: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
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 acb5db6cf5 Rename Security.MarginModel to BuyingPowerModel 2018-01-31 11:47:34 +01:00
Stefano Raggi 05e3420d05 Move logic in CalculateOrderQuantity to SecurityMarginModel 2018-01-31 11:47:33 +01:00
Michael Handschuh 2e421c78cc Add MarketOnCloseOrder.DefaultSubmissionTimeBuffer
This is the default time span before market close that we'll allow an MOC
order to be placed. Nominally set to 15 minutes + 30 second buffer for
processing/transport.
2018-01-23 13:34:53 -05:00
Jared 755a0f8ba7 Merge pull request #1475 from StefanoRaggi/symbol-null-comparison-fix
Fix bug in Symbol inequality operator
2018-01-15 17:15:26 -05:00
Stefano Raggi 013edbcbcb Reuse existing OrderResponseErrorCode.AlgorithmWarmingUp 2018-01-15 23:01:17 +01:00
Stefano Raggi 89a59351cd Add OnWarmupFinished method to QCAlgorithm
This method is being added to allow algorithms to complete initialization tasks that cannot be executed during Initialize, such as cancelling existing open orders in live trading.
This method will be called only once, when the warmup task is complete.

Closes #1043
2018-01-15 13:46:30 +01:00
Stefano Raggi 1075571752 Replace Symbol.Empty checks with null checks 2018-01-12 21:56:10 +01:00
AlexCatarino 53ba7ee140 Adds OrderResponse error message for quantity less than lot size 2018-01-04 22:38:26 +00:00
AlexCatarino bffa952c0a Fix missing tag from Liquidate call
Orders that are placed with Liquidate method did not come with the tag.
2017-12-19 14:40:05 +00:00
AlexCatarino 4c982f37f9 Fixes CalculateOrderQuantity
Since we were not rounding off feeToPriceRatio, we were reducing order quantity more than needed in limit cases.
Fixes RegressionTests that were wrongly modified.
2017-12-04 14:04:27 +00:00
AlexCatarino 122ff90e23 Fixes CalculateOrderQuantity to handle decimal quantities
In quantity calculation, we didn't reduce the order quantity by decimal numbers, leading to a big step when dealing with crypto-currencies. For example, from 2.3456 it would drop to 1.3456 where values in between should've been tested.
2017-12-04 14:03:03 +00:00
Stefano Raggi a24164ecec Refactor OrderProperties class to IOrderProperties interface
This change will make it easier to add other planned brokerage features:
for Interactive Brokers, besides Financial Advisor support, we will be adding IB algorithmic orders soon (PR #1203).
2017-10-26 18:22:11 +02:00
Stefano Raggi ddb3c7d33b Add DefaultOrderProperties to QCAlgorithm
The properties in the default instance can be modified by users duing Initialize.
These properties are always copied into all new orders submitted with any method available (Order, SetHoldings, etc.)
2017-10-26 18:15:08 +02:00
jameschch@outlook.com 578efe843f Further changes for crypto type 2017-08-29 12:19:15 +01:00
12112 921ec8f983 merge from upstream 2017-08-22 16:56:35 +01:00
Stefano Raggi 9b3909b6e8 Fix a couple of bugs in BasicTemplateOptionsAlgorithm
The algorithm had two issues:
1. the LINQ query for contract selection was not including the option right (Put or Call)
2. the algorithm was submitting two extra orders at the end of the day (when market closed)

A helper method was also added in QCAlgorithm to determine if the market is open for a given symbol at the current time.
2017-07-22 21:26:03 +02: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
oswaldozapata 255823390a Updated to use liquidated string as default value of argument so this can be consistent with other methods that accept a tag. 2017-04-24 21:07:59 -04:00
oswaldozapata e3ae31258b Now when Liquidating, the tag field on the trade list will show as "Liquidated" to indicate that this was due to a Liquidate() call. 2017-04-24 00:41:39 -04:00
AlexCatarino b51464361b Fixes current holdings value computation in CalculateOrderQuantity
The variable currentHoldingsValue didn't take into account the quote currency conversion rate.
2017-04-21 17:03:50 +01:00
Stefano Raggi 5d10fcaa9e Do not submit orders during warmup 2017-01-17 23:41:25 +01:00
quant1729 5a57b4d25b Merge branch 'futures' 2016-12-29 22:12:58 +01:00
Stefano Raggi 8cbb8051c1 Add check for zero unitprice in SetHoldings
Prevents possible DivideByZeroException with non-USD Forex pairs at Tick resolution
2016-12-20 17:42:02 +01:00
quant1729 b3590647b5 Support for option strategies in API, QL option pricing models:
- Added OptionStrategies class with 10 popular option strats
- Defined OptionStrategy class
- Added support for trading of option strategies in QCAlgorithm.Trading.cs
- Added several estimator interfaces to introduce QL pricing models extention points: IDividendYieldEstimator, IRiskFreeRateEstimator, IUnderlyingVolatilityEstimator provided default implementation (flat term structure)
- Added QLOptionPriceModel class that contains meat of the calculations
- Added OptionPriceModels class that exposes 12 popular option pricing models to the user: those include Black Scholes, Barone-Adesi Whaley, Bjerksund Stensland, Crank Nicolson FD, Binomial Trees and more.
- Modified Greeks class to support lazy evaluation and introduce IV
- Partially tested on live data and trading (IQFeed/IB) and backtests. Need more data for tests.
2016-09-20 17:14:25 +02:00
quant1729 5b2b4753d4 Added support for basic option strategies 2016-09-18 21:26:38 +02: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
jameschch@outlook.com befbfc20ca merge latest upstream 2016-07-26 20:03:03 +01:00
jaredbroad 1642aed05a Refactor PreOrderChecksImpl() and add lot size check for 0-quantity orders 2016-07-13 16:00:37 -04:00
jameschch@outlook.com 464e2a1a15 Remove obsolete comment 2016-07-03 18:57:57 +01:00