Compare commits

...

270 Commits
15780 ... 16294

Author SHA1 Message Date
Martin-Molinero
17ca8a743f Refactor universe historical data source (#7837)
* Refactor universe historical data source

- Add new universe history API methods
- Refactor QuantBook UniverseHistory to use the universe selection
  itself instead of a given func
- Refactor and rename fundamental types
- Refactor AddUniverse API to handle universe collection data which
  holds another type internally, like fundamental

* Fix minor bug causing ApiDataProvider not to serve Bitfinex universe data

* Further improvements to add universe API

* Handle no selection function
2024-03-12 13:41:49 -03:00
Roman Yavnikov
a98a50237b Helper: Method for Retrieving Historical Ticker Symbols (#7826)
* feat: helper to return old name of symbols
feat: test
refactor: test a little bit neat

* feat: SplitHistoryRequest() with different mapped symbol
feat: test
refactor: RetrieveSymbolHistoricalDefinitions

* refactor: split historyRequest by historical symbol name
refactor: change location of extension
refactor: change location of test extension

* revert: extra changes

* fix: validation on RequiresMapping in SplitHistoryRequest
feat: add Future Symbol tests

* move: extension method to another file

* fix: wrong extension call param position

* fix: wrong extension call param position in test

* refactor: IEnumerable foreach to more simple form
feat: add TickerDateRange struct instead of Tuple
fix: test

* refactor: map extension alway returns empty result

* refactor: SplitHistory extension returns original HistoryRequest

* feature: new extension for RequiresMapping except Futures

* fix: validation of symbol map file to contains something

* refactor: extension test cases

* feat: assert of right ticker in tests

* fix: split historical request with using Local Time instead of UTC
fix: test description

* feat: test helper IEnumerable of TimeZones

* test: validate right EndDate with different TimeZones

* remove: validation of end of date
test: several new test cases

* feat: additional test with specific dateTime

* remove: extra Extension method validation on future and mapping
2024-03-11 11:53:40 -03:00
Martin-Molinero
51b018c616 Update Kraken Symbol Properties (#7844)
* Update symbol-properties-database.csv

Added additional pair
Corrected the config for the SOLUSD pair

* Update Kraken SPDB

---------

Co-authored-by: t984375 <162788827+t984375@users.noreply.github.com>
2024-03-11 10:43:11 -03:00
Louis Szeto
c049a35121 Add Option Gamma, Vega, Theta, Rho Indicator (#7830)
* Add gamma indicator

* add helper method

* add unit tests

* add in regression tests

* Address peer review

* add vega indicator

* add theta and rho indicators

* Address peer review, refactor
2024-03-11 10:32:36 -03:00
Martin-Molinero
8c66e2e715 Update InsufficientBuyingPowerForAutomaticExerciseRegressionAlgorithm.cs 2024-03-07 12:22:08 -03:00
Martin-Molinero
bb3931d911 Update readme.md 2024-03-06 14:58:50 -03:00
Martin-Molinero
feff802479 Standardize trade count statistic (#7827)
* Standarize trade count statistic

* Rename 'Total Trades' to 'Total Orders'
2024-03-06 14:52:34 -03:00
Martin-Molinero
dcbb2d3cf8 Skip failing yahoo data downloader test (#7833) 2024-03-06 11:37:06 -03:00
Jhonathan Abreu
f298f6e21a Handle insufficient margin for option exercise (#7828)
* Handle insufficient margin for option exercise

* Minor change

* Minor changes
2024-03-05 15:39:30 -04:00
Jhonathan Abreu
ce197afe44 Populate order properties for option exercise orders (#7829)
* Populate order properties for option exercise orders

* Minor change

* Not setting broker id for options exercises

* Minor change
2024-03-05 14:19:06 -04:00
Jhonathan Abreu
637fe75b25 Update pythonnet version to 2.0.28 (#7821)
* Bumped pythonnet version to 2.0.27

* Update pythonnet version to 2.0.28
2024-03-05 11:30:40 -04:00
Louis Szeto
6bf2acd0da Allow smoothing in Implied Volatility and add forward tree model (#7820)
* Allow mirror contract and smoothing IV

* Python wrapper on smoothing IV

* helper method update

* Add forward tree model

* modify and add unit tests and data

* address peer review

* address peer review
2024-03-04 11:00:04 -03:00
Jhonathan Abreu
5e2957cbf0 Refactor config file enviroments to match brokerages namespaces (#7823)
* Refactor config file enviroments to match brokerages namespaces

* Use class name only for brokerages and DQH in config file
2024-02-29 14:36:06 -04:00
Martin-Molinero
78c3f81b96 Research configuration initialization improvement (#7825)
- Minor research configuration handling improvement on initialization,
  making sure we reload configs
2024-02-29 15:13:59 -03:00
Martin-Molinero
e500a6b466 QuantBook Initialization Order (#7822)
- QuantBook should first initialize the system handlers and later the
  algorithm handlers, like done by the engine
2024-02-28 17:07:11 -03:00
Martin-Molinero
b9ec218870 Update readme.md 2024-02-28 11:27:47 -03:00
Louis Szeto
e39cec40f5 Implement dividend yield model (#7758)
* dividend yield plug-in model interface

* dividend yield model python wrapper

* Implement symbol dividend yield models

* unit tests on dividend yield provider

* Update IV indicator

* IV indicator unit tests

* update Delta indicator

* Delta indicator unit tests

* update helper method

* Nit

* Address peer review

* Address 2nd peer review

* readability

* Regression tests

* dividend yield model

* Address review

* Fix unit tests

* Minor fix

* Fix tests

---------

Co-authored-by: Martin Molinero <martin.molinero1@gmail.com>
2024-02-27 12:39:46 -03:00
Ashutosh
ea5e4ac8d0 Update symbol-properties-database.csv (#7795)
* Update symbol-properties-database.csv

Updating Symbol properties database to reflect kraken API information.

#### Description
Updated the market_ticker column of Symbol properties database to reflect information as per Kraken API.

#### Related Issue
Close #7794

#### Motivation and Context
We updated symbol mapping for the Kraken market.

#### Requires Documentation Change
No

#### How Has This Been Tested?
<!--- Please describe in detail how you tested your changes. -->
<!--- Include details of your testing environment, and the tests you ran to -->
<!--- see how your change affects other areas of the code, etc. -->

#### Types of changes
<!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: -->
- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] Refactor (non-breaking change which improves implementation)
- [ ] Performance (non-breaking change which improves performance. Please add associated performance test and results)
- [X] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to change)
- [ ] Non-functional change (xml comments/documentation/etc)

#### Checklist:
<!--- The following is a checklist of items that MUST be completed before a PR is accepted -->
<!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! -->
- [X] My code follows the code style of this project.
- [X] I have read the **CONTRIBUTING** [document](https://github.com/QuantConnect/Lean/blob/master/CONTRIBUTING.md).
- [X] I have added tests to cover my changes. <!--- If not applicable, please explain why -->
- [X] All new and existing tests passed.
- [X] My branch follows the naming convention `bug-<issue#>-<description>` or `feature-<issue#>-<description>`

<!--- Template inspired by https://www.talater.com/open-source-templates/#/page/99 -->

* Update symbol-properties-database.csv

- Update as per peer review

* Correction
2024-02-27 10:45:34 -04:00
Martin-Molinero
1f975332c3 Update readme.md 2024-02-27 10:59:26 -03:00
Martin-Molinero
aa6b909a93 Update readme.md 2024-02-27 10:29:38 -03:00
Will Tindall
9cfd8b7403 Implement Risk Metrics: Value At Risk (#7757)
* Implement VaR in PortfolioStatistics

* Added ValueAtRisk indicator

* Refactored ValueAtRiskTests

* Added returns column to test data

* Change indicator helper method name

* Addressed comments
2024-02-26 11:02:20 -03:00
Pronoy Chowdhury
fec27a56ce Chande Variable Index Dynamic Average (VIDYA) Indicator (#7797)
* Chande Variable Index Dynamic Average (VIDYA) Indicator

* Improvements

* Improvements

* Final Changes

* Editted, Retested

* Comments

* Minor Corrections

* Updated Datetime Format of test data to US Standards

---------

Co-authored-by: Pronoy Chowdhury <rokstarr.dbz@outlook.com>
2024-02-26 10:55:01 -03:00
Roman Yavnikov
e96c08e208 feat: downloader data provider returning null (#7812) 2024-02-23 15:45:47 -03:00
Jhonathan Abreu
d942d58717 Add null check for history in lean data writer (#7814) 2024-02-23 15:45:35 -03:00
Martin-Molinero
387eae9e73 Update readme.md 2024-02-21 18:16:53 -03:00
Martin-Molinero
7e61483ad7 Adjust API tests to fetch creds from globals (#7806) 2024-02-21 17:53:46 -03:00
Martin-Molinero
8595aff670 Handle history provider returning null (#7804) 2024-02-21 15:44:22 -03:00
Martin-Molinero
e375afbe20 Dynamically setup brokerage history provider wrapper (#7802) 2024-02-21 12:03:31 -03:00
Martin-Molinero
1a1f64e7a6 Update readme.md 2024-02-21 10:09:16 -03:00
Martin-Molinero
2e9c7ade2c Initialize report correctly (#7803)
- Fix report initialization, adding CI tests
2024-02-21 10:02:43 -03:00
Jhonathan Abreu
d3928fba6b Manual option contract addition for delisted underlyings error (#7799)
* Throw when trying to add option contracts for delisted underlyings

* Minor change
2024-02-21 09:02:07 -04:00
Jhonathan Abreu
09db45c91d Universes immediate selection (#7785)
* Make sure continuous futures universe selection is performed right away on the start of the algorithm.

This ensures the Future.Mapped is not null

* Minor changes

* Minor fixes

* Update regression algorithms stats

* Add DC futures map file

* Update DC futures map file

* Update regression algorithms stats

* Include ETFs for immediate universe selection

* Include Coarse Fundamentals for immediate universe selection

* Include Futures Chain Universe for immediate selection

* Add Option Chain Universe test

* Include custom universes for immediate selection

* Minor updates

* Include constituents universes for immediate selection

* Minor update

* Minor changes, docs and stats updates

* Minor changes

* Minor changes and clean up

* Minor regression algorithm stat update
2024-02-21 08:59:58 -04:00
Ricardo Andrés Marino Rojas
64fe4ba13b Update LinearWeightedMovingAverage (#7798)
* Add improvements and unit tests

* Add Improvements
2024-02-20 16:51:06 -03:00
Martin-Molinero
2a82c6f9bb Consolidate Configuration.Get usages (#7796) 2024-02-20 13:37:22 -03:00
Ricardo Andrés Marino Rojas
6f6fbee6ee Handle DivisionByZero exception in indicators (#7788)
* Solve bug and add indicator unit test

* Nit change

* Add more checks

* Improve solution

* Nit change

* Solve bugs

* Improve implementation

* Nit change
2024-02-19 16:02:51 -03:00
Martin-Molinero
67b9ecf391 Minor config tweaks (#7792) 2024-02-19 12:05:00 -03:00
Ricardo Andrés Marino Rojas
0e81589efa Bug add future option ozn (#7791)
* Models OZN: 10-Year US Treasury Future Options

<!--- Provide a general summary of your changes in the Title above -->

#### Description
We added future option for OZN

#### Related Issue
Close #7783
<!--- This project only accepts pull requests related to open issues -->
<!--- If suggesting a new feature or change, please discuss it in an issue first -->
<!--- If fixing a bug, there should be an issue describing it with steps to reproduce -->
<!--- Please link to the issue here: -->

#### Motivation and Context
 We added future option supported by CME
https://www.cmegroup.com/markets/interest-rates/us-treasury/10-year-us-treasury-note.contractSpecs.options.html#optionProductId=317

#### Requires Documentation Change
No

#### How Has This Been Tested?
I tested the change using fake files to check if mapping is correct.

#### Types of changes
<!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: -->
- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] Refactor (non-breaking change which improves implementation)
- [ ] Performance (non-breaking change which improves performance. Please add associated performance test and results)
- [X] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to change)
- [ ] Non-functional change (xml comments/documentation/etc)

#### Checklist:
<!--- The following is a checklist of items that MUST be completed before a PR is accepted -->
<!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! -->
- [X] My code follows the code style of this project.
- [X] I have read the **CONTRIBUTING** [document](https://github.com/QuantConnect/Lean/blob/master/CONTRIBUTING.md).
- [X] I have added tests to cover my changes. <!--- If not applicable, please explain why -->
- [X] All new and existing tests passed.
- [X] My branch follows the naming convention `bug-<issue#>-<description>` or `feature-<issue#>-<description>`

<!--- Template inspired by https://www.talater.com/open-source-templates/#/page/99 -->

* Add unit tests

---------

Co-authored-by: Ashutosh <ashutoshrana171@gmail.com>
2024-02-16 19:13:04 -03:00
Martin-Molinero
07dbfc42a5 Improve consolidator scan (#7789)
* Improve consolidator scan

- Improve consolidator scan to be triggered even if no data is present.
  Adding new regression test, updating existing

* Adding more tests & minor tweaks
2024-02-16 17:22:49 -03:00
Martin-Molinero
ea15e014e2 Live delisting handled (#7774)
- Adjust live equity delisting to be map files based like splits and
  dividends. Adding unit test
- Expand existing unit tests asserting delistings in live mode, set
  securities to not tradable
2024-02-16 16:56:42 -03:00
Martin-Molinero
d602e260b4 Update readme.md 2024-02-13 12:28:20 -03:00
Martin-Molinero
e31a898269 Update readme.md 2024-02-13 11:16:48 -03:00
Roman Yavnikov
1dd186acb4 CoinApi Extraction: Removing from Lean.ToolBox (#7777)
* feat: remove CoinApi realization from ToolBox

* fix: ComposeDataQueueHandlerInstances
we have removed all IDataQueueHandler from ToolBox
2024-02-13 10:40:30 -03:00
Ricardo Andrés Marino Rojas
330946785f Add improvement (#7778) 2024-02-13 10:40:15 -03:00
Jhonathan Abreu
48ce5ef88d Refactor API projects test to avoid leaving created projects in account (#7773) 2024-02-08 17:24:49 -03:00
Martin-Molinero
76a0bdd769 Fix scatter chart point serialization (#7772)
- Fix scatter chart point sometimes being serialized as an array. Adding
  unit test
2024-02-08 15:36:38 -03:00
Ricardo Andrés Marino Rojas
b7740edd15 Solve bug and add unit tests (#7767) 2024-02-07 17:51:28 -03:00
Ricardo Andrés Marino Rojas
0264d346e6 Add obsolete flag (#7768) 2024-02-07 17:50:03 -03:00
Ricardo Andrés Marino Rojas
f59a6be589 Add Python version of AllShortableSymbolsCoarseSelectionRegressionAlgorithm.cs (#7766)
* Add Python version

* Improve implementation

* Improve implementation
2024-02-07 11:46:48 -03:00
Ricardo Andrés Marino Rojas
a5b309ae23 Add CSharp version of BasicTemplateOptionsConsolidationAlgorithm (#7756)
* Add CSharp version

* Nit change
2024-02-07 11:46:41 -03:00
Martin-Molinero
3d673d6de1 RefreshEnumerator retry on stale file exception (#7764)
- The refresh enumerator will retry on stale file handle exception.
  Adding unit test
2024-02-06 19:26:59 -03:00
Martin-Molinero
fdb8c20a1a Update readme.md 2024-02-06 18:02:51 -03:00
Martin-Molinero
6fe368106a Obsolete VAR for V instead (#7763) 2024-02-06 17:50:20 -03:00
Martin-Molinero
379e2d3405 Add optional PositionSide for TerminalLink (#7762)
* Add optional PositionSide for TerminalLink

* Minor rename
2024-02-06 16:08:24 -03:00
Ricardo Andrés Marino Rojas
711a7b42d4 Add missing constructor in OptionChainedUniverseSelectionModel (#7741)
* Solve bug and add regression tests

* Add regression stats

* Improve regression algo

* Improve regression algos
2024-02-05 15:56:29 -03:00
Martin-Molinero
3fef33fbf4 Rename Daily Performance Index Name (#7752) 2024-02-05 15:42:35 -03:00
Ricardo Andrés Marino Rojas
32d39622c0 Solve division by zero bug in AccelerationBands Indicator (#7743)
* Solve bug and add unit test

* Nit change

* Nit change
2024-02-05 15:14:45 -03:00
Roman Yavnikov
d3877c8ea9 remove: AlphaVantage from ToolBox (#7751) 2024-02-05 15:13:38 -03:00
Martin-Molinero
2097a3f392 Handle a DQH failure (#7750)
- Handle IDQH failure as a runtime error. Added unit tests
2024-02-05 15:13:08 -03:00
Jhonathan Abreu
98a3fd4306 Delayed Settlement Cash Not Freed for Removed Assets (#7727)
* Delay security removal when there are pending settlements

* Add unit test

* Minor fixes

* Minor fix

* Replace HasUnsettledFunds method with UnsettledCash in ISettlementModel

* Minor fix

* Minor fix

* Address peer review

Replace ISettlementModel UnsettledCash property with GetUnsettledCash method that returns a CashAmount instead of a decimal to include the currency

* Minor fix

* Address peer review
2024-02-05 15:12:51 -03:00
Martin-Molinero
ef728bc91f Update readme.md 2024-02-02 20:37:39 -03:00
Martin-Molinero
1c973d12a5 Minor chart improvements (#7744)
* Minor chart improvements

- Add base series tooltip template. Adding unit tests
- Reduce null chart points to a single addition

* Add null values always

* Fixes & minor tweaks

* Serialize ChartPoint as array
2024-02-02 17:27:37 -03:00
Jhonathan Abreu
8b804c4eca Add new EnablePositionSide terminal link order property (#7747) 2024-02-02 16:20:59 -04:00
Jhonathan Abreu
701a4672c5 Make sure universe selection methods can return symbol Ids (#7745) 2024-02-02 15:47:52 -04:00
Martin-Molinero
63cff706e4 Update readme.md 2024-02-01 19:14:54 -03:00
Martin-Molinero
6828e164e0 Update readme.md 2024-02-01 18:38:22 -03:00
Martin-Molinero
7705895cc6 Portfolio margin chart (#7719)
* Portfolio state chart

- Cleanup and renames
- Add series.IndexName. Uodating unit tests
- Add Chart.LegendDisabled. Adding new unit tests
- Add ChartPoint.Tooltip. Updating unit tests
- Minor compression tweak. Adding unit test
- Add ChartJsonConverter. Adding unit tests

* Minor chart serialization order tweak

* Refactor portfolio state sampling and storing

* Move PortfolioMargin into a lean side chart
2024-02-01 12:43:08 -03:00
Jhonathan Abreu
4262bb9152 Refactor API project tests (#7738)
Avoiding leaving undeleted projects in the account used for testing
2024-01-31 19:12:18 -03:00
Martin-Molinero
645aa73e8e Fix tags deserialization (#7736)
- Fix tags deserialization, adding unit test
2024-01-30 19:50:11 -03:00
Jhonathan Abreu
d4ba8ccead Backtest self-categorization (#7683)
* Implement backtest self-naming and self-tagging

* Minor unit test fix

* Minor api changes

* Minor changes

* Send packet messages when algorithm's name or tags are updated

* Minor fixes

* Address peer review

* Backtest name and tags API calls

Plus, first version of CI for API tests

* Add endpoint to update a backtest set of tags

* Minor GH actions change

* Address peer review

* Add algorithm naming and tagging unit tests

* Minor backtest API changes
2024-01-30 14:59:08 -03:00
Ricardo Andrés Marino Rojas
6f29130221 Add headers to http client (#7735) 2024-01-30 13:31:08 -03:00
Roman Yavnikov
4c88e3184c IEX Extraction: Removing from Lean.ToolBox (#7734)
* remove: ToolBox\IEX

* revert: IEX config in config.json
remove: IEX downloader param in toolboxParse
2024-01-30 09:50:36 -03:00
Ashutosh
3f6a907485 Models All Index Futures Listed in CME (#7722)
* Models All Index Futures Listed in CME

We added:
NIY, ENY, FT1, FT5, E3G, FTU, TPD, TPY

* Models All Index Futures Listed in CME

We added international index futures:
NIY, ENY, FT5, FT1, E3G, FTU, TPD and TPY

* Remove unused imports

* Address peer review:
- Corrected serial contract logic
- Corrected minimum price fluctuation
- Corrected “Yen” to “JPY”

Added equity index futures:
RX, ESG, RS1 and SDA
2024-01-29 13:29:12 -03:00
Jhonathan Abreu
ec530d8e37 Introduce new OrderPosition enum (#7730) 2024-01-29 11:56:10 -04:00
Louis Szeto
3a10afeac5 Option Delta Indicator (#7704)
* Add base indicator for greeks

* Add option delta indicator

* Add helper method

* Add unit tests

* Address peer review

* Fix minor bugs

* Change OptionDelta into Delta

* rename helper method
2024-01-29 12:54:57 -03:00
Ricardo Andrés Marino Rojas
00e1cae16b Stop support of MOC orders for Options in IB Brokerage Model (#7725)
* Fix bug and add unit tests

* Improve implementation

* Improve implementation
2024-01-29 12:53:23 -03:00
Jhonathan Abreu
07ded61fe9 Fix currency formatting (#7723)
* Replace currency string formatting with Lean currency symbols.

Also clean up orders tags from having redundant information.

* Setting default order tag only after price currency is properly set

* Minor fixes and new unit tests

* Minor fixes
2024-01-25 12:20:05 -03:00
Ricardo Andrés Marino Rojas
0cd979f3bd Solve bug in ETFConstituentsUniverseSelectionModel (#7724)
* Fix bug in ETFConstituentUniverseSelectionModel()

The bug was raised after calling an overload constructor using just the
ticker as parameter. Since the universeFilterFunc was null, the method
Extensions.TryConvertToDelegate<T> returned true and thus, the filter
func assigned was the one returned by the method
`ConvertToUniverseSelectionSymbolDelegate()` which used the null
filterfunc.

* Handle potential future bugs
2024-01-25 11:32:04 -03:00
Ricardo Andrés Marino Rojas
3a9059ae4f Add into MHDB missing CME Futures early closes and late opens (#7718)
* Update MHDB

* Improve changes
2024-01-25 10:41:44 -03:00
Ricardo Andrés Marino Rojas
518ab562ec Fix bug in LiveTradingRealTimeHandler (#7696)
* Initial draft of the solution

* Add improvments

* nit changes

* Improve implementation

* Enhance unit tests

* Add one more unit test

* Fix failing tests and update MHDB

* Add requested changes

* Nit change

* Add tweaks to MarketHoursDatabase class

* Solve bug and add unit tests

* Update unit tests

* Address requested changes

* Handle potential bug

* Nit change

* Minor review

---------

Co-authored-by: Martin Molinero <martin.molinero1@gmail.com>
2024-01-24 11:59:09 -03:00
Roman Yavnikov
20a5f690f8 Update IQFeed Configuration and Remove Deprecated Parameter (#7717)
* fix: change wrong IQFeed config to new one

* remove: iqfeed param in leanArgumentParser
2024-01-24 10:24:26 -03:00
Nikolay Baraboshkin
17902e2f7d Update Binance currency pairs (#7693)
* Update Binance currency pairs

* list FDUSD as a stablecoin, fix tests
2024-01-23 17:56:00 -03:00
Jhonathan Abreu
9df4a397d5 Update Bybit symbols in SPDB (#7715) 2024-01-23 13:36:15 -03:00
Martin-Molinero
3a8a3dd27f Add support to unzip stream (#7713)
- Add support to unzip a stream. Adding unit test
2024-01-23 13:35:45 -03:00
Jhonathan Abreu
3dab2e42eb Handle/filter new brokerage-side orders (#7706)
* Handle/filter brokerage side orders

* Add unit tests

* Minor fix

* Add unrequested security for new brokerage-side orders

* Add unit test for algorithms overriding the brokerage message handler

* Add unit test for python algorithm overriding the brokerage message handler

* Minor change

* Address peer review
2024-01-23 12:01:03 -04:00
Jhonathan Abreu
1c93df8156 Merge early closes and late opens properly in MHDB. (#7712)
A more specific entry might contain some of the same early close/late open dates as the common entry but with different times. This makes sure this is handle and the more specific ones take precedence.
2024-01-22 14:45:43 -04:00
Ricardo Andrés Marino Rojas
580a043baf Add early closes for U.S. Indices in MHDB (#7707)
* Add Unit tests and early closes to MHDB

* Nit change

* Add missing early closes
2024-01-19 19:21:22 -03:00
Roman Yavnikov
6cb9164c7a remove: IQFeed mentions (#7705) 2024-01-19 12:17:46 -03:00
Will Tindall
ed9fb4a194 Add Unit Tests for IPortfolioOptimizer Classes (#7691)
* MaximumSharpeRatioPortfolioOptimizerTests

* MinimumVariancePortfolioOptimizerTests

* UnconstrainedMeanVariancePortfolioOptimizerTests

* Addressed comments

* Address comments v2

* Refactored tests with base test class. Added Python wrapper tests

Base test class and python wrapper tests
2024-01-19 12:14:05 -03:00
Louis Szeto
0b833b065e Implied Volatility Indicator for Options (#7680)
* Add IV indicator

* Fix bug

* Add QCAlgorithm helper method

* Add unit tests

* Add OptionPricingModelType, as option for greeks & IV estimation

* Nit, and fix bug

* Address peer review

* Fix bug

* Fix bug on CRR

* Ensure test indicator initiate correctly

* Address 2nd review

* Check for FOPs and index options as well

* Add comparison with QuantLib

* CRR not follow BSM

* minor bug fix
2024-01-18 13:50:49 -03:00
Martin-Molinero
8ec2c4beeb Update readme.md 2024-01-18 12:59:36 -03:00
Martin-Molinero
fa329a9d51 Minor brokerage setup handler message improvement (#7700) 2024-01-17 17:55:56 -03:00
Martin-Molinero
adfb594d93 Asset plot improvement (#7699)
* Asset plot improvement

- Add optional symbol for chart instance, to create an asset plot
- Fix Order PriceAdjustmentModel deserialization. Updating unit test

* Add series ZIndex. Adding unit test

* Fix clone, adding more tests
2024-01-17 14:46:45 -03:00
Roman Yavnikov
1eaf4d6ae0 Flexible trading days per year property (#7690)
* feat: new `TradingDaysPerYear` prop in IAlgorithmSettings

* feat: getTradingDayPerYear by BrokerageModel
feat: init algo tradingDaysPerYear in brokerage|BacktestingSetupHandler
refactor: nullable `TradingDayPerYear`

* remove: hardcoded value:252 in statistics

* test: `algorithm.Settings.TradingDaysPerYear` for different brokerage
fix: tests calculation of `AnnualPerformance()`

* fix: Report generator by tradingDayPerYear

* fix: hardcoded value in PortfolioStatisticsTests

* fix: tradingDayPerYear in AnnualPerformanceTest
remove: extra spacing

* feat: backwards compatibility for TradingDaysPerYear

* feat: several UTest for AlgoSetting's TradingDaysPerYear prop

* fix: existed algo + test

* feat: regression algo with checking of tradingDayPerYear in OnEndOfAlgorithm()

* refactor: GetBrokerageTradingDayPerYear -> SetBrokerage... in BaseSetupHandler
refactor: carry out tradingDayPerYear at the top level and pass variable

* remove: default valuine in test param
remove: extra comment.

* fix: missed init TradingDaysPerYear in report.portfolioAlgo
fix: hardcoded value to tradingDaysPerYear

* fix: nullable TradingDaysPerYear in AlgorithmConfiguration
feat: UTest for PortfolioLooperAlgo
feat: add advanced description

* feat: test PortfolioStatistics with different tradingDaysPerYear

* revert: PortfolioLooper with TradingDaysPerYear implementation

* revert: nullable TradingDaysPerYear in AlgoConfiguration
remove: SetBrokerageTradingDayPerYear in BaseResultHandler

* style: remove empty row
2024-01-17 14:45:57 -03:00
Martin-Molinero
bf2f310cae Future SymbolRepresentation Future Parsing (#7695)
- Improve future symbol representation future parsing. Adding more unit
  tests
2024-01-15 20:54:10 -03:00
Roman Yavnikov
cc8caa9635 Future Stop Market Order in Out Market Hours (#7678)
* feat: stopMarketFill in FutureFillModel + test

* feat: futureStopMarket RegressionAlgo on PY|C#

* feature: add validation of market time in utest

* feature: validate exchange hours when order filled in regression algos

* feat: validation of StopMarket Type
fix: styling format in PY

* fix: validation on ExtendedMarketHours in FutureFillMode
feature: validate that all stop orders was completed in algos

* fix: validation: asset.Subscription -> ConfigProvider.GetSubscriptionData
fix:style: missed braces

* fix: asset.IsInternalFeed() -> general includeInternalConfigs flag
remove: extra login in algo

* feat: write comment why we use includeInternalConfigs in true
remove: extra log in PY version of algo
2024-01-11 18:43:08 -03:00
Ricardo Andrés Marino Rojas
41a6fb721a Add potential fix to overflow bug in FractalAdaptiveMovingAverage.cs (#7689)
* Add potential fix

* Handle NaN and Infinity cases
2024-01-11 17:20:46 -03:00
Martin-Molinero
27356512b8 Clean up pythonnet runtime exception build paths (#7687)
- Clean up pythonnet runtime exception build paths
2024-01-11 10:56:09 -03:00
Martin-Molinero
abd092ac63 Update readme.md 2024-01-09 19:44:48 -03:00
Ricardo Andrés Marino Rojas
6a8edc1f34 Add SetSettlementModel() method (#7684)
* Rebase - Add Support

* nit changes
2024-01-09 19:38:17 -03:00
Roman Yavnikov
4913a59f28 remove: deprecated PriceProvider (#7682) 2024-01-09 19:37:28 -03:00
alex
4c79d91635 fix some grammar in Data/readme.md (#7679) 2024-01-09 19:34:55 -03:00
Roman Yavnikov
0a1e481883 refactor: Globals.DataFolder -> Globals.GetDataFolderPath() (#7685) 2024-01-09 19:34:13 -03:00
Martin-Molinero
6879e93d79 Update readme.md 2024-01-08 18:56:23 -03:00
Martin-Molinero
1f4eee88dd CoinApi GDAX to Coinbase rename (#7677) 2024-01-08 18:11:59 -03:00
Ricardo Andrés Marino Rojas
c6ca0eeea5 Improve brokerage model python wrapper (#7672)
* Improve GetFillModel()

* Add support for other methods

* Add regresion algos and improvements

* Make Python algorithms regression tests

* Improve unit tests

* Minor changes
2024-01-08 18:11:18 -03:00
Martin-Molinero
3f3d13a1df Update readme.md 2024-01-05 18:02:58 -03:00
Jared
f497a0206c Update BacktestingResultHandler.cs (#7675) 2024-01-05 18:00:02 -03:00
Martin-Molinero
0ba796c4cf Add project owner to API project read (#7674) 2024-01-05 16:58:03 -03:00
Roman Yavnikov
50ccec9a01 feat: gdax -> coinbase (#7633)
* feat: gdax -> coinbase

* feat: defaultBrokerageModel gdax -> coinbase

* refactor: coinbaseBrokerageModel
fix: gdax test

* feat: add coinbase market hours

* feat: symbolPropDB gdax -> coinbase

* fix: gdax to coinbase tests

* fix: coinbase Fees data

* remove: gdax market-hours

* revert: stopMarket order Type by date + test

* fix: coinbase test (fee was changed)
revert: old test with stopMarket gdax
fix: pandas padding

* refactor: gdaxLiveTrading -> CoinbaseLiveTrading
remove: gdax configs

* remove: old gdax testdata files

* refactor: gdax route -> coinbase route
feat: add deprecated gdax info
feat: some string "gdax" -> "coinbase"

* fix: style brackets

* fix: config coinbase data-queue-handler

* revert: public StablePairsGDAX collection

* rename: GdaxBrokerageModel to CoinbaseBrokerageModel in tests
rename: gdax -> coinbase in DefaultMarketMap
rename: gdaxBrokerageModelTest to Coinbase...

* revert: coinbase changes in toolbox (deprecated)

* remove: override Clone() in GDAX\Coinbase-OrderProperties

* typo: ops missing brackets

* rename: Market.Gdax -> Coinbase in Test
remove: ref on gdax

* test: compatibility of GDAXOrderProperties

* fix: coinbase brokerageName enum number

* feat: readonly to stablePairs Gdax/Coinbase
remove: GetFeeModel() in GDAXBrokerageModel {}

* test: gdax market name compatible with coinbase

* rename: config to old ones

* feat: coinbase CanUpdateOrder()

* rename: plus to commit 4135c91

* feat: coinbase fee model + test

* fix: stable fees data

* update: coinbase symbol-properties-database.csv

* fix:  validation of MinimumOrderSize in SubmitOrder()

* feat: gdax -> coinbase

* feat: defaultBrokerageModel gdax -> coinbase

* refactor: coinbaseBrokerageModel
fix: gdax test

* feat: add coinbase market hours

* feat: symbolPropDB gdax -> coinbase

* fix: gdax to coinbase tests

* fix: coinbase Fees data

* remove: gdax market-hours

* revert: stopMarket order Type by date + test

* fix: coinbase test (fee was changed)
revert: old test with stopMarket gdax
fix: pandas padding

* refactor: gdaxLiveTrading -> CoinbaseLiveTrading
remove: gdax configs

* remove: old gdax testdata files

* refactor: gdax route -> coinbase route
feat: add deprecated gdax info
feat: some string "gdax" -> "coinbase"

* fix: style brackets

* fix: config coinbase data-queue-handler

* revert: public StablePairsGDAX collection

* rename: GdaxBrokerageModel to CoinbaseBrokerageModel in tests
rename: gdax -> coinbase in DefaultMarketMap
rename: gdaxBrokerageModelTest to Coinbase...

* revert: coinbase changes in toolbox (deprecated)

* remove: override Clone() in GDAX\Coinbase-OrderProperties

* typo: ops missing brackets

* rename: Market.Gdax -> Coinbase in Test
remove: ref on gdax

* test: compatibility of GDAXOrderProperties

* fix: coinbase brokerageName enum number

* feat: readonly to stablePairs Gdax/Coinbase
remove: GetFeeModel() in GDAXBrokerageModel {}

* test: gdax market name compatible with coinbase

* rename: config to old ones

* feat: coinbase CanUpdateOrder()

* rename: plus to commit 4135c91

* feat: coinbase fee model + test

* fix: stable fees data

* update: coinbase symbol-properties-database.csv

* fix:  validation of MinimumOrderSize in SubmitOrder()

* fix: skipped gdax name to coinbase

* feature: visible Symbol prop in DefaultOrderBook
2024-01-05 16:57:19 -03:00
Martin-Molinero
1d52e5b14a Update readme.md 2024-01-04 16:41:41 -03:00
Daniel Suh
50ab04e30d Implement Time Series Forecast Indicator (#7654)
* initialize TimeSeriesForecast

* tests pass

* spy_tsf.csv added

* added csv to tests

* comment

* fix requested changes

* remove commented out code

* remove ds_store and sln

---------

Co-authored-by: Daniel Suh <daniel.suh@duke.edu>
2024-01-04 16:20:29 -03:00
Ronit Jain
ff83d72487 add required options for local reuslt service (#7660) 2024-01-04 16:18:56 -03:00
Martin-Molinero
3db813c9ae Minor git ignore addition (#7658) 2024-01-04 11:48:26 -03:00
Ricardo Andrés Marino Rojas
eeb44d841a Add partial support for live algorithm redeployment with custom data (#7655)
* First Draft of the solution

Handle the case where the security has already been added in the
algorithm

* Improve implementation

* Improve changes

* Add unit test

* Improve unit tests

* Fix bugs in unit tests

* Nit changes

* Nit changes

* Improve implementation

* Solve bugs in unit tests

* Add more unit tests
2024-01-04 11:13:52 -03:00
Martin-Molinero
e0fdbb2618 Plotting Limits Handling Improvements (#7657)
* Plotting Limits Handling Improvements

- Improve the handling and enforcement of plotting limits
- Increase local default limits

* Minor plotting test fix
2024-01-03 14:21:13 -03:00
Jhonathan Abreu
b75ed58411 Fix combo order quantity update (#7651)
* Fix combo order quantity update

* Minor changes

* Fix unit tests

* Cleanup
2024-01-03 11:11:23 -04:00
Martin-Molinero
aaab65fd7f Fix disabled subsampling (#7656)
- Fix disable subsampling which was adjusting series point times,
  updating unit tests to reproduce issue
2024-01-02 20:54:19 -03:00
Martin-Molinero
65f8590d94 Clean up unused toolbox classes (#7652)
- Remove QuantQuoteConverter program
- Remove QC Visualizer
2024-01-02 18:55:32 -03:00
Martin-Molinero
2525824390 ConsolidateChartPoints method override type (#7650) 2023-12-29 13:24:29 -03:00
Ricardo Andrés Marino Rojas
1b8f396f1a Fix bug in GetLastKnownPrices() method (#7649)
* First draft

* Update regression algos and add unit tests
2023-12-29 13:24:18 -03:00
Ricardo Andrés Marino Rojas
2020f12825 Fix bug in UniverseSelection.Top() method (#7647)
* Solve bug and fix regression test

* Add regression tests

* Improve implementation

* Nit change
2023-12-28 14:49:30 -03:00
Martin-Molinero
3e00abb2e4 Fix Live trading OrderEvents Serialization format (#7646)
- Live trading result handler was storing order events with a different
  format since it wasn't using the expected json converter
2023-12-27 19:19:01 -03:00
Ricardo Andrés Marino Rojas
0f47ba657d Solve race condition bug in LocalObjectStore (#7645)
* Solve bug and add unit tests

The bug was raised due to a race condition when writing a file and
deleting it. In order to stop it, a check condition was added at the end
of the PersistData() method to remove files that have just been deleted.

* Nit changes

* Add a different constructor for the test
2023-12-27 19:18:02 -03:00
Jhonathan Abreu
8cdb2d4c10 Add options and future chain providers to composer (#7644) 2023-12-27 14:42:21 -04:00
Ricardo Andrés Marino Rojas
d8a68afc3f Add Support to Run Algos Without Specifying the Algorithm Language (#7643)
* First draft  of the feature

* Improve implementation

* Add more unit tests
2023-12-26 19:18:54 -03:00
Martin-Molinero
a76fad952d Allow disabling subsampling (#7642)
- Optionally allow disabling subsampling, adding unit tests
2023-12-26 11:06:34 -03:00
Martin-Molinero
939b14a6e8 ApiConnection Improvements (#7640)
- Add support for async API calls
- Reuse HttpAuthenticator when possible
2023-12-22 13:30:02 -03:00
Jhonathan Abreu
9601155e28 Remove Polygon from Toolbox (#7638)
* Remove Polygon from Toolbox

* Minor changes
2023-12-21 13:08:53 -03:00
Martin-Molinero
51c70f6c46 Adjust for high/low sampling values (#7639) 2023-12-20 18:05:10 -03:00
Martin-Molinero
dbad754a93 Reduce latency of initial results (#7634)
- Reduce latency of initial Lean results, from 30 to 5 seconds
2023-12-19 20:02:12 -03:00
Martin-Molinero
cd2e4edeb1 Update readme.md 2023-12-15 17:01:17 -03:00
Derek Melchin
3eb9dbb55c Update Alpha.cs (#7630)
The old description is incorrect. A stock can have positive Alpha but have negative Beta. In this case, if the benchmark increases, the performance of the stock may be dominated by its negative Beta, causing it to underperform the benchmark.
2023-12-15 15:59:23 -03:00
Ricardo Andrés Marino Rojas
9bd69a5032 Fix bugs related with Culture Format (#7626)
* Fix bugs related with Culture Format

* Change .Parse method to .TryParse

* Change NumberStyles.Currency to NumberStyles.Any
2023-12-15 15:58:21 -03:00
Alexandre Catarino
d30357db5f Fixes Parse Future Symbol (#7624)
* Adds Unit Tests for ParseFutureSymbol

Tests:
- Ambiguous year with missing decade
- Non-ambiguous known year
- Expiring before 2000

* Fixes Missing Decade Tests

If the ticket doesn't provide a decade, VXZ2, we assume the current decade. So VXZ2 expires on Dec 2022.

* Fixes SymbolRepresentation.ParseFutureSymbol

Use the value of `futureYear` to handle contracts that expire before 2000. (E.g.: NQZ99).
Tickers from live trading may not provide futureYear. Use the current decade (2020).
2023-12-14 20:25:26 -03:00
Ricardo Andrés Marino Rojas
bc313a999b Add PyObject Constructor Overload for FuncRiskFreeRateInterestRateModel (#7625)
* Add overload and regression tests

* Nit changes

* Nit change

* Nit change
2023-12-14 11:04:42 -03:00
Jhonathan Abreu
442dd771a3 Remove dynamic options filter behavior (#7620)
* Make options filter non-dynamic by default and explicitly set

* Deprecate ContractSecurityFilterUniverse.OnlyApplyFilterAtMarketOpen

* Add regression algorithm

* Remove dynamic option chain filter behavior
2023-12-14 10:56:52 -03:00
Martin-Molinero
59b9e571a1 Minor series sampling improvements (#7627)
- Fix bug where there might not be any data to sample. Adding unit test
- Fix bug where candlestick sampling might add point which shouldn't be
  there. Adding unit tests
- Adjust series json converter to serialize any base series type. Adding
  unit test
2023-12-14 09:57:20 -03:00
Derek Melchin
eefa74baaa Add Sortino ratio to statistics and report (#6698)
* Add Sortino ratio to statistics and report

* Adds Sortino Ratio to Report Key Statistics

* Addresses Peer-Review

Reuse `SharpeRatioReportElement` and change the template.

* Reuse Calculations Across Statistics and PortfolioStatistics

* Adds Sortino Ratio to Regression Algorithms

* Removes Sortino Ratio from Optimization Result Table

---------

Co-authored-by: Alexandre Catarino <AlexCatarino@users.noreply.github.com>
2023-12-12 21:06:13 -03:00
Martin-Molinero
fd2a8f84b9 Add support for null chart points (#7622)
* Add support for null chart points

- Add support for null value chart points, updating existing and adding
  new unit tests

* Minor selfreview tweaks

* Address review & fix deserialization bug

* Ignore null values when using NullResultValueTypeJsonConverter

* Narrow NullResultValueTypeJsonConverter conversion support

* Allow inherit of series sampler
2023-12-12 20:26:58 -03:00
Alexandre Catarino
bf30c7d437 Remove Empty Line After Class Summary (#7621)
The empty line causes a problem parsing the summary as the class description.
Removes `&` from S&P.
2023-12-12 20:23:23 -03:00
Ricardo Andrés Marino Rojas
882dcd44b5 Fix Ultimate Oscillator divide by zero exception (#7618)
* Solve bug and add unit test

The bug was raised when the sum of the True Range values was zero. Since
the Ultimate Oscillator provides a more reliable indicator of momentum,
if the prices don't change, its value should be zero, as there is no
acceleration of a security's price.

* enhance implementation
2023-12-08 15:21:07 -03:00
Jhonathan Abreu
b53d76ff3a Bump pythonnet version to 2.0.26 (#7616) 2023-12-08 13:38:39 -04:00
Martin-Molinero
93e63a6250 Add stockplot series type (#7615) 2023-12-07 19:50:17 -03:00
Alexandre Catarino
b84774388c Index.IsTradable Can Be Set (#7610)
* Index.IsTradable Can Be Set

Indices are not tradable. LEAN will not set it to `true`, but the users can for backtesting.

* Adds Regression Tests

* Revert Changes to ProcessSecurityChanges
2023-12-06 21:02:10 -03:00
Ricardo Andrés Marino Rojas
a6580b33fe Update SPDB and add unit test (#7613) 2023-12-06 20:39:40 -03:00
Ricardo Andrés Marino Rojas
09530be51a Solve Invariant of Culture bugs (#7608)
After running the regression tests in my local pc, I found some of them
were failing in the stats. Then, after debugging them I realized it was
because some of the strings were being casted without using
InvariantCulture parameter.
2023-12-05 15:32:03 -03:00
Ricardo Andrés Marino Rojas
dcb5f8ee4e Merge branches 7501 and 7506 (#7605)
* Update Future-cme-[*] and Future-cme-ES

Acoording to `pandas_market_calendars` there were some dates in
Future-cme-[*] who wasn't early_closes, so they needed to be removed
from there. On the other hand, the early closes list of Future-cme-ES were
shifted by 1 hour according to CME webpage. Besides, there were some
missing dates.

* Update CME Future entries in MHDB

* Rebase

* nit change

* Fix unit tests

* Resume after early close/halts

* Add missing dates in MHDB and fix bugs in it

* Fix bug, add more unit tests and add docs

* fix regression algos

* address required changes

* Update failing regression test stats

After debugging the tests it was found they were failing due to the last
change on SecurityExchangeHours.IsOpen(). That method wasn't taking into
account that even if there is a late open after an early close if the
timespan is after the early close but before the late open, the market
is still close.

* enhance solution

* Update and fix bugs in MHDB

* Address required changes and update stats

* Update stats after rebase

* Nit change

* Missing update to regression test

* Use MHDB instead of USHoliday for Expiration Dates

VIX expiry function now relies completely on MHDB. However, it had to be
created an entry in MHDB for VIX since there wasn't one for it. CBOE
webpage only provided 2023 holidays so only those dates were considered
in the Holidays entry in MHDB. Therefore, some unit tests failed so it
was necessary to change also the VIX entry in FuturesExpiryFunctionsTestData.xml.

* Remove Global.cs/USHolidays class

* Use a lazy implementation

* First draft of the solution

* Use MHDB in FuturesExpiryFunctions.cs

* Remove unused class and fix indentation errors

* Fix indentation errors

* Nit changes

* Merge branches 7501 and 7506

* Merge changes in 7501 and 7506

In order to check compatibility between those branches, a new branch
was created out of branch 7501 and then it was merged with branch 7506.
2 regression tests and 8 unit tests failed, the regression tests failed on
the DataPoint stats. On the other hand, the unit tests failed since the
default parameter UseEquityHoliday was removed from
FuturesExpirtyUtilityFunctions.AddBusinessDays() and from other methods in
the same class too.

* Add missing changes

* Remove repeated good fridays

* Address minor review

---------

Co-authored-by: Martin Molinero <martin.molinero1@gmail.com>
2023-12-04 18:09:57 -03:00
Martin-Molinero
e5ab96a306 Update readme.md 2023-12-04 12:40:11 -03:00
Martin-Molinero
67472b62c6 Future daily settlement model fix (#7607)
- Future daily settlement model fix. Adding unit test reproducing issue
2023-12-04 12:10:18 -03:00
Roman Yavnikov
639ae479a8 feat: ETFConstituentsModel overloading constructor (#7598)
* feat: ETFConstituentsModel overloading constructor
* test

* feat: new constructor of ETFConstituentsUniverse
test: support all constructor on c#

* feat: cached symbol in ETFConstituentsUniverse.py
test: validate getting symbol from cahed collection

* remove: extra ctor in ETFConstituentsUniverseSelectionModel

* refactor: add miss condition secType in py
refactor: rename out existTicker -> Symbol
refacotr: rewrite test

* feat: new ETFConstituentsFrameworkAlgos

* refactor: more neat ETFConstituentsAlgos

* fix: CompositeUniverse to SetUniverse
2023-12-01 17:20:52 -03:00
Martin-Molinero
cdedac9eda Update readme.md 2023-11-29 15:04:12 -03:00
Martin-Molinero
e85ccb3e36 Minor SerializedOrderEvent Tweak (#7603) 2023-11-29 11:19:56 -03:00
Martin-Molinero
f1627a9c96 Minor foundation update (#7602)
* Minor foundation update

* Add Xtransformers test
2023-11-28 18:23:43 -03:00
Jhonathan Abreu
82ee9f3599 Ensure crypto futures case is considered in time-in-force-checks (#7601)
Also ensure crypto futures ticks can be read from a line
2023-11-27 19:44:16 -03:00
Adrian Tkacz
f4b41c5793 Alpha Indicator #6985 (#7566)
* Alpha Indicator #6985

* Switched to RateOfChange and Beta

* Added RiskFreeRate param

* Added overload method (without name)

* Changed how Return is calculated
Code refactoring

* Use interest rate provider to automatically get the risk free rate

* Removed InterestRateProvider

* Applied Risk-Free Interest Rate Model

---------

Co-authored-by: Adrian Tkacz <adrian.tkacz@creatdy.com>
2023-11-24 11:31:15 -03:00
Martin-Molinero
c67dcfcc69 Order PriceAdjustmentMode & LeanManager tweaks (#7595)
- Relax PriceAdjustmentMode set property restriction to facilitate
  testing
- Set LocalLeanManager protected
2023-11-22 17:20:22 -03:00
Jhonathan Abreu
f8ca85cb5d Risk-Free Interest Rate Model (#7594)
* Implement risk free interest rate as an algorithm model

* Use risk free insterest rate model in Sharpe Ratio indicator

* Address peer review

Also added python wrapper

* Take pyobject as interest rate model in Sharpe Ratio indicator

* Minor fix

* Minor fix

* Address peer review
2023-11-22 16:17:34 -04:00
Roman Yavnikov
4c034bd40f Brokerage.Eze, launcher config (#7593)
* feature: eze config in launcher

* feat: add support IndexOption
2023-11-22 10:23:35 -03:00
Jhonathan Abreu
4b1f751adb Update Pythonnet version to 2.0.25 (#7591) 2023-11-21 17:25:36 -04:00
Martin-Molinero
7498d2e6e2 QuantBook Universe Selection (#7587)
* QuantBook Universe Selection

- QuantBook universe selection helper method. Adding new unit tests.
- Universe selection data sets improvements

* QuantBook API renames
2023-11-21 17:05:02 -03:00
Martin-Molinero
adaa2f5862 Cleanup data cache provider in tests (#7588) 2023-11-21 16:48:36 -03:00
Jhonathan Abreu
a761c769be Fix brokerage transaction handler null object access bug (#7586)
* Fix using brokerage transaction handler algo befor set

Brokerage open orders are being set before algorithm is set to the transaction handler, so SetPriceAdjustmentMode needs to get the algo to use

* Update unit tests
2023-11-20 11:00:55 -03:00
Gustavo Aviles
6cc2bc64c0 Update enum docs to match others (#7583) 2023-11-20 10:49:02 -03:00
Jhonathan Abreu
314a334e88 Price adjustment mode Order property (#7582)
* Add new Order.PriceAdjustmentMode property

* Minor fix and unit test

* Minor fix and regression algorithms' stats update

* Unit test fixes

* Minor fix

* Set order price adjustment mode to raw always for live trading
2023-11-17 16:09:03 -04:00
Martin-Molinero
830df29f73 Avoid termination on empty live cash balance (#7581)
- Avoid algorithm termination on empty live cash balance if there was no
  error
2023-11-17 11:16:00 -03:00
Martin-Molinero
5e9901c667 Shortable modeling improvements (#7579)
* Shortable modeling improvements

- Do not limit live trading because of shortable model, will send
  algorithm warning
- Add Interactive brokers shortable provider
- Minor LocalDiskShortableProvider API changes

* Fix shorted order update

- Fix shorted order update. Updating regression algorithm

* Minor improvement

* Address reviews
2023-11-16 16:25:56 -03:00
Alexandre Catarino
1a66846f9e Improves Error Handling in OptionPriceModelResult.Evaluate (#7575)
* Improves Error Handling in OptionPriceModelResult.Evaluate

Use the maturity calculation to calculate dividend and risk free discount to prevent the `negative time` error.

Adds Exception Message and StackTrade to `DebuggingEnabled` messages.

* Set Evaluation Date Before Every Calculation

Adds loggings to record the reference date which is set by the `Settings.setEvaluationDate` method.
2023-11-16 16:05:47 -03:00
Martin-Molinero
408ffc0067 Add null slippage model (#7580)
- Add null single instance slippage model
2023-11-16 16:03:37 -03:00
Martin-Molinero
e983383e0e Revert "Store traded securities' subscriptions in results (#7567)" (#7578)
This reverts commit 145ead7cec.
2023-11-15 21:01:15 -03:00
Martin-Molinero
428d620203 Revert "Disable traded securities configs storage for live trading (#7574)" (#7577)
This reverts commit 9029c70a99.
2023-11-15 21:00:36 -03:00
Martin-Molinero
de10a1d669 Remove securities from algorithm collection (#7573)
- Once a security has been delisted or no longer selected by any
  universe it will be remove from the main algorithm securities
  collection but kept in the new Complete collection, this improves
  performance in long running backtests where security collection can
  get enumerated in different cases
- Minor refactor for security exchange local time to avoid having to set
  it explicitly
2023-11-15 17:09:43 -03:00
Jhonathan Abreu
9029c70a99 Disable traded securities configs storage for live trading (#7574)
* Disable storing trades securities configs for live trading

* Minor change

* Minor change
2023-11-15 11:25:47 -04:00
Grzegorz Wodnicki
3f818dc878 correlation as lean indicator #6983 (#7543)
* correlation as lean indicator #6983

* correlation as lean indicator #6983, added SPY QQQ test and Spearman test

* correlation as lean indicator #6983

* correlation as lean indicator #6983, fixes after review

* correlation as lean indicator #6983, fixes after review

* correlation as lean indicator #6983, fixes after review

* correlation as lean indicator #6983, added AcceptsQuoteBarsAsInput Test

* Minor review changes

---------

Co-authored-by: Grzegorz Wodnicki <info@funchips.co.uk>
Co-authored-by: Martin Molinero <martin.molinero1@gmail.com>
2023-11-13 20:40:14 -03:00
Jhonathan Abreu
145ead7cec Store traded securities' subscriptions in results (#7567)
* Store traded securities subscription data configs to disk

* Delegate traded subscriptions storage to the data monitor

* Add unit tests

* Address peer review

* Minor changes
2023-11-13 20:39:57 -03:00
Ricardo Andrés Marino Rojas
5c226319b0 Use MHDB in VIX FutureExpiryFunction (#7564) 2023-11-10 20:31:34 -03:00
Jhonathan Abreu
81723ddf46 Get ZipDataCacheProvider timer from config (#7563) 2023-11-10 14:07:00 -03:00
Roman Yavnikov
dd27a65960 Eze: remove extra internal accessors (#7561)
* feat: init eze-brokerage

* remove: eze from market collection

* remove: extra comma

* feat: add missing Security support

* feat: add Eze Order Properties

* feat: description, less code, remove extra configs

* Minor changes

* remove: internal accessor from EzeOrderProperties

---------

Co-authored-by: Martin Molinero <martin.molinero1@gmail.com>
2023-11-10 13:55:00 -03:00
Martin-Molinero
978494c12c Update readme.md 2023-11-06 19:13:57 -03:00
Martin Molinero
1f22299036 Cleanup 2023-11-06 18:57:05 -03:00
Martin-Molinero
e78d3083c5 Async universe selection (#7556)
* Async universe selection

- Add support for async universe selection, which will happen ahead of
  time in the data stack for a performance improvement

* Thrown if using Coarse+Fine Asynchronous Universe selectioon
2023-11-06 18:46:20 -03:00
Roman Yavnikov
e0251bdb23 Feature/eze support (#7526)
* feat: init eze-brokerage

* remove: eze from market collection

* remove: extra comma

* feat: add missing Security support

* feat: add Eze Order Properties

* feat: description, less code, remove extra configs

* Minor changes

---------

Co-authored-by: Martin Molinero <martin.molinero1@gmail.com>
2023-11-06 12:35:38 -03:00
Martin-Molinero
c5eaf34b4e Update readme.md 2023-11-02 18:27:02 -03:00
Jhonathan Abreu
a9d26084f9 Options algorithm performance enhancement (#7555)
* Ignore non-market universe data for security cache storage

This is a performance enhancement

* Minor refactor
2023-11-02 17:20:54 -04:00
Martin-Molinero
2f75c68312 Minor test brokerages fixes (#7552)
* AlgorithmStub Lazy Pandas Converter Set

* Fix brokerages tests adding orders twice
2023-11-01 18:23:30 -03:00
Jhonathan Abreu
d2f8c73d31 Invalidate option orders during a stock split (#7550)
* Invalidate option orders during a stock split

* Add unit test

* Minor changes

* Minor comments

* Options orders on split one time warning
2023-11-01 17:07:04 -03:00
Martin-Molinero
7c176910d7 Make sure algorithmstubs initializes python (#7551)
- Make sure the test algorithm stubs class initializes python before
  trying to set the pandas data converter which requires python
2023-11-01 15:09:00 -03:00
Martin-Molinero
4237d40173 Minor fix for python history tests (#7549)
* Minor fix for python history tests

* Add comment explaning why

* Handle enumerator throwing exception
2023-10-31 18:49:57 -03:00
Martin-Molinero
9f79016975 Fix new fundamental python deadlock 2 (#7548)
Fix new fundamnental python history usecase deadlock
2023-10-31 15:44:52 -03:00
Jhonathan Abreu
c0801afdbe Fix using custom data with Bybit brokerage model (#7547)
* Fix using custom data with Bybit brokerage model

* Add unit tests
2023-10-31 14:19:17 -03:00
Martin-Molinero
b21b6b9859 Fix deadlock on python new fundamentals (#7546) 2023-10-31 10:27:19 -03:00
Martin-Molinero
43585ac194 Add missing local OOS optimization config (#7545) 2023-10-30 19:12:52 -03:00
Martin-Molinero
4b06ca9147 Out of sample support tweaks (#7542)
* Add backtest job end date handling

* Fixes & rebases

* Refactor out of sample configuration handling

* Minor datetime format tweak
2023-10-27 18:23:21 -03:00
Louis Szeto
7d3733ccb7 Slippage model by market impact factors (#7513)
* Add Market Impact Slippage Model

* Add unit tests

* Add regression tests and random seeds

* Address peer review 1

* Add non-negative logic choice

* address peer review 2

* timezone setting adjustment

* Address peer review 2

* address second review

* minor updates

* minor updates

* Nit

* fix regression tests

* fix CI

* Rebase and fix CI

* regression test
2023-10-27 17:43:44 -03:00
Alexandre Catarino
f5d4bc4f7b Beta Indicator Supports QuoteBar (#7540)
* Adds Unit Test to Assert Beta Accepts QuoteBar

Beta must support QuoteBar for Forex/CDF and QuoteBarConsolidators

* Beta Indicator Supports QuoteBar
2023-10-27 13:12:39 -04:00
Martin-Molinero
265fbf7e60 Minor tweak for fundamental datetime type (#7541) 2023-10-27 11:51:26 -03:00
Jhonathan Abreu
2963936695 Bump Pythonnet version to 2.0.24 (#7539) 2023-10-27 10:02:08 -04:00
Jhonathan Abreu
d81f57b7a6 Bybit futures backtesting support (#7530)
* Add Bybit brokerage model regression algorithm

* Add BibytFutures brokerage model name and Bybit backtesting regression algorithms

* Add Bybit margin calculations unit tests

* Minor changes in data

* Unify Bybit Spot and Futures brokerage model into one class

* Add new Bybit configurations

* Revert config change
2023-10-26 20:03:10 -03:00
Martin-Molinero
88c7f7ff3b Fix QuantBook fundamental unit test (#7537) 2023-10-26 18:37:45 -03:00
Martin-Molinero
2e2136f7b8 Add missing multiperiod fields fundamental properties (#7536) 2023-10-26 13:15:05 -03:00
Martin-Molinero
f8b258d329 New Fundamental Data (#7490)
* New Fundamental Data

* Minor CIK lookup fix

* Handle live mode & delete unexisting properties

* Minor coarse fundamental adjustment

* Add fundamental history support

* Fix unit tests

* Performance improvements

* Fixes

* Minor regression algorithm fix

* Improvements. Add FundamentalUniverseSelectionModel

* Change default values

* Fix unit test

* Minor tweaks

* Fix unit test

* Minor error handling improvement

* Fix rebase
2023-10-25 15:47:42 -03:00
Martin-Molinero
4411d4a8fc Add missing Shimmy dependency (#7532)
- Add missing shimmy dependency
- Update, to normalize arm libraries with amd
2023-10-24 20:21:21 -03:00
Alexandre Catarino
99affdebef Updates Beta Indicator (#7533)
Adds a new constructor overload that matches the pattern in Lean: Symbol, Symbol, other types.
Adds a new constructor that infers the indicator name: "B(period)".
2023-10-24 19:57:47 -03:00
Martin-Molinero
8fa1f3659c Reduce foundation size (#7527)
- Reduce foundation size and minor library update
2023-10-23 13:14:46 -03:00
Martin-Molinero
005bebe224 Add new libraries and updates (#7522)
* Add new libraries and updates

* ARM foundation update

- Deleting creme library which has been merged into already included river, because it causes copulae build to fail
- Deleting Riskfolio-Lib which would try to install old numpy and fail
2023-10-20 19:19:32 -03:00
Jhonathan Abreu
1df11c0c64 Add Pythonnet's ClrBubbledException interpreter (#7523)
* Add ClrBubbleExceptionInterpreter

* Add ClrBubbledExceptionInterpreter tests

* Bump pythonnet version to 2.0.23

* Minor changes

* Minor change

* Minor fix

* Fix failing unit tests
2023-10-20 11:26:47 -03:00
Martin-Molinero
fff037b9c9 Bybit coinapi support (#7519) 2023-10-18 10:36:35 -03:00
Martin-Molinero
2959581d19 Update to pythonnet 2-0-22 (#7515) 2023-10-13 10:23:05 -03:00
Jhonathan Abreu
2232861c64 Modify AggregationManager implementation to improve reutilization (#7514) 2023-10-12 11:44:49 -03:00
Ricardo Andrés Marino Rojas
33eb9dec9b Solve missing bug with TimeZones (#7511) 2023-10-11 15:44:39 -03:00
Jhonathan Abreu
07fbbe65bb Default market hours to Always Open for base securities without subscription (#7509)
* Set default always open market hours entry for base security without subscription

Also return proper matching subscription for custom data symbols wihtout subscription.

* Minor changes

* Minor change
2023-10-11 15:36:38 -03:00
Alexandre Catarino
6e854550aa Adds Logging to OptionPriceModelResult.Evaluate (#7510)
To investigate zero Implied Volatility and Greeks.
2023-10-11 11:00:00 -03:00
Alexandre Catarino
93086b06db Improves Expiration/SetFilter Documentation (#7508)
The minimum and maximum expiration description was not correct.
2023-10-10 21:01:06 -03:00
Ricardo Andrés Marino Rojas
b86f001f8a Remove wrong Holiday from MHDB (#7503)
* Fix bug and add unit tests

* Update regression test
2023-10-09 20:49:37 -03:00
Ricardo Andrés Marino Rojas
844602c04a Fix bug with custom data subscription with the same symbol from multiple exchanges (#7500)
* Fix bug and add regression algo

* nit changes

* nit changes
2023-10-04 18:27:25 -03:00
Jhonathan Abreu
1a5a08175b New Terminal Link order properties (#7499)
* Add Account, Broker and Strategy TerminalLink order properties

* Minor changes
2023-10-04 18:16:39 -03:00
Alexandre Catarino
cbccb6e5cf Adds SimpleCustomFillModel to CustomModelsAlgorithm (#7498)
* Adds `SimpleCustomFillModel` to `CustomModelsAlgorithm`

The simple fill model shows how to implement a simpler version of the most popular order fills: Market, Stop Market and Limit.

This model was tested on QuantConnect Cloud, and will serve as additonal example, since we don't have an example that does not reuse the method of the base class.

* Handles Tick Resolution Case

Tick-resolution data doesn't have TradeBar. We can use the security price, since it represents a trade (`TickTrade`).
2023-10-04 18:07:32 -03:00
Martin-Molinero
78a9b80bbf Minor live result handler sampling fix (#7497)
- Make sure in live trading the result handler will correctly update the
  algorithm equity
2023-10-03 14:41:55 -04:00
Ricardo Andrés Marino Rojas
a0914e2ab1 Copy Data folder (#7496) 2023-10-03 09:48:56 -03:00
Jhonathan Abreu
fb3409d8a2 Custom data sourced from the object store (#7493)
* Support sourcing custom data from ObjectStore

* Add Python regression algorithm

* Wire engine to pass ObjectStore down to the stream readers

* Minor changes

* Minor unit tests fixes

* Remove unused SetupHandlerParameters.ObjectStore

* Minor changes

* Minor changes

* Support single-file zipped data to be sourced from object store

* Assert object store custom data history requests in regression algorithms

* Add custom object store data live data feed unit test

* Add multi-file object store custom data regression algorithms

* Minor fix
2023-10-02 15:54:57 -03:00
Ricardo Andrés Marino Rojas
b4bad69772 Dynamically Adjust Risk Free Rate of Return (#7489)
* First attempt to solve the bug

* Enhance implementation

* Enhance implementation

* Simplify implementation

* Rebase regression stats

* Solve unit test bugs

* Review

* Update Rolling.Sharpe() method

* Update regression stats

* Update unit tests

* Update missing regression algos

* Update Rolling.cs

---------

Co-authored-by: Martin Molinero <martin.molinero1@gmail.com>
Co-authored-by: Martin-Molinero <martin@quantconnect.com>
2023-10-02 13:42:28 -03:00
Ricardo Andrés Marino Rojas
b29e009d4d Remove unused methods (#7494)
All of the methods removed were used in the Statistics.Generate()
method, which is used no more in LEAN (See commit fac6f46)
2023-09-29 20:13:56 -03:00
Jhonathan Abreu
28eb1a4da4 Wire ROC for updates in risk parity PCM (#7485) 2023-09-26 11:28:12 -03:00
Ricardo Andrés Marino Rojas
2a1539cce6 Add Notes field in FixOrderProperties (#7491) 2023-09-26 11:27:03 -03:00
Martin-Molinero
b08fc979cf Update readme.md 2023-09-26 09:24:30 -03:00
Martin-Molinero
2128630389 Add Terminal Link Custom Order Notes (#7488) 2023-09-25 13:13:05 -03:00
Sebastian Karasek
6d35bfd3bc Ignore duplicate brokerage data (#7487) 2023-09-25 13:09:43 -03:00
Jhonathan Abreu
d12772d8eb Fix race condition in OptionModelsConsistency algorithms regarding log handler (#7482) 2023-09-22 12:01:33 -04:00
Louis Szeto
3db538d690 Add missing documentation attributes (#7481)
* Add missing documentation attributes

* Address peer review
2023-09-22 11:10:07 -03:00
Jhonathan Abreu
1c85ab164f Updated UniverseDefinitions.ETF|Index overloads for Python compatibility. (#7480)
Calling UniverseDefinition.ETF("TICKER",...) in Python was resolving the UserDefinition.ETF(Symbol...) overload due to Symbol's implicit string operator, causing the symbol to be wrongly created.
2023-09-21 18:12:27 -03:00
Ricardo Andrés Marino Rojas
d9923929b9 Solve bug in Tick Consolidator for Quote and Trade Tick types (#7475)
* Changes up to the date

* Revert "Changes up to the date"

This reverts commit 45dc9756bc.

* First attempt to solve bug

* Improve solution

* Add unit tests

* Fix bugs and add regression tests

* Solve bugs
2023-09-21 11:31:16 -03:00
Jhonathan Abreu
39f5f55b17 Avoid adding extra index subscriptions in AddOptionContract (#7479)
* Check for existing subscription before adding underlying in AddOptionContract

* Minor change
2023-09-21 11:30:05 -03:00
Martin-Molinero
a6c5448bb2 Add Bybit stable currencies & fix test log (#7474) 2023-09-20 13:56:59 -03:00
Martin-Molinero
0e182ae75f Add terminal link order properties (#7471) 2023-09-18 19:03:34 -03:00
Martin-Molinero
621d16eea8 Adjust order processor set location (#7468) 2023-09-18 12:17:55 -03:00
Martin-Molinero
fbad58161b Update readme.md 2023-09-18 11:47:33 -03:00
Sebastian Karasek
8a243059b0 Add Bybit integration (#7442)
* Add Bybit integration (#5898)

* Bybit order property update

XML docs

* Revert changes to Exchange.cs

* Cleanup

* Add bybit to config.json

* Fix default markets

* Update symbol properties

* Add file headers

* Fix possible order status for updating

* Update spdb

* Fix spdb

* Fix spdb
Remove orderbook depth settings

* Throws exception when spot brokerage is created with margin account
Fix tests

* Remove USDC contracts
2023-09-18 11:08:40 -03:00
Martin-Molinero
d276d6382d Update Binance SPDB (#7466)
* Update Binance SPDB

- Update Binance & BinanceUS SPDB

* Fix unit tests
2023-09-15 20:05:42 -03:00
Martin-Molinero
489fc5bd5f Fix chart api fetching and deserialization (#7467) 2023-09-15 20:04:46 -03:00
Ricardo Andrés Marino Rojas
fb489daa3e Feature trading technologies order properties (#7465)
* Create TradingTechnologiesOrderProperties

* Add XML docs

* Nit change

* Abstract FIX order properties
2023-09-15 12:50:47 -03:00
Alexandre Catarino
7e27ab74bb Deprecates IAlgorithmSettings.DataSubscriptionLimit (#7457)
* Deprecates IAlgorithmSettings.DataSubscriptionLimit

We will let the brokerage check and notify users that they have subscribed to datafeeds beyond their quota.

* Removes Unit Test

Also remove usage in `EmptyEquityAndOptions400Benchmark`.
2023-09-08 19:41:52 -03:00
Martin-Molinero
f93c9edfcb Update readme.md 2023-09-08 18:22:35 -03:00
Jhonathan Abreu
60a69cbf1d Fix brokerage tests race condition (#7458)
* Fix brokerage tests filled order modification race condition

* Listen to fill event in test setup in brokerage tests

* Minor changes

* Address peer review

* Minor changes
2023-09-07 19:35:29 -03:00
Henrik Strand
eccd1e7931 Fix typo (#7460) 2023-09-07 19:27:34 -03:00
Jhonathan Abreu
90a6d2f68f Insight and PortfolioTarget tag (#7456)
* Add Tag property to Insight

* Add PortfolioTarget Tag property

* Minor change

* Minor unit test fix
2023-09-07 16:59:01 -04:00
Jhonathan Abreu
372c197890 One-time warning for mismatching canonical/contracts security models (#7452)
* Send one-time warning about mismatching canonicals/contracts models

* Add regression algorithms
2023-09-06 10:57:16 -04:00
Martin-Molinero
f0c253c50b Update readme.md 2023-08-30 17:23:15 -03:00
Martin-Molinero
76c0ab01ee Update readme.md 2023-08-30 13:56:24 -03:00
Ricardo Andrés Marino Rojas
e47b4e63ab Collective2 module modernization and finalization (#7448)
* Removed platformId support from C2.
Modernized C2 API calls to APIv4.
Added C2 rate limiters (RateGate).
Added response logging so users can easily debug their code.
Added a few symbols for the demo.

* Address requested changes

* Address requested changes

---------

Co-authored-by: Francis Gingras <francis@collective2.com>
2023-08-30 13:48:10 -03:00
Landon Wilkins
f70cf97dee [typo] Update readme.md (#7449) 2023-08-30 12:59:29 -03:00
Ricardo Andrés Marino Rojas
b9f3b1a4a4 Add support for Fill models with COMBO orders in Python (#7446)
* Add support for Combo Orders with Fill Model

- Override ComboMarketFill, ComboLimitFill, ComboLegLimitFill in
  FillModelPythonWrapper.cs
- Modify FillModel.Fill() to use Python Fill model if it exists when the
  order is COMBO
- Add regression algorithm ComboOrdersFillModelAlgorithm.py

* Add regression algorithm

* Add regression algos

* Fix bug
2023-08-29 10:06:32 -03:00
Martin-Molinero
1645f9877e Minor serialization tweak (#7447) 2023-08-28 10:30:34 -03:00
Martin-Molinero
52c6d43d2e Update readme.md 2023-08-25 15:56:05 -03:00
Martin-Molinero
04fc0d5093 Update readme.md 2023-08-25 15:36:49 -03:00
Martin-Molinero
56164f636a Fix for continuous contract mapping (#7445)
- Remove mapping mode from map file since it can be reused and make it
  an argument when mapping. Adding unit test
2023-08-25 14:19:51 -03:00
Martin-Molinero
dc64a340ba Minor live performance improvements (#7441) 2023-08-23 19:20:46 -03:00
Ricardo Andrés Marino Rojas
8e0e823f66 Add Lumber Futures LBR (#7440)
* Update SB, MHDB and ExpirationFunctions

* Add unit tests

* Address required changes

* Nit change

* Nit change
2023-08-23 19:19:16 -03:00
Ricardo Andrés Marino Rojas
18e848853d Approximate order price for options when using IB Fee model (#7436)
* Modify IB Fee model to work without order.Price

* Fix bugs and add unit tests

* Update regression tests

* Solve bug and address changes

* Nit change

* Fix stats
2023-08-23 09:56:23 -03:00
Martin-Molinero
038d7a26b2 Update readme.md 2023-08-21 11:56:59 -03:00
Martin-Molinero
4ca5526461 Refactor object store file handling (#7438)
- Add FileHandler for local object store file operations
2023-08-21 10:11:07 -03:00
Louis Szeto
d9e4dba687 Change default American Option Pricing model to Binomial CRR model (#7426)
* Add unit test and test data

* Add unit test for model greeks accuracy and comparison

* Add regression test

* Correction on previous unit test to use realtime official IB Greeks

* Switch default American option price model to CRR model

* Address peer review
2023-08-18 14:34:46 -03:00
Martin-Molinero
5f2bae1de5 COrrectly handle subt generation failure (#7434) 2023-08-17 13:06:54 -03:00
Ricardo Andrés Marino Rojas
e065c752cc Fix bugs in InteractiveBrokersFeeModel.cs for Combo Market Order fees (#7432)
* Draft of unit test to reproduce error

* Fix bug and regression tests

* Remove draft unit test

* Check fees in ComboMarketOrderAlgorithm.cs

* Fix bug in fees for combo orders

- Update regression tests
- Solve bug in fees when combo orders had legs with different quantity
- Solve bug in fees when combo orders had legs with different security
  types
- Update IB comission rate for options where the price is higher than 0.1 USD

* Add explaining comments

* Use leg security fee model
2023-08-14 19:18:53 -03:00
Martin-Molinero
bc34c33c77 Update readme.md 2023-08-10 14:49:09 -03:00
Martin-Molinero
8f1dc76c7f Fix optimization candlestick handling (#7430)
* Fix optimization candlestick handling

- Fixes for optimization candlestick handling
- Centralize deserialization of ChartPoint into new
  ChartPointJsonConverter

* Minor fixes

- Update failing tests
- Update CI to fail if anything fails
2023-08-10 13:34:19 -03:00
Martin-Molinero
505ea3bd72 Update readme.md 2023-08-10 10:16:50 -03:00
Martin-Molinero
eecafbea09 Update readme.md 2023-08-10 09:48:29 -03:00
Martin-Molinero
0b47c84b8a Update readme.md 2023-08-09 15:10:30 -03:00
Ricardo Andrés Marino Rojas
4c3658f9d4 Fix bug in Momentum indicator (#7424)
* First attempt to fix bug

* Address requested changes

* Do not hide WarmUpPeriod property
2023-08-09 14:56:24 -03:00
Martin-Molinero
d8c58fb9e2 Minor candlestick json converter backwards compatility fix (#7428)
- Minor bug fix for candlestick json converter backwards compatibility,
  detected running the new report generator on an old lean backtest
  result json
2023-08-09 14:53:00 -03:00
Ricardo Andrés Marino Rojas
1fd0dd3566 Do not embellish parameters key names (#7427) 2023-08-09 14:27:10 -03:00
2204 changed files with 210016 additions and 92687 deletions

30
.github/workflows/api-tests.yml vendored Normal file
View File

@@ -0,0 +1,30 @@
name: API Tests
on:
push:
branches: ['*']
tags: ['*']
pull_request:
branches: [master]
jobs:
build:
runs-on: ubuntu-20.04
# Only run on push events (not on pull_request) for security reasons in order to be able to use secrets
if: ${{ github.event_name == 'push' }}
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Free space
run: df -h && rm -rf /opt/hostedtoolcache* && df -h
- name: Run API Tests
uses: addnab/docker-run-action@v3
with:
image: quantconnect/lean:foundation
options: --workdir /__w/Lean/Lean -v /home/runner/work:/__w -e GITHUB_REF=${{ github.ref }} -e QC_JOB_USER_ID=${{ secrets.QC_JOB_USER_ID }} -e QC_API_ACCESS_TOKEN=${{ secrets.QC_API_ACCESS_TOKEN }} -e QC_JOB_ORGANIZATION_ID=${{ secrets.QC_JOB_ORGANIZATION_ID }}
shell: bash
run: |
# Build
dotnet build /p:Configuration=Release /v:quiet /p:WarningLevel=1 QuantConnect.Lean.sln
# Run Projects tests
dotnet test ./Tests/bin/Release/QuantConnect.Tests.dll --blame-hang-timeout 300seconds --blame-crash --filter "FullyQualifiedName=QuantConnect.Tests.API.ProjectTests" -- TestRunParameters.Parameter\(name=\"log-handler\", value=\"ConsoleErrorLogHandler\"\)

View File

@@ -23,8 +23,8 @@ jobs:
shell: bash
run: |
# Build
dotnet build /p:Configuration=Release /v:quiet /p:WarningLevel=1 QuantConnect.Lean.sln
dotnet build /p:Configuration=Release /v:quiet /p:WarningLevel=1 QuantConnect.Lean.sln && \
# Run Tests
dotnet test ./Tests/bin/Release/QuantConnect.Tests.dll --blame-hang-timeout 300seconds --blame-crash --filter "TestCategory!=TravisExclude&TestCategory!=ResearchRegressionTests" -- TestRunParameters.Parameter\(name=\"log-handler\", value=\"ConsoleErrorLogHandler\"\)
dotnet test ./Tests/bin/Release/QuantConnect.Tests.dll --blame-hang-timeout 300seconds --blame-crash --filter "TestCategory!=TravisExclude&TestCategory!=ResearchRegressionTests" -- TestRunParameters.Parameter\(name=\"log-handler\", value=\"ConsoleErrorLogHandler\"\) && \
# Generate & Publish python stubs
echo "GITHUB_REF $GITHUB_REF" && (([[ $GITHUB_REF = refs/tags/* ]] && chmod +x ci_build_stubs.sh && ./ci_build_stubs.sh -t -g -p) || echo "Skipping stub generation")
echo "GITHUB_REF $GITHUB_REF" && if [[ $GITHUB_REF = refs/tags/* ]]; then (chmod +x ci_build_stubs.sh && ./ci_build_stubs.sh -t -g -p); else echo "Skipping stub generation"; fi

30
.github/workflows/report-generator.yml vendored Normal file
View File

@@ -0,0 +1,30 @@
name: Report Generator Tests
on:
push:
branches: ['*']
tags: ['*']
pull_request:
branches: [master]
jobs:
build:
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Free space
run: df -h && rm -rf /opt/hostedtoolcache* && df -h
- uses: addnab/docker-run-action@v3
with:
image: quantconnect/lean:foundation
options: --workdir /__w/Lean/Lean -v /home/runner/work:/__w
shell: bash
run: |
# Build
dotnet build /p:Configuration=Release /v:quiet /p:WarningLevel=1 QuantConnect.Lean.sln
# Run Backtest
cd ./Launcher/bin/Release && dotnet QuantConnect.Lean.Launcher.dll && cd ../../../
# Run Report
cd ./Report/bin/Release && dotnet ./QuantConnect.Report.dll --backtest-data-source-file ../../../Launcher/bin/Release/BasicTemplateFrameworkAlgorithm.json --close-automatically true

View File

@@ -34,14 +34,10 @@ jobs:
dotnet test ./Tests/bin/Release/QuantConnect.Tests.dll --filter "FullyQualifiedName=QuantConnect.Tests.Python.PythonVirtualEnvironmentTests.AssertVirtualEnvironment"
# Run Python Package Tests
dotnet test ./Tests/bin/Release/QuantConnect.Tests.dll --filter "FullyQualifiedName=QuantConnect.Tests.Python.PythonPackagesTests" --blame-hang-timeout 120seconds --blame-crash
# Run Pomegranate & Neuralprophet Python Package Test
dotnet test ./Tests/bin/Release/QuantConnect.Tests.dll --filter "FullyQualifiedName=QuantConnect.Tests.Python.PythonPackagesTests.PomegranateTest|Neuralprophet" --blame-hang-timeout 120seconds --blame-crash
# Run StableBaselines Python Package Test
dotnet test ./Tests/bin/Release/QuantConnect.Tests.dll --filter "FullyQualifiedName=QuantConnect.Tests.Python.PythonPackagesTests.StableBaselinesTest" --blame-hang-timeout 120seconds --blame-crash
# Run AxPlatform Python Package Test
dotnet test ./Tests/bin/Release/QuantConnect.Tests.dll --filter "FullyQualifiedName=QuantConnect.Tests.Python.PythonPackagesTests.AxPlatformTest" --blame-hang-timeout 120seconds --blame-crash
# Run NBeats Python Package Test
dotnet test ./Tests/bin/Release/QuantConnect.Tests.dll --filter "FullyQualifiedName=QuantConnect.Tests.Python.PythonPackagesTests.NBeatsTest" --blame-hang-timeout 120seconds --blame-crash
# Run TensorlyTest Python Package Test
dotnet test ./Tests/bin/Release/QuantConnect.Tests.dll --filter "FullyQualifiedName=QuantConnect.Tests.Python.PythonPackagesTests.TensorlyTest" --blame-hang-timeout 120seconds --blame-crash
# Run NeuralTangents, Ignite Python Package Test
@@ -59,4 +55,4 @@ jobs:
# Run Scikeras Python Package Test
dotnet test ./Tests/bin/Release/QuantConnect.Tests.dll --filter "FullyQualifiedName=QuantConnect.Tests.Python.PythonPackagesTests.ScikerasTest" --blame-hang-timeout 120seconds --blame-crash
# Run Transformers
dotnet test ./Tests/bin/Release/QuantConnect.Tests.dll --filter "FullyQualifiedName=QuantConnect.Tests.Python.PythonPackagesTests.Transformers" --blame-hang-timeout 120seconds --blame-crash
dotnet test ./Tests/bin/Release/QuantConnect.Tests.dll --filter "FullyQualifiedName=QuantConnect.Tests.Python.PythonPackagesTests.Transformers|XTransformers" --blame-hang-timeout 120seconds --blame-crash

3
.gitignore vendored
View File

@@ -1,3 +1,6 @@
# OS Files
.DS_Store
# Object files
*.o
*.ko

View File

@@ -84,30 +84,31 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "199"},
{"Total Orders", "199"},
{"Average Win", "0.00%"},
{"Average Loss", "0.00%"},
{"Compounding Annual Return", "-12.611%"},
{"Drawdown", "0.200%"},
{"Expectancy", "-0.585"},
{"Net Profit", "-0.172%"},
{"Sharpe Ratio", "-10.169"},
{"Sharpe Ratio", "-11.13"},
{"Sortino Ratio", "-16.704"},
{"Probabilistic Sharpe Ratio", "12.075%"},
{"Loss Rate", "78%"},
{"Win Rate", "22%"},
{"Profit-Loss Ratio", "0.87"},
{"Alpha", "-0.149"},
{"Alpha", "-0.156"},
{"Beta", "0.035"},
{"Annual Standard Deviation", "0.008"},
{"Annual Variance", "0"},
{"Information Ratio", "-9.603"},
{"Tracking Error", "0.215"},
{"Treynor Ratio", "-2.264"},
{"Treynor Ratio", "-2.478"},
{"Total Fees", "$199.00"},
{"Estimated Strategy Capacity", "$26000000.00"},
{"Lowest Capacity Asset", "SPY R735QTJ8XC9X"},
{"Portfolio Turnover", "119.89%"},
{"OrderListHash", "3c4c4085810cc5ecdb927d3647b9bbf3"}
{"OrderListHash", "2b4c6d1cb2fc32e25f9a744e8aa7229a"}
};
}
}

View File

@@ -120,30 +120,31 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "9"},
{"Total Orders", "9"},
{"Average Win", "0.86%"},
{"Average Loss", "-0.27%"},
{"Compounding Annual Return", "184.364%"},
{"Drawdown", "1.700%"},
{"Expectancy", "1.781"},
{"Net Profit", "1.442%"},
{"Sharpe Ratio", "4.86"},
{"Sharpe Ratio", "4.836"},
{"Sortino Ratio", "10.481"},
{"Probabilistic Sharpe Ratio", "59.497%"},
{"Loss Rate", "33%"},
{"Win Rate", "67%"},
{"Profit-Loss Ratio", "3.17"},
{"Alpha", "4.181"},
{"Alpha", "4.164"},
{"Beta", "-1.322"},
{"Annual Standard Deviation", "0.321"},
{"Annual Variance", "0.103"},
{"Information Ratio", "-0.795"},
{"Tracking Error", "0.532"},
{"Treynor Ratio", "-1.18"},
{"Treynor Ratio", "-1.174"},
{"Total Fees", "$14.78"},
{"Estimated Strategy Capacity", "$47000000.00"},
{"Lowest Capacity Asset", "IBM R735QTJ8XC9X"},
{"Portfolio Turnover", "41.18%"},
{"OrderListHash", "9da9afe1e9137638a55db1676adc2be1"}
{"OrderListHash", "e07dec6ddf0ef6b5d9c791b0593ec4dc"}
};
}
}

View File

@@ -97,7 +97,7 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "0"},
{"Total Orders", "0"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "0%"},
@@ -105,6 +105,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Expectancy", "0"},
{"Net Profit", "0%"},
{"Sharpe Ratio", "0"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "0%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},

View File

@@ -94,7 +94,7 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "0"},
{"Total Orders", "0"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "0%"},
@@ -102,6 +102,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Expectancy", "0"},
{"Net Profit", "0%"},
{"Sharpe Ratio", "0"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "0%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},

View File

@@ -114,30 +114,31 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "1"},
{"Total Orders", "3"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "12.939%"},
{"Drawdown", "0.300%"},
{"Expectancy", "0"},
{"Net Profit", "0.289%"},
{"Sharpe Ratio", "4.233"},
{"Sharpe Ratio", "3.924"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "68.349%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "0.035"},
{"Alpha", "0.028"},
{"Beta", "0.122"},
{"Annual Standard Deviation", "0.024"},
{"Annual Variance", "0.001"},
{"Information Ratio", "-3.181"},
{"Tracking Error", "0.142"},
{"Treynor Ratio", "0.842"},
{"Treynor Ratio", "0.78"},
{"Total Fees", "$1.00"},
{"Estimated Strategy Capacity", "$35000000.00"},
{"Lowest Capacity Asset", "IBM R735QTJ8XC9X"},
{"Portfolio Turnover", "1.51%"},
{"OrderListHash", "bd88c6a0e10c7e146b05377205101a12"}
{"OrderListHash", "381bb9310f9dceb8a79a56849789bdab"}
};
}
}

View File

@@ -116,7 +116,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 63;
public long DataPoints => 74;
/// <summary>
/// Data Points count of the algorithm history
@@ -128,30 +128,31 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "3"},
{"Total Orders", "3"},
{"Average Win", "0%"},
{"Average Loss", "-0.03%"},
{"Compounding Annual Return", "-2.594%"},
{"Drawdown", "0.000%"},
{"Expectancy", "-1"},
{"Net Profit", "-0.034%"},
{"Sharpe Ratio", "-7.854"},
{"Sharpe Ratio", "-10.666"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "1.216%"},
{"Loss Rate", "100%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "-0.022"},
{"Alpha", "-0.029"},
{"Beta", "0.004"},
{"Annual Standard Deviation", "0.003"},
{"Annual Variance", "0"},
{"Information Ratio", "-0.768"},
{"Tracking Error", "0.241"},
{"Treynor Ratio", "-4.689"},
{"Treynor Ratio", "-6.368"},
{"Total Fees", "$8.60"},
{"Estimated Strategy Capacity", "$5500000.00"},
{"Lowest Capacity Asset", "ES VMKLFZIH2MTD"},
{"Portfolio Turnover", "66.80%"},
{"OrderListHash", "802a335b5c355e83b8cd2174f053c1b9"}
{"OrderListHash", "0ade3a7a7aaafa3263082c93cf17c4d8"}
};
}
}

View File

@@ -176,30 +176,31 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "2"},
{"Total Orders", "2"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "5512.811%"},
{"Drawdown", "1.000%"},
{"Expectancy", "0"},
{"Net Profit", "5.333%"},
{"Sharpe Ratio", "64.137"},
{"Sharpe Ratio", "64.084"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "95.977%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "25.72"},
{"Alpha", "25.763"},
{"Beta", "2.914"},
{"Annual Standard Deviation", "0.423"},
{"Annual Variance", "0.179"},
{"Information Ratio", "66.11"},
{"Tracking Error", "0.403"},
{"Treynor Ratio", "9.315"},
{"Treynor Ratio", "9.308"},
{"Total Fees", "$8.60"},
{"Estimated Strategy Capacity", "$22000000.00"},
{"Lowest Capacity Asset", "ES XFH59UK0MYO1"},
{"Portfolio Turnover", "122.11%"},
{"OrderListHash", "e7021bd385f366771ae00abd3a46a22e"}
{"OrderListHash", "679692e30a7cf3b54b09af766589df80"}
};
}
}

View File

@@ -93,7 +93,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 12164;
public long DataPoints => 12170;
/// <summary>
/// Data Points count of the algorithm history
@@ -105,19 +105,20 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "20"},
{"Total Orders", "20"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "386219349.202%"},
{"Drawdown", "5.200%"},
{"Expectancy", "0"},
{"Net Profit", "11.912%"},
{"Sharpe Ratio", "1604181.92"},
{"Sharpe Ratio", "1604181.904"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "0%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "2144881.34"},
{"Alpha", "2144882.02"},
{"Beta", "31.223"},
{"Annual Standard Deviation", "1.337"},
{"Annual Variance", "1.788"},
@@ -128,7 +129,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Estimated Strategy Capacity", "$2600000.00"},
{"Lowest Capacity Asset", "ES 31C3JQS9D84PW|ES XCZJLC9NOB29"},
{"Portfolio Turnover", "495.15%"},
{"OrderListHash", "64221a660525c4259d5bd852eef1299c"}
{"OrderListHash", "51ae811a9f7a26ae8eb96cdcefe1ab59"}
};
}
}

View File

@@ -220,7 +220,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 608372;
public long DataPoints => 608378;
/// <summary>
/// Data Points count of the algorithm history
@@ -232,30 +232,31 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "2"},
{"Total Orders", "2"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "347.065%"},
{"Drawdown", "0.900%"},
{"Expectancy", "0"},
{"Net Profit", "1.951%"},
{"Sharpe Ratio", "15.548"},
{"Sharpe Ratio", "15.402"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "95.977%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "1.885"},
{"Alpha", "1.886"},
{"Beta", "1.066"},
{"Annual Standard Deviation", "0.155"},
{"Annual Variance", "0.024"},
{"Information Ratio", "13.528"},
{"Tracking Error", "0.142"},
{"Treynor Ratio", "2.258"},
{"Treynor Ratio", "2.237"},
{"Total Fees", "$3.57"},
{"Estimated Strategy Capacity", "$760000.00"},
{"Lowest Capacity Asset", "ES XCZJLDQX2SRO|ES XCZJLC9NOB29"},
{"Portfolio Turnover", "32.31%"},
{"OrderListHash", "738240babf741f1bf79f85ea5026ec4c"}
{"OrderListHash", "8d248c2234fec09fbe09f86735fefd99"}
};
}
}

View File

@@ -129,30 +129,31 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "3"},
{"Total Orders", "3"},
{"Average Win", "2.73%"},
{"Average Loss", "-2.98%"},
{"Compounding Annual Return", "-4.619%"},
{"Drawdown", "0.300%"},
{"Expectancy", "-0.042"},
{"Net Profit", "-0.332%"},
{"Sharpe Ratio", "-3.149"},
{"Sharpe Ratio", "-4.614"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "0.427%"},
{"Loss Rate", "50%"},
{"Win Rate", "50%"},
{"Profit-Loss Ratio", "0.92"},
{"Alpha", "-0.015"},
{"Alpha", "-0.022"},
{"Beta", "-0.012"},
{"Annual Standard Deviation", "0.005"},
{"Annual Variance", "0"},
{"Information Ratio", "-2.823"},
{"Tracking Error", "0.049"},
{"Treynor Ratio", "1.372"},
{"Treynor Ratio", "2.01"},
{"Total Fees", "$2.00"},
{"Estimated Strategy Capacity", "$5700000.00"},
{"Lowest Capacity Asset", "AOL VRKS95ENLBYE|AOL R735QTJ8XC9X"},
{"Portfolio Turnover", "0.55%"},
{"OrderListHash", "568fe7c2a11960436660db1231f2cfd2"}
{"OrderListHash", "f4c70895e766de85de883a25ca0b5c08"}
};
}
}

View File

@@ -169,7 +169,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 5797;
public long DataPoints => 5798;
/// <summary>
/// Data Points count of the algorithm history
@@ -181,30 +181,31 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "2"},
{"Total Orders", "2"},
{"Average Win", "0%"},
{"Average Loss", "-0.23%"},
{"Compounding Annual Return", "-15.596%"},
{"Drawdown", "0.200%"},
{"Expectancy", "-1"},
{"Net Profit", "-0.232%"},
{"Sharpe Ratio", "-7.739"},
{"Sharpe Ratio", "-8.903"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "1.216%"},
{"Loss Rate", "100%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "0.024"},
{"Alpha", "0.015"},
{"Beta", "-0.171"},
{"Annual Standard Deviation", "0.006"},
{"Annual Variance", "0"},
{"Information Ratio", "-11.082"},
{"Tracking Error", "0.043"},
{"Treynor Ratio", "0.291"},
{"Treynor Ratio", "0.335"},
{"Total Fees", "$2.00"},
{"Estimated Strategy Capacity", "$2800000.00"},
{"Lowest Capacity Asset", "AOL VRKS95ENLBYE|AOL R735QTJ8XC9X"},
{"Portfolio Turnover", "1.14%"},
{"OrderListHash", "ae0b430e9c728966e3736fb352a689c6"}
{"OrderListHash", "99fd501dbd9e78656be9b32869fc32e0"}
};
}
}

View File

@@ -128,7 +128,7 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "2"},
{"Total Orders", "2"},
{"Average Win", "0%"},
{"Average Loss", "-0.05%"},
{"Compounding Annual Return", "-4.548%"},
@@ -136,6 +136,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Expectancy", "-1"},
{"Net Profit", "-0.051%"},
{"Sharpe Ratio", "0"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "0%"},
{"Loss Rate", "100%"},
{"Win Rate", "0%"},
@@ -151,7 +152,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Estimated Strategy Capacity", "$30000.00"},
{"Lowest Capacity Asset", "AAPL VXBK4Q9ZIFD2|AAPL R735QTJ8XC9X"},
{"Portfolio Turnover", "0.07%"},
{"OrderListHash", "546b6182e1df2d222178454d8f311566"}
{"OrderListHash", "b01a993665c5333c37de9dbef0717e14"}
};
}
}

View File

@@ -100,7 +100,7 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "0"},
{"Total Orders", "0"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "0%"},
@@ -108,6 +108,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Expectancy", "0"},
{"Net Profit", "0%"},
{"Sharpe Ratio", "0"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "0%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},

View File

@@ -79,7 +79,7 @@ namespace QuantConnect.Algorithm.CSharp
// things like manually added, auto added, internal, and any other boolean state we need to track against a single security)
throw new Exception("The underlying equity data should NEVER be removed in this algorithm because it was manually added");
}
if (_expectedSecurities.AreDifferent(Securities.Keys.ToHashSet()))
if (_expectedSecurities.AreDifferent(Securities.Total.Select(x => x.Symbol).ToHashSet()))
{
var expected = string.Join(Environment.NewLine, _expectedSecurities.OrderBy(s => s.ToString()));
var actual = string.Join(Environment.NewLine, Securities.Keys.OrderBy(s => s.ToString()));
@@ -116,7 +116,7 @@ namespace QuantConnect.Algorithm.CSharp
}
// find first put above market price
return u.IncludeWeeklys()
.Strikes(+1, +1)
.Strikes(+1, +3)
.Expiration(TimeSpan.Zero, TimeSpan.FromDays(1))
.Contracts(c => c.Where(s => s.ID.OptionRight == OptionRight.Put));
});
@@ -141,16 +141,6 @@ namespace QuantConnect.Algorithm.CSharp
public override void OnSecuritiesChanged(SecurityChanges changes)
{
if (changes.AddedSecurities.Count > 1)
{
// added event fired for underlying since it was added to the option chain universe
if (changes.AddedSecurities.All(s => s.Symbol != Underlying))
{
var securities = string.Join(Environment.NewLine, changes.AddedSecurities.Select(s => s.Symbol));
throw new Exception($"This algorithm intends to add a single security at a time but added: {changes.AddedSecurities.Count}{Environment.NewLine}{securities}");
}
}
if (changes.AddedSecurities.Any())
{
foreach (var added in changes.AddedSecurities)
@@ -213,7 +203,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 200618;
public long DataPoints => 200807;
/// <summary>
/// Data Points count of the algorithm history
@@ -225,7 +215,7 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "6"},
{"Total Orders", "6"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "0%"},
@@ -233,6 +223,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Expectancy", "0"},
{"Net Profit", "0%"},
{"Sharpe Ratio", "0"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "0%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
@@ -245,10 +236,10 @@ namespace QuantConnect.Algorithm.CSharp
{"Tracking Error", "0"},
{"Treynor Ratio", "0"},
{"Total Fees", "$6.00"},
{"Estimated Strategy Capacity", "$2000.00"},
{"Estimated Strategy Capacity", "$3000.00"},
{"Lowest Capacity Asset", "GOOCV 305RBR0BSWIX2|GOOCV VP83T1ZUHROL"},
{"Portfolio Turnover", "1.19%"},
{"OrderListHash", "550a99c482106defd8ba15f48183768e"}
{"Portfolio Turnover", "1.49%"},
{"OrderListHash", "3adcc7ebf4153baabb073a8152e8cb2b"}
};
}
}

View File

@@ -95,30 +95,31 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "19"},
{"Total Orders", "19"},
{"Average Win", "0%"},
{"Average Loss", "0.00%"},
{"Compounding Annual Return", "271.720%"},
{"Drawdown", "2.500%"},
{"Expectancy", "-1"},
{"Net Profit", "1.754%"},
{"Sharpe Ratio", "11.994"},
{"Sharpe Ratio", "11.954"},
{"Sortino Ratio", "29.606"},
{"Probabilistic Sharpe Ratio", "74.160%"},
{"Loss Rate", "100%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "0.618"},
{"Alpha", "0.616"},
{"Beta", "0.81"},
{"Annual Standard Deviation", "0.185"},
{"Annual Variance", "0.034"},
{"Information Ratio", "3.961"},
{"Tracking Error", "0.061"},
{"Treynor Ratio", "2.746"},
{"Treynor Ratio", "2.737"},
{"Total Fees", "$21.45"},
{"Estimated Strategy Capacity", "$830000.00"},
{"Lowest Capacity Asset", "SPY R735QTJ8XC9X"},
{"Portfolio Turnover", "20.49%"},
{"OrderListHash", "6ee62edf1ac883882b0fcef8cb3e9bae"}
{"OrderListHash", "48d8e1195003665a2febf547c075d07f"}
};
}
}

View File

@@ -121,30 +121,31 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "5"},
{"Total Orders", "5"},
{"Average Win", "0.46%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "296.356%"},
{"Drawdown", "1.400%"},
{"Expectancy", "0"},
{"Net Profit", "1.776%"},
{"Sharpe Ratio", "13.013"},
{"Sharpe Ratio", "12.966"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "80.409%"},
{"Loss Rate", "0%"},
{"Win Rate", "100%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "0.68"},
{"Alpha", "0.678"},
{"Beta", "0.707"},
{"Annual Standard Deviation", "0.16"},
{"Annual Variance", "0.026"},
{"Information Ratio", "1.378"},
{"Tracking Error", "0.072"},
{"Treynor Ratio", "2.946"},
{"Treynor Ratio", "2.935"},
{"Total Fees", "$28.30"},
{"Estimated Strategy Capacity", "$4700000.00"},
{"Lowest Capacity Asset", "AIG R735QTJ8XC9X"},
{"Portfolio Turnover", "29.88%"},
{"OrderListHash", "ac3f4dfcdeb98b488b715412ad2d6c4f"}
{"OrderListHash", "b26f2f30082b754b065c41bb0ace44cc"}
};
}
}

View File

@@ -74,30 +74,31 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "3"},
{"Total Orders", "3"},
{"Average Win", "1.02%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "296.066%"},
{"Drawdown", "2.200%"},
{"Expectancy", "0"},
{"Net Profit", "1.775%"},
{"Sharpe Ratio", "9.373"},
{"Sharpe Ratio", "9.34"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "68.302%"},
{"Loss Rate", "0%"},
{"Win Rate", "100%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "0.105"},
{"Alpha", "0.106"},
{"Beta", "1.021"},
{"Annual Standard Deviation", "0.227"},
{"Annual Variance", "0.052"},
{"Information Ratio", "25.083"},
{"Tracking Error", "0.006"},
{"Treynor Ratio", "2.086"},
{"Treynor Ratio", "2.079"},
{"Total Fees", "$10.33"},
{"Estimated Strategy Capacity", "$38000000.00"},
{"Lowest Capacity Asset", "SPY R735QTJ8XC9X"},
{"Portfolio Turnover", "59.74%"},
{"OrderListHash", "af3a9c98c190d1b6b36fad184e796b0b"}
{"OrderListHash", "b5a7935f37d94eb20f6bcd88578dbaee"}
};
}
}

View File

@@ -113,7 +113,7 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "2"},
{"Total Orders", "2"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "0%"},
@@ -121,6 +121,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Expectancy", "0"},
{"Net Profit", "0%"},
{"Sharpe Ratio", "0"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "0%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
@@ -136,7 +137,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Estimated Strategy Capacity", "$230000.00"},
{"Lowest Capacity Asset", "AAPL VXBK4QQIRLZA|AAPL R735QTJ8XC9X"},
{"Portfolio Turnover", "0.25%"},
{"OrderListHash", "228194dcc6fd8689a67f383577ee2d85"}
{"OrderListHash", "afec48c499382b1d01af22daafe9f648"}
};
}
}

View File

@@ -93,30 +93,31 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "10"},
{"Total Orders", "10"},
{"Average Win", "0%"},
{"Average Loss", "-0.01%"},
{"Compounding Annual Return", "-14.233%"},
{"Drawdown", "3.300%"},
{"Expectancy", "-1"},
{"Net Profit", "-0.168%"},
{"Sharpe Ratio", "62.499"},
{"Sharpe Ratio", "62.464"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "0%"},
{"Loss Rate", "100%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "1.116"},
{"Alpha", "1.117"},
{"Beta", "1.19"},
{"Annual Standard Deviation", "0.213"},
{"Annual Variance", "0.046"},
{"Information Ratio", "70.778"},
{"Tracking Error", "0.043"},
{"Treynor Ratio", "11.206"},
{"Treynor Ratio", "11.2"},
{"Total Fees", "$22.21"},
{"Estimated Strategy Capacity", "$340000000.00"},
{"Lowest Capacity Asset", "FB V6OIPNZEM8V9"},
{"Portfolio Turnover", "26.92%"},
{"OrderListHash", "a259afcf4ee1c65ce5d26588ab645dbf"}
{"OrderListHash", "be09b39c5d01b0694f474ea7f7c5ae09"}
};
}
}

View File

@@ -104,30 +104,31 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "21"},
{"Total Orders", "23"},
{"Average Win", "0.00%"},
{"Average Loss", "-0.01%"},
{"Compounding Annual Return", "-75.275%"},
{"Drawdown", "5.800%"},
{"Expectancy", "-0.609"},
{"Net Profit", "-5.581%"},
{"Sharpe Ratio", "-3.25"},
{"Sharpe Ratio", "-3.288"},
{"Sortino Ratio", "-3.828"},
{"Probabilistic Sharpe Ratio", "5.546%"},
{"Loss Rate", "73%"},
{"Win Rate", "27%"},
{"Profit-Loss Ratio", "0.43"},
{"Alpha", "-0.498"},
{"Alpha", "-0.495"},
{"Beta", "1.484"},
{"Annual Standard Deviation", "0.196"},
{"Annual Variance", "0.039"},
{"Information Ratio", "-3.843"},
{"Tracking Error", "0.141"},
{"Treynor Ratio", "-0.43"},
{"Treynor Ratio", "-0.435"},
{"Total Fees", "$31.25"},
{"Estimated Strategy Capacity", "$550000000.00"},
{"Lowest Capacity Asset", "AAPL R735QTJ8XC9X"},
{"Portfolio Turnover", "7.33%"},
{"OrderListHash", "6aab808e341ae46946b91ba378073531"}
{"OrderListHash", "b2ec2148ac94b67038a5bb4a2655f0a6"}
};
}
}

View File

@@ -168,7 +168,7 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "1"},
{"Total Orders", "1"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "0%"},
@@ -176,6 +176,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Expectancy", "0"},
{"Net Profit", "0%"},
{"Sharpe Ratio", "0"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "0%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
@@ -191,7 +192,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Estimated Strategy Capacity", "$42000000.00"},
{"Lowest Capacity Asset", "AAPL R735QTJ8XC9X"},
{"Portfolio Turnover", "99.56%"},
{"OrderListHash", "18e41dded4f8cee548ee02b03ffb0814"}
{"OrderListHash", "92cacc8a537ff29960b6d092c3f92cf1"}
};
}
}

View File

@@ -82,7 +82,7 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "0"},
{"Total Orders", "0"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "0%"},
@@ -90,6 +90,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Expectancy", "0"},
{"Net Profit", "0%"},
{"Sharpe Ratio", "0"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "0%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},

View File

@@ -171,13 +171,16 @@ namespace QuantConnect.Algorithm.CSharp
{
public AllShortableSymbolsRegressionAlgorithmBrokerageModel() : base()
{
ShortableProvider = new RegressionTestShortableProvider();
}
public override IShortableProvider GetShortableProvider(Security security)
{
return new RegressionTestShortableProvider();
}
}
private class RegressionTestShortableProvider : LocalDiskShortableProvider
{
public RegressionTestShortableProvider() : base(SecurityType.Equity, "testbrokerage", Market.USA)
public RegressionTestShortableProvider() : base("testbrokerage")
{
}
@@ -188,6 +191,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <returns>Symbol/quantity shortable as a Dictionary. Returns null if no entry data exists for this date or brokerage</returns>
public Dictionary<Symbol, long> AllShortableSymbols(DateTime localTime)
{
var shortableDataDirectory = Path.Combine(Globals.DataFolder, SecurityType.Equity.SecurityTypeToLower(), Market.USA, "shortable", Brokerage);
var allSymbols = new Dictionary<Symbol, long>();
// Check backwards up to one week to see if we can source a previous file.
@@ -195,7 +199,7 @@ namespace QuantConnect.Algorithm.CSharp
var i = 0;
while (i <= 7)
{
var shortableListFile = Path.Combine(ShortableDataDirectory.FullName, "dates", $"{localTime.AddDays(-i):yyyyMMdd}.csv");
var shortableListFile = Path.Combine(shortableDataDirectory, "dates", $"{localTime.AddDays(-i):yyyyMMdd}.csv");
foreach (var line in DataProvider.ReadLines(shortableListFile))
{
@@ -231,7 +235,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// This is used by the regression test system to indicate which languages this algorithm is written in.
/// </summary>
public Language[] Languages { get; } = { Language.CSharp};
public Language[] Languages { get; } = { Language.CSharp, Language.Python };
/// <summary>
/// Data Points count of all timeslices of algorithm
@@ -248,30 +252,31 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "5"},
{"Total Orders", "5"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "19.147%"},
{"Drawdown", "0%"},
{"Expectancy", "0"},
{"Net Profit", "0.192%"},
{"Sharpe Ratio", "231.673"},
{"Sharpe Ratio", "221.176"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "0%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "0.163"},
{"Alpha", "0.156"},
{"Beta", "-0.007"},
{"Annual Standard Deviation", "0.001"},
{"Annual Variance", "0"},
{"Information Ratio", "4.804"},
{"Tracking Error", "0.098"},
{"Treynor Ratio", "-22.526"},
{"Treynor Ratio", "-21.505"},
{"Total Fees", "$307.50"},
{"Estimated Strategy Capacity", "$2600000.00"},
{"Lowest Capacity Asset", "GOOCV VP83T1ZUHROL"},
{"Portfolio Turnover", "10.61%"},
{"OrderListHash", "0069f402ffcd2d91b9018b81badfab81"}
{"OrderListHash", "9c129e856afe96579b52cbfe95237100"}
};
}
}

View File

@@ -1,122 +0,0 @@
/*
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using QuantConnect.Interfaces;
using System.Collections.Generic;
using QuantConnect.Data.UniverseSelection;
using QuantConnect.Data.Custom.AlphaStreams;
using QuantConnect.Algorithm.Framework.Alphas;
using QuantConnect.Algorithm.Framework.Execution;
using QuantConnect.Algorithm.Framework.Portfolio;
using QuantConnect.Algorithm.Framework.Selection;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Example algorithm consuming an alpha streams portfolio state and trading based on it
/// </summary>
public class AlphaStreamsUniverseSelectionTemplateAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
{
/// <summary>
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
/// </summary>
public override void Initialize()
{
SetStartDate(2018, 04, 04);
SetEndDate(2018, 04, 06);
SetAlpha(new AlphaStreamAlphaModule());
SetExecution(new ImmediateExecutionModel());
Settings.MinimumOrderMarginPortfolioPercentage = 0.01m;
SetPortfolioConstruction(new EqualWeightingAlphaStreamsPortfolioConstructionModel());
SetUniverseSelection(new ScheduledUniverseSelectionModel(
DateRules.EveryDay(),
TimeRules.Midnight,
SelectAlphas,
new UniverseSettings(UniverseSettings)
{
SubscriptionDataTypes = new List<Tuple<Type, TickType>>
{new(typeof(AlphaStreamsPortfolioState), TickType.Trade)},
FillForward = false,
}
));
}
private IEnumerable<Symbol> SelectAlphas(DateTime dateTime)
{
Log($"SelectAlphas() {Time}");
foreach (var alphaId in new[] {"623b06b231eb1cc1aa3643a46", "9fc8ef73792331b11dbd5429a"})
{
var alphaSymbol = new Symbol(SecurityIdentifier.GenerateBase(typeof(AlphaStreamsPortfolioState), alphaId, Market.USA),
alphaId);
yield return alphaSymbol;
}
}
/// <summary>
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
/// </summary>
public bool CanRunLocally { get; } = true;
/// <summary>
/// This is used by the regression test system to indicate which languages this algorithm is written in.
/// </summary>
public Language[] Languages { get; } = { Language.CSharp };
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 893;
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 2;
/// <summary>
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
/// </summary>
public virtual Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "2"},
{"Average Win", "0%"},
{"Average Loss", "-0.12%"},
{"Compounding Annual Return", "-13.200%"},
{"Drawdown", "0.200%"},
{"Expectancy", "-1"},
{"Net Profit", "-0.116%"},
{"Sharpe Ratio", "0"},
{"Probabilistic Sharpe Ratio", "0%"},
{"Loss Rate", "100%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "0"},
{"Beta", "0"},
{"Annual Standard Deviation", "0"},
{"Annual Variance", "0"},
{"Information Ratio", "2.474"},
{"Tracking Error", "0.339"},
{"Treynor Ratio", "0"},
{"Total Fees", "$0.00"},
{"Estimated Strategy Capacity", "$83000.00"},
{"Lowest Capacity Asset", "BTCUSD XJ"},
{"Portfolio Turnover", "2.31%"},
{"OrderListHash", "2b94bc50a74caebe06c075cdab1bc6da"}
};
}
}

View File

@@ -1,136 +0,0 @@
/*
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using QuantConnect.Orders;
using System.Collections.Generic;
using QuantConnect.Data.Custom.AlphaStreams;
using QuantConnect.Algorithm.Framework.Execution;
using QuantConnect.Algorithm.Framework.Portfolio;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Example algorithm with existing holdings consuming an alpha streams portfolio state and trading based on it
/// </summary>
public class AlphaStreamsWithHoldingsBasicTemplateAlgorithm : AlphaStreamsBasicTemplateAlgorithm
{
private decimal _expectedSpyQuantity;
/// <summary>
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
/// </summary>
public override void Initialize()
{
SetStartDate(2018, 04, 04);
SetEndDate(2018, 04, 06);
SetCash(100000);
SetExecution(new ImmediateExecutionModel());
UniverseSettings.Resolution = Resolution.Hour;
Settings.MinimumOrderMarginPortfolioPercentage = 0.001m;
SetPortfolioConstruction(new EqualWeightingAlphaStreamsPortfolioConstructionModel());
// AAPL should be liquidated since it's not hold by the alpha
// This is handled by the PCM
var aapl = AddEquity("AAPL", Resolution.Hour);
aapl.Holdings.SetHoldings(40, 10);
// SPY will be bought following the alpha streams portfolio
// This is handled by the PCM + Execution Model
var spy = AddEquity("SPY", Resolution.Hour);
spy.Holdings.SetHoldings(246, -10);
AddData<AlphaStreamsPortfolioState>("94d820a93fff127fa46c15231d");
}
public override void OnOrderEvent(OrderEvent orderEvent)
{
if (_expectedSpyQuantity == 0 && orderEvent.Symbol == "SPY" && orderEvent.Status == OrderStatus.Filled)
{
var security = Securities["SPY"];
var priceInAccountCurrency = Portfolio.CashBook.ConvertToAccountCurrency(security.AskPrice, security.QuoteCurrency.Symbol);
_expectedSpyQuantity = Portfolio.TotalPortfolioValueLessFreeBuffer / priceInAccountCurrency;
_expectedSpyQuantity = _expectedSpyQuantity.DiscretelyRoundBy(1, MidpointRounding.ToZero);
}
base.OnOrderEvent(orderEvent);
}
public override void OnEndOfAlgorithm()
{
if (Securities["AAPL"].HoldStock)
{
throw new Exception("We should no longer hold AAPL since the alpha does not");
}
// we allow some padding for small price differences
if (Math.Abs(Securities["SPY"].Holdings.Quantity - _expectedSpyQuantity) > _expectedSpyQuantity * 0.03m)
{
throw new Exception($"Unexpected SPY holdings. Expected {_expectedSpyQuantity} was {Securities["SPY"].Holdings.Quantity}");
}
}
/// <summary>
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
/// </summary>
public bool CanRunLocally { get; } = true;
/// <summary>
/// This is used by the regression test system to indicate which languages this algorithm is written in.
/// </summary>
public Language[] Languages { get; } = { Language.CSharp };
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public override long DataPoints => 2313;
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public override int AlgorithmHistoryDataPoints => 1;
/// <summary>
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
/// </summary>
public override Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "2"},
{"Average Win", "0.01%"},
{"Average Loss", "0.00%"},
{"Compounding Annual Return", "-87.617%"},
{"Drawdown", "3.100%"},
{"Expectancy", "8.518"},
{"Net Profit", "-1.515%"},
{"Sharpe Ratio", "-2.45"},
{"Probabilistic Sharpe Ratio", "0%"},
{"Loss Rate", "50%"},
{"Win Rate", "50%"},
{"Profit-Loss Ratio", "18.04"},
{"Alpha", "0.008"},
{"Beta", "1.015"},
{"Annual Standard Deviation", "0.344"},
{"Annual Variance", "0.118"},
{"Information Ratio", "-0.856"},
{"Tracking Error", "0.005"},
{"Treynor Ratio", "-0.83"},
{"Total Fees", "$3.09"},
{"Estimated Strategy Capacity", "$8900000000.00"},
{"Lowest Capacity Asset", "AAPL R735QTJ8XC9X"},
{"Portfolio Turnover", "34.12%"},
{"OrderListHash", "788eb2c74715a78476ba0db3b2654eb6"}
};
}
}

View File

@@ -195,11 +195,11 @@ namespace QuantConnect.Algorithm.CSharp.Alphas
private const int _numberOfSymbolsFine = 20;
private const int _numberOfSymbolsInPortfolio = 10;
private int _lastMonth = -1;
private Dictionary<Symbol, decimal> _dollarVolumeBySymbol;
private Dictionary<Symbol, double> _dollarVolumeBySymbol;
public GreenBlattMagicFormulaUniverseSelectionModel() : base(true)
{
_dollarVolumeBySymbol = new Dictionary<Symbol, decimal>();
_dollarVolumeBySymbol = new ();
}
/// <summary>
@@ -245,7 +245,7 @@ namespace QuantConnect.Algorithm.CSharp.Alphas
where x.CompanyReference.CountryId == "USA"
where x.CompanyReference.PrimaryExchangeID == "NYS" || x.CompanyReference.PrimaryExchangeID == "NAS"
where (algorithm.Time - x.SecurityReference.IPODate).TotalDays > 180
where x.EarningReports.BasicAverageShares.ThreeMonths * x.EarningReports.BasicEPS.TwelveMonths * x.ValuationRatios.PERatio > 5e8m
where x.EarningReports.BasicAverageShares.ThreeMonths * x.EarningReports.BasicEPS.TwelveMonths * x.ValuationRatios.PERatio > 5e8
select x;
double count = filteredFine.Count();
@@ -287,4 +287,4 @@ namespace QuantConnect.Algorithm.CSharp.Alphas
}
}
}
}
}

View File

@@ -97,7 +97,7 @@ namespace QuantConnect.Algorithm.CSharp.Alphas
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "2465"},
{"Total Orders", "2465"},
{"Average Win", "0.26%"},
{"Average Loss", "-0.24%"},
{"Compounding Annual Return", "7.848%"},

View File

@@ -0,0 +1,33 @@
/*
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Example algorithm using the asynchronous universe selection functionality
/// </summary>
public class AsynchronousUniverseRegressionAlgorithm : FundamentalRegressionAlgorithm
{
/// <summary>
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
/// </summary>
public override void Initialize()
{
base.Initialize();
UniverseSettings.Asynchronous = true;
}
}
}

View File

@@ -88,30 +88,31 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "52"},
{"Total Orders", "52"},
{"Average Win", "0.00%"},
{"Average Loss", "0.00%"},
{"Compounding Annual Return", "0.096%"},
{"Drawdown", "0.100%"},
{"Expectancy", "3.321"},
{"Net Profit", "0.089%"},
{"Sharpe Ratio", "0.798"},
{"Sharpe Ratio", "-8.214"},
{"Sortino Ratio", "-9.025"},
{"Probabilistic Sharpe Ratio", "40.893%"},
{"Loss Rate", "24%"},
{"Win Rate", "76%"},
{"Profit-Loss Ratio", "4.67"},
{"Alpha", "-0.001"},
{"Alpha", "-0.008"},
{"Beta", "0.008"},
{"Annual Standard Deviation", "0.001"},
{"Annual Variance", "0"},
{"Information Ratio", "-1.961"},
{"Tracking Error", "0.092"},
{"Treynor Ratio", "0.08"},
{"Treynor Ratio", "-0.826"},
{"Total Fees", "$52.00"},
{"Estimated Strategy Capacity", "$32000000000.00"},
{"Lowest Capacity Asset", "SPY R735QTJ8XC9X"},
{"Portfolio Turnover", "0.02%"},
{"OrderListHash", "cf43585a8d1781f04b53a4f1ee3380cb"}
{"OrderListHash", "e6711c76cb05bbb575ca067664348d88"}
};
}
}

View File

@@ -158,30 +158,31 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "1"},
{"Total Orders", "1"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "733913.744%"},
{"Drawdown", "15.900%"},
{"Expectancy", "0"},
{"Net Profit", "6.828%"},
{"Sharpe Ratio", "203744786353.302"},
{"Sharpe Ratio", "203744786353.299"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "0%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "456382350698.561"},
{"Alpha", "456382350698.622"},
{"Beta", "9.229"},
{"Annual Standard Deviation", "2.24"},
{"Annual Variance", "5.017"},
{"Information Ratio", "228504036840.953"},
{"Tracking Error", "1.997"},
{"Treynor Ratio", "49450701625.718"},
{"Treynor Ratio", "49450701625.717"},
{"Total Fees", "$23.65"},
{"Estimated Strategy Capacity", "$200000000.00"},
{"Lowest Capacity Asset", "ES VMKLFZIH2MTD"},
{"Portfolio Turnover", "351.80%"},
{"OrderListHash", "dd38e7b94027d20942a5aa9ac31a9a7f"}
{"OrderListHash", "23cf084b30ec3d70b1b9f54c9b3b975f"}
};
}
}

View File

@@ -120,14 +120,15 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "1"},
{"Total Orders", "1"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "271.453%"},
{"Drawdown", "2.200%"},
{"Expectancy", "0"},
{"Net Profit", "1.692%"},
{"Sharpe Ratio", "8.888"},
{"Sharpe Ratio", "8.854"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "67.609%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
@@ -138,12 +139,12 @@ namespace QuantConnect.Algorithm.CSharp
{"Annual Variance", "0.049"},
{"Information Ratio", "-14.565"},
{"Tracking Error", "0.001"},
{"Treynor Ratio", "1.978"},
{"Treynor Ratio", "1.97"},
{"Total Fees", "$3.44"},
{"Estimated Strategy Capacity", "$56000000.00"},
{"Lowest Capacity Asset", "SPY R735QTJ8XC9X"},
{"Portfolio Turnover", "19.93%"},
{"OrderListHash", "9e4bfd2eb0b81ee5bc1b197a87ccedbe"}
{"OrderListHash", "0c0f9328786b0c9e8f88d271673d16c3"}
};
}
}

View File

@@ -296,7 +296,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 1272232;
public long DataPoints => 1267414;
/// <summary>
/// Data Points count of the algorithm history
@@ -308,30 +308,31 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "3"},
{"Total Orders", "3"},
{"Average Win", "0%"},
{"Average Loss", "-0.40%"},
{"Compounding Annual Return", "-22.717%"},
{"Drawdown", "0.400%"},
{"Expectancy", "-1"},
{"Net Profit", "-0.329%"},
{"Sharpe Ratio", "-7.887"},
{"Sharpe Ratio", "-14.095"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "1.216%"},
{"Loss Rate", "100%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "-0.001"},
{"Alpha", "-0.01"},
{"Beta", "0.097"},
{"Annual Standard Deviation", "0.002"},
{"Annual Variance", "0"},
{"Information Ratio", "7.39"},
{"Tracking Error", "0.015"},
{"Treynor Ratio", "-0.131"},
{"Treynor Ratio", "-0.234"},
{"Total Fees", "$2.00"},
{"Estimated Strategy Capacity", "$0"},
{"Lowest Capacity Asset", "GOOCV VP83T1ZUHROL"},
{"Portfolio Turnover", "17.02%"},
{"OrderListHash", "85cbf92f01c2c91b5f710b7eeefecbe1"}
{"OrderListHash", "774204888824c3df9182b17dd7b55a2e"}
};
}
}

View File

@@ -84,7 +84,7 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "1"},
{"Total Orders", "1"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "0%"},
@@ -92,6 +92,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Expectancy", "0"},
{"Net Profit", "0%"},
{"Sharpe Ratio", "0"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "0%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
@@ -105,9 +106,9 @@ namespace QuantConnect.Algorithm.CSharp
{"Treynor Ratio", "0"},
{"Total Fees", "€298.35"},
{"Estimated Strategy Capacity", "€85000.00"},
{"Lowest Capacity Asset", "BTCEUR XJ"},
{"Lowest Capacity Asset", "BTCEUR 2XR"},
{"Portfolio Turnover", "107.64%"},
{"OrderListHash", "2ba443899dcccc79dc0f04441f797bf9"}
{"OrderListHash", "b0544d71cee600ef1f09c6000d6a3229"}
};
}
}

View File

@@ -54,7 +54,7 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "1"},
{"Total Orders", "1"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "0%"},
@@ -62,6 +62,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Expectancy", "0"},
{"Net Profit", "0%"},
{"Sharpe Ratio", "0"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "0%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
@@ -75,9 +76,9 @@ namespace QuantConnect.Algorithm.CSharp
{"Treynor Ratio", "0"},
{"Total Fees", "€596.71"},
{"Estimated Strategy Capacity", "€85000.00"},
{"Lowest Capacity Asset", "BTCEUR XJ"},
{"Lowest Capacity Asset", "BTCEUR 2XR"},
{"Portfolio Turnover", "107.64%"},
{"OrderListHash", "af1850fbc1faefaf2da98080e92c43a0"}
{"OrderListHash", "64c44a56824e67b86213539212d08e25"}
};
}
}

View File

@@ -87,14 +87,15 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "1"},
{"Total Orders", "1"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "271.453%"},
{"Drawdown", "2.200%"},
{"Expectancy", "0"},
{"Net Profit", "1.692%"},
{"Sharpe Ratio", "8.888"},
{"Sharpe Ratio", "8.854"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "67.609%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
@@ -105,12 +106,12 @@ namespace QuantConnect.Algorithm.CSharp
{"Annual Variance", "0.049"},
{"Information Ratio", "-14.565"},
{"Tracking Error", "0.001"},
{"Treynor Ratio", "1.978"},
{"Treynor Ratio", "1.97"},
{"Total Fees", "$3.44"},
{"Estimated Strategy Capacity", "$56000000.00"},
{"Lowest Capacity Asset", "SPY R735QTJ8XC9X"},
{"Portfolio Turnover", "19.93%"},
{"OrderListHash", "9e4bfd2eb0b81ee5bc1b197a87ccedbe"}
{"OrderListHash", "0c0f9328786b0c9e8f88d271673d16c3"}
};
}
}

View File

@@ -14,7 +14,6 @@
*/
using QuantConnect.Data;
using QuantConnect.Orders;
using QuantConnect.Interfaces;
using QuantConnect.Brokerages;
using System.Collections.Generic;
@@ -22,12 +21,12 @@ using System.Collections.Generic;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Basic template algorithm for the Atreyu brokerage
/// Basic template algorithm for the Axos brokerage
/// </summary>
/// <meta name="tag" content="using data" />
/// <meta name="tag" content="using quantconnect" />
/// <meta name="tag" content="trading and orders" />
public class BasicTemplateAtreyuAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
public class BasicTemplateAxosAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
{
/// <summary>
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
@@ -38,14 +37,8 @@ namespace QuantConnect.Algorithm.CSharp
SetEndDate(2013, 10, 11);
SetCash(100000);
SetBrokerageModel(BrokerageName.Atreyu);
SetBrokerageModel(BrokerageName.Axos);
AddEquity("SPY", Resolution.Minute);
DefaultOrderProperties = new AtreyuOrderProperties
{
// Currently only support order for the day
TimeInForce = TimeInForce.Day
};
}
/// <summary>
@@ -88,14 +81,15 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "1"},
{"Total Orders", "1"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "39.143%"},
{"Drawdown", "0.500%"},
{"Expectancy", "0"},
{"Net Profit", "0.423%"},
{"Sharpe Ratio", "5.634"},
{"Sharpe Ratio", "5.498"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "67.498%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
@@ -111,7 +105,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Estimated Strategy Capacity", "$150000000.00"},
{"Lowest Capacity Asset", "SPY R735QTJ8XC9X"},
{"Portfolio Turnover", "4.98%"},
{"OrderListHash", "d549c64ee7f5e3866712b3c7dbd64caa"}
{"OrderListHash", "c198b0d9bf2b4c41d69c7ea4750f09b5"}
};
}
}

View File

@@ -118,7 +118,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 703956;
public long DataPoints => 713395;
/// <summary>
/// Data Points count of the algorithm history
@@ -130,30 +130,31 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "3"},
{"Average Win", "5.51%"},
{"Total Orders", "5"},
{"Average Win", "2.90%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "12.437%"},
{"Drawdown", "1.500%"},
{"Compounding Annual Return", "13.087%"},
{"Drawdown", "1.100%"},
{"Expectancy", "0"},
{"Net Profit", "6.079%"},
{"Sharpe Ratio", "1.604"},
{"Probabilistic Sharpe Ratio", "88.038%"},
{"Net Profit", "6.387%"},
{"Sharpe Ratio", "1.532"},
{"Sortino Ratio", "871.704"},
{"Probabilistic Sharpe Ratio", "90.613%"},
{"Loss Rate", "0%"},
{"Win Rate", "100%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "0.091"},
{"Beta", "-0.02"},
{"Alpha", "0.088"},
{"Beta", "-0.022"},
{"Annual Standard Deviation", "0.054"},
{"Annual Variance", "0.003"},
{"Information Ratio", "-1.399"},
{"Tracking Error", "0.099"},
{"Treynor Ratio", "-4.276"},
{"Total Fees", "$6.45"},
{"Estimated Strategy Capacity", "$0"},
{"Information Ratio", "-1.35"},
{"Tracking Error", "0.1"},
{"Treynor Ratio", "-3.781"},
{"Total Fees", "$10.75"},
{"Estimated Strategy Capacity", "$1100000000.00"},
{"Lowest Capacity Asset", "ES VMKLFZIH2MTD"},
{"Portfolio Turnover", "1.39%"},
{"OrderListHash", "624c51bc6451dfb74335b99c04e3ed16"}
{"Portfolio Turnover", "2.32%"},
{"OrderListHash", "c42bb4b319557346b155cd2c06ade894"}
};
}
}

View File

@@ -123,7 +123,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 2169065;
public long DataPoints => 2217325;
/// <summary>
/// Data Points count of the algorithm history
@@ -135,30 +135,31 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "5"},
{"Total Orders", "5"},
{"Average Win", "4.45%"},
{"Average Loss", "-0.26%"},
{"Compounding Annual Return", "8.423%"},
{"Drawdown", "0.800%"},
{"Expectancy", "8.202"},
{"Net Profit", "4.162%"},
{"Sharpe Ratio", "1.089"},
{"Sharpe Ratio", "0.951"},
{"Sortino Ratio", "2.8"},
{"Probabilistic Sharpe Ratio", "53.568%"},
{"Loss Rate", "50%"},
{"Win Rate", "50%"},
{"Profit-Loss Ratio", "17.40"},
{"Alpha", "0.06"},
{"Alpha", "0.053"},
{"Beta", "-0.005"},
{"Annual Standard Deviation", "0.054"},
{"Annual Variance", "0.003"},
{"Information Ratio", "-1.681"},
{"Tracking Error", "0.099"},
{"Treynor Ratio", "-11.74"},
{"Treynor Ratio", "-10.255"},
{"Total Fees", "$10.75"},
{"Estimated Strategy Capacity", "$190000000.00"},
{"Lowest Capacity Asset", "ES VMKLFZIH2MTD"},
{"Portfolio Turnover", "2.34%"},
{"OrderListHash", "2a0aa0c11df66d81ebf0f7b3e9048bbc"}
{"OrderListHash", "8a6ad6061fc3c311934a0801c26744eb"}
};
}
}

View File

@@ -213,7 +213,7 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "10"},
{"Total Orders", "12"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "0%"},
@@ -221,6 +221,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Expectancy", "0"},
{"Net Profit", "0%"},
{"Sharpe Ratio", "0"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "0%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
@@ -234,9 +235,9 @@ namespace QuantConnect.Algorithm.CSharp
{"Treynor Ratio", "0"},
{"Total Fees", "$85.34"},
{"Estimated Strategy Capacity", "$0"},
{"Lowest Capacity Asset", "BTCEUR XJ"},
{"Lowest Capacity Asset", "BTCEUR 2XR"},
{"Portfolio Turnover", "118.08%"},
{"OrderListHash", "1bf1a6d9dd921982b72a6178f9e50e68"}
{"OrderListHash", "77458586d24f1cd00623d63da8279be2"}
};
}
}

View File

@@ -245,7 +245,7 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "4"},
{"Total Orders", "5"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "0%"},
@@ -253,6 +253,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Expectancy", "0"},
{"Net Profit", "0%"},
{"Sharpe Ratio", "0"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "0%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
@@ -268,7 +269,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Estimated Strategy Capacity", "$500000000.00"},
{"Lowest Capacity Asset", "ADAUSDT 18R"},
{"Portfolio Turnover", "0.16%"},
{"OrderListHash", "254f39d98378b1e7aa397b1f1e49c6cc"}
{"OrderListHash", "ed329700a93491ffe30354769767c6aa"}
};
}
}

View File

@@ -208,7 +208,7 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "2"},
{"Total Orders", "3"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "0%"},
@@ -216,6 +216,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Expectancy", "0"},
{"Net Profit", "0%"},
{"Sharpe Ratio", "0"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "0%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
@@ -231,7 +232,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Estimated Strategy Capacity", "$370000000.00"},
{"Lowest Capacity Asset", "ADAUSDT 18R"},
{"Portfolio Turnover", "0.12%"},
{"OrderListHash", "d2c6198197a4d18fa0a81f5933d935a6"}
{"OrderListHash", "5b1290390c34b0e64ac0b9e834c27b07"}
};
}
}

View File

@@ -78,14 +78,15 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "1"},
{"Total Orders", "1"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "246.546%"},
{"Drawdown", "1.200%"},
{"Expectancy", "0"},
{"Net Profit", "3.464%"},
{"Sharpe Ratio", "19.148"},
{"Sharpe Ratio", "19.094"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "97.754%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
@@ -96,12 +97,12 @@ namespace QuantConnect.Algorithm.CSharp
{"Annual Variance", "0.019"},
{"Information Ratio", "-34.028"},
{"Tracking Error", "0"},
{"Treynor Ratio", "2.651"},
{"Treynor Ratio", "2.644"},
{"Total Fees", "$3.45"},
{"Estimated Strategy Capacity", "$970000000.00"},
{"Lowest Capacity Asset", "SPY R735QTJ8XC9X"},
{"Portfolio Turnover", "10.09%"},
{"OrderListHash", "33d01821923c397f999cfb2e5b5928ad"}
{"OrderListHash", "418c8ec9920ec61bdefa2d02a8557048"}
};
}
}

View File

@@ -99,14 +99,15 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "3"},
{"Total Orders", "3"},
{"Average Win", "0%"},
{"Average Loss", "-1.01%"},
{"Compounding Annual Return", "261.134%"},
{"Drawdown", "2.200%"},
{"Expectancy", "-1"},
{"Net Profit", "1.655%"},
{"Sharpe Ratio", "8.505"},
{"Sharpe Ratio", "8.472"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "66.840%"},
{"Loss Rate", "100%"},
{"Win Rate", "0%"},
@@ -117,12 +118,12 @@ namespace QuantConnect.Algorithm.CSharp
{"Annual Variance", "0.05"},
{"Information Ratio", "-33.445"},
{"Tracking Error", "0.002"},
{"Treynor Ratio", "1.893"},
{"Treynor Ratio", "1.885"},
{"Total Fees", "$10.32"},
{"Estimated Strategy Capacity", "$27000000.00"},
{"Lowest Capacity Asset", "SPY R735QTJ8XC9X"},
{"Portfolio Turnover", "59.86%"},
{"OrderListHash", "ad2216297c759d8e5aef48ff065f8919"}
{"OrderListHash", "75c4c7221e2e70d0aa5c9844aae9009c"}
};
}
}

View File

@@ -176,7 +176,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 1332;
public long DataPoints => 1334;
/// <summary>
/// Data Points count of the algorithm history
@@ -188,30 +188,31 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "2"},
{"Total Orders", "2"},
{"Average Win", "0.53%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "3.011%"},
{"Drawdown", "0.000%"},
{"Expectancy", "0"},
{"Net Profit", "0.528%"},
{"Sharpe Ratio", "1.999"},
{"Sharpe Ratio", "1.285"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "83.704%"},
{"Loss Rate", "0%"},
{"Win Rate", "100%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "0.023"},
{"Alpha", "0.015"},
{"Beta", "-0.004"},
{"Annual Standard Deviation", "0.011"},
{"Annual Variance", "0"},
{"Information Ratio", "-4.774"},
{"Tracking Error", "0.084"},
{"Treynor Ratio", "-4.853"},
{"Treynor Ratio", "-3.121"},
{"Total Fees", "$4.30"},
{"Estimated Strategy Capacity", "$5900000000.00"},
{"Lowest Capacity Asset", "ES VMKLFZIH2MTD"},
{"Portfolio Turnover", "0.27%"},
{"OrderListHash", "40e4b91ec89383f6501d9ba324e50eb9"}
{"OrderListHash", "9fb6d9433c29815301d818ccd7f3863f"}
};
}
}

View File

@@ -151,7 +151,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 75401;
public long DataPoints => 75403;
/// <summary>
/// Data Points count of the algorithm history
@@ -163,30 +163,31 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "2700"},
{"Total Orders", "2700"},
{"Average Win", "0.00%"},
{"Average Loss", "0.00%"},
{"Compounding Annual Return", "-99.777%"},
{"Drawdown", "4.400%"},
{"Expectancy", "-0.724"},
{"Net Profit", "-4.430%"},
{"Sharpe Ratio", "-31.389"},
{"Sharpe Ratio", "-31.63"},
{"Sortino Ratio", "-31.63"},
{"Probabilistic Sharpe Ratio", "0%"},
{"Loss Rate", "83%"},
{"Win Rate", "17%"},
{"Profit-Loss Ratio", "0.65"},
{"Alpha", "-3.059"},
{"Alpha", "-3.065"},
{"Beta", "0.128"},
{"Annual Standard Deviation", "0.031"},
{"Annual Variance", "0.001"},
{"Information Ratio", "-81.232"},
{"Tracking Error", "0.212"},
{"Treynor Ratio", "-7.618"},
{"Treynor Ratio", "-7.677"},
{"Total Fees", "$6237.00"},
{"Estimated Strategy Capacity", "$14000.00"},
{"Lowest Capacity Asset", "GC VOFJUCDY9XNH"},
{"Portfolio Turnover", "9912.69%"},
{"OrderListHash", "8f92e1528c6477a156449fd1e86527e7"}
{"OrderListHash", "398c0383a9ba3235f15ac472a7fbcb8a"}
};
}
}

View File

@@ -117,7 +117,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public virtual long DataPoints => 13948;
public virtual long DataPoints => 14038;
/// <summary>
/// Data Points count of the algorithm history
@@ -129,30 +129,31 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public virtual Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "122"},
{"Average Win", "0.09%"},
{"Total Orders", "128"},
{"Average Win", "0.26%"},
{"Average Loss", "-0.01%"},
{"Compounding Annual Return", "-0.486%"},
{"Drawdown", "0.500%"},
{"Expectancy", "-0.837"},
{"Net Profit", "-0.490%"},
{"Sharpe Ratio", "-1.968"},
{"Probabilistic Sharpe Ratio", "0%"},
{"Loss Rate", "98%"},
{"Win Rate", "2%"},
{"Profit-Loss Ratio", "8.94"},
{"Alpha", "-0.003"},
{"Beta", "-0.001"},
{"Annual Standard Deviation", "0.002"},
{"Compounding Annual Return", "-0.071%"},
{"Drawdown", "0.400%"},
{"Expectancy", "-0.116"},
{"Net Profit", "-0.071%"},
{"Sharpe Ratio", "-1.999"},
{"Sortino Ratio", "-1.806"},
{"Probabilistic Sharpe Ratio", "10.091%"},
{"Loss Rate", "97%"},
{"Win Rate", "3%"},
{"Profit-Loss Ratio", "27.29"},
{"Alpha", "-0.008"},
{"Beta", "0.001"},
{"Annual Standard Deviation", "0.004"},
{"Annual Variance", "0"},
{"Information Ratio", "-1.397"},
{"Information Ratio", "-1.367"},
{"Tracking Error", "0.089"},
{"Treynor Ratio", "5.001"},
{"Total Fees", "$272.54"},
{"Treynor Ratio", "-5.445"},
{"Total Fees", "$285.44"},
{"Estimated Strategy Capacity", "$1000.00"},
{"Lowest Capacity Asset", "ES VRJST036ZY0X"},
{"Portfolio Turnover", "3.27%"},
{"OrderListHash", "61ad5bfa7e2135a85a82c986329335cf"}
{"Portfolio Turnover", "3.41%"},
{"OrderListHash", "1666cd6c277c6ea8b1b46d5dfa6bac9f"}
};
}
}

View File

@@ -136,7 +136,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public virtual long DataPoints => 57752;
public virtual long DataPoints => 57754;
/// <summary>
/// Data Points count of the algorithm history
@@ -148,30 +148,31 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public virtual Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "2"},
{"Total Orders", "2"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "-81.734%"},
{"Drawdown", "4.100%"},
{"Expectancy", "0"},
{"Net Profit", "-2.169%"},
{"Sharpe Ratio", "-10.195"},
{"Sharpe Ratio", "-10.299"},
{"Sortino Ratio", "-10.299"},
{"Probabilistic Sharpe Ratio", "0%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "-1.206"},
{"Alpha", "-1.212"},
{"Beta", "0.238"},
{"Annual Standard Deviation", "0.072"},
{"Annual Variance", "0.005"},
{"Information Ratio", "-15.404"},
{"Tracking Error", "0.176"},
{"Treynor Ratio", "-3.077"},
{"Treynor Ratio", "-3.109"},
{"Total Fees", "$4.62"},
{"Estimated Strategy Capacity", "$17000000.00"},
{"Lowest Capacity Asset", "GC VL5E74HP3EE5"},
{"Portfolio Turnover", "43.23%"},
{"OrderListHash", "323b899ae80aa839e320806411665ce7"}
{"OrderListHash", "1daca8b4534258de0f1bf09214205b77"}
};
}
}

View File

@@ -41,37 +41,38 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public override long DataPoints => 163392;
public override long DataPoints => 163410;
/// <summary>
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
/// </summary>
public override Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "2"},
{"Total Orders", "2"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "-92.667%"},
{"Drawdown", "5.000%"},
{"Expectancy", "0"},
{"Net Profit", "-3.314%"},
{"Sharpe Ratio", "-6.303"},
{"Sharpe Ratio", "-6.359"},
{"Sortino Ratio", "-11.237"},
{"Probabilistic Sharpe Ratio", "9.333%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "-1.465"},
{"Alpha", "-1.47"},
{"Beta", "0.312"},
{"Annual Standard Deviation", "0.134"},
{"Annual Variance", "0.018"},
{"Information Ratio", "-14.77"},
{"Tracking Error", "0.192"},
{"Treynor Ratio", "-2.718"},
{"Treynor Ratio", "-2.742"},
{"Total Fees", "$4.62"},
{"Estimated Strategy Capacity", "$52000000.00"},
{"Lowest Capacity Asset", "GC VL5E74HP3EE5"},
{"Portfolio Turnover", "43.77%"},
{"OrderListHash", "18ffd3a774c68da83d867e3b09e3e05d"}
{"OrderListHash", "ba6e16f476a2ddeeaab9c9091664f7a1"}
};
}
}

View File

@@ -140,7 +140,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public virtual long DataPoints => 48688;
public virtual long DataPoints => 48690;
/// <summary>
/// Data Points count of the algorithm history
@@ -152,7 +152,7 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public virtual Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "0"},
{"Total Orders", "0"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "0%"},
@@ -160,6 +160,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Expectancy", "0"},
{"Net Profit", "0%"},
{"Sharpe Ratio", "0"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "0%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},

View File

@@ -47,7 +47,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public override long DataPoints => 147769;
public override long DataPoints => 147771;
/// <summary>
/// Data Points count of the algorithm history
@@ -59,7 +59,7 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public override Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "0"},
{"Total Orders", "0"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "0%"},
@@ -67,6 +67,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Expectancy", "0"},
{"Net Profit", "0%"},
{"Sharpe Ratio", "0"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "0%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},

View File

@@ -41,37 +41,38 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public override long DataPoints => 86963;
public override long DataPoints => 87393;
/// <summary>
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
/// </summary>
public override Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "636"},
{"Total Orders", "638"},
{"Average Win", "0.02%"},
{"Average Loss", "-0.01%"},
{"Compounding Annual Return", "-1.606%"},
{"Compounding Annual Return", "-1.610%"},
{"Drawdown", "1.600%"},
{"Expectancy", "-0.841"},
{"Net Profit", "-1.617%"},
{"Sharpe Ratio", "-5.092"},
{"Net Profit", "-1.622%"},
{"Sharpe Ratio", "-8.787"},
{"Sortino Ratio", "-5.428"},
{"Probabilistic Sharpe Ratio", "0.000%"},
{"Loss Rate", "96%"},
{"Win Rate", "4%"},
{"Profit-Loss Ratio", "3.21"},
{"Alpha", "-0.01"},
{"Alpha", "-0.018"},
{"Beta", "-0.003"},
{"Annual Standard Deviation", "0.002"},
{"Annual Variance", "0"},
{"Information Ratio", "-1.473"},
{"Tracking Error", "0.089"},
{"Treynor Ratio", "3.137"},
{"Total Fees", "$1451.88"},
{"Treynor Ratio", "5.593"},
{"Total Fees", "$1456.18"},
{"Estimated Strategy Capacity", "$9000.00"},
{"Lowest Capacity Asset", "ES VP274HSU1AF5"},
{"Portfolio Turnover", "17.86%"},
{"OrderListHash", "de6a834d1b5e7aeb40f6cf9dba16782d"}
{"Portfolio Turnover", "17.91%"},
{"OrderListHash", "19d70e24c5d0922d1557de4adbf60ab5"}
};
}
}

View File

@@ -151,7 +151,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 224660;
public long DataPoints => 224662;
/// <summary>
/// Data Points count of the algorithm history
@@ -163,30 +163,31 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "8282"},
{"Total Orders", "8282"},
{"Average Win", "0.00%"},
{"Average Loss", "0.00%"},
{"Compounding Annual Return", "-100.000%"},
{"Drawdown", "13.900%"},
{"Expectancy", "-0.824"},
{"Net Profit", "-13.874%"},
{"Sharpe Ratio", "-19.202"},
{"Sharpe Ratio", "-19.346"},
{"Sortino Ratio", "-19.346"},
{"Probabilistic Sharpe Ratio", "0%"},
{"Loss Rate", "89%"},
{"Win Rate", "11%"},
{"Profit-Loss Ratio", "0.64"},
{"Alpha", "2.477"},
{"Alpha", "2.468"},
{"Beta", "-0.215"},
{"Annual Standard Deviation", "0.052"},
{"Annual Variance", "0.003"},
{"Information Ratio", "-58.37"},
{"Tracking Error", "0.295"},
{"Treynor Ratio", "4.66"},
{"Treynor Ratio", "4.695"},
{"Total Fees", "$19131.42"},
{"Estimated Strategy Capacity", "$130000.00"},
{"Lowest Capacity Asset", "GC VOFJUCDY9XNH"},
{"Portfolio Turnover", "32523.20%"},
{"OrderListHash", "85cdd035d7c7a3da178d1c2dff31f1bd"}
{"OrderListHash", "584fbdabd837921edc6a7e99759b9c66"}
};
}
}

View File

@@ -43,37 +43,38 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public override long DataPoints => 16247;
public override long DataPoints => 16265;
/// <summary>
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
/// </summary>
public override Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "152"},
{"Average Win", "0.09%"},
{"Total Orders", "156"},
{"Average Win", "0.31%"},
{"Average Loss", "-0.01%"},
{"Compounding Annual Return", "-0.644%"},
{"Drawdown", "0.600%"},
{"Expectancy", "-0.872"},
{"Net Profit", "-0.649%"},
{"Sharpe Ratio", "-2.343"},
{"Probabilistic Sharpe Ratio", "0%"},
{"Loss Rate", "99%"},
{"Win Rate", "1%"},
{"Profit-Loss Ratio", "8.76"},
{"Alpha", "-0.004"},
{"Compounding Annual Return", "-0.024%"},
{"Drawdown", "0.400%"},
{"Expectancy", "-0.035"},
{"Net Profit", "-0.025%"},
{"Sharpe Ratio", "-1.602"},
{"Sortino Ratio", "-1.913"},
{"Probabilistic Sharpe Ratio", "11.172%"},
{"Loss Rate", "97%"},
{"Win Rate", "3%"},
{"Profit-Loss Ratio", "36.65"},
{"Alpha", "-0.007"},
{"Beta", "-0.001"},
{"Annual Standard Deviation", "0.002"},
{"Annual Standard Deviation", "0.005"},
{"Annual Variance", "0"},
{"Information Ratio", "-1.409"},
{"Information Ratio", "-1.359"},
{"Tracking Error", "0.089"},
{"Treynor Ratio", "3.76"},
{"Total Fees", "$338.96"},
{"Treynor Ratio", "8.008"},
{"Total Fees", "$347.56"},
{"Estimated Strategy Capacity", "$1000.00"},
{"Lowest Capacity Asset", "ES VRJST036ZY0X"},
{"Portfolio Turnover", "4.07%"},
{"OrderListHash", "e2d7f858dcad2d760f776bec1065b2f1"}
{"Portfolio Turnover", "4.16%"},
{"OrderListHash", "ce63f5e611a7ab2f49d49c9fdc777ef5"}
};
}
}

View File

@@ -41,37 +41,38 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public override long DataPoints => 227220;
public override long DataPoints => 228938;
/// <summary>
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
/// </summary>
public override Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "1970"},
{"Total Orders", "1990"},
{"Average Win", "0.01%"},
{"Average Loss", "-0.01%"},
{"Compounding Annual Return", "-4.641%"},
{"Compounding Annual Return", "-4.683%"},
{"Drawdown", "4.700%"},
{"Expectancy", "-0.911"},
{"Net Profit", "-4.675%"},
{"Sharpe Ratio", "-5.76"},
{"Net Profit", "-4.717%"},
{"Sharpe Ratio", "-7.178"},
{"Sortino Ratio", "-5.126"},
{"Probabilistic Sharpe Ratio", "0%"},
{"Loss Rate", "97%"},
{"Win Rate", "3%"},
{"Profit-Loss Ratio", "2.04"},
{"Alpha", "-0.03"},
{"Alpha", "-0.038"},
{"Beta", "-0.008"},
{"Annual Standard Deviation", "0.005"},
{"Annual Variance", "0"},
{"Information Ratio", "-1.699"},
{"Information Ratio", "-1.702"},
{"Tracking Error", "0.09"},
{"Treynor Ratio", "4.067"},
{"Total Fees", "$4495.98"},
{"Treynor Ratio", "5.049"},
{"Total Fees", "$4538.98"},
{"Estimated Strategy Capacity", "$3000.00"},
{"Lowest Capacity Asset", "ES VP274HSU1AF5"},
{"Portfolio Turnover", "56.20%"},
{"OrderListHash", "e65e1dace0d1679c2026155628ca3077"}
{"Portfolio Turnover", "56.68%"},
{"OrderListHash", "4ebc10fed9201f59aa7fcd90fbb49448"}
};
}
}

View File

@@ -87,14 +87,15 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "1"},
{"Total Orders", "1"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "227.693%"},
{"Drawdown", "2.000%"},
{"Expectancy", "0"},
{"Net Profit", "1.529%"},
{"Sharpe Ratio", "8.889"},
{"Sharpe Ratio", "8.855"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "67.609%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
@@ -105,12 +106,12 @@ namespace QuantConnect.Algorithm.CSharp
{"Annual Variance", "0.049"},
{"Information Ratio", "-14.564"},
{"Tracking Error", "0.001"},
{"Treynor Ratio", "1.978"},
{"Treynor Ratio", "1.971"},
{"Total Fees", "$3.44"},
{"Estimated Strategy Capacity", "$110000000.00"},
{"Lowest Capacity Asset", "SPY R735QTJ8XC9X"},
{"Portfolio Turnover", "19.96%"},
{"OrderListHash", "f409be3a7c63d9c1394c2e6c005a15ee"}
{"OrderListHash", "0f357e8eeee4108d6b53f2b671e97f29"}
};
}
}

View File

@@ -124,30 +124,31 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public virtual Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "3"},
{"Total Orders", "3"},
{"Average Win", "6.15%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "435.569%"},
{"Drawdown", "3.400%"},
{"Expectancy", "0"},
{"Net Profit", "5.516%"},
{"Sharpe Ratio", "-6.262"},
{"Sharpe Ratio", "-6.336"},
{"Sortino Ratio", "-12.182"},
{"Probabilistic Sharpe Ratio", "0.011%"},
{"Loss Rate", "0%"},
{"Win Rate", "100%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "-0.223"},
{"Alpha", "-0.226"},
{"Beta", "0.02"},
{"Annual Standard Deviation", "0.034"},
{"Annual Variance", "0.001"},
{"Information Ratio", "-7.032"},
{"Tracking Error", "0.107"},
{"Treynor Ratio", "-10.779"},
{"Treynor Ratio", "-10.906"},
{"Total Fees", "$0.00"},
{"Estimated Strategy Capacity", "$3000.00"},
{"Lowest Capacity Asset", "SPX XL80P3GHDZXQ|SPX 31"},
{"Portfolio Turnover", "24.07%"},
{"OrderListHash", "5dbee236086bb2c39e2fbeac068280fd"}
{"OrderListHash", "d1987f604e6d61584838ccc94adf7256"}
};
}
}

View File

@@ -35,30 +35,31 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public override Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "71"},
{"Total Orders", "81"},
{"Average Win", "1.28%"},
{"Average Loss", "-0.06%"},
{"Compounding Annual Return", "-20.546%"},
{"Drawdown", "1.800%"},
{"Expectancy", "-0.402"},
{"Net Profit", "-0.922%"},
{"Sharpe Ratio", "-2.856"},
{"Sharpe Ratio", "-2.903"},
{"Sortino Ratio", "-6.081"},
{"Probabilistic Sharpe Ratio", "22.230%"},
{"Loss Rate", "97%"},
{"Win Rate", "3%"},
{"Profit-Loss Ratio", "19.95"},
{"Alpha", "-0.155"},
{"Alpha", "-0.157"},
{"Beta", "0.025"},
{"Annual Standard Deviation", "0.053"},
{"Annual Variance", "0.003"},
{"Information Ratio", "-2.07"},
{"Tracking Error", "0.121"},
{"Treynor Ratio", "-6.089"},
{"Treynor Ratio", "-6.189"},
{"Total Fees", "$0.00"},
{"Estimated Strategy Capacity", "$300000.00"},
{"Lowest Capacity Asset", "SPX XL80P3GHDZXQ|SPX 31"},
{"Portfolio Turnover", "24.63%"},
{"OrderListHash", "9e974939d13fd3255c6291a65d2c1eb9"}
{"OrderListHash", "380076bc7854977f46318e8add9f1a25"}
};
}
}

View File

@@ -146,7 +146,7 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public virtual Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "8220"},
{"Total Orders", "8220"},
{"Average Win", "0.00%"},
{"Average Loss", "0.00%"},
{"Compounding Annual Return", "-100.000%"},

View File

@@ -50,30 +50,31 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public override Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "72"},
{"Total Orders", "81"},
{"Average Win", "0.00%"},
{"Average Loss", "0.00%"},
{"Compounding Annual Return", "-0.006%"},
{"Drawdown", "0.000%"},
{"Expectancy", "-0.486"},
{"Net Profit", "0.000%"},
{"Sharpe Ratio", "-1.628"},
{"Sharpe Ratio", "-101.77"},
{"Sortino Ratio", "-9053542.758"},
{"Probabilistic Sharpe Ratio", "17.439%"},
{"Loss Rate", "97%"},
{"Win Rate", "3%"},
{"Profit-Loss Ratio", "17.50"},
{"Alpha", "-0"},
{"Alpha", "-0.003"},
{"Beta", "-0"},
{"Annual Standard Deviation", "0"},
{"Annual Variance", "0"},
{"Information Ratio", "-0.449"},
{"Tracking Error", "0.138"},
{"Treynor Ratio", "1.87"},
{"Treynor Ratio", "116.921"},
{"Total Fees", "$0.00"},
{"Estimated Strategy Capacity", "$0"},
{"Lowest Capacity Asset", "SPX XL80P59H5E6M|SPX 31"},
{"Portfolio Turnover", "0.00%"},
{"OrderListHash", "0df3713aeb32e9c0738200f2a109e2f9"}
{"OrderListHash", "5ae07f747205646e859ab43fb1828711"}
};
}
}

View File

@@ -97,14 +97,15 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "1"},
{"Total Orders", "1"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "-0.010%"},
{"Drawdown", "0.000%"},
{"Expectancy", "0"},
{"Net Profit", "-0.008%"},
{"Sharpe Ratio", "-1.183"},
{"Sharpe Ratio", "-497.389"},
{"Sortino Ratio", "-73.22"},
{"Probabilistic Sharpe Ratio", "0.001%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
@@ -120,7 +121,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Estimated Strategy Capacity", "₹61000000000.00"},
{"Lowest Capacity Asset", "YESBANK UL"},
{"Portfolio Turnover", "0.00%"},
{"OrderListHash", "6cc69218edd7bd461678b9ee0c575db5"}
{"OrderListHash", "0cfbdeedf1ba2a02af1b6b35dfe8aac3"}
};
}
}

View File

@@ -121,14 +121,15 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public virtual Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "6"},
{"Total Orders", "6"},
{"Average Win", "0%"},
{"Average Loss", "0.00%"},
{"Compounding Annual Return", "-0.386%"},
{"Drawdown", "0.000%"},
{"Expectancy", "-1"},
{"Net Profit", "-0.004%"},
{"Sharpe Ratio", "-23.595"},
{"Sharpe Ratio", "-328.371"},
{"Sortino Ratio", "-328.371"},
{"Probabilistic Sharpe Ratio", "0%"},
{"Loss Rate", "100%"},
{"Win Rate", "0%"},
@@ -144,7 +145,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Estimated Strategy Capacity", "₹84000.00"},
{"Lowest Capacity Asset", "JUNIORBEES UL"},
{"Portfolio Turnover", "0.04%"},
{"OrderListHash", "57558324bc9b67b36ae33c3e1c191740"}
{"OrderListHash", "5823d79e97915654a8f68ae5fa600b5a"}
};
}
}

View File

@@ -116,7 +116,7 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "91"},
{"Total Orders", "91"},
{"Average Win", "0.09%"},
{"Average Loss", "-0.01%"},
{"Compounding Annual Return", "5.732%"},

View File

@@ -102,7 +102,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 475788;
public long DataPoints => 471135;
/// <summary>
/// Data Points count of the algorithm history
@@ -114,7 +114,7 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "3"},
{"Total Orders", "3"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "0%"},
@@ -122,6 +122,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Expectancy", "0"},
{"Net Profit", "0%"},
{"Sharpe Ratio", "0"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "0%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
@@ -133,11 +134,11 @@ namespace QuantConnect.Algorithm.CSharp
{"Information Ratio", "0"},
{"Tracking Error", "0"},
{"Treynor Ratio", "0"},
{"Total Fees", "$75.00"},
{"Total Fees", "$26.00"},
{"Estimated Strategy Capacity", "$70000.00"},
{"Lowest Capacity Asset", "GOOCV W78ZERHAOVVQ|GOOCV VP83T1ZUHROL"},
{"Portfolio Turnover", "61.34%"},
{"OrderListHash", "cee5cc2b0f80c308b496cac0b8668163"}
{"Portfolio Turnover", "61.31%"},
{"OrderListHash", "a36c60c5fb020121d6541683138d8f28"}
};
}
}

View File

@@ -112,7 +112,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 475777;
public long DataPoints => 471124;
/// <summary>
/// Data Points count of the algorithm history
@@ -124,7 +124,7 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "418"},
{"Total Orders", "420"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "0%"},
@@ -132,6 +132,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Expectancy", "0"},
{"Net Profit", "0%"},
{"Sharpe Ratio", "0"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "0%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
@@ -143,11 +144,11 @@ namespace QuantConnect.Algorithm.CSharp
{"Information Ratio", "0"},
{"Tracking Error", "0"},
{"Treynor Ratio", "0"},
{"Total Fees", "$418.00"},
{"Total Fees", "$543.40"},
{"Estimated Strategy Capacity", "$3000.00"},
{"Lowest Capacity Asset", "GOOCV W78ZFMEBBB2E|GOOCV VP83T1ZUHROL"},
{"Portfolio Turnover", "338.56%"},
{"OrderListHash", "e0289a2989c91934656ff7e578f5e810"}
{"Portfolio Turnover", "338.60%"},
{"OrderListHash", "c9eb598f33939941206efc018eb6ee45"}
};
}
}

View File

@@ -109,7 +109,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 475777;
public long DataPoints => 471124;
/// <summary>
/// Data Points count of the algorithm history
@@ -121,7 +121,7 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "2"},
{"Total Orders", "2"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "0%"},
@@ -129,6 +129,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Expectancy", "0"},
{"Net Profit", "0%"},
{"Sharpe Ratio", "0"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "0%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
@@ -144,7 +145,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Estimated Strategy Capacity", "$1300000.00"},
{"Lowest Capacity Asset", "GOOCV 30AKMEIPOSS1Y|GOOCV VP83T1ZUHROL"},
{"Portfolio Turnover", "10.71%"},
{"OrderListHash", "838e313ba57850227ec810ed8fb85a23"}
{"OrderListHash", "6b2f02d5cedb870e539a7bfb967c777f"}
};
}
}

View File

@@ -0,0 +1,144 @@
/*
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
using QuantConnect.Data;
using QuantConnect.Data.Consolidators;
using QuantConnect.Data.Market;
using QuantConnect.Data.UniverseSelection;
using QuantConnect.Interfaces;
using System;
using System.Collections.Generic;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// A demonstration of consolidating options data into larger bars for your algorithm.
/// </summary>
public class BasicTemplateOptionsConsolidationAlgorithm: QCAlgorithm, IRegressionAlgorithmDefinition
{
private Dictionary<Symbol, IDataConsolidator> _consolidators = new();
public override void Initialize()
{
SetStartDate(2013, 10, 7);
SetEndDate(2013, 10, 11);
SetCash(1000000);
var option = AddOption("SPY");
option.SetFilter(-2, 2, 0, 189);
}
public void OnQuoteBarConsolidated(object sender, QuoteBar quoteBar)
{
Log($"OnQuoteBarConsolidated called on {Time}");
Log(quoteBar.ToString());
}
public void OnTradeBarConsolidated(object sender, TradeBar tradeBar)
{
Log($"OnTradeBarConsolidated called on {Time}");
Log(tradeBar.ToString());
}
public override void OnSecuritiesChanged(SecurityChanges changes)
{
foreach(var security in changes.AddedSecurities)
{
IDataConsolidator consolidator;
if (security.Type == SecurityType.Equity)
{
consolidator = new TradeBarConsolidator(TimeSpan.FromMinutes(5));
(consolidator as TradeBarConsolidator).DataConsolidated += OnTradeBarConsolidated;
}
else
{
consolidator = new QuoteBarConsolidator(new TimeSpan(0, 5, 0));
(consolidator as QuoteBarConsolidator).DataConsolidated += OnQuoteBarConsolidated;
}
SubscriptionManager.AddConsolidator(security.Symbol, consolidator);
_consolidators[security.Symbol] = consolidator;
}
foreach(var security in changes.RemovedSecurities)
{
_consolidators.Remove(security.Symbol, out var consolidator);
SubscriptionManager.RemoveConsolidator(security.Symbol, consolidator);
if (security.Type == SecurityType.Equity)
{
(consolidator as TradeBarConsolidator).DataConsolidated -= OnTradeBarConsolidated;
}
else
{
(consolidator as QuoteBarConsolidator).DataConsolidated -= OnQuoteBarConsolidated;
}
}
}
/// <summary>
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
/// </summary>
public bool CanRunLocally { get; } = true;
/// <summary>
/// This is used by the regression test system to indicate which languages this algorithm is written in.
/// </summary>
public Language[] Languages { get; } = { Language.CSharp, Language.Python };
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 3943;
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 0;
/// <summary>
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Orders", "0"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "0%"},
{"Drawdown", "0%"},
{"Expectancy", "0"},
{"Net Profit", "0%"},
{"Sharpe Ratio", "0"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "0%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "0"},
{"Beta", "0"},
{"Annual Standard Deviation", "0"},
{"Annual Variance", "0"},
{"Information Ratio", "-8.91"},
{"Tracking Error", "0.223"},
{"Treynor Ratio", "0"},
{"Total Fees", "$0.00"},
{"Estimated Strategy Capacity", "$0"},
{"Lowest Capacity Asset", ""},
{"Portfolio Turnover", "0%"},
{"OrderListHash", "d41d8cd98f00b204e9800998ecf8427e"}
};
}
}

View File

@@ -134,14 +134,15 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "2"},
{"Total Orders", "2"},
{"Average Win", "0%"},
{"Average Loss", "-1.31%"},
{"Compounding Annual Return", "-15.304%"},
{"Drawdown", "1.300%"},
{"Expectancy", "-1"},
{"Net Profit", "-1.311%"},
{"Sharpe Ratio", "-3.31"},
{"Sharpe Ratio", "-3.607"},
{"Sortino Ratio", "-1.188"},
{"Probabilistic Sharpe Ratio", "0.035%"},
{"Loss Rate", "100%"},
{"Win Rate", "0%"},
@@ -157,7 +158,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Estimated Strategy Capacity", "$0"},
{"Lowest Capacity Asset", "GOOCV W78ZFMML01JA|GOOCV VP83T1ZUHROL"},
{"Portfolio Turnover", "0.05%"},
{"OrderListHash", "0b52bbe98ade8e3aab943e64fcf4abfe"}
{"OrderListHash", "3330cabe259c0abbc1010707554ae3d7"}
};
}
}

View File

@@ -100,7 +100,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 1253773;
public long DataPoints => 1252633;
/// <summary>
/// Data Points count of the algorithm history
@@ -112,7 +112,7 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "2"},
{"Total Orders", "2"},
{"Average Win", "0%"},
{"Average Loss", "-0.40%"},
{"Compounding Annual Return", "-21.622%"},
@@ -120,6 +120,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Expectancy", "-1"},
{"Net Profit", "-0.311%"},
{"Sharpe Ratio", "0"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "0%"},
{"Loss Rate", "100%"},
{"Win Rate", "0%"},
@@ -135,7 +136,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Estimated Strategy Capacity", "$0"},
{"Lowest Capacity Asset", "GOOCV VP83T1ZUHROL"},
{"Portfolio Turnover", "15.08%"},
{"OrderListHash", "0f8537495f5744c02191656d6b3f9205"}
{"OrderListHash", "8f60c485b60fe6a6dece59bc89e74997"}
};
}
}

View File

@@ -151,7 +151,7 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "4"},
{"Total Orders", "4"},
{"Average Win", "0.14%"},
{"Average Loss", "-0.28%"},
{"Compounding Annual Return", "0%"},
@@ -159,11 +159,12 @@ namespace QuantConnect.Algorithm.CSharp
{"Expectancy", "0.502"},
{"Net Profit", "-386.489%"},
{"Sharpe Ratio", "-0.033"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "1.235%"},
{"Loss Rate", "0%"},
{"Win Rate", "100%"},
{"Profit-Loss Ratio", "0.50"},
{"Alpha", "-95.983"},
{"Alpha", "-94.012"},
{"Beta", "263.726"},
{"Annual Standard Deviation", "30.617"},
{"Annual Variance", "937.371"},
@@ -174,7 +175,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Estimated Strategy Capacity", "$0"},
{"Lowest Capacity Asset", "AAPL R735QTJ8XC9X"},
{"Portfolio Turnover", "13.46%"},
{"OrderListHash", "83c9fb13ee32284702779eff8d11c608"}
{"OrderListHash", "802ed167e77f73ae87ee12d0cf2c879c"}
};
}
}

View File

@@ -109,7 +109,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 32492;
public long DataPoints => 32351;
/// <summary>
/// Data Points count of the algorithm history
@@ -121,30 +121,31 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "4"},
{"Total Orders", "5"},
{"Average Win", "0%"},
{"Average Loss", "-0.07%"},
{"Compounding Annual Return", "-12.496%"},
{"Drawdown", "0.200%"},
{"Expectancy", "-1"},
{"Net Profit", "-0.134%"},
{"Sharpe Ratio", "-8.839"},
{"Sharpe Ratio", "-9.78"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "0%"},
{"Loss Rate", "100%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "0.083"},
{"Alpha", "0.075"},
{"Beta", "-0.054"},
{"Annual Standard Deviation", "0.008"},
{"Annual Variance", "0"},
{"Information Ratio", "-18.699"},
{"Tracking Error", "0.155"},
{"Treynor Ratio", "1.296"},
{"Treynor Ratio", "1.434"},
{"Total Fees", "$4.00"},
{"Estimated Strategy Capacity", "$1000.00"},
{"Lowest Capacity Asset", "AAPL 2ZTXYMUAHCIAU|AAPL R735QTJ8XC9X"},
{"Portfolio Turnover", "2.28%"},
{"OrderListHash", "81e8a822d43de2165c1d3f52964ec312"}
{"OrderListHash", "3f6cce0fcc7b988ba378a357ede1af93"}
};
}
}

View File

@@ -105,7 +105,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public virtual long DataPoints => 65536;
public virtual long DataPoints => 57794;
/// <summary>
/// Data Points count of the algorithm history
@@ -117,30 +117,31 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public virtual Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "5"},
{"Total Orders", "5"},
{"Average Win", "0%"},
{"Average Loss", "-0.69%"},
{"Compounding Annual Return", "58.005%"},
{"Drawdown", "0.400%"},
{"Expectancy", "-0.5"},
{"Net Profit", "0.588%"},
{"Sharpe Ratio", "1.448"},
{"Sharpe Ratio", "0.836"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "51.980%"},
{"Loss Rate", "50%"},
{"Win Rate", "50%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "0.288"},
{"Alpha", "0.286"},
{"Beta", "-0.04"},
{"Annual Standard Deviation", "0.004"},
{"Annual Variance", "0"},
{"Information Ratio", "-98.963"},
{"Tracking Error", "0.072"},
{"Treynor Ratio", "-0.149"},
{"Treynor Ratio", "-0.086"},
{"Total Fees", "$0.00"},
{"Estimated Strategy Capacity", "$580000.00"},
{"Lowest Capacity Asset", "SPXW 31K54PVWHUJHQ|SPX 31"},
{"Portfolio Turnover", "0.48%"},
{"OrderListHash", "174bd0a99916d58ca3f12139306940db"}
{"OrderListHash", "f3f48428583b1f81646d830e1d8ddaa6"}
};
}
}

View File

@@ -48,7 +48,7 @@ namespace QuantConnect.Algorithm.CSharp
// weekly option SPX contracts
var spxw = AddIndexOption(spx, "SPXW");
spxw.SetFilter(u => u.Strikes(0, 1)
spxw.SetFilter(u => u.Strikes(-1, +1)
// single week ahead since there are many SPXW contracts and we want to preserve performance
.Expiration(0, 7)
.IncludeWeeklys());
@@ -66,7 +66,7 @@ namespace QuantConnect.Algorithm.CSharp
OptionChain chain;
if (slice.OptionChains.TryGetValue(_spxOption, out chain))
{
// we find the first expiration group of call options and order them in ascending strike
// we find the first expiration group of call options and order them in ascending strike
var contracts = chain
.Where(x => x.Right == OptionRight.Call)
.OrderBy(x => x.Expiry)
@@ -109,7 +109,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public virtual long DataPoints => 35451;
public virtual long DataPoints => 40893;
/// <summary>
/// Data Points count of the algorithm history
@@ -121,30 +121,31 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public virtual Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "4"},
{"Average Win", "0.12%"},
{"Average Loss", "0.00%"},
{"Compounding Annual Return", "8.975%"},
{"Total Orders", "10"},
{"Average Win", "0.47%"},
{"Average Loss", "-0.01%"},
{"Compounding Annual Return", "99.729%"},
{"Drawdown", "0.100%"},
{"Expectancy", "62.078"},
{"Net Profit", "0.110%"},
{"Sharpe Ratio", "-7.925"},
{"Probabilistic Sharpe Ratio", "1.216%"},
{"Expectancy", "24.484"},
{"Net Profit", "0.890%"},
{"Sharpe Ratio", "8.078"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "93.697%"},
{"Loss Rate", "50%"},
{"Win Rate", "50%"},
{"Profit-Loss Ratio", "125.16"},
{"Alpha", "-0.012"},
{"Beta", "0.001"},
{"Annual Standard Deviation", "0"},
{"Profit-Loss Ratio", "49.97"},
{"Alpha", "-1.975"},
{"Beta", "0.301"},
{"Annual Standard Deviation", "0.021"},
{"Annual Variance", "0"},
{"Information Ratio", "-103.223"},
{"Tracking Error", "0.069"},
{"Treynor Ratio", "-2.449"},
{"Information Ratio", "-143.477"},
{"Tracking Error", "0.049"},
{"Treynor Ratio", "0.566"},
{"Total Fees", "$0.00"},
{"Estimated Strategy Capacity", "$1800000.00"},
{"Estimated Strategy Capacity", "$13000000.00"},
{"Lowest Capacity Asset", "SPXW XKX6S2GM9PGU|SPX 31"},
{"Portfolio Turnover", "0.03%"},
{"OrderListHash", "38db27781e4df93687d0895df9796c7d"}
{"Portfolio Turnover", "0.28%"},
{"OrderListHash", "8d50e6156e48b316007f3455d2bd0410"}
};
}
}

View File

@@ -0,0 +1,93 @@
/*
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
using System;
using QuantConnect.Data;
using System.Collections.Generic;
using QuantConnect.Orders;
using System.Linq;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// This example demonstrates how to add index asset types and change the tradable condition
/// </summary>
/// <meta name="tag" content="using data" />
/// <meta name="tag" content="benchmarks" />
/// <meta name="tag" content="indexes" />
public class BasicTemplateTradableIndexAlgorithm : BasicTemplateIndexAlgorithm
{
private OrderTicket _ticket;
/// <summary>
/// Initialize your algorithm and add desired assets.
/// </summary>
public override void Initialize()
{
base.Initialize();
Securities[Spx].IsTradable = true;
}
/// <summary>
/// Index EMA Cross trading underlying.
/// </summary>
public override void OnData(Slice slice)
{
base.OnData(slice);
_ticket ??= MarketOrder(Spx, 1);
}
public override void OnEndOfAlgorithm()
{
if (!_ticket.Status.IsFill())
{
throw new Exception("Index is tradable.");
}
}
/// <summary>
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
/// </summary>
public override Dictionary<string, string> ExpectedStatistics => new()
{
{"Total Orders", "5"},
{"Average Win", "6.15%"},
{"Average Loss", "-0.01%"},
{"Compounding Annual Return", "434.741%"},
{"Drawdown", "3.400%"},
{"Expectancy", "589.124"},
{"Net Profit", "5.510%"},
{"Sharpe Ratio", "-6.336"},
{"Sortino Ratio", "-12.182"},
{"Probabilistic Sharpe Ratio", "0.011%"},
{"Loss Rate", "50%"},
{"Win Rate", "50%"},
{"Profit-Loss Ratio", "1179.25"},
{"Alpha", "-0.226"},
{"Beta", "0.02"},
{"Annual Standard Deviation", "0.034"},
{"Annual Variance", "0.001"},
{"Information Ratio", "-7.032"},
{"Tracking Error", "0.107"},
{"Treynor Ratio", "-10.906"},
{"Total Fees", "$0.00"},
{"Estimated Strategy Capacity", "$3000.00"},
{"Lowest Capacity Asset", "SPX XL80P3GHDZXQ|SPX 31"},
{"Portfolio Turnover", "24.13%"},
{"OrderListHash", "41644492e032f38d0d9be0915f09a03b"}
};
}
}

View File

@@ -64,7 +64,7 @@ namespace QuantConnect.Algorithm.CSharp.Benchmarks
"OSCR", "WOLF", "SYF", "GOGL", "HES", "PHM", "CWEB", "ALDX", "BTWN", "AFL", "PPL", "CIM"
};
Settings.DataSubscriptionLimit = 1000000;
SetWarmUp(TimeSpan.FromDays(1));
foreach(var ticker in equity_symbols)
{

View File

@@ -53,7 +53,7 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public override Dictionary<string, string> ExpectedStatistics => new()
{
{"Total Trades", "49"},
{"Total Orders", "49"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "0%"},
@@ -61,6 +61,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Expectancy", "0"},
{"Net Profit", "0%"},
{"Sharpe Ratio", "0"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "0%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
@@ -76,7 +77,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Estimated Strategy Capacity", "₮220000.00"},
{"Lowest Capacity Asset", "BTCUSDT 18N"},
{"Portfolio Turnover", "22.80%"},
{"OrderListHash", "7417649395922ff3791471b4f3b5c021"}
{"OrderListHash", "3981b9ec6c7940ae6b0e763212390cc6"}
};
}
}

View File

@@ -53,7 +53,7 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public override Dictionary<string, string> ExpectedStatistics => new()
{
{"Total Trades", "49"},
{"Total Orders", "49"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "0%"},
@@ -61,6 +61,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Expectancy", "0"},
{"Net Profit", "0%"},
{"Sharpe Ratio", "0"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "0%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
@@ -76,7 +77,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Estimated Strategy Capacity", "₮12000000.00"},
{"Lowest Capacity Asset", "BTCUSDT 18N"},
{"Portfolio Turnover", "22.80%"},
{"OrderListHash", "7417649395922ff3791471b4f3b5c021"}
{"OrderListHash", "3981b9ec6c7940ae6b0e763212390cc6"}
};
}
}

View File

@@ -52,7 +52,7 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public override Dictionary<string, string> ExpectedStatistics => new()
{
{"Total Trades", "49"},
{"Total Orders", "49"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "0%"},
@@ -60,6 +60,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Expectancy", "0"},
{"Net Profit", "0%"},
{"Sharpe Ratio", "0"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "0%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
@@ -75,7 +76,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Estimated Strategy Capacity", "$2000.00"},
{"Lowest Capacity Asset", "BTCUSD E3"},
{"Portfolio Turnover", "0.28%"},
{"OrderListHash", "7f892f0c42d8826ff770ee602fe207a2"}
{"OrderListHash", "3c23bc8622691cb9d4cacb00de5b0dd8"}
};
}
}

View File

@@ -52,7 +52,7 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public override Dictionary<string, string> ExpectedStatistics => new()
{
{"Total Trades", "49"},
{"Total Orders", "49"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "0%"},
@@ -60,6 +60,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Expectancy", "0"},
{"Net Profit", "0%"},
{"Sharpe Ratio", "0"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "0%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
@@ -75,7 +76,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Estimated Strategy Capacity", "$640000.00"},
{"Lowest Capacity Asset", "BTCUSD E3"},
{"Portfolio Turnover", "0.28%"},
{"OrderListHash", "7f892f0c42d8826ff770ee602fe207a2"}
{"OrderListHash", "3c23bc8622691cb9d4cacb00de5b0dd8"}
};
}
}

View File

@@ -88,30 +88,31 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "14"},
{"Total Orders", "14"},
{"Average Win", "0%"},
{"Average Loss", "-0.23%"},
{"Compounding Annual Return", "63.336%"},
{"Drawdown", "1.100%"},
{"Expectancy", "-1"},
{"Net Profit", "0.674%"},
{"Sharpe Ratio", "4.042"},
{"Sharpe Ratio", "3.986"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "58.892%"},
{"Loss Rate", "100%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "-0.592"},
{"Alpha", "-0.595"},
{"Beta", "0.57"},
{"Annual Standard Deviation", "0.133"},
{"Annual Variance", "0.018"},
{"Information Ratio", "-13.918"},
{"Tracking Error", "0.104"},
{"Treynor Ratio", "0.943"},
{"Treynor Ratio", "0.93"},
{"Total Fees", "$40.20"},
{"Estimated Strategy Capacity", "$4400000.00"},
{"Lowest Capacity Asset", "AIG R735QTJ8XC9X"},
{"Portfolio Turnover", "64.47%"},
{"OrderListHash", "7e43a08e470a1709c7f7066d6ed1d445"}
{"OrderListHash", "b1a3afb0457810d2b512ae48fe3f5a01"}
};
}
}

View File

@@ -0,0 +1,263 @@
/*
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using System.Collections.Generic;
using QuantConnect.Data;
using QuantConnect.Brokerages;
using QuantConnect.Indicators;
using QuantConnect.Orders;
using QuantConnect.Interfaces;
using QuantConnect.Securities.CryptoFuture;
using QuantConnect.Data.Market;
using QuantConnect.Securities;
using System.Linq;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Algorithm demonstrating and ensuring that Bybit crypto futures brokerage model works as expected
/// </summary>
public class BybitCryptoFuturesRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
{
private CryptoFuture _btcUsdt;
private CryptoFuture _btcUsd;
private ExponentialMovingAverage _fast;
private ExponentialMovingAverage _slow;
private Dictionary<Symbol, int> _interestPerSymbol = new();
public override void Initialize()
{
SetStartDate(2022, 12, 13);
SetEndDate(2022, 12, 13);
// Set strategy cash (USD)
SetCash(100000);
SetBrokerageModel(BrokerageName.Bybit, AccountType.Margin);
AddCrypto("BTCUSDT", Resolution.Minute);
_btcUsdt = AddCryptoFuture("BTCUSDT", Resolution.Minute);
_btcUsd = AddCryptoFuture("BTCUSD", Resolution.Minute);
// create two moving averages
_fast = EMA(_btcUsdt.Symbol, 30, Resolution.Minute);
_slow = EMA(_btcUsdt.Symbol, 60, Resolution.Minute);
_interestPerSymbol[_btcUsdt.Symbol] = 0;
_interestPerSymbol[_btcUsd.Symbol] = 0;
// the amount of USDT we need to hold to trade 'BTCUSDT'
_btcUsdt.QuoteCurrency.SetAmount(200);
// the amount of BTC we need to hold to trade 'BTCUSD'
_btcUsd.BaseCurrency.SetAmount(0.005m);
}
public override void OnData(Slice data)
{
var interestRates = data.Get<MarginInterestRate>();
foreach (var interestRate in interestRates)
{
_interestPerSymbol[interestRate.Key]++;
var cachedInterestRate = Securities[interestRate.Key].Cache.GetData<MarginInterestRate>();
if (cachedInterestRate != interestRate.Value)
{
throw new Exception($"Unexpected cached margin interest rate for {interestRate.Key}!");
}
}
if (!_slow.IsReady)
{
return;
}
if (_fast > _slow)
{
if (!Portfolio.Invested && Transactions.OrdersCount == 0)
{
var ticket = Buy(_btcUsd.Symbol, 1000);
if (ticket.Status != OrderStatus.Invalid)
{
throw new Exception($"Unexpected valid order {ticket}, should fail due to margin not sufficient");
}
Buy(_btcUsd.Symbol, 100);
var marginUsed = Portfolio.TotalMarginUsed;
var btcUsdHoldings = _btcUsd.Holdings;
// Coin futures value is 100 USD
var holdingsValueBtcUsd = 100;
if (Math.Abs(btcUsdHoldings.TotalSaleVolume - holdingsValueBtcUsd) > 1)
{
throw new Exception($"Unexpected TotalSaleVolume {btcUsdHoldings.TotalSaleVolume}");
}
if (Math.Abs(btcUsdHoldings.AbsoluteHoldingsCost - holdingsValueBtcUsd) > 1)
{
throw new Exception($"Unexpected holdings cost {btcUsdHoldings.HoldingsCost}");
}
// margin used is based on the maintenance rate
if (Math.Abs(btcUsdHoldings.AbsoluteHoldingsCost * 0.05m - marginUsed) > 1
|| _btcUsd.BuyingPowerModel.GetMaintenanceMargin(_btcUsd) != marginUsed)
{
throw new Exception($"Unexpected margin used {marginUsed}");
}
Buy(_btcUsdt.Symbol, 0.01);
marginUsed = Portfolio.TotalMarginUsed - marginUsed;
var btcUsdtHoldings = _btcUsdt.Holdings;
// USDT futures value is based on it's price
var holdingsValueUsdt = _btcUsdt.Price * _btcUsdt.SymbolProperties.ContractMultiplier * 0.01m;
if (Math.Abs(btcUsdtHoldings.TotalSaleVolume - holdingsValueUsdt) > 1)
{
throw new Exception($"Unexpected TotalSaleVolume {btcUsdtHoldings.TotalSaleVolume}");
}
if (Math.Abs(btcUsdtHoldings.AbsoluteHoldingsCost - holdingsValueUsdt) > 1)
{
throw new Exception($"Unexpected holdings cost {btcUsdtHoldings.HoldingsCost}");
}
if (Math.Abs(btcUsdtHoldings.AbsoluteHoldingsCost * 0.05m - marginUsed) > 1
|| _btcUsdt.BuyingPowerModel.GetMaintenanceMargin(_btcUsdt) != marginUsed)
{
throw new Exception($"Unexpected margin used {marginUsed}");
}
// position just opened should be just spread here
var unrealizedProfit = Portfolio.TotalUnrealizedProfit;
if ((5 - Math.Abs(unrealizedProfit)) < 0)
{
throw new Exception($"Unexpected TotalUnrealizedProfit {Portfolio.TotalUnrealizedProfit}");
}
if (Portfolio.TotalProfit != 0)
{
throw new Exception($"Unexpected TotalProfit {Portfolio.TotalProfit}");
}
}
}
// let's revert our position
else if (Transactions.OrdersCount == 3)
{
Sell(_btcUsd.Symbol, 300);
var btcUsdHoldings = _btcUsd.Holdings;
if (Math.Abs(btcUsdHoldings.AbsoluteHoldingsCost - 100 * 2) > 1)
{
throw new Exception($"Unexpected holdings cost {btcUsdHoldings.HoldingsCost}");
}
Sell(_btcUsdt.Symbol, 0.03);
var btcUsdtHoldings = _btcUsdt.Holdings;
// USDT futures value is based on it's price
var holdingsValueUsdt = _btcUsdt.Price * _btcUsdt.SymbolProperties.ContractMultiplier * 0.02m;
if (Math.Abs(btcUsdtHoldings.AbsoluteHoldingsCost - holdingsValueUsdt) > 1)
{
throw new Exception($"Unexpected holdings cost {btcUsdtHoldings.HoldingsCost}");
}
// position just opened should be just spread here
var profit = Portfolio.TotalUnrealizedProfit;
if ((5 - Math.Abs(profit)) < 0)
{
throw new Exception($"Unexpected TotalUnrealizedProfit {Portfolio.TotalUnrealizedProfit}");
}
// we barely did any difference on the previous trade
if ((5 - Math.Abs(Portfolio.TotalProfit)) < 0)
{
throw new Exception($"Unexpected TotalProfit {Portfolio.TotalProfit}");
}
}
}
public override void OnOrderEvent(OrderEvent orderEvent)
{
Debug(Time + " " + orderEvent);
}
public override void OnEndOfAlgorithm()
{
Log($"{Time} - TotalPortfolioValue: {Portfolio.TotalPortfolioValue}");
Log($"{Time} - CashBook: {Portfolio.CashBook}");
if (_interestPerSymbol.Any(kvp => kvp.Value == 0))
{
throw new Exception("Expected interest rate data for all symbols");
}
}
/// <summary>
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
/// </summary>
public bool CanRunLocally { get; } = true;
/// <summary>
/// This is used by the regression test system to indicate which languages this algorithm is written in.
/// </summary>
public Language[] Languages { get; } = { Language.CSharp, Language.Python };
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 8625;
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 60;
/// <summary>
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Orders", "5"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "0%"},
{"Drawdown", "0%"},
{"Expectancy", "0"},
{"Net Profit", "0%"},
{"Sharpe Ratio", "0"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "0%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "0"},
{"Beta", "0"},
{"Annual Standard Deviation", "0"},
{"Annual Variance", "0"},
{"Information Ratio", "0"},
{"Tracking Error", "0"},
{"Treynor Ratio", "0"},
{"Total Fees", "$0.60"},
{"Estimated Strategy Capacity", "$200000000.00"},
{"Lowest Capacity Asset", "BTCUSDT 2V3"},
{"Portfolio Turnover", "1.08%"},
{"OrderListHash", "114cfc5cfe796850f7ac29c2e63407d6"}
};
}
}

View File

@@ -0,0 +1,172 @@
/*
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using System.Collections.Generic;
using QuantConnect.Data;
using QuantConnect.Brokerages;
using QuantConnect.Indicators;
using QuantConnect.Orders;
using QuantConnect.Interfaces;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Algorithm demonstrating and ensuring that Bybit crypto brokerage model works as expected
/// </summary>
public class BybitCryptoRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
{
private Symbol _btcUsdt;
private ExponentialMovingAverage _fast;
private ExponentialMovingAverage _slow;
private bool _liquidated;
public override void Initialize()
{
SetStartDate(2022, 12, 13);
SetEndDate(2022, 12, 13);
// Set account currency (USDT)
SetAccountCurrency("USDT");
// Set strategy cash (USD)
SetCash(100000);
// Add some coin as initial holdings
// When connected to a real brokerage, the amount specified in SetCash
// will be replaced with the amount in your actual account.
SetCash("BTC", 1m);
SetBrokerageModel(BrokerageName.Bybit, AccountType.Cash);
_btcUsdt = AddCrypto("BTCUSDT").Symbol;
// create two moving averages
_fast = EMA(_btcUsdt, 30, Resolution.Minute);
_slow = EMA(_btcUsdt, 60, Resolution.Minute);
}
public override void OnData(Slice data)
{
if (Portfolio.CashBook["USDT"].ConversionRate == 0 || Portfolio.CashBook["BTC"].ConversionRate == 0)
{
Log($"USDT conversion rate: {Portfolio.CashBook["USDT"].ConversionRate}");
Log($"BTC conversion rate: {Portfolio.CashBook["BTC"].ConversionRate}");
throw new Exception("Conversion rate is 0");
}
if (!_slow.IsReady)
{
return;
}
var btcAmount = Portfolio.CashBook["BTC"].Amount;
if (_fast > _slow)
{
if (btcAmount == 1m && !_liquidated)
{
Buy(_btcUsdt, 1);
}
}
else
{
if (btcAmount > 1m)
{
Liquidate(_btcUsdt);
_liquidated = true;
}
else if (btcAmount > 0 && _liquidated && Transactions.GetOpenOrders().Count == 0)
{
// Place a limit order to sell our initial BTC holdings at 1% above the current price
var limitPrice = Math.Round(Securities[_btcUsdt].Price * 1.01m, 2);
LimitOrder(_btcUsdt, -btcAmount, limitPrice);
}
}
}
public override void OnOrderEvent(OrderEvent orderEvent)
{
Debug(Time + " " + orderEvent);
}
public override void OnEndOfAlgorithm()
{
Log($"{Time} - TotalPortfolioValue: {Portfolio.TotalPortfolioValue}");
Log($"{Time} - CashBook: {Portfolio.CashBook}");
var btcAmount = Portfolio.CashBook["BTC"].Amount;
if (btcAmount > 0)
{
throw new Exception($"BTC holdings should be zero at the end of the algorithm, but was {btcAmount}");
}
}
/// <summary>
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
/// </summary>
public bool CanRunLocally { get; } = true;
/// <summary>
/// This is used by the regression test system to indicate which languages this algorithm is written in.
/// </summary>
public Language[] Languages { get; } = { Language.CSharp, Language.Python };
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 2883;
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 60;
/// <summary>
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Orders", "3"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "0%"},
{"Drawdown", "0%"},
{"Expectancy", "0"},
{"Net Profit", "0%"},
{"Sharpe Ratio", "0"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "0%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "0"},
{"Beta", "0"},
{"Annual Standard Deviation", "0"},
{"Annual Variance", "0"},
{"Information Ratio", "0"},
{"Tracking Error", "0"},
{"Treynor Ratio", "0"},
{"Total Fees", "₮51.65"},
{"Estimated Strategy Capacity", "₮560000.00"},
{"Lowest Capacity Asset", "BTCUSDT 2UZ"},
{"Portfolio Turnover", "44.04%"},
{"OrderListHash", "b3a9eb7392ba1eb7eb0cc387f7382b6c"}
};
}
}

View File

@@ -0,0 +1,184 @@
/*
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using System.Collections.Generic;
using QuantConnect.Data;
using QuantConnect.Brokerages;
using QuantConnect.Indicators;
using QuantConnect.Interfaces;
using System.IO;
using QuantConnect.Orders;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Algorithm demonstrating and ensuring that Bybit crypto brokerage model works as expected with custom data types
/// </summary>
public class BybitCustomDataCryptoRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
{
private Symbol _btcUsdt;
private ExponentialMovingAverage _fast;
private ExponentialMovingAverage _slow;
public override void Initialize()
{
SetStartDate(2022, 12, 13);
SetEndDate(2022, 12, 13);
SetAccountCurrency("USDT");
SetCash(100000);
SetBrokerageModel(BrokerageName.Bybit, AccountType.Cash);
var symbol = AddCrypto("BTCUSDT").Symbol;
_btcUsdt = AddData<CustomCryptoData>(symbol, Resolution.Minute).Symbol;
// create two moving averages
_fast = EMA(_btcUsdt, 30, Resolution.Minute);
_slow = EMA(_btcUsdt, 60, Resolution.Minute);
}
public override void OnData(Slice data)
{
if (!_slow.IsReady)
{
return;
}
if (_fast > _slow)
{
if (Transactions.OrdersCount == 0)
{
Buy(_btcUsdt, 1);
}
}
else
{
if (Transactions.OrdersCount == 1)
{
Liquidate(_btcUsdt);
}
}
}
public override void OnOrderEvent(OrderEvent orderEvent)
{
Debug(Time + " " + orderEvent);
}
public class CustomCryptoData : BaseData
{
public decimal Open;
public decimal High;
public decimal Low;
public decimal Close;
public decimal Volume;
public override DateTime EndTime
{
get { return Time + Period; }
set { Time = value - Period; }
}
public TimeSpan Period
{
get { return QuantConnect.Time.OneMinute; }
}
public override SubscriptionDataSource GetSource(SubscriptionDataConfig config, DateTime date, bool isLiveMode)
{
var tickTypeString = config.TickType.TickTypeToLower();
var formattedDate = date.ToStringInvariant(DateFormat.EightCharacter);
var source = Path.Combine(Globals.DataFolder, "crypto", "bybit", config.Resolution.ToString().ToLower(),
config.Symbol.Value.ToLower(), $"{formattedDate}_{tickTypeString}.zip");
return new SubscriptionDataSource(source, SubscriptionTransportMedium.LocalFile, FileFormat.Csv);
}
public override BaseData Reader(SubscriptionDataConfig config, string line, DateTime date, bool isLiveMode)
{
var csv = line.ToCsv(6);
var data = new CustomCryptoData
{
Symbol = config.Symbol,
Time = date.Date.AddMilliseconds(csv[0].ToInt32()).ConvertTo(config.DataTimeZone, config.ExchangeTimeZone),
Open = csv[1].ToDecimal(),
High = csv[2].ToDecimal(),
Low = csv[3].ToDecimal(),
Close = csv[4].ToDecimal(),
Volume = csv[5].ToDecimal(),
Value = csv[4].ToDecimal()
};
return data;
}
}
/// <summary
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
/// </summary>
public bool CanRunLocally { get; } = true;
/// <summary>
/// This is used by the regression test system to indicate which languages this algorithm is written in.
/// </summary>
public Language[] Languages { get; } = { Language.CSharp, Language.Python };
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 4324;
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 60;
/// <summary>
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Orders", "2"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "0%"},
{"Drawdown", "0%"},
{"Expectancy", "0"},
{"Net Profit", "0%"},
{"Sharpe Ratio", "0"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "0%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "0"},
{"Beta", "0"},
{"Annual Standard Deviation", "0"},
{"Annual Variance", "0"},
{"Information Ratio", "0"},
{"Tracking Error", "0"},
{"Treynor Ratio", "0"},
{"Total Fees", "₮0.00"},
{"Estimated Strategy Capacity", "₮0"},
{"Lowest Capacity Asset", "BTCUSDT.CustomCryptoData 2US"},
{"Portfolio Turnover", "34.30%"},
{"OrderListHash", "6d099b57951f4801f9c07fba5f4c9f05"}
};
}
}

View File

@@ -137,7 +137,7 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "2"},
{"Total Orders", "5"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "0%"},
@@ -145,6 +145,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Expectancy", "0"},
{"Net Profit", "0%"},
{"Sharpe Ratio", "0"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "0%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
@@ -158,9 +159,9 @@ namespace QuantConnect.Algorithm.CSharp
{"Treynor Ratio", "0"},
{"Total Fees", "$0.00"},
{"Estimated Strategy Capacity", "$370000.00"},
{"Lowest Capacity Asset", "ETHUSD XJ"},
{"Lowest Capacity Asset", "ETHUSD 2XR"},
{"Portfolio Turnover", "104.59%"},
{"OrderListHash", "aea2e321d17414c1f3c6fa2491f10c88"}
{"OrderListHash", "ec714d818fa30597e992d4c6e939e68c"}
};
}
}

View File

@@ -66,7 +66,7 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "70"},
{"Total Orders", "70"},
{"Average Win", "0.07%"},
{"Average Loss", "-0.51%"},
{"Compounding Annual Return", "-89.548%"},

View File

@@ -111,7 +111,7 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "19"},
{"Total Orders", "19"},
{"Average Win", "39.16%"},
{"Average Loss", "-8.81%"},
{"Compounding Annual Return", "-99.857%"},

View File

@@ -195,7 +195,7 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "1015"},
{"Total Orders", "1015"},
{"Average Win", "0.01%"},
{"Average Loss", "0.00%"},
{"Compounding Annual Return", "-12.674%"},

View File

@@ -81,7 +81,7 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "150"},
{"Total Orders", "150"},
{"Average Win", "0.16%"},
{"Average Loss", "-0.11%"},
{"Compounding Annual Return", "-19.320%"},

View File

@@ -87,7 +87,7 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "1005"},
{"Total Orders", "1005"},
{"Average Win", "0.96%"},
{"Average Loss", "-0.33%"},
{"Compounding Annual Return", "76.267%"},

View File

@@ -81,7 +81,7 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "671"},
{"Total Orders", "671"},
{"Average Win", "0.07%"},
{"Average Loss", "-0.04%"},
{"Compounding Annual Return", "-80.820%"},

View File

@@ -107,7 +107,7 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "1217"},
{"Total Orders", "1217"},
{"Average Win", "2.69%"},
{"Average Loss", "-0.93%"},
{"Compounding Annual Return", "-99.756%"},

View File

@@ -82,7 +82,7 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "735"},
{"Total Orders", "735"},
{"Average Win", "0.08%"},
{"Average Loss", "-0.05%"},
{"Compounding Annual Return", "-93.946%"},

View File

@@ -82,7 +82,7 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "603"},
{"Total Orders", "603"},
{"Average Win", "0.20%"},
{"Average Loss", "-0.26%"},
{"Compounding Annual Return", "-100.000%"},

View File

@@ -75,7 +75,7 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "35"},
{"Total Orders", "35"},
{"Average Win", "0.07%"},
{"Average Loss", "-0.07%"},
{"Compounding Annual Return", "-68.407%"},

View File

@@ -75,7 +75,7 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "35"},
{"Total Orders", "35"},
{"Average Win", "0.05%"},
{"Average Loss", "-0.10%"},
{"Compounding Annual Return", "-72.444%"},

View File

@@ -76,7 +76,7 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "162"},
{"Total Orders", "162"},
{"Average Win", "0.10%"},
{"Average Loss", "-0.35%"},
{"Compounding Annual Return", "-94.432%"},

Some files were not shown because too many files have changed in this diff Show More