57 Commits

Author SHA1 Message Date
Jhonathan Abreu b8e49a94ad Python models conversion to PEP8 (#7969)
* Python models conversion to PEP8

* Python models conversion to PEP8

* Minor fix
2024-04-23 10:45:36 -04:00
Jhonathan Abreu 77591f90c7 PEP8 python algorithms conversion (#7950)
Benchmarks / build (push) Has been cancelled
API Tests / build (push) Has been cancelled
Python Virtual Environments / build (push) Has been cancelled
Build & Test Lean / build (push) Has been cancelled
Regression Tests / build (push) Has been cancelled
Report Generator Tests / build (push) Has been cancelled
Research Regression Tests / build (push) Has been cancelled
* PEP8 python algorithms conversion

* Fix: Get python or c# methods in PythonData as python wrapper

* Convert portfolio models to PEP8
2024-04-18 19:43:48 -03:00
Louis Szeto 279a306758 Update TrailingStopRiskManagementModel model to cancel insights (#7131)
Regression Tests / build (push) Has been cancelled
Benchmarks / build (push) Has been cancelled
Build & Test Lean / build (push) Has been cancelled
Research Regression Tests / build (push) Has been cancelled
Python Virtual Environments / build (push) Has been cancelled
* Update risk model to cancel insight

* Updates Regression Tests

---------

Co-authored-by: Alexandre Catarino <AlexCatarino@users.noreply.github.com>
2023-03-23 15:29:04 -03:00
Louis Szeto f684940a7c Update MaximumUnrealizedProfitPercentPerSecurity model to cancel insights (#7121)
* Update regression test

* Update model to expire insights

* Avoid remove insights

* Update regression test

* Use InsightManager Cancel to Expire All Insights

* Update CompositeRiskManagementModelFrameworkAlgorithm

This regression also depends on `MaximumUnrealizedProfitPercentPerSecurity` and `MaximumDrawdownPercentPerSecurity` but `MaximumDrawdownPercentPerSecurity` doesn't close positions.

---------

Co-authored-by: Alexandre Catarino <AlexCatarino@users.noreply.github.com>
2023-03-23 12:23:42 -03:00
Derek Melchin 9c92a67510 Update MaximumDrawdownPercentPortfolio model to cancel insights (#7105)
Regression Tests / build (push) Has been cancelled
Python Virtual Environments / build (push) Has been cancelled
Benchmarks / build (push) Has been cancelled
Build & Test Lean / build (push) Has been cancelled
Research Regression Tests / build (push) Has been cancelled
* Remove OnEndOfAlgorithm and update expected trades

* Update models to cancel insights

* Update expected results

There are 3 trades instead of 2 because the PCM does a rebalance

* Remove `Remove` method call

* Update to use the new `Cancel` method
2023-03-23 12:02:04 -03:00
Derek Melchin b401fde07e Update MaximumDrawdownPercentPerSecurity model to cancel insights (#7103)
Regression Tests / build (push) Has been cancelled
Benchmarks / build (push) Has been cancelled
Build & Test Lean / build (push) Has been cancelled
Research Regression Tests / build (push) Has been cancelled
Python Virtual Environments / build (push) Has been cancelled
* Remove OnEndOfAlgorithm and update expected trade count

* Update models to cancel insights

* Update expected results

* Remove `Remove` method call

* Update to use the new `Cancel` method
2023-03-23 11:11:27 -03:00
Derek Melchin 0fa2ea19bc Reset trailing stop model highwater mark upon security liquidation (#6724)
Regression Tests / build (push) Has been cancelled
Python Virtual Environments / build (push) Has been cancelled
Benchmarks / build (push) Has been cancelled
Build & Test Lean / build (push) Has been cancelled
Research Regression Tests / build (push) Has been cancelled
* Fix trailing stop reset

* Add regression algorithm
2022-11-07 17:46:46 -03:00
Jhonathan Abreu 69dd4fc638 Fixed bug for trailing stop model tracking original security price (#6356)
Regression Tests / build (push) Has been cancelled
Build & Test Lean / build (push) Has been cancelled
Research Regression Tests / build (push) Has been cancelled
* Reproduce TrailingStopRiskManagementModel bug with test case

* Fix TrailingStopRiskManagementModel to make it relative to max price

* Adapted old TrailingStopRiskManagementModel test to new implementation

* Fix TrailingStopRiskManagementModel Python version

* Fixed TrailingStopRiskFrameworkAlgorithm regression tests data

* Handling both long and short positions in TrailingStopRiskManagementModel

* Traking holdings value instead of unrealized profit in TrailingStopRiskManagementModel

* Checking for position side change in TrailingStopRiskManagementModel

* Handling immediate liquidation in TrailingStopRiskManagementModel
2022-05-26 19:50:54 -03:00
Martin-Molinero aaba566954 Alpha Streams Improvements. Python Imports (#5874)
Regression Tests / build (push) Has been cancelled
Build & Test Lean / build (push) Has been cancelled
* Order handling improvements

- Execution model will only trigger market order if they are above the
  minimum order margin portfolio percetage value
- SecurityCache.Reset is complete

* Python Import fixes

- Add regression test for ImmediateExecutionModel minimum order margin
  check
2021-08-24 11:15:48 -03:00
IlshatGaripov eccca2c029 Fix for Trailing Stop Risk Management Model (#5791)
Regression Tests / build (push) Has been cancelled
Build & Test Lean / build (push) Has been cancelled
* To fix the referenced issue

* Fixing up TrailingStopRiskManagementModel

* Fix-ups to address review

* Impl. tests + relevant improvements

* Minor logic improvement at first dictionary update

* Regression test small fix

* Adds explicit 'D' suffix for numbers in test case double arr

* Use integer values in test cases

* Removes failing testcases in MaximumDrawdownPercentPerSecurityTests (!) & renaming

* Revert "Removes failing testcases in MaximumDrawdownPercentPerSecurityTests (!) & renaming"

This reverts commit f9cd279f8cc5e9e1ede5b6f1eae5f4266b7dd295.

* Fix up for failing test cases
2021-08-20 15:14:36 -03:00
Marco Grassi e823dfdfb7 fix a typo, and remove all unnecessary semicolumns in Python (#5795)
Regression Tests / build (push) Has been cancelled
Build & Test Lean / build (push) Has been cancelled
2021-07-27 16:05:13 -03:00
Martin-Molinero 03f56481d4 Refactor python algorithm import (#5657)
Regression Tests / build (push) Has been cancelled
Build & Test Lean / build (push) Has been cancelled
* Python research import improvements

- Improve start.py for research env
- Remove unrequired imports

* Centralize algorithm imports

* Add regression test GH action

* Unit test python import clean up

* Join research and main imports

* More python import clean up

* Fix failing skipped regression algorithm
2021-06-15 19:06:06 -03:00
Louis Szeto 20e9fd7899 bug-#4846-Fail on restart investing after liquidation on MaximumDrawdownPercentPortfolio.py (#4847)
* Fail on restart investing after liquidation

I added a line so that the trailing high value could be rebalanced and the investment process won't be stop by high value always more than current value by drawdown percent.

* Update MaximumDrawdownPercentPortfolio.py

* Fix for MaximumDrawdownPercentPortfolio

- Fix C# MaximumDrawdownPercentPortfolio to reset portfolio value after
  liquidation. Only reset once we have actually adjusted some targets.
  Updating regression algorithms.

Co-authored-by: Martin Molinero <martin.molinero1@gmail.com>
2020-10-15 13:34:08 -03:00
Martin Molinero 4d108094e5 Implement QCAlgorithm.AddRiskManagement
- Implemention `QCAlgorithm.AddRiskManagement`
- Adding Py/C# regression test algoririthms
- Moving `CompositeRiskManagementModel` from `Framework` to `Algorithm`
project
2019-04-08 10:53:06 -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
AlexCatarino 00963aa07d Adds Check for Fundamental data in MaximumSectorExposureRiskModel
`MaximumSectorExposureRiskModel` needs `IndustryTemplateCode` which is only found in Equity data with Fundamental data. Thus, we check whether all active securities have such information.
2019-02-25 22:51:25 +00:00
AlexCatarino 25baaf179a Implements python version of TrailingStopRiskManagementModel
- Implements python version of `TrailingStopRiskManagementModel`
- Implements python version of `TrailingStopRiskFrameworkAlgorithm`
2018-11-07 15:50:40 +00:00
AlexCatarino 5389f9bf8b Implements python version of MaximumDrawdownPercentPortfolio
- Implements python version of `MaximumDrawdownPercentPortfolio`
- Implements python version of  `MaximumPortfolioDrawdownFrameworkAlgorithm`
2018-11-06 23:52:52 +00:00
AlexCatarino b20716a282 Adds python version CompositeRiskManagementModel
The C# version was supposed to handle python modules, but when they inherit from a C# module, pythonnet send them as C# objects. Consequently, they are not wrapped and cannot be used. The python version of `CompositeRiskManagementModel` solves the issue.

- Implements python version of `MaximumUnrealizedProfitPercentPerSecurity`

- Updates `CompositeRiskManagementModelFrameworkAlgorithm` in order to use python risk model.
2018-11-06 23:22:53 +00:00
AlexCatarino b89bc97d61 - Use ValidateImplementationOf method in RiskManagementModelPythonWrapper
- Use recently implemented `ValidateImplementationOf` extension method in `RiskManagementModelPythonWrapper`
2018-11-06 23:11:21 +00:00
Jared e3cd28cae3 Merge pull request #2643 from dd-w/feature/portfolio_max_drawdown
Feature: Maximum Portfolio Drawdown
2018-11-05 09:25:26 -08:00
David c35649b1b5 Add support for trailing portfolio stop loss 2018-11-04 08:41:38 +08:00
David f2aacb2645 Removed logging message 2018-10-29 08:57:54 +00:00
David b59550dd59 Initial TrailingStop implementation
Restructured


Update message


Added removal of trailing highs for unnecessary securities


Add logging message


Improvements


Rename


Add regression Algorithm


Changed to use TradeBar values instead of only current price


Cleaned msg layout


Update Regression test
2018-10-29 08:57:44 +00:00
David 879843c9a8 Refactored TotalDrawdownPercent() 2018-10-26 09:03:07 +01:00
David f41315cb69 Remove non-conforming features 2018-10-25 23:40:50 +01:00
David dfd8027715 Add regression algorithm - MaximumPortfolioDrawdownFrameworkAlgorithm 2018-10-25 00:03:57 +01:00
David 3b089af75a Added MaximumDrawdownPercentPortfolio Risk Management Model
Updates
2018-10-25 00:03:36 +01:00
Michael Handschuh 72327507ad Rename MaximumUnrealizedProfitPerSecurty->MaximumUnrealizedProfitPercentPerSecurity
While it is a long name, this aims to provide consistency with it's inverted
brethern, the MaximumDrawdownPercentPerSecurity risk model
2018-10-15 13:52:41 -04:00
Michael Handschuh 446e07aa56 Fix composition bug in CompositeRiskManagementModel
The CompositeRiskManagementModel aims to provide support for multiple
risk management models. In order to accomplish this, it must respect
the return values from each individual model. As previously written,
the composite model was allowing models run later to completely nuke
the targets produced by earlier models. This change performs the
composition of targets using the same technique as is used when over
laying the risk adjusted targets on top of the portfolio construction
model's targets. This approach gives preference, by symbol, to the
risk adjusted targets, but if there is no risk adjusted target, then
it uses the targets from the previous step. For example, if targets
for A, B, C, and D are produced by PCM, then risk model 1 adjusts to
zero targets for B and cuts the targets for C in half, these are then
piped to risk model 2 (A, C/2, D). Risk model 2 may return ZERO targets.
This doesn't mean we should remove all the targets, it simply means
that the risk model didn't adjust any and we should use the output
from risk model 1. Now, let's say risk model 2 zeroes out A and cuts
B in half again, the final result should (and now is) C/4, D. IOW,
risk models only return deltas, things to be changed, so returning
nothing means there are no changes.
2018-10-15 13:52:41 -04:00
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
David 76e5ae4784 Fix namespace 2018-10-08 22:11:07 +01: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
Stefano Raggi 5c9b81cef1 Fix Python initialization and imports for multiple tests 2018-10-02 20:28:13 +02:00
Stefano Raggi c6092648bd Update Python version of MaximumDrawdownPercentPerSecurity to be same as C# version 2018-08-02 12:51:27 +02:00
AlexCatarino cfcc387f7f Fixes Div by Zero exceptions in framework models 2018-07-19 15:05:05 +01:00
AlexCatarino 7bffd60c2d Minor framework fixes
- `NullExecutionModel.py`: return array instead of void
- `NullRiskManagementModel.cs`: inherit from base class instead of interface
2018-05-16 13:37:38 +01:00
AlexCatarino 97d6420e2a Python risk management models subclass C# RiskManagementModel
- Adds python version of `NullRiskManagementModel`
2018-05-15 20:52:13 +01:00
Michael Handschuh 2bb99a595b Add base class for risk management models
Update existing models to derive from new base class
2018-05-11 01:55:16 -04:00
Michael Handschuh d3d331f100 Make risk management models overrideable 2018-05-07 16:14:13 -04:00
AlexCatarino 6250ed900e Use UniverseManager.ActiveSecurities instead of Securities
Framework models should not loop over `algorithm.Securities` since it contains all securities that were ever added to the algorithm, but `UniverseManager.ActiveSecurities` that contains only the active securities.

Instances of `PortfolioTargetCollection` are intended to be a class level variables and not a method level variables. As a class member it maintains a complete set of all portfolio targets so you can operate against a 'full view' instead of the potentially streaming targets (which can come in one by one as alpha is generated).
2018-05-03 22:02:08 +01:00
AlexCatarino 182e8b46ad Implements MaximumSectorExposureRiskManagementModel
Provides an implementation of `IRiskManagementModel` that limits the sector exposure to the specified percentage
2018-05-03 21:50:11 +01:00
AlexCatarino d81de45772 Implements python version of MaximumDrawdownPercentPerSecurity. 2018-04-27 22:29:10 +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
Jared c8ce15c749 Fix missing constructor arg 2018-04-11 14:07:26 -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 b40b873edb Set default ctor args for MaximumDrawdownPercentPerSecurity 2018-04-03 16:20:39 -04:00