Commit Graph

396 Commits

Author SHA1 Message Date
AlexCatarino 191d92b7ea Adds python version of RsiAlphaModel 2018-04-11 11:07:51 +01:00
AlexCatarino 5a23a18fb8 Adds python version of EmaCrossAlphaModel 2018-04-11 11:07:51 +01:00
AlexCatarino 35cb62d65a Adds python version of MacdAlphaModel 2018-04-11 11:07:51 +01:00
AlexCatarino 8325b77c07 Adds python version of ConstantAlphaModel 2018-04-11 11:07:51 +01:00
Michael Handschuh 3d7c49d6d2 Add targets parameter to IRiskManagementModel.ManageRisk
The current targets are passed into the risk model for risk assessment.
The risk model is only required to return any changes required from the
point of view of the risk model. The risk adjusted targets are given
priority, and if no risk adjusted target is specified for a symbol than
the target produced by porfolio construction will be used.
2018-04-10 19:38:17 -04:00
Michael Handschuh 3db242203e Add ScheduledUniverseSelectionModel
The ScheduledUniverseSelectionModel wraps the new ScheduledUniverse.
ScheduledUniverse is similar to the UserDefinedUniverse we use to create
universes for dopbox/remote files w/ symbol listing. The new abstraction
that 'turns on' this no-data/scheduled based universe behavior is the
ITimeTriggeredUniverse, which exposes GetTriggerTimes which yields the
date/times your univese selection function will be called.

A regression algorithm was also added to cover the new feature.
2018-04-10 19:24:36 -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
Michael Handschuh b63f148b54 Rename SetPortfolioSelection to SetUniverseSelection
This was missed in the rename of IPortfolioSelectionModel -> IUniverseSelectionModel
2018-04-10 16:55:31 -04:00
AlexCatarino bf1aa7fa4c Implements Insight.Price helper method.
Implements `Insight.Price` method to make it easier to create new instances of `Insight` of `InsightType.Price`.
Standardize the parameter order to `Symbol`, `TimeSpan`, `InsightType`, `InsightDirection`, `Double`, `Double`.
2018-04-10 19:49:29 +01:00
AlexCatarino a4db921b87 Updates pythonnet
Rebase with pythonnet/master
2018-04-09 18:59:59 +01: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 8e6c51148d Only log insights in debug mode
This was original added as debugging code before formally adding a
'DebugMode' flag for framework algorithms
2018-04-06 16:43:11 -04:00
Michael Handschuh 31bc9d0544 Add method to easily warmup indicators
Three methods were added to enable easier consumption of an enumerable
of slices returned from a history request. The dictionary version is
most likely to be used by python, while the functional versions allow
for lots of flexibility in how you'd like to consume the stream of slices.
2018-04-06 16:30:28 -04:00
Michael Handschuh 0b90c67f6f Warmup STD indicator in StandardDeviation exec model 2018-04-06 16:30:27 -04:00
Michael Handschuh 64349fea13 Remove cash modelling logic from OrderSizing.GetUnorderedQuantity
After much review, it was determined that this was much more confusing than it
was helpful. The removed implementation hinged on the thinking that the construction
model would be emitting targets as quantities of cash and not quantities of virtual
positions. A previous commit added a warning message for cash modelling and this
commit removes a (bad) attempt at making cash modelling work as expected. For now,
if you want to use cash modelling with the algorithm framework, careful thought will
need to be applied to the implementation of the portofio construction model AND the
execution model. They'll each need to be speaking on the same terms. As of this point,
we're unsure of a means to address all concerns, and so are leaving it as a warning
message coupled with decent documentation in the commit history regarding our
discussions/thoughts on the topics.

