Commit Graph

396 Commits

Author SHA1 Message Date
Michael Handschuh d818b56d6e Add MaximumUnrealizedProfitPerSecurity risk model
This is the inverse of the MaximumDrawdownPercentPerSecurity risk model.
It's goal is to liquidate holdings for a security when the unrealized profit
passes a specified threshold. This can viewed as a 'take the money and run'
risk model.
2018-10-13 03:30:13 -04:00
Martin Molinero eaba3ab24e Fix ManualUniverse duplicate effort
- Removed usages of algorithm.Securities.key as a parameter for the
`ManualUniverseSelectionModel()` since those securities, added through
`AddXXXX` calls will be managed by the `UserDefinedUniverse`. This was
causing for Universes to try to add the same subscription requests
- Adding new empty constructor for ManualUniverseSelectionModel,
required for Python
- ManualUniverse will return any existing SDC for the
symbol. This is for maintaining existing behavior and
preventing breaking changes: Specifically motivated by usages of
Algorithm.Securities.Keys as constructor parameter of the
ManualUniverseSelectionModel, since those Symbols added by Addxxx()
calls will already be managed by the UserDefinedUniverse
- Making some format modifications to aling with used Lean formatting
2018-10-12 18:30:04 -03:00
David 76e5ae4784 Fix namespace 2018-10-08 22:11:07 +01:00
Michael Handschuh cdd1ad83c6 Merge pull request #2572 from Martin-Molinero/refactor-2571-universe-getsubscriptionrequests-createsecurity
Refactor Universe.GetSubscriptionRequests - Obsolete Universe.CreateSecurity
2018-10-08 11:53:48 -04:00
David 9e25420ba5 Convert to RiskManagmentModel 2018-10-06 15:01:07 +01:00
David cbb7eda706 Copy CompositeAlphaModel.cs 2018-10-06 14:34:18 +01:00
Martin Molinero 5221999b88 Addressing reviews
- Some formatting, comments changes
- Removing SubscriptionManager from new FuturesChainUniverse constructor
- Making Option and Future properties in FutureChainUniverse and
OptionChainUniverse
2018-10-04 16:08:12 -03:00
Stefano Raggi 5c9b81cef1 Fix Python initialization and imports for multiple tests 2018-10-02 20:28:13 +02:00
Martin Molinero 4e424c4f19 Refactor UserDefinedUniverse, UniverseSelection
- Obsolete Universe.CreateSecurity, Universe.SetSecurityInitializer,
Universe.GetSubscriptionRequests(Security security, DateTime currentTimeUtc, DateTime maximumEndTimeUtc)
- Adding new GetSubscriptionRequests() overload that will receive
instance which implementes new ISubscriptionService
- UserDefinedUniverse will stop using Security.Subscriptions
2018-10-02 09:59:23 -03:00
Stefano Raggi 399274b29b Fix ScheduledUniverseSelectionModelRegressionAlgorithm.py regression failure 2018-09-28 15:17:38 +02:00
AlexCatarino 340d1d81ff Adds key check after History requests in framework models …
`RsiAlphaModel` and `BlackLittermanOptimizationPortfolioConstructionModel` didn't have a key check after a history request. If a history request retuns no data for a given symbol, trying to access the pandas dataframe results in a `KeyError`.
2018-09-19 17:39:31 +01:00
AlexCatarino 8b8d2d2d6f Adds key check after History requests in framework models
`RsiAlphaModel` and `BlackLittermanOptimizationPortfolioConstructionModel` didn't have a key check after a history request. If a history request retuns no data for a given symbol, trying to access the pandas dataframe results in a `KeyError`.
2018-09-19 16:11:50 +01:00
Stefano Raggi 0f86363def Add missing null checks in Python models 2018-08-21 18:23:50 +02:00
Stefano Raggi c694e9faae Post merge fixes 2018-08-21 18:10:52 +02:00
Stefano Raggi cead4e608e Update EqualWeightingPortfolioConstructionModel to check for null targets 2018-08-21 18:10:52 +02:00
Stefano Raggi 4abc525a38 PortfolioTarget.Percent returns null if error 2018-08-21 18:10:51 +02:00
Michael 144765db08 Merge pull request #2430 from QuantConnect/bug-2426-manual-universe-selection-model-name-fix
Fix symbol name in ManualUniverseSelectionModel
2018-08-21 11:44:49 -04:00
Stefano Raggi 9d2ed09068 Fix symbol name in ManualUniverseSelectionModel 2018-08-21 17:03:24 +02:00
AlexCatarino 76cc75006c Refactors BlackLittermanOptimizationPortfolioConstructionModel
1. Apply the pattern used in `EqualWeightingPortfolioConstructionModel`
2. Change the logic to compute the views from the insights.
3. Change the logis to compute the posterior mean and covariance

