Commit Graph

34 Commits

Author SHA1 Message Date
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 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
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 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
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 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 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
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
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 b07928bd58 Properly account for market hours in alpha prediction periods
If we make a prediction for 1 day in the future, we actually mean 1 trading day.
This change updates the alpha analysis logic to take into account the security's
market hours.
2017-12-28 11:27:41 -05:00
Michael Handschuh 8e776a9fb5 Make QCAlgorithmFramework abstract
This simplifies things when loading algorithms.
2017-12-17 17:00:24 -05:00
Michael Handschuh b4b3aae112 Rename Signal -> Alpha
Whoa... I think I got everything :)
2017-12-15 18:24:58 -05:00
Michael Handschuh ac23fade5c Mark QCAlgorithmFramework overrides as sealed
This is to prevent derived types from overriding these implementation as
they're critical to the proper function of the class. This removes the
existing reflection checks that would accomplish the same thing, but at
runtime instead of compile time.
2017-12-14 19:43:26 -05:00
Michael Handschuh d8ef289c9b Add IAlgorithm.IsFrameworkAlgorithm and BacktestingResut.IsFrameworkAlgorithm
Flag indicates whether or not the algorithm is a framework algorithm.
2017-12-14 19:43:26 -05:00
Michael Handschuh 36311be93f Remove ISignal, add Signal.GeneratedTimeUtc
This abstraction point is completely unwarranted. The signal object is really
just a DTO and it's extensible as it is currently defined. This also allows us
to enforce certain behaviors, such as internal set of GeneratedTimeUtc.

Removes GeneratedTimeUtc from the result object as it's now directly on the signal.
2017-12-12 11:57:03 -05:00
Michael Handschuh 39f5080a40 Rename framework events to OnFramework<Event>
This more closely follows existing conventions.
2017-12-08 12:04:53 -05:00
Michael Handschuh 791799bf52 Fire SignalsGenerated only if there are any signals
Was previously firing on every time step, check to ensure we've actually generated
signals before firing the event.
2017-12-08 10:07:54 -05:00
Michael Handschuh c093b45319 Add IAlgorithm.SignalsGenerated event
This event will fire each time step that generates signals and will
include all signals generated by the algorithm at that time step.
2017-12-08 10:07:54 -05:00
Michael Handschuh dac63225cf Set default executon and risk management models 2017-12-08 10:07:54 -05:00
Michael Handschuh 14a2a09581 Add explicit methods for updating framework models
IAlgorithm.FrameworkOnData is used to pulse models with new data each time step
IAlgorithm.FrameworkOnSecuritiesChanged is used to pulse models with security changes

These two functions need to be separate to ensure that if we add an indicator during
the securities changed event that it will get the data from the current time step.
This forces us to call the securities changed event before we invoke the consolidators
for the current time step.
2017-12-08 10:07:54 -05:00
Michael Handschuh b8f6afe4e8 Add model setter methods 2017-12-08 10:07:54 -05:00
Michael Handschuh 755dcb30ab Add IRiskManagementModel
The risk management model is intended to check the algorithm's positions
at the end of each time step to potentially exit positions that are losing
too much.
2017-12-08 10:07:54 -05:00
Michael Handschuh ae422bb6c2 Check algorithm framework models for null
Framework algorithms are expected to set these models. All of these models
should be user specified. The execution model could be defaulted to the immediate
model, but perhaps it's best that users are explicit
2017-12-08 10:07:54 -05:00
Michael Handschuh 7076928904 Add IExecutionModel
The execution model is responsible for executing trades to achieve the desired
portfolio targets
2017-12-08 10:07:54 -05:00
Michael Handschuh 343bbf2c59 Add IPortfolioConstructionModel
The portoflio construction model generates portoflio targets from signals
2017-12-08 10:07:53 -05:00
Michael Handschuh 514434692b Add ISignalModel
This change includes a check to prevent users from overriding methods  required
by the framework. This is non-ideal and we should perhaps look into alternatives
to this approach, which could involve additional methods on IAlgorithm. In order
to not lose access to these events at the algorithm level, we could expose them
as C# events (not sure python compatibility?)
2017-12-08 10:07:53 -05:00
Michael Handschuh 0591d45db2 Add QCAlgorithmFramwork w/ IPortfolioSelectionModel
Adds a default implementation of IPortfolioSelectionModel that creates a
universe using the securities explicitly defined by the user.
2017-12-08 10:07:53 -05:00