Again, the key for cash modelling working properly is just that the portfolio
construction model and the execution model agree on what each target means and
also agree on how virual positions vs currency balances are handled and managed.
2018-04-06 16:30:27 -04:00
Michael Handschuh 81ec10578f Emit warning message when using framework w/ cash modelling
Cash modelling poses several unique problems w.r.t the algorithm framework.
One constant issue is that our primary cash brokerage, GDAX, doesn't support
the concept of virtual positions. Another issue is the very concept of a
vitual position. In cash modelling, there are no virtual positions, just
currencies. In this model an issue is how do we phrase portfolio targets.
For example, if I emit a target of 10 BTC/USD but don't own an USD, what
does that mean? I might have millions of dollars of LTC, but since I don't
own any USD I won't be able to execute on BTC/USD. A smart algorithm might
sell some LTC for BTC instead. At this point, we're getting into the nitty
gritty of an individual algorithm and how that algorithm might transition
between various currencies. The framewor absolutely supports these types of
things, but it requires agreement between the portfolio construction model
and the execution model as to exactly what a target is describing. In the
margin world, a target on BTC/USD simply means to change your virtual
position in that currency pair, but in the cash world, I could see it meaning
a direct amount of BTC (or USD depending on target direction +/-).

TL;DR -- Add a warning describing potentially unexpected behavior with the
open source models as written.
2018-04-06 16:30:27 -04:00
Michael Handschuh f30709adf3 Add SecurityHolding.Target and check when removing from universe
When removing a security from a universe it's important to ensure that there
is not an outstanding portfolio target for that security that hasn't been
reached yet. A common pattern is (or should be) in the portfolio construction
model's OnSecuritiesChanged, emit a zero portfolio target for that security to
instruct the execution model to liquidate any holdings. Since the execution
model might not submit an order immediately, we need to be sure not to remove
the data subscription in UniverseSelection.ApplyUniverseSelection until we're
sure that the zero target has been reached.

In support of this, we've added the target to the security's holding class an
update it as part of the framework infrastructure. The universe selection
infrastructure can then query the security's current target to ensure that it
either doesn't have one (null) or that it is a zero target. This new condition,
coupled with the existing conditions (no holdings/no open orders) is sufficient
to guarantee that we're not removing security data subscriptions while they're
still needed by framework modules.

NOTE: This implementation was written under the assumption of using margin based
accounting and NOT cash modelling. We'll possibly need to revist these checks
when we move to fully support cash modelling within framework algorithms. The
next commit will prevent the VWAP/STD execution models from even attempting to
work under cash modelling.
2018-04-06 16:30:27 -04:00
Michael Handschuh 9221e954cd Remove securities after complete removal from universe
The execution models should maintain references to symbol data as long as
the security is a member of at least one universe. It's important to note
here that 'membership' in the universe is not the same as 'recently selected'
by the universe. A security remains a member even after it's been deselected
until it has zero holdings and zero open orders.

