Commit Graph

63 Commits

Author SHA1 Message Date
Jared a2a63ae058 Merge pull request #3016 from QuantConnect/feature-3015-add-weight-to-insights
Add Insight optional Weight
2019-06-04 16:52:48 -07:00
Martin Molinero e294b3c3e2 Fix overflow exception
- Adding new `AlgorithmSettings` Min and Max absolute portfolio target
percentage
- Adding new `PortfolioConstructionModel.FilterInvalidInsightMagnitude()`
helper method that will be used by the `BlackLitterman` and
`MeanVariance` optiomization portfolio construction models to skip
insights with extreme magnitudes that will cause exceptions
- `PortfolioTarget.Percentage()` will now verify requested percent is
withing the settings values
2019-05-23 20:30:44 -03:00
Martin Molinero e21a8fec35 Address review, use inheritance
- New InsightWeightingPortfolioConstructionModel will inherit from EqualWeightingPortfolioConstructionModel
2019-04-24 11:05:15 -03:00
Martin Molinero 39ae3c6970 Addressing reviews
- Adding two new unit tests: 0 weight insight and null weight insight
- Fix bug in python `InsightWeightingPortfolioConstructionModel`
2019-04-24 11:05:14 -03:00
Martin Molinero 968adcea32 Adding InsightWeightingPortfolioConstructionModel
- Adding new `InsightWeightingPortfolioConstructionModel` that will
generate percent `Targets` based on the latest active `Insight` `Weight` per
`Symbol`.
   - Will ignore `Insights` that have no `Weight`.
   - If the sum of all the last active `Insight` per `Symbol` is bigger than 1, it
will factor down each target percent holdings proportionally so the sum is 1.
- Adding unit tests
- Adding a new regression test framework algorithm
- Note most of the code, including tests, are reused from the
`EqualWeightingPortfolioConstructionModel`
2019-04-24 11:05:14 -03:00
Martin Molinero cfa08a11fb Address reviews
- Removing `using QCAlgorithmFramework = QuantConnect.Algorithm.QCAlgorithm`
- Removing `QCAlgorithmFrameworkBridge`
- Removing `IsFrameworkAlgorithm`
- Making `EmitInsightBasedOnFill` private. Adding new
`IOrderEventProvider` exposing an `event` to which `QCAlgorithm` will
subscribe.
- `AccountType.Cash` algorithms will be allowed to manually trade and
emight insights manually or with alpha model.
2019-04-03 21:55:44 -03:00
Martin Molinero 19f1806ddc Address review: readd Framework project 2019-04-03 21:55:43 -03:00
Martin Molinero 32ac3146b4 Merge Framework and Classic Algorithms
- Merging Framework and Bridge algorithms into classic QCAlgorithm
class.
- Removing Framework project, VS17 and VS15
2019-04-03 21:54:32 -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
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 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
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 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
Jing Wu f94710df6d Fix the bug of empty views from alpha models thorw the error 2018-06-19 16:59:39 -04:00
AlexCatarino 617341b01f Do not consider expired insights 2018-05-28 12:47:06 +01:00
AlexCatarino 595700e340 Fixes EqualWeightingPortfolioConstructionModel logic
`EqualEeightingPortfolioConstructionModel` (C# and Python) allocates all cash to the stocks who have insights in universe.
- Fixes regression tests to reflect the model logic change
- Fixes imports in python algorithms to use python models when available
2018-05-28 12:47:06 +01:00
AlexCatarino ab59c6970a Python portfolio construction models subclass C# PortfolioConstructionModel 2018-05-15 20:53:12 +01:00
AlexCatarino efb75a9e30 Implements python version of NullPortfolioConstructionModel 2018-05-15 12:13:41 +01:00
Michael Handschuh 2c0f9a580a Add base class for portoflio construction models
Update existing models to derive from new base class
2018-05-11 01:50:45 -04:00
Michael Handschuh 1e2e9cf11e Make portfolio construction models overrideable 2018-05-07 16:13:10 -04:00
AlexCatarino 7f2902eee2 Implements python version of EqualWeightingPortfolioConstructionModel 2018-05-03 21:50:11 +01:00
AlexCatarino 6e1d113922 Minor models fixes
- ConstantAlphaModel.py: sets default value `None` for magnitude and confidence
- BlackLittermanPortfolioConstructionModel.py: removes logging.
2018-05-03 21:50:11 +01:00
AlexCatarino fd461ed252 Refactors python framework models to avoid using generator
We are not using python lists instead of generator (yield) because we get better exception information in this case. The aim is to lead users to avoid using generators and/or know its limitations.
2018-04-26 19:31:11 +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
Jing Wu 4d649447e7 add black litterman portfolio construction model 2018-04-25 09:34:48 -04:00
Michael Handschuh 41a6e582f3 Convert framework model parameters to use arrays
Arrays make for easier consumption in python algorithms
2018-04-10 19:24:35 -04:00
Jared f32f351a4d Merge pull request #1832 from AlexCatarino/feature-1798-adds-meanvariancemodel
Implements MeanVarianceOptimizationAlgorithm
2018-04-08 20:27:17 -04:00
Michael Handschuh 92c5e64024 Adds VWAP and STD execution models
VWAP will submit market orders while the current price is more favorable than VWAP.
STD will submit market orders while the current price is a configured number of
standard deviations away from the mean in the favorable direction.
2018-04-06 16:30:26 -04:00
AlexCatarino a73cf3e328 Fixes HistoricalReturnsAlphaModel and MeanVarianceOptimizationPortfolioConstructionModel
Those models were not handling security removal properly. Once a security is removed, consolidators need to be removed.
2018-04-06 19:44:15 +01:00
AlexCatarino 133d2cd461 Implements peer-review requests
1. `HistoricalReturnsAlphaModel`:
   1. Adds lookback period for return calculation
   2. Adds return-depend direction to insights
   3. Refactors indicator history warm-up
2. `MeanVarianceOptimizationPortfolioConstructionModel`:
   1. Adds lookback period for return calculation
   2. Adds exception for null magnitude
   3. Refactors indicator history warm-up
3. Other minor fixes:
   1. Default target return was 2 instead of 0.02 (2%)
   2. Proper removal of consolidator subscriptions
2018-04-06 00:28:05 +01:00
AlexCatarino 92238a02fc Implements MeanVarianceOptimizationAlgorithm
This framework algorithm alpha model is  HistoricalReturnsAlphaModel and the  portfolio construction model is MeanVarianceOptimizationPortfolioConstructionModel.
This examples implements an algorithm that rebalances the portfolio according to modern portfolio theory.
2018-04-06 00:28:05 +01:00
Jing Wu 7d7ae4464a remove unnecessary insight direction in target percent 2018-04-06 00:28:04 +01:00
Jing Wu d31bcac5d5 minor bug imporovement 2018-04-06 00:28:04 +01:00
Jing Wu cd32f955de add mean variance optimization portfolio construction model 2018-04-06 00:28:04 +01:00