Use `UnconstrainedMeanVariancePortfolioOptimizer` in `BlackLittermanPortfolioOptimizationFrameworkAlgorithm` to bypass the difference in regression tests with `IPortfolioOptimizer` that rely on different algorithms in C# and python.

Adds unit tests for BLOPCV to test the implementation against Black and Litterman 1999 paper.
2018-08-20 21:01:14 +01:00
AlexCatarino 9c99794bfb Adds covariance parameter in IPortfolioOptimizer.Optimize
Add a multi-dimensional array of double representing the covariance. Some models, e.g., Black-Litterman may want to optimize a covariance that is different from the historical one.

Adds UnconstrainedMeanVariancePortfolioOptimizer: a simple optimizer that has a solution, therefore no numerical optimization method is required.
2018-08-20 20:51:02 +01:00
AlexCatarino 45c8df325e Fixes the time guard condition using less and equal
If `algorithm.UtcTime` is equal to `nextExpireTime`, the model should not emit new targets.
2018-08-13 19:45:25 +01:00
AlexCatarino 239a5a909e Fixes EqualWeightingPortfolioConstructionModel not flattening expired insights
- When there are or aren'tt new insights, the EqualWeightingPortfolioConstructionModel will creates a target to flatten delisted securities from the universe of expired insights.
- Helper methods were added to deal with removing expired insights and getting active ones and used in `EqualWeightingPortfolioConstructionModel`
- Adds unit test
- Updates framework algorithms
2018-08-13 19:45:25 +01:00
AlexCatarino d4f67b212d Refactors RsiAlphaModel
The model was assuming that we could only add elements to the dictionary field if there was data in the history request which is not required.
2018-08-08 12:10:22 +01:00
Jared b9d4536b08 Merge pull request #2362 from QuantConnect/bug-2357-fix-insight-close-time
Fix insight close and analysis times
2018-08-07 16:26:18 -04:00
AlexCatarino 48c87ffb93 Refactors RsiAlphaModel logic in OnSecuritiesChanged
The history request to warm up the RSI indicator is performed before it is created.
2018-08-07 20:53:17 +01:00
Michael Handschuh 4fd16f6daf Fix resolution of insight close times, allow user defined close times
Fixes a bug where we were using the security's data resolution to compute
the insight's close time. This led a case such as insight.Period == 20days
to step 20days worth of tradable minutes (assuming minute data resolution),
yielding a close time that was very far in the future.

We also add different means of specifying an insight's period/close time:
1. Specify insight period as a TimeSpan and we compute close time
2. Specify insight period and a resolution and bar count and we compute close time
3. Specify insight close time local directly and we compute the insight period

The key here is maintaining consistency between the three different approaches
which is heavily validated with the corresponding unit tests.

Edits also made to trust the insight's close time as the analysis end time in
the case where the analysis period == insight period (extra analysis period = 0).
Given the current setup (extra analysis period == 0), this guarantees that close
and analysis end times are equivalent.

