Commit Graph

75 Commits

Author SHA1 Message Date
Michael Handschuh e65f718577 Enforce consistency in AddData<T> C#/Python
See #3332 - initial pre-factoring/clean-up
2019-09-24 10:34:34 -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
AlexCatarino 45c81371a3 Implements ConvertToSymbolEnumerable Extension Method
Following the convert python objects patter, it replaces `QCAlgorithm.GetSymbolsFromPyObject`.
Add unit tests.
2019-09-05 23:55:30 -03:00
Martin Molinero 24527e0cc2 Address reviews - Renaming 2019-08-21 16:30:03 -03:00
Martin Molinero 73d780daae Moving UsesMapFiles to DataType
- Custom data types will know whether or not Lean should use map files
- Updating regression test with sample custom data using map files,
which can run locally
- Adding unit tests for the `SubscriptionDataReaderHistoryProvider`,
checking it mappes equities and options correctly
2019-08-20 17:33:41 -03:00
Gerardo Salazar e6a510d803 Add Mapfile support for custom data sources 2019-08-20 16:56:02 -03:00
Martin Molinero 1983f36792 Allow Python selection to return unchanged
- We will now check if python selection method returned `Universe.Unchanged`
- Removing `ToList()` call on fine and coarse data before sending it to
the python algorithm
- Adding regression algorithms
2019-07-31 15:36:07 -03:00
AlexCatarino 0b0a1b31ff Refactors PythonIndicator
In order to provide full Lean Indicator functionality to python custom indicators, they need to inherit from a C# class. `PythonIndicator` will serve for this purpose.
Algorithms can use the former version (no inheritance).
2019-07-26 00:35:57 +01:00
AlexCatarino 84d548b5f2 Adds Custom Python Indicator Support for QCAlgorithm.PlotIndicator
In order to add support custom python indicators for `QCAlgorithm.PlotIndicator`, we created a `PythonIndicator` class that wraps the custom python indicator. In `QCAlgorithm`, the reference of the wrapper is saved into a dictionary keyed by the python indicator handle.
2019-07-23 22:02:33 +01:00
Jared 4f47df2ce8 Merge pull request #3022 from AlexCatarino/feature-3007-calendar-consolidators
Implements Calendar (Weekly/Monthly) Consolidator
2019-04-10 14:35:13 -07: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
AlexCatarino 0202df35f4 Replaces Enum CalendarType for Static Class with the Same Name
Replaces Enum `CalendarType` for static class with the same name. This class defines two properties (`Weekly` and `Monthly`) that can be used to define the previous calendar date (Monday or 1st of current month) which will correspont to the `Time` of a `IBaseData` object.

Refactor `PeriodCountConsolidatorBase` to define use `GetRoundedBarTime` based on a period specification that depends on the constructor overload: `integer`, `TimeSpan` or `Func<DateTime, CalendarInfo>`. The last one can be set with the `CalendarType` properties.
2019-04-08 22:10:04 +01:00
AlexCatarino 5314e7426d Implements Calendar (Weekly/Monthly) Consolidator
Implements consolidators that group bars by a calendar unit (week or month).
2019-04-08 22:10:04 +01:00
Jared ee2d7ef36c Merge pull request #2768 from Martin-Molinero/refactor-2767-add-new-history-request-factory-class
Adding new HistoryRequestFactory
2018-12-21 08:56:23 -08:00
AlexCatarino b5918f3bf2 Fixes Plot(string, PyObject) handling of indicators. 2018-12-21 14:46:59 +00:00
Martin Molinero 541b4e3a00 Adding new HistoryRequestFactory
- Adding new `HistoryRequestFactory` class. Will provide some methods to
facilitate the creation of new `HistoryRequests`. Moving
`CreateHistoryRequest` and `GetStartTimeAlgoTz` into the new
`HistoryRequestFactory`. And consolidating `GetStartTimeAlgoTz` and
`GetStartTimeAlgoTzForSecurity`.
2018-12-19 16:14:42 -03:00
AlexCatarino 70e2ef9480 Changes the custom data type base class
By using the python object parant class, which is either `PythonQuandl` or `PythonData`, instead of `DynamicData`, the `AlgorithmManager.Stream` method can find a matching subcription data configuration used to create a data feed packet.