In the next commit we'll add an extra condition which will confirm that there
are also zero outstanding portfolio targets for the security.
2018-04-06 16:30:27 -04:00
Michael Handschuh 3b8c6124bc Improve readability of PriceIsFavorable
These methods were phrased in the negative sense. This change
reads how one would expect, if certain conditons are met, then
buy -- vs, if certain condition is not met, don't buy.
2018-04-06 16:30:26 -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
Michael Handschuh a443be7e6e Add QCAlgorithmFramework.DebugMode
Setting this to true enables logging of model inputs and
outputs. Be careful about your universe size, it can generate
a LOT of data
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 be0f553381 revert changes in project file 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
Michael Handschuh f11acf1246 Remove Insight.Equals
This method is misleading at best and incorrect at worst.
Insight objects should use reference equality or compare ids to
perform equality checking. The only usage, in MacdAlphaModel,
was easily converted to not relying on this method.
2018-04-03 23:32:34 -04:00
Michael Handschuh b40b873edb Set default ctor args for MaximumDrawdownPercentPerSecurity 2018-04-03 16:20:39 -04:00
Michael Handschuh a56d02e8a2 Set default values for MacdAlphaModel ctor args
Model constructor arguments changed to only accept MACD indicator parameters.
2018-04-03 16:20:38 -04:00
Michael Handschuh 82bbfde0be Define default values for EmaCrossAlphaModel
Model constructor arguments simplified to only contain EMA parameters.
2018-04-03 16:20:15 -04:00
Michael Handschuh 3895fa461a Remove RsiAlphaModel.Parameters, replace w/ ctor args
Model constructor arguments simplified to only contain RSI parameters.
2018-04-03 16:19:48 -04:00
Michael Handschuh b1ac56d63c Fix capitalization of QC acronyms 2018-03-29 15:30:05 -04:00
Michael Handschuh d87c121d4b Rename IPortfolioSelectionModel -> IUniverseSelectionModel 2018-03-29 12:18:44 -04:00
Michael Handschuh e73a3eb3db Update ManageRisk to return portfolio targets
These targets act as overrides and get sent into the execution model just
the same as the ones emitted from the construction model.
2018-03-27 17:48:22 -04:00
Michael Handschuh 6535409453 Zero portfolio targets when security removed from universe 2018-03-27 15:33:16 -04:00
Michael Handschuh f5656f6113 Add EmaCrossAlphaModel
Simple alpha model that uses a fast/slow ema cross to generate
a prediction.
2018-03-26 17:33:14 -04:00
Michael Handschuh c5704a1cd4 Rename SimplePortfolioConstructionModel -> EqualWeightingPortoflioConstructionModel
The simple name was too simple and too vague. Equal weighting nicely
describes the purpose and intent of this model
2018-03-26 17:33:13 -04:00
Michael Handschuh 64b9766685 Add RsiAlphaModel 2018-03-26 16:42:24 -04:00
Jared 20c6db9b01 Merge pull request #1763 from QuantConnect/bug-1762-manual-selection-add-symbols-to-symbolcache
Add entries to SymbolCache for ManualPortoflioSelectionModel symbols
2018-03-23 17:53:58 -04:00
Michael Handschuh 794c71bb55 Add entries to SymbolCache for ManualPortoflioSelectionModel symbols
This ensures similar behavior to using AddSecurity directly.
2018-03-23 17:07:37 -04:00
Michael Handschuh a7128ad0db Add QC500PortfolioSelectionModel 2018-03-23 15:10:39 -04:00
AlexCatarino b8cfbd7c24 Improves error message in python wrappers 2018-03-14 12:30:50 +00:00
AlexCatarino 35d29060d0 Implements python support for custom models in framework
Adds method overload that accept a `PyObject` to `SetAlpha`, `SetExecution`, `SetPortfolioConstruction`, `SetPortfolioSelection` and `SetRiskManagement`. In these methods, a custom model written in python will be wrapped around the respective `PythonWrapper`.
2018-03-13 11:35:31 +00:00
AlexCatarino 5d82c32040 Removes the abstract classifier of QCAlgorithmFramework
This change is required because pythonnet cannot initialize abstract types. Loader.cs was modified to avoid loading QCAlgorithmFramework type.
2018-03-12 22:42:42 +00:00
Michael Handschuh 6b239674e2 Renames Alpha -> Insight
The term 'alpha' is used to describe the entire algorithm. Therefore, 'alpha'
produces insights. From this we have things like IAlphaModel, which is the model
defining how insights are produced. We have IAlphaHandler, which defines how the
insights from a single 'alpha' (the algorithm) are managed, analyzed, and stored.
Types closer to the individual prediction level, such as InsightDirection, or
InsightScore relate directly to exactly 1 insight. The distinction between the
two became more clear as we developed the insights API, and from that effort it
was decided to harmonize alpha/insight terminology across the various QC systems.
2018-03-09 16:12:56 -05:00
Michael Handschuh 3f7b7702a4 Add Alpha.ReferenceValue
Gets the current value for the specified 'type'.
For example, this could be the price of the asset at the moment
the prediction was made.
2018-03-08 16:33:29 -05:00
Michael Handschuh 18a559943e Upgrade LEAN Python to 3.6 from 2.7
- Adds log to display the python version the algorithm is using.
- Fixes python algorithms that were failing because of small subtleties
like leading zeroes.
- Updates pythonnet with a version compiled with python 3.6 flags

- Changes in DockerfileFoundation: we now use miniconda to manage the python
environment.
- Took the opportunity to add NTLK (#1349), Tensorforce (#1369) and
PyTorch/Pyro (#1385).
- Changes readme in Algorithm.Python to show steps to install miniconda
2018-02-23 15:09:06 -05:00
Stefano Raggi a39e6a8e28 Revert "Merge pull request #1526 from AlexCatarino/python3"
This reverts commit 2e523992d0, reversing
changes made to fa48fc23ea.
2018-02-14 16:03:12 +01:00