Commit Graph

101 Commits

Author SHA1 Message Date
Martin Molinero 2c1cf0fa93 Address reviews
- Adding new regression test algorithm
- `SecurityPortfolioManager` will subscribe to the `CashBook.Updated`
event to invalidate the `TotalPortfolioValue
2019-06-07 17:51:30 -03:00
Jared adf4dba49b Merge pull request #3271 from QuantConnect/overall-performance-improvements-v2
More Overall performance improvements
2019-06-07 07:08:48 -07:00
Martin Molinero 168fb98e20 Fix Turnover Ratio for Futures/CFDs
- `Futures` and `CFDs` sales value will use `ContractMultiplier` as the
rest of the securities.
- `FitnessScore` values will be truncated, not rounded, to 3 decimal places.
- Reducing code duplication for calculating the
`CompoundingAnnualPerformance`
2019-06-06 20:06:54 -03:00
Martin Molinero 08b72c5907 Overall performance improvements v2
- Adding `LazyToUpper()` implementation, that will avoid the call to
`ToUpper` if the string is already upper.
- Reduce the timezone conversions at `Time.EachTradeableDayInTimeZone`
- `TotalPortfolioValue` will iterate over all securities once
- Adding new `SecurityIdentifier` cache, significant impact for
algorithms using coarse/fine data
2019-06-05 17:06:59 -03:00
Jared 26f4a0a490 Merge pull request #3000 from Adalyat/bug-2874/custom-currency-length
Support custom currency length
2019-06-04 16:35:54 -07:00
Martin Molinero ee4f8fee82 Overall performance improvements
- `TimeSliceFactory` will avoid creating empty collections
- `ExecutionModels` will check target collection count before trying to
enumerate
- Reduce calls to .`TotalPortfolioValue`
- `SecurityValues` will only be created when required
- `TimeKeeper` will use TimeZone unique Id as dictionary key. The
TimeZone hash is expensive.
- `AlgorithmManager` will avoid calling `DateTime.UtcNow`,
`ConvertFromUtc()` and `RoundDownInTimeZone()`
2019-06-03 15:09:02 -03:00
Adalyat Nazirov 4b2ae22fbf requested changes: change method documentation 2019-06-01 20:27:29 +03:00
Adalyat Nazirov 0fc894de81 decompose the crypto into each currency pair 2019-06-01 20:27:29 +03: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
Martin Molinero fa122fa809 Add missing PyObject.Dispose calls
- Adding _some_ of the missing PyObject.Dispose calls. In the cases
where C# is calling the Python side.
   - Note that Python calls to C# code is correctly handling the
   disposure of resources.
2019-04-10 15:03:10 -03:00
Stefano Raggi 273d6e90da Fix parsing of crypto tick data with sub-millisecond timestamps
- also updated extension methods ToInt32 and ToInt64 to support input strings with decimals
2019-01-21 16:47:27 +01:00
Martin Molinero d9195317e3 C# decimal to Python conversion
- This commit is related to PR 19 in QC/pythonnet
   - C# decimal will be cast to C# double and converted into python
   float
- Adding new `decimal.py` into the python algorithm project. This is
required for backwards compatibility with users performing operations
over expected decimal types (like `Price`)
- Updating two python regression test algorithms using custom python
execution models to be aware and ignore floating point precision errors
when handling order sizing.
2019-01-15 12:13:42 -03:00
Michael Handschuh 14af88f220 Add Task extension methods for safe synchronous await
Task.Result has many dangers surrounding the original captured SynchronizationContext.
Issues arise when the original thread context is also waiting on the task to complete
causing a deadlock. In 99% of cases in library code, there's no need to utilize the
SyncronizationContext for executing delegates in the calling thread's context. This
viewpoint is heavily supported by MSDN literate and various programming forums alike:

https://msdn.microsoft.com/en-us/magazine/gg598924.aspx
https://msdn.microsoft.com/en-us/magazine/jj991977.aspx
https://medium.com/bynder-tech/c-why-you-should-use-configureawait-false-in-your-library-code-d7837dce3d7f
https://stackoverflow.com/questions/27851073/why-would-i-bother-to-use-task-configureawaitcontinueoncapturedcontext-false
2018-09-28 13:24:20 -04:00
Martin Molinero 40b5629674 Fix infinite loop at ExchangeRoundDownInTimeZone 2018-08-09 14:26:04 -03:00
Martin Molinero f45a7938cf ToOrderTicket now correctly sets order field 2018-07-11 10:21:08 -03:00
Worthy7 f740f784d2 Update to deal with algo names issue
Updated to avoid issues where an algo name is a subset of another algo name
2018-06-13 12:29:21 +09:00
AlexCatarino a4233c7179 Improves Extensions.TryConvert to avoid test by exception
Instead of letting `PyObject.AsManagedObject` throw an exception because the types do not match, we check whether the target type is assignable from the python object type.

This PR fixes PR #2102 that caused a bug in Symbol[] convertion.

Unit tests were added to test all changes.
2018-06-12 22:39:16 +01:00
Michael Handschuh bb21171943 Implements python Consolidate API
Collapse QuoteBar to TradeBar if trade bar handler specified
2018-06-12 13:17:49 -04:00
AlexCatarino e6e8f7ebf2 Improves Extensions.TryConvert to avoid test by exception
Instead of letting `PyObject.AsManagedObject` throw an exception because the types do not match, we check whether the target type is assignable from the python object type.
2018-06-11 13:35:21 +01:00
AlexCatarino 19d403fd46 Assures that Coarse and Fine Fundamental are passed as List to AddUniverse 2018-05-23 15:13:07 +01:00
AlexCatarino b96ffea114 fixup! Fixes Extensions.TryConvert 2018-05-15 21:02:59 +01:00
AlexCatarino 394c215348 Fixes Extensions.TryConvert
When a python class is a subclass of a C# class, `Extensions.TryConvert` should return `false`. Currenty it was returnig true and the result was reduced to the parent class.
2018-05-15 20:45:00 +01:00
AlexCatarino 381e30da4d Implements ConvertToDelegate helper method 2018-05-10 19:08:34 +01:00
AlexCatarino 264da8a596 Calls python destructor to trigger exceptions
The exception in ignored because the generator isn't closed until it is being deleted (automatically in this case, when Python exits); the generator __del__ handler closes the generator, which triggers an exception of there is one.
2018-04-26 18:46:33 +01:00
AlexCatarino f3135b118e Adds Name attribute to python alpha models
These `Name` values match those in C# alpha models.
2018-04-19 18:04:01 +01:00
AlexCatarino 0a529b5485 Implements TryConvertToDelegate extension method
Condenses three PythonUtil static methods that converts python objects in a multidelegate into one.
2018-04-12 17:03:38 +01:00
Michael Handschuh 1c93dc7576 Add IEnumerable.BatchBy(batchSize) extension method 2018-03-21 08:26:51 -04:00
AlexCatarino 2f500fc1b6 Minor corrections 2018-03-08 12:06:54 +00:00
AlexCatarino dc24980e90 Adds Extension method that converts a PyObject into a ManagedObject
Adds an extension method that wraps PyObject.AsManagedObject method to isolate PyObject reflection handling.
2018-03-08 10:54:19 +00:00
AlexCatarino 682b312c0f Moves GetStringBetweenChars to Extensions from PythonUtil
Since this method is not exclusive of python algorithms, it is being moved to Extension methods.
2018-03-07 23:24:35 +00:00
AlexCatarino 654d6ad9ce Adds overloads with PyObject to Logging and Debug methods
We enable Logging and Debug methods to accept python objects to avoid the need of calling the str method.
Those objects are safely converted into string objects.
2018-02-09 00:48:44 +00:00
Michael Handschuh 69d3a10a93 Decompose DefaultAlphaHandler into IAlphaManagerExtension
The IAlphaManagerExtension defines a type that needs to react to events produced
by the AlphaManager. The actual events were removed in favor of a interface to
handle the events. This removes the need to wire events and instead just pass the
extensions to the alph manager and it will handle invoking the extensions at the
appropriate time.

This change removes all charting and statistics aggregation logic from the alpha
handler and moves it into dedicated types, AlphaChartingManagerExtension and
AlphaStatisticsManagerExtension. The resulting types are highly decoupled from the
LEAN ecosystem allowing them to be easily unit tested, whereas before the logic
was embedded in a handler with many many dependencies which would be very hard to
properly unit test.

As part of this change (and in preparation for moving scoring to the alpha thread)
the resolution of SecurityValues was removed from the alpha manager. In this new
pattern, the alpha manager is pushed generated alphas and security values at each
time step.
2018-01-12 12:08:40 -05:00
Michael Handschuh b07928bd58 Properly account for market hours in alpha prediction periods
If we make a prediction for 1 day in the future, we actually mean 1 trading day.
This change updates the alpha analysis logic to take into account the security's
market hours.
2017-12-28 11:27:41 -05: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
Michael Handschuh ec70a3516e Add ExchangeRoundDownInTimeZone ext
Performs rounding of data time in the specified time zone until
the range is within market hours.
2017-10-02 12:16:06 -04:00
Michael Handschuh 05b3b2d90d Add RoundDownInTimeZone extension
Performs rounding of data time in the specified time zone.
2017-10-02 12:16:05 -04:00
Michael Handschuh 6292f1e286 Clean white space 2017-10-02 12:16:05 -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 71239d70c6 Added extension method to that converts Order to OrderTicket 2017-08-25 15:08:00 -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
AlexCatarino 0b711f8dcd ToDecimal extension method allows negative numbers
When a string that represents a negative decimal was parsed with ToDecimal extension method, it returned a wrong number.
2017-07-28 13:18:21 +01:00
Andrew 2d319d8c42 Programmatically determine futures expiry
In order to correctly determine the expiry for futures contracts, Lean
will programmatically determine the expiry date from the expiry year and
month.  A general method is created in this PR for adding more expiry date
functions.  The expiry dates have been tested against expiry dates listed
on the CME website.
2017-04-28 16:52:03 -04:00
Andrew 5cedbeae3f Leveraging existing extension method to remove trailing 0s 2017-04-05 12:49:28 -04:00
Stefano Raggi d9db470532 Update ToDecimal extension to handle whitespace 2017-04-02 20:50:27 +02:00
quant1729 ddbb7c902c Added support for light data file cache 2017-01-11 14:19:15 +08:00
quant1729 48721125dc Revert "Fixed bug with static zip archive caching. Added new caching data file provider. Refactored IDataFileProvider interface."
This reverts commit c59743dc42.
2017-01-11 11:27:28 +08:00
quant1729 c59743dc42 Fixed bug with static zip archive caching. Added new caching data file provider. Refactored IDataFileProvider interface. 2017-01-08 09:25:26 +08:00
quant1729 3819561a82 Merge branch 'futures' into master-futures-merged
Conflicts:
	Common/QuantConnect.csproj
	Tests/RegressionTests.cs
2016-12-01 17:32:40 +01:00
Andrew Hart 920ba77096 Update live-data url and port in config.json
Remove noise added by visual studio. Includes one minor change to
ApiDataQueueHandlerTests.
2016-11-30 09:48:41 -05:00
Andrew Hart 5a2f664327 Add ToSHA256 as a static extension method in Extensions.cs 2016-11-09 12:00:13 -05:00