Closes #2694
2018-11-13 19:29:34 +00: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
Martin Molinero 2967776130 Refactor AddToUserDefinedUniverse
AddToUserDefinedUniverse will receive configuration settings as parameters.
2018-10-02 09:59:33 -03:00
Michael Handschuh fdc866fda0 Reverting 'Merge pull request #2483 python-history-provider'
We didn't experience the expected performance improvements. Locally under
unit test there was aboout an order of magnitude throughput increase, but
when run against the history benchmark, this new approach was 60% slower.
We're reverting this for now to perform further analysis and better
understand the performance profiling of the python history stack.
2018-09-18 18:37:23 -04:00
AlexCatarino 5456f53545 Fix exception message: remove unrequired \ 2018-09-17 19:05:49 +01:00
AlexCatarino 8ac671d7ab Minor improvements
- Do not throw, but log, when a entry in the zip file does not exist. It can happen in trade bar data for options/futures since a given contract may only exist as quote bar.
- Verify whether the minimum requires arguments ("periods", "span" and "start") are present in the dictionary used to pass the variables.
- Adds doctring to History.
- Fixes type check for custom data.
2018-09-17 19:05:49 +01:00
AlexCatarino 3bc4d661c8 Implements Futures and Options support
Since futures and options have multiple entries in the zip file, we need to include the entry name in the request.
Futures have multiple open market periods during on trading day, therefore we need to apply a more complex mask to pandas dataframe index.
2018-09-17 19:05:49 +01:00
AlexCatarino aa078ec7d1 Implements Tick resolution support
- Removes HistoryRequest inheritance in PandasHistoryRequest
2018-09-17 19:05:49 +01:00
AlexCatarino 602644c65d Fix the implementation to support adjusted prices and non-regular market hours handling
- Adds unit tests.
2018-09-17 19:05:48 +01:00
AlexCatarino 3e4a71cd50 Creates QCAlgorithm.py: a bridge between C# QCAlgorithm and python algorithms 2018-09-17 19:05:48 +01:00
AlexCatarino c3023825e0 Fixes custom data type mismatch in python algorithms
If the custom data type is a C# type, it should be used instead of wrapping it around a `PythonActivator` object.
2018-07-23 13:30:02 +01:00
AlexCatarino e40a318f88 Fixes "object isn't callable" bug in Universe Selection
Reverse the order that a `PyObject` is attempt to be converted into a `Universe` object and a `Func`.
2018-07-03 17:19:03 +01:00
AlexCatarino 4853e50dd2 Fixes ambigous call bug for Download method
Adds more overloads and remove the optional arguments.
2018-06-28 19:00:31 +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 19d403fd46 Assures that Coarse and Fine Fundamental are passed as List to AddUniverse 2018-05-23 15:13:07 +01:00
AlexCatarino e9cef63e12 Refactors GetSymbolsFromPyObject method
GetSymbolsFromPyObject now returns IEnumerable<Symbol> and throws if its argument is not Symbol or Symbol[] object and if the Symbol has not been added to the Securities object.
2018-03-23 19:19:52 +00:00
AlexCatarino f588e190f2 Fix data consolidation with python custom data
When creating a CRL type in runtime to represent a python custom data class, we need define `DynamicData` as its parent class so that it passes the `IsAssignableFrom` condition in `SubscriptionManager.AddConsolidator`
2018-03-14 17:55:22 +00:00
AlexCatarino 5e2f24b90f Uses PyObject.TryConvert to determine which indicator type will be registered
Minor fixes in RegisterIndicator tests.
2018-03-08 10:54:19 +00:00
AlexCatarino 28c5fe3f16 Fixes RegisterIndicator for python algorithms
The check for Lean indicators was testing for `Indicator`, `BarIndicator` and `TradeBarIndicator` types where it should check for `IndicatorBase<T>` which includes `WindowIndicator<T>`.
2018-03-08 10:51:29 +00:00
AlexCatarino 0f57c2fd43 Fixes Custom Data for Python
In order to access the custom data classes, the module containing them was added to the ObjectActivator. This was unnecessary if it wasn't a custom data algorithm.
Also, this operation would not be taken into account if the custom data class were defined after the algorithm was created: this is the case for QuantBook.
We refactor how custom data is handled: a new class was added to provide a instance creation factory that creates an instance of each python custom type.
2018-03-01 19:28:30 +00:00
AlexCatarino e3cda2afe8 Improves Plot(string,PyObject) logic and test
In this new approach, we test whether the argument is a Indicator before we try to plot it. If fail, throws a ArgumentException error.
2018-02-28 18:46:00 +00:00
AlexCatarino bd18dfc2f8 Adds test for new Plot overload
This text is ignore since Travis does have pythonnet installed.
2018-02-27 22:11:07 +00:00
AlexCatarino 0ea19b0558 Adds overload to Plot method to handle indicator special cases
For cases where implicit conversion to decimal from indicator was not properly handled by pythonnet, we expliticly get `Current.Value` and redirect to `Plot(string,decimal)` overload.
2018-02-27 12:36:37 +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
AlexCatarino 6827624f83 Adds RegisterIndicator overloads that takes python-defined indicators
Adds example for this feature
2018-02-07 12:31:18 +00:00
AlexCatarino 599c00be5b Historical Data Requests fetchs data from non-subscribed securities
It was not possible to add a security based on its historical data, since we needed to add the security before requesting its security data. Universe Selection algorithms are an example of such usage.
2018-01-16 18:08:28 +00:00
Michael Handschuh 0cc6a53e9c Set correct time zone for custom data in MarketHoursDatabase
Add MarketHoursDatabase.SetEntry and SetEntryAlwaysOpen. This allows runtime modification of the
market hours database which is necessary for correct custom data time zone handling.

Extracts complicate ternary logic into its own method and make it human readable.
Set the market hours entry for custom data universe subscriptions defaulting to the security's time zone.
2018-01-04 12:36:57 -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 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
AlexCatarino 0efd3a0c48 Renames Fetch to Download 2017-12-04 22:20:19 +00:00
AlexCatarino fb12e79a1c Changes PandasConverter accessibility levels
Private field PandasConverter _converter is now public property PandasConverter.
With this change, we will be able to use it in QuantBook.
2017-12-04 21:38:39 +00:00
AlexCatarino 96562b335f Implements authentication headers 2017-12-04 21:25:41 +00:00
AlexCatarino 783d841a59 Changes AddData method return type
Unlike other methods used to add securities to the algorithm that return a Security or a derived object, AddData was returning void. This commit change it to return Security for consistency.
2017-11-16 14:41:08 +00:00
AlexCatarino b31e7e18a6 Adds support for Historical Requests of Custom Data for python 2017-11-01 12:43:06 +00:00