Commit Graph

309 Commits

Author SHA1 Message Date
AlexCatarino c820ad4c36 Adds python version of C# execution models
- Typoes were fixed in `ImmediateExecutionModel.cs`;
- Refactors `PriceIsFavorable` methods in `StandardDeviationExecutionModel` and `VolumeWeightedAveragePriceExecutionModel` C# models;
- Adds python version of C# execution models
2018-04-19 11:52:10 +01:00
AlexCatarino 95d8bee73e Adds constructor overload to CompositeAlphaModel that accepts python objects 2018-04-19 11:29:15 +01:00
AlexCatarino 7c6cc4e1dd Refactors AlphaModelPythonWrapper.Name
The cleanest way to get a python type name, when we know it is an instance of a class, is getting the value of the  `__class__.__name__` attribute.

- Changes `CommonAlphaModelTests.ModelNameTest`:
  Since it requires some string manipulation to have the exact model name for C# and Python, we don't define `Name` in the python models and accept the default value from `AlphaModelPythonWrapper.Name`.
2018-04-19 11:28:06 +01:00
AlexCatarino dc273f3da9 Fixes RsiAlphaModel.py typo
In the static method `Insight.Price`, `.Price` was missing.
2018-04-18 20:12:52 +01:00
Michael Handschuh 1b8a5846a7 Fix risk adjusted targets debug logging
This was always logging, even when the risk model wasn't overriding
any of the targets. The new check checks to see if the risk model
created any override targets, and if so, we'll print all of the
targets as they will be submitted to the execution model.
2018-04-18 10:36:15 -04:00
Michael Handschuh f47c700746 Add CompositeAlphaModel
The composite model combines multiple alpha models into a singular model and
properly sets each insight's SourceModel property to the name of the model that
generated the insight
2018-04-17 16:50:24 -04:00
Michael Handschuh 90d54da87c Add INamedModel and implement in existing alpha models
Alpha models can choose to implement the Name property, if not, the system
will use the model's type name as the Insight.SourceModel.
Existing tests were updated to also assert expected model names
2018-04-17 16:50:16 -04:00
Michael Handschuh c3c6a9aff8 Add Insight.SourceModel
This identifier is used to determine the alpha model that generated.
This is NOT ideal, since it requires users to specify the value, more
thought will be givent to how we can resolve this value automatically

Adds test for surviving roundtrip copy operation.
2018-04-17 16:36:47 -04:00
AlexCatarino df698d1925 Adds constructor overloads with PyObject parameter to UniverseSelectionModel
The PyObject parameter is converted into selector function of `Func<T1,T2>` type so that the model can user universe selector methods defined in python algorithms.
2018-04-12 17:09:03 +01:00
Jared 258cb60d93 Merge pull request #1805 from AlexCatarino/feature-1798-python-alpha-models
Adds python versions of available Alpha Models
2018-04-11 14:22:53 -04:00
Jared c8ce15c749 Fix missing constructor arg 2018-04-11 14:07:26 -04:00
AlexCatarino f437db8833 Fixes C# MacdAlphaModel
MACD was created with a helper method and registered for automatic updates, where we should use the constructor.
2018-04-11 11:17:44 +01:00
AlexCatarino 58493a2f21 Updates python version Lean AlphaModels to reflect API changes
Refactors unit tests.
2018-04-11 11:16:04 +01:00
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