Commit Graph

144 Commits

Author SHA1 Message Date
Martin Molinero b28f9f501a Refactor and fix Slice bugs
- Fixing Python slice enumeration which would not happen when custom
data was present. Adding unit test
- Fix Slice constructor which would fail to create data collections due
to relying on non-deterministic 'slice._data'. Adding unit test
- Improving custom data retrieval for symbols which have more than 1
data type in a slice. Adding unit test
- First step refactoring slice internally, no behavior changed
2020-03-27 12:44:05 -03:00
Martin Molinero 6eb08334cd Revert GetBuyingPower removal
- Fix bug where OptioMarginModel would return 0 initial margin required
2020-02-24 14:06:16 -03:00
Jared 7f941edeec Merge pull request #4087 from QuantConnect/bug-4080-fix-report-creator-macosx-pythonpath
Fixes issue where report creator could not be ran in Mac OSX
2020-02-11 16:56:58 -08:00
Gerardo Salazar d3a34dcd70 Fixes issue where report creator could not be ran in Mac OSX
* Adds `PythonInitializer.SetPythonPathEnvironmentVariable(...?)` method
2020-02-11 15:01:47 -08:00
AlexCatarino 0beaab873f Implements Wrappers for __str__ and __repr__ in PandasData.Remapper 2020-02-11 16:54:51 +00:00
Martin Molinero 85f5b68972 Address reviews
- Revert `OptionMarginModel` behavior change
- Renames
- Refactor future intraday margin modelling
2020-02-04 18:41:15 -03:00
Martin Molinero 6eb45baa59 Refactor GetMaximumOrderQuantityForTargetBuyingPower
- Refactoring `GetMaximumOrderQuantityForTargetValue` into
`GetMaximumOrderQuantityForTargetBuyingPower` which algorithm uses
margin
- Reducing code duplication
- Adding unit tests
- Fixing futures margin model. Adding intra day logic.
2020-02-04 18:41:15 -03:00
Martin Molinero 936af7df7b Refactor BuyingPowerModel
- Remove unrequired `GetBuyingPower`
- Making `BuyingPowerModel.GetMaintenanceMarginRequirement` protected
instead of public
- Adding `GetMaximumOrderQuantityForDeltaBuyingPower` to replace
public `GetMaintenanceMarginRequirement` and improve API experience for
consumers like the `DefaultMarginCallModel`
- Adding new unit tests
2020-02-04 18:41:15 -03:00
Martin Molinero cd9bf4cc77 Making WorkerThread static
- Making WorkerThread instance static
- Adding PythonInitialize.AddPythonPaths(), useful to add paths to
python after initialization
2020-01-14 11:31:58 -03:00
Martin Molinero 19edc94f0f Improve pandas Symbol key support
- Add support for Symbol key access for pandas ix and iloc results
- Wrapp pdf merge, join, concat method results
- Wrapp pandas.concat method result with `Remapper`
- Adding unit tests
2019-11-20 13:48:42 -03:00
Martin Molinero 68ad2f51b6 Address reviews
- Replacing `BaseData.AdjustResolution` for `DefaultResolution` and
`SupportedResolutions`
- Making `Resolution` nullable for `Algorithm.AddData` methods
- The `ISubscriptionDataConfigService` will set the default resolution
if none was provided and assert it is supported
- Fix bug with `PythonData` `IsSparseData` and `RequiresMapping`
resolution
2019-11-04 20:42:30 -03:00
Martin Molinero 1d43dcd601 Add BaseData.AdjustResolution
- Adding `BaseData.AdjustResolution()` that should return a valid
resolution for the given data and security type.
This allows us to set a limitation which is useful to avoid invalid data
requests or unnecessary fill forward situations. The user will be
notified through a console message.
- Adding unit and regression test
- Updating example algorithms custom data resolution
- Some performance improvements. Wont change console color if
`SelectedOptimization` is defined
2019-11-04 20:38:26 -03:00
AlexCatarino b97d11d37a Addresses Reviews
- Covers another level on inheritance of Market Data by using `Type.IsAssignableFrom`
- Caches the list of `MethodInfo` for custom data types to avoid redefining that list.
2019-10-22 15:14:04 +01:00
AlexCatarino 0cca6869f7 Fixes Support for Custom Data
When custom data classes inherited from market data classes such as `TradeBar`, it created duplicate entries. Therefore, we need to exclude the common properties in the private field `PandasData._members`.
2019-10-22 15:14:04 +01:00
Martin Molinero 0b9862a7a7 Fix for PythonSlice 2019-10-02 23:22:52 -03:00
Martin Molinero 1cb4856557 Add support for Symbol as key for Pandas dataframe
- Improve user experience allowing users to use `Symbol` instance as key
for pandas data frame
2019-10-01 18:43:38 -03:00
Martin Molinero 6fabe30317 Add backwards compatibility index.levels[0]
- Add backwards compatibility shim for the `df.index.levels[0]` use
case. Reverting broken use cases and adding unit tests.
2019-09-24 10:34:35 -03:00
Martin Molinero b6b7720a1e Add more backwards compatible cases
- Moving mapper from C# to Python since some cases did not work when
implemented in C#
- Small changes to `PandasDataFrameHistoryAlgorithm` which runs till the
end with no errors
- Adding more backwards compatible unit tests
2019-09-24 10:34:35 -03:00
Martin Molinero 6a2f5b09f2 Improvements
- Add new dependency to documentation, docker files, python setup readme
- Adding backwards compatibility pandas DataFrame unit tests
- Adding missing cases for backwards compatility shim
2019-09-24 10:34:35 -03:00
Martin Molinero 8dbbbb618f Pandas and CustomData mapping fixes
- Add Pandas backwards compatibility shim
- Adding `MappingExtensions` which will remove data type from the
`Symbol.ID.Symbol` value to resolve the `MapFile`
- `SecurityIdentifier.TryParse()` will throw when given an invalid
`SecurityType`
2019-09-24 10:34:35 -03:00
Michael Handschuh d709d1c4e0 Update Common 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 14:13:24 -04: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
Martin Molinero d6b89a6d0d Adding some logs to Python initialization 2019-08-05 13:14:52 -03:00
Jared 992d721d08 Revert "Reduce python load time 30% (#3440)" (#3441)
Reverts test commit 70017f0e05.
2019-07-28 18:37:34 -07:00
Jared 70017f0e05 Reduce python load time 30% (#3440)
Optimize python load times
2019-07-28 17:20:52 -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
Martin Molinero 082906ed14 Test memory leak fix 2019-04-10 12:36:35 -03:00
AlexCatarino 38574ef9d5 Adds missing Py.GIL() in VolatilityModelPythonWrapper.Volatility 2019-02-14 23:13:56 +00:00
AlexCatarino 11742406b7 Adds "sort=True" argument to pandas.concat call in PandasConverter
From [pandas-docs](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.concat.html):
> The current default of sorting is deprecated and will change to not-sorting in a future version of pandas.
>
> Explicitly pass sort=True to silence the warning and sort. > Explicitly pass sort=False to silence the warning and not sort.
2019-02-07 12:59:37 +00:00
AlexCatarino ef59fa7ba2 Updates pythonnet package.
In the new package:
- C# decimal conversion will use C# double and python float due to the big performance impact of converting C# decimal to python decimal;
2019-01-18 23:18:35 +00:00
Martin Molinero 103bf638b5 Adding Pandas MultiIndex cache
- Adding a cache for the `Pandas.MultiIndex`, giving a significant
performance improvement.
- Adding new `ListComparer` class. Adding unit tests.
2019-01-11 14:00:32 -03:00
Martin Molinero 3d918bae1b PandasData will convert DateTime once
- `PandasData` will convert DateTime to python once and share it among
consumers giving a performance improvement.
2019-01-10 11:45: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 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 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
Jared e17184d01e Merge pull request #2719 from Martin-Molinero/refactor-2718-rename-context-to-parameters
Renaming BuyingPower..Context to BuyingPower..Parameters
2018-12-04 11:20:31 -08:00
Jared 69e6c3726a Merge pull request #2714 from StefanoRaggi/refactor-2701-ibuyingpowermodel-context
Refactor additional IBuyingPowerModel methods to use context objects
2018-12-04 11:13:06 -08:00
Stefano Raggi bd4c799d2b Rename parameter classes from Context to Parameters 2018-11-29 22:05:49 +01:00
Martin Molinero 46baedf858 Refactor FillModels
- Modifying `IFillModel` interface removing old methods and adding new
method `Fill Fill(FillModelParameters)`. This is a breaking change.
- Adding new `PythonWrapper` property for the `FillModel` base class.
This is required due to a limitation in PythonNet:
   - Given C# class T has `virtual` methods A and B. Where method A
   calls method B. And given custom python class L inherits class T.
   And overrides method B. When class L calls
   base method A (of class T). And when method A internally calls method B.
   It will call C# implementation, not the python override. This issue
   is solved going back to the `PythonWrapper`. Adding unit tests.
- Adding new `Parameters` property for the `FillModel` base class that will
be set by the call to `Fill()`. The `Parameters` property will be used by
the modified `XxxxFill()` implementations
- Adding new `Fill` result object for the `Fill(FillModelParameters)`
method
- Adding new check before removing a `SubscriptionDataConfig` due to the FillModels consuming the configuration collection when determining which Price to use. WIll now only remove the `SDC` if the symbol was removed from the selecting `universe`, this will avoid the case where the symbol is never deselected and the subscription ends, which happens at the end of all executions.
- Adding unit tests showcasing retro compatibility.
- Enabling C# `CustomModelsAlgorithm` as a regression test. Python
version returns a different result due to random number generation.
2018-11-29 15:38:46 -03:00
Martin Molinero 7ce09f22cb Renaming Context to Parameters
- Renaming `BuyingPowerContext` to `BuyingPowerParameters` and
`ReservedBuyingPowerForPositionContext` to
`ReservedBuyingPowerForPositionParameters`
2018-11-29 15:02:09 -03:00
Stefano Raggi 78f3b4b099 Refactor additional IBuyingPowerModel methods to use context objects 2018-11-27 22:50:15 +01:00
AlexCatarino b89bc97d61 - Use ValidateImplementationOf method in RiskManagementModelPythonWrapper
- Use recently implemented `ValidateImplementationOf` extension method in `RiskManagementModelPythonWrapper`
2018-11-06 23:11:21 +00:00
Martin Molinero 239664277f Refactor Volatility Models
- Removing usages of Security.Configuration properties from existing
Volatility Models, without modifying existing interfaces. Adding unit
tests for existing behavior
- Adding new BaseVolatilityModel, which will have a setter for a
ISubscriptionDataConfigProvider which will be called by the system.
Adding unit tests for this behavior.
- Adding new `SubscriptionDataConfigExtensions` static class which will
provide methods used to determine different configuration properties for
a given set of `SubscriptionDataConfigs`. The behavior was extracted
from current `Security` class behavior regarding the `SubscriptionBag`.
Adding unit tests covering exepected behavior here.
2018-10-29 16:57:23 -03:00
Martin-Molinero 6629ba379d Merge branch 'master' into feature/2606-custom-brokerage-message-handler 2018-10-26 18:14:03 -03:00
Michael Handschuh 85942b3f14 Add BrokerageMessageHandlerPythonWrapper
This will enable python users to implement IBrokerageMessageHandler
2018-10-16 19:26:46 -04:00
Michael Handschuh 7189cb916f Add PythonWrapper.ValidateImplementationOf<T>
Provides an extension method that python wrappers can call to
validate that the provided python implementation implements all
of the required members.
2018-10-16 19:26:46 -04:00
Michael Handschuh cb726cb60a Refactor IBuyingPowerModel.GetBuyingPower
In preparation for sweeping changes that will require adding a currency converter
parameter to this method and augmenting the return value to be a CashAmount. This
ensure the future change won't produce a compile-time breaking change. An extension
method was also added as a shim to keep any existing code functional
2018-10-16 18:44:22 -04:00
Michael Handschuh df0e19ef27 Refactor IBuyingPowerModel.GetReservedBuyingPowerForPosition
In preparation for sweeping changes that will require adding a currency converter
parameter to this method and augmenting the return value to be a CashAmount. This
ensure the future change won't produce a compile-time breaking change. An extension
method was also added as a shim to keep any existing code functional
2018-10-16 18:14:17 -04:00
Stefano Raggi 5c9b81cef1 Fix Python initialization and imports for multiple tests 2018-10-02 20:28:13 +02:00