Regression statistics were updated and expectedly we get many more insights that
have completed analysis, and as such, average scores have also changed.
2018-08-07 11:21:11 -04:00
Michael a366063aed Merge pull request #2354 from AlexCatarino/bug-2353-fix-equal-weighting-pcm
Fixes EqualWeightingPortfolioConstructionModel
2018-08-07 10:54:37 -04:00
AlexCatarino e0c380d08c Fixes EqualWeightingPortfolioConstructionModel
Adds targets with direction zero to remove invested securities that do not have active insights.
2018-08-06 13:19:03 +01:00
Stefano Raggi 089199dadf Fix Python version of RsiAlphaModel to be same as C# version 2018-08-03 20:37:50 +02:00
Michael ed5a8254cc Merge pull request #2338 from QuantConnect/risk-management-models-unit-tests
Add unit tests for MaximumDrawdownPercentPerSecurity risk management model
2018-08-02 10:49:02 -04:00
Michael cfb05d190f Merge pull request #2328 from AlexCatarino/feature-2326-implements-futures-template-framework
Implements BasicTemplateFuturesFrameworkAlgorithm
2018-08-02 10:44:09 -04:00
Stefano Raggi c6092648bd Update Python version of MaximumDrawdownPercentPerSecurity to be same as C# version 2018-08-02 12:51:27 +02:00
AlexCatarino 38b03bfd28 Adds XML documentation for selection models 2018-08-01 18:47:46 +01:00
AlexCatarino 0bc157a8e7 Removes logging from framework models and algorithms
Shipped modules should be silent unless error case.
2018-07-31 19:16:17 +01:00
AlexCatarino 47b3abfca2 Improves the logic to select active insights
- Also: adds unit tests for `EqualWeightingPortfolioConstructionModel`
2018-07-31 19:01:02 +01:00
AlexCatarino 01a77a274b Fixes InsightDirection.Flat allocation in EqualWeightingPortfolioConstructionModel
The allocation should be calculated for symbols which last insights are not `InsightDirection.Flat`. For example, if the last insight of SPY and of IBM are Up, and of AIG is flat, then 50% of equity should be allocated in SPY, 50% in IBM and 0% in AIG. Before this fix, we would have 33% SPY, 33%, IBM and 0% AIG.
2018-07-31 12:09:24 +01:00
AlexCatarino e5ed09924b Implements BasicTemplateFuturesFrameworkAlgorithm
This algorithm shows how to implement a futures strategy in a framework algorithm.
`FutureUniverseSelectionModel` portfolio selection model was implemented to provide a base class to help create other futures universe selection models.
2018-07-30 22:21:47 +01:00
Martin Molinero c73b7bb62f Adding smarter methods for PortfolioTargetCollection 2018-07-27 10:48:55 -03:00
AlexCatarino b402c3673e Fixes MVOPC: it was not testing whether all magnitures are zero
- Changes `ExpectedStatistics` in MVOFA
  - All regression tests now
- Removes unnecessary constructor arguments in `ReturnsSymbolData`
- Tide up code and add method summaries.
2018-07-24 16:53:11 +01:00
wildart b025f01293 review fixes
- separete classes for optimizers
- refactored `ReturnsSymbolData`
2018-07-24 16:53:11 +01:00
Art Wild d5996fb7c8 MV & BL portfolio optimization implementation
Closes #1998. Closes #2219.
2018-07-24 16:53:11 +01:00
AlexCatarino b0d1606118 Refactors portfolio construction models with portfolio optimization
- Creates `MinimumVariancePortfolioOptimizer` and `MaximumSharpeRatioPortfolioOptimizer` portfolio optimizer. They implement `Optimize` method that returns a array of float representing the portfolio weights.
- Refactors `BlackLittermanOptimizationPortfolioConstructionModel` and `MeanVarianceOptimizationPortfolioConstructionModel` to use the portfolio optimizers. Part of the logic in BLOPC was changed to match the MVOPC one.
- Adds `BlackLittermanPortfolioOptimizationFrameworkAlgorithm` similar to `MeanVarianceOptimizationFrameworkAlgorithm` that uses BLOPC.
2018-07-20 23:09:48 +01:00
AlexCatarino ada48acfde Implements IPortfolioOptimizer interface
Provides an interface to portfolio optimization algorithms that can be used in portfolio construction models.
2018-07-20 22:28:42 +01:00
AlexCatarino 3252b60b39 Fixs typo in EqualWeightingPortfolioConstructionModel.py 2018-07-19 16:38:26 +01:00
AlexCatarino cfcc387f7f Fixes Div by Zero exceptions in framework models 2018-07-19 15:05:05 +01:00
David d7fc6ead84 Fixed missing override from HistoricalReturnsAlphaModel 2018-07-18 22:20:37 +01:00
AlexCatarino 8e3b7153b2 Rebase with pythonnet/master and fix datetime UTC bug
Updates pythonnet with pythonnet/master and fix datetime issue ([65ac279](https://github.com/QuantConnect/pythonnet/commit/65ac279a03dbded39fe3e28bb79c233f0c970f6f)).
2018-07-16 11:52:54 +01:00
AlexCatarino 19502cc40b Adds support to multi asset type pairs
Securities from different types may have different timezones. In this case, daily resolution data is split in two slices in a history request, so these slices are grouped together to determined whether we have data from all the symbols in the same date.
2018-07-12 15:17:21 +01:00
AlexCatarino 009a136be3 Adds minimum correlation requiment to accept a candidate pair 2018-07-11 23:40:30 +01:00
AlexCatarino c59ff47ed7 Refactors PearsonCorrelationPairsTradingAlphaModelFrameworkAlgorithm
- Moves `PearsonCorrelationPairsTradingAlphaModel` class to its own file in order to make it available as a framework model.
- Follows existing pattern design that alpha models receive a lookback and a `Resolution` object.
- Algorithm implements `IRegressionAlgorithmDefinition`.
2018-07-11 23:40:30 +01:00