Compare commits

...

1915 Commits
10197 ... 16636

Author SHA1 Message Date
Roman Yavnikov
c556d16775 Feature: new Tick constructor for TickType.OpenInterest (#8323)
* feat: create OpenInterest constrcutor of Tick

* feat: GetSubscribedSymbols by TickType

* test:feat: GetSubscribeSymbolsBySpecificTickType

* refactor: equal channel name with InvariantCultureIgnoreCase
2024-09-17 12:52:24 -03:00
Martin-Molinero
6351773a01 Option universe resolution improvements (#8324)
* Option universe improvements

- Improvement for resolution handling of option universes, affecting
  performance in live mode. Adding regression algorithm

* Minor fix for research test
2024-09-16 10:22:58 -03:00
Jhonathan Abreu
bf4b08e202 Fix: adjust option expiry reference date (#8322)
* Fix: adjust option expiry reference date

* Add universe files

* Update data and other minor changes

* Minor changes

* Add regression algorithm summary
2024-09-13 18:22:26 -04:00
Jhonathan Abreu
fa9ff399cc Euro Stoxx 50 Index and Index Futures support (#8278)
* EUREX data

EUREX data model and sample data

* Add EUREX futures expiry function and sample algorithms

* Add EuroStoxx50 futures map and factor files

* Reduce eurex data for repo

* Map eurex market to primary exchange

* Update Euro Stoxx 50 (FESX) map and factol files

* Update Euro Stoxx 50 (FESX) minute data

* Added EURSD data

* Added 2 basic FESX futures algorithms in CSharp and Python (#2)

* Add regression algorithms

* Update regression algorithms and data

* Minor change

* Cleanup

---------

Co-authored-by: paulius-an <118921953+paulius-an@users.noreply.github.com>
2024-09-12 10:00:16 -04:00
Jhonathan Abreu
16c4259342 Add QCAlgorithm.OptionChain() method to fetch option chains (#8316)
* Add new QCAlgorithm.OptionChain method to get full data option chain

* Add extension method to get canonical symbol

* Support future options in new OptionChain method

* Replace option chain provider with OptionChain method in some regression algorithms

* Add new regression algorithms for OptionChain method

* Replace option chain provider with OptionChain method in some regression algorithms

* Minor

* Cleanup

* Minor changes in regression algorithms

* Minor adjustments
2024-09-11 15:15:51 -04:00
Ricardo Andrés Marino Rojas
724d0b06a5 Add extra argument in QuantBook.UniverseHistory() for using an IDateRule (#8301)
* First draft of the solution

* Handle end date better

* Improve unit tests

* Add extra argument in missing method

* Nit change

* Nit change

* Nit change

* Undo changes to C# generic UniverseHistory()

* Address suggestions

* Improve unit test

* Add null checks

* Minor adjustment

---------

Co-authored-by: Martin Molinero <martin.molinero1@gmail.com>
2024-09-11 13:41:57 -03:00
Ricardo Andrés Marino Rojas
ba7fe05574 Add BeforeMarketOpen() and AfterMarketClose() date rules (#8311)
* First draft of the solution

* Add unit tests

* Improve unit tests

* Nit changes
2024-09-10 15:56:31 -03:00
Ricardo Andrés Marino Rojas
50437946e2 Add missing end_date in python regression algorithm (#8315) 2024-09-10 14:33:44 -03:00
Ricardo Andrés Marino Rojas
418970bb48 Add TravisExclude category to failing CI unit test (#8313) 2024-09-10 13:25:41 -03:00
Roman Yavnikov
bef045a360 Fix: Get GroupOrders ByBrokerageId (#8310)
* fix: Get GroupOrders ByBrokerageId

* test:feat: return all combo orders with the same brokerageId
2024-09-10 13:25:22 -03:00
Jhonathan Abreu
49bf436aa2 Remove Lean path info from runtime exceptions (#8309)
* Strip lean path info from runtime exceptions

* Minor fix
2024-09-09 17:54:29 -04:00
Jhonathan Abreu
e29bb2c5e0 File-based options universe (#8212)
* Initial options universe with greeks implementation

* Options universe improvements

* Address peer review

* File based options universe fixes and improvements.

- Adjust OptionUniverse start-end times and period.
- Adapt unit tests and some algorithms to pass with new options universe selection.

* Updated options regression algorithms stats for new universe data

* Updated options regression algorithms stats for new universe data

* Updated options regression algorithms stats for new universe data

* Updated options regression algorithms stats for new universe data

* Updated options regression algorithms stats for new universe data

* Option chain provider with new options universe

* Allow canonical option history requests

* Address peer review

* Address peer review

* Fix symbols parsing in OptionUniverse

* Fix universe selection subscriptions start time to not include extended market hours

* Minor changes

* Minor changes

* Peer recommended changes and fixes

* Update regression algorithm stats

* Update regression algorithms stats and minor fixes

* Fix option chain provider history request

* Round option indicators values

* Added option universe csv header property

* Update regression algorithms stats

* Update regression algorithms stats

* Data fixes and regression algos stats update

* Unit test fixes

* Minor changes

* Option chain handling in live trading data feed

* Minor changes

* Added processed data provider

* Fix thread-safety violation in Slice class

* Minor change

* Update options filter universe API to use OptionUniverse data

Add new filter methods for greeks, IV and open interest

* Option filter universe api updates

* Add OptionUniverse history regression algorithms

* Add regression algorithms for new options filter universe api methods

* Added options greeks data and updated regression algorithms

* Address peer review

* Address peer review

* Add more assertions to new options filter api regression algorithms

* Minor performance improvement.

Reduce greeks binomial model steps to 140

* Minor tests updates

* Greeks numerical models performance improvements

* Greeks numerical models performance improvements

* Revert array pool change for option pricing numerical models

* Update default dividend yield provider depending on option type

* [TEST]

* Add helper method con calculate time till expiration

* Use double in price option numerical models

* Implied volatility calculation improvements

- Adjust root finding method accuracy as a factor of the option price
- Use BSM to get a first guess

* Cleanup

* Some regression algorithms and unit tests cleanup

* Regression tests updates after rebasing from master

* Add universe files

* Self review and cleanup

* Minor regression tests updates after rebase

* Fix: set data time zone to same as exchange tz for options universes

* Minor change

* Minor change

* Fix for live trading options universe selection

* Keep underlying when aggregating collections in BaseDataCollectionAggregatorEnumerator

* Update index options regression algorithms stats

* Minor change

* Address peer review

* Memory usage improvements

* Minor build fix

* Minor changes and test fixes

* Cache symbols in OptionUniverse

* Cleanup

* Fix index option creation in OptionUniverse

* Use cached underlying SID when parsing from string

* Abstract symbols cache to BaseDataCollection

* Return actual underlying symbol when mapping decomposing ICO ticker

* Address peer review

* Minor performance improvements reduce garbage

* Limit Symbols and SIDs cache size to help with memory usage

* Minor fix in symbols and sid cache cleanup

* Build fix

* Lazily parse greeks on individual access

* Cleanup and tests

* Address peer review

* Minor greeks fix

---------

Co-authored-by: Martin Molinero <martin.molinero1@gmail.com>
2024-09-09 12:39:31 -03:00
Dennis Yemelyanov
8fcc9f7d4e fix some comments for option security types (#8304) 2024-09-09 11:37:26 -03:00
Andy Geach
5209332074 Update readme.md to remove references to Visual Studio for Mac, which has been discontinued (#8298) 2024-09-06 11:59:28 -03:00
Roman Yavnikov
adfad475cc Feature:TradeStationBrokerage: support ComboMarket && ComboLimit (#8290)
* refactor: adding OrderId in GroupOrderManger

* feat: new support of OrderTypes in TradeStationBrokerageModel
feat: unSupported OrderTypes in CanUpdateOrder's TradeStationBrokerageModel

* feat: AllOrNone property in TradeStationOrderProperties

* feat: unsupported SubmitCrossZero of Combo Order in TSBrokerageModel

* test:feat: submit / update CrossZero Combo Orders

* feat: new Message Brokerage error message
refactor: use new Message in TradeStationBrokerageModel

* feat: setter of Id in GroupOrderManager

* feat: new constructor of GroupOrderManager

* feat: develop GroupOrderCacheManager service

* fix: groupOrderManger.Id in OrderProvider

* fix: incrementOrderGroupOrderManagerID in BrokerageTransactionHandler
feat: add _groupOrderManagerId in OrderProvider

* remove: extra semicolon

* refactor: prevent increment GroupOrderID

* feat: add new Exchanges

* feat: Try Get Group Combo Orders extension

* refactor: ComboORderType in TSBrokerageModel

* remove: implementing of prop ID in GroupOrderManager

* refactor: UnsupportedCrossZeroByOrderType message

* fix: warning of UnsupportedCrossZeroByOrderType

* fix: several exchanges code based on tradier docs
https://documentation.tradier.com/brokerage-api/reference/exchanges

* feat: add missed Exchange in Global class

* refactor: possible update LimitPrice in TSBrokerageModel
test:feat: validate upddate LimitPrice of ComboLimit Order

* refactor: GroupOrderCacheManager
remove: TryGetGroupCachedOrders from extension

* refactor: exchange SPHR to MIAX_SAPPHIRE

* remove: Exchange BYX cuz It is BATS_Y

* refactor: change position of Exchange C2

* refactor: change constructor's access modifier in class Exchange
2024-09-06 10:31:14 -03:00
Martin-Molinero
21fcadf0f8 Ignore failing live future option unit test (#8300) 2024-09-05 16:42:42 -03:00
Ricardo Andrés Marino Rojas
e893e67e9b Throw exception when base currency not found (#8289)
* First draft of the solution

* The same check for crytpo is done before

* Fix failing unit tests

* Remove non perpetual crypto futures from SPDB

* Address requests

* Fix failing unit tests
2024-09-04 12:14:53 -03:00
Alexandre Catarino
3b588d04fb Adds Overload to AddIndexOption (#8291)
* Adds Overload to AddIndexOption

Simplify usage. We don't need to create/add the underlying explicitly, see AddIndexOption(string, Resolution, string, bool) overload.

* Addresses Peer-Review

- Default market is `null` instead of `Market.USA` allowing for `BrokerageModel` setup.
- `AddIndexOption` and `AddIndexOptionContract` methods now return `indexOption` objects.

* Fixes Logic Bug
2024-09-04 10:30:05 -03:00
Ricardo Andrés Marino Rojas
e81bcbb987 Improve PythonIndicator.IsReady implementation (#8287)
* First draft of the solution

* nit change

* Add improvements

* Fix failing unit tests

* Add improvements
2024-09-04 10:07:13 -03:00
Roman Yavnikov
96e91b446d Fix: #8226, update spdb binance/binanceus (#8293)
* feature: update binance spdb data

* feature: update binanceus spdb data

* test:fix: EURUSDC stable coins conversation
2024-09-04 10:05:07 -03:00
Ricardo Andrés Marino Rojas
403f0348bd Update Bybit SPDB (#8294)
* Update Bybit SPDB

* Remove trailing comma
2024-09-03 17:55:12 -03:00
Ricardo Andrés Marino Rojas
eeeb310438 Update minimum price variation of some entries of CME futures in SPDB (#8288)
* Update some entries of CME futures in SPDB

* Adjust 6B minimum price variation
2024-08-28 19:59:40 -03:00
oussamanahdi
271f0bb08e Update readme.md (#8286) 2024-08-26 19:11:04 -03:00
Ricardo Andrés Marino Rojas
3a09c70851 Fix warm up indicator bugs (#8279)
* Potential solution

* Try a different approach

* Improve unit tests

* Nit change

* Improve implementation

* Fix another bug and improve unit tests
2024-08-26 10:20:40 -03:00
Roman Yavnikov
f31251732e Fix: Coinbase MinimumOrderSize tests based on new SPDB data (#8276)
* test:fix: minimValue based on new SPDB data

* fix: Estimated Strategy Capacity in FractionalQuantityRegressionAlgorithm
2024-08-23 11:47:45 -03:00
Roman Yavnikov
9baacdbdd6 feat: Coinbase SPDB update (#8273) 2024-08-22 17:42:58 -03:00
Martin-Molinero
363d469d6a Minor indicator history fix (#8270)
* Minor indicator history fix

- Take into account warmup period when used, the last bar of the warmup
  period is counted as a data point.
- Fix bug where in some cases the last data point could of been missed
  and the indicator not updated with it

* Minor tweak
2024-08-22 16:48:26 -03:00
Ricardo Andrés Marino Rojas
c186addf94 Add missing price magnifier in SPDB (#8271) 2024-08-22 16:44:26 -03:00
Ricardo Andrés Marino Rojas
17049dcd56 Fix null exception thrown in SubscriptionManager.ScanPastConsolidators (#8267)
* Initial draft of the solution

* Improve implemetation

* Nit change

* Address requests

* Switch from LinkedList ot List

* Fix bug
2024-08-22 09:55:41 -03:00
Jhonathan Abreu
d88387ac67 Extend Python wrappers error messages (#8257)
* Implement runtime checks for python wrappers

* Implement runtime checks for python wrappers

* Add more python wrappers runtime checks

* Add dictionary conversion unit tests

* Add python wrappers runtime checks for properties

* CLeanup base python wrapper messages
2024-08-19 14:27:32 -04:00
Ricardo Andrés Marino Rojas
74c3501ed3 Fix bug for history requests with custom symbols (#8262)
* Potential solution to the bug

* Add test file

* Fix bugs

* Address requested changes
2024-08-19 15:26:42 -03:00
Ricardo Andrés Marino Rojas
a543af71dc Solve bug (#8256) 2024-08-19 11:57:21 -03:00
Jhonathan Abreu
9b332c2149 Dividend yield calculation fix (#8264)
* Fix dividend yield calculation

* Get security price as input for dividend yield provider

* Account for splits in dividend yield provider

* Fix split adjustment for dividend yield calculation

* Use right dividend yield in options indicators
2024-08-19 09:30:05 -04:00
keshavdalmia10
1e620e54fe Feature 8132 implement vortex indicator (#8242)
* Implemented the vortex indicator.

* changed the vortex.cs calculations

* chore: Refactor VortexTests.cs and QCAlgorithm.Indicators.cs

* Refactor VortexTests.cs

* made changes according to the comments

* used indicator exxtension methods

* made changes in the naming convention and added condition for division by zero.

* Using composite indicators to clean up

---------

Co-authored-by: Jhonathan Abreu <jdabreu25@gmail.com>
2024-08-14 15:43:21 -03:00
Martin-Molinero
7879795207 Enable daily precise end time by default (#8254)
* Default daily precise end times

- Enable by default daily precise end times. Updating stats
- Minor fix for algorithm manager consolidator updates, adding new regression test
  asserting behavior and updating others
- Minor fix for SubscriptionData creator avoid round down on warmup if
  not appropiate
- Adjust consolidators to emit on daily strict end times if requested
  daily resolution and setting enabled
- Updating regression algorithms

* Skip daily data on extended market hours

* Some cleanup and self review

* Revert unrequired change
2024-08-14 12:49:56 -03:00
Noah Misch
d2d366e3f9 Fix sign of order quantity in example algorithm OnMarginCall(). (#8251)
Despite the comments about avoiding margin calls and about padding, this
turned a proposed sale of 100 shares into a *buy* of 110 shares.
2024-08-12 17:40:51 -03:00
Ricardo Andrés Marino Rojas
5226b7a468 Add more options to Field class (#8228)
* First draft of the solution

* Reduce duplication and add more properties

* Add regression tests

* Add xml docs

* Add unit tests

* Improve regression and unit tests

* Address requested changes

* Address request and improve unit tests

* Add unit test and fix bug

* Improve unit tests and implementation

* Nit change

* Address reviews

* Improve regression tests

* Address requests

* Fix bug

* Address requests
2024-08-07 19:08:34 -03:00
FemtoTrader
1947a58541 Implements new indicator - CKS - ChandeKrollStop (#8198)
* Implements ChandeKrollStop

* readonly

* Move IsReady/WarmUpPeriod above the constructors

* remove private _period

* minor

* rename Stops to Short/Long

* using Maximum/Minimum

* fix tests

* rename some variables and use movingAverageType for ATR

* movingAverageType
2024-08-07 14:51:39 -03:00
Roman Yavnikov
1bca3f6081 feat: missed reference on DownloaderDataProvider in Lean.Launcher (#8247) 2024-08-07 14:51:05 -03:00
Noah Misch
2b1136e446 Fix algorithms using OnData(TradeBars) w/o using arg or other OnData(). (#8245)
Commit d24f665ee4 removed the
Engine/AlgorithmManager.cs support for OnData(TradeBars), making these
methods dead code.  Hence, some of these algorithms no longer placed
orders.  Fix by changing OnData(TradeBars) to OnData(Slice).  Files that
use the TradeBars argument or use OnData(Dividends) have the same
trouble; leave them for future work.
2024-08-06 10:15:56 -03:00
Roman Yavnikov
86fcc40c3e Feature: Generic brokerage downloader wrapper (#8235)
* feat: new constructor of AlgorithmNodePacket

* refactor: extract JobQueue configuration

* remove: not used `using` in IDataDownloader

* feat: create BrokerageDataDownloader

* Revert "refactor: extract JobQueue configuration"

This reverts commit 5778936b71.

* Revert "feat: new constructor of AlgorithmNodePacket"

This reverts commit d7a565ff76.

* feat: new config `data-download-brokerage` in DataDownloadProvider

* refactor: initialize in BrokerageDataDownloader

* remove: not used `using` in Program's DataDownloadProvider

* remove: not used ref on QuantConnect.Queue proj

* refactor: use default market based on SecurityType

* refactor: MarketName in DataDownloadConfig struct
test:feat: validate MarketName

* feat: support Canonical Symbols in BrokerageDataDownloader

* remove: not used command arguments

* feat: init CacheProvider of IOptionChainProvider in Downloader

* feat: add brokerage message event in BrokerageDataDownloader
2024-07-31 19:02:13 -03:00
Jhonathan Abreu
9eb484625d Default option pricing models for options indicators (#8229)
* Set best recommended model based on option style.

The best option model will be used in options indicators based on option style if not specified

* Reduced Greeks/IV numerical models steps to 100

* Minor fixes

* Minor changes and improvements

* Changed default pricing model for IV

* Minor performance improvements

* Minor performance improvements and fixes

* Minor change

* Minor regression algorithm fix

* Update greek indicators internal IV indicator only when not user provided

* Revert unnecessary changes

* Minor changes

* Cleanup
2024-07-30 10:15:21 -04:00
FemtoTrader
85ca5be258 Implements new indicator - RSV - Rogers-Satchell volatility (#8183)
* implement Rogers-Satchell volatility

* naming RSVolat to avoid confusion between volume and volatility

* fix InitializeIndicator call

* fix AcceptsRenkoBarsAsInput test

* add symbol parameter to InitializeIndicator

* Update RogersSatchellVolatility.cs

* some fixes after review

* Return 0 when Open High Low or Close is 0

* IBaseDataBar
2024-07-29 14:47:16 -03:00
Martin-Molinero
9a84a6bd17 Minor test brokerage security provider improvement (#8231) 2024-07-29 13:41:37 -03:00
Martin-Molinero
a46acef9f8 Minor improvements (#8223)
- Liquidate takes into account invested flag
- Minor tweaks for symbol representation parsing
2024-07-23 12:18:26 -03:00
keshavdalmia10
69fa2fd689 Made changes in the ParseOptionTickerOSI function. Now it can handle … (#8219)
* Made changes in the ParseOptionTickerOSI function. Now it can handle both with and without space

* added new function GenerateOptionTickerOSICompact and added the test cases for it, expanded test cases for ParseOptionTickerOSI

* added assertions for strikePrice and date, corrected the indentation
2024-07-23 11:23:11 -03:00
Martin-Molinero
2df58bbca3 Accept live UniverseProvider returning null (#8222)
- Similar to HistoryProviders and Live DataQueueHandler calls, adjust
  live Universe provider manager to handle null returned values
2024-07-23 10:30:19 -03:00
Martin-Molinero
050030bca8 Minor improvement to Invested holdings flag (#8221) 2024-07-23 10:27:40 -03:00
FemtoTrader
7e40b4f1ab Implements new indicator - SOBV - Smoothed On Balance Volume (#8180)
* fix conflict

* fix all SmoothedOnBalanceVolumeTests tests except AcceptsRenkoBarsAsInput

* fix InitializeIndicator call

* fix AcceptsRenkoBarsAsInput test

* add symbol parameter to InitializeIndicator

* shorter
2024-07-22 18:27:52 -03:00
FemtoTrader
229d636628 implements generate_reference_data_from_talib.py (#8196) 2024-07-22 14:50:24 -03:00
FemtoTrader
034bf3d8ae add script using tulipy (#8194) 2024-07-22 14:43:33 -03:00
Martin-Molinero
31b32442c8 Fix Alpaca option order types (#8220) 2024-07-22 14:24:47 -03:00
Ricardo Andrés Marino Rojas
9a92933397 ARIMA indicator error handling (#8218)
* First draft of the solution

* Add comments

* Address requests

* Nit change

* Fix bug
2024-07-22 14:24:12 -03:00
Ricardo Andrés Marino Rojas
97959d560a Add liquidate method overloads (#8210)
* First draft of the solution

* First draft of the tests

* Nit changes

* Nit change

* Add improvements

* Improve unit tests

* Regression algos

* Nit change

* Nit changes

* Improve unit tests

* Improve unit test

* Nit change

* Address reviews
2024-07-22 12:48:53 -03:00
Martin-Molinero
0352a0b07c Fix Alpaca Order Fees (#8217)
- Fix alpaca order fees. Expanding unit tests
- Improve base brokerage test framework
2024-07-22 12:48:34 -03:00
FemtoTrader
bd87ba6f14 Implements new indicator CHOP - Choppiness Index (#8178)
* WIP

* Implement CHOP

* 0m instead of 0

* readonly

* doc - param

* fix InitializeIndicator call

* return 100 when max_high = min_low

* remove unused imports

* remove unused imports

* add symbol parameter to InitializeIndicator

* Update ChoppinessIndex.cs

* Update ChoppinessIndex.cs

* decimal

* fix testing IsReady

* move WarmUpPeriod
2024-07-22 12:14:53 -03:00
Martin-Molinero
ab601cbb08 Minor fix for cross order id (#8213) 2024-07-19 15:20:31 -03:00
FemtoTrader
72a1bd4c48 Implements new indicator StochRSI - Stochastic Relative Strength Index (#8163)
* tests passing except ResetProperly and WarmsUpProperly

* doc

* minor fixes

* doc - return

* fix InitializeIndicator call

* workaround ResetsProperly

* fix WarmsUpProperly test

* remove WriteLine

* remove WriteLine

* cr

* fix data

* open high low defaults to close when these columns don't exist into data

* simplify using ternary operator

* better fix for ResetsProperly

* fix some code conventions issues

* fix some review issues

* Update StochasticRelativeStrengthIndex.cs
2024-07-19 09:26:39 -03:00
Martin-Molinero
3bdde74096 Minor brokerage testing improvements (#8209) 2024-07-18 14:34:29 -03:00
Roman Yavnikov
ba626f18d2 Feature: Implementation Alpaca Brokerage (#8203)
* feat: Alpace models implementation

* Address reviews

---------

Co-authored-by: Martin Molinero <martin.molinero1@gmail.com>
2024-07-16 12:26:26 -03:00
FemtoTrader
12f6263d8b Implements new indicator VWMA - Volume Weighted Moving Average (#8161)
* WIP

* private fields are camelCased

* private fields starts with underscore

* remove unused imports

* fix WarmsUpProperly test

* fix InitializeIndicator call

* IndicatorValueIsNotZeroAfterReceiveRenkoBars

* add constructor

* return close price if _sumV=0

* no Renko bars

* some fixes after review
2024-07-16 11:14:39 -03:00
FemtoTrader
14db9caf90 Implements new indicator ForceIndex (#8155)
* WIP

* All tests are passing except AcceptsRenkoBarsAsInput

* Update QuantConnect.Tests.csproj

* comment formating and use input.EndTime

* fix AcceptsRenkoBarsAsInput test

* fix InitializeIndicator call

* add symbol parameter to InitializeIndicator

* FI above FISH
2024-07-16 11:14:14 -03:00
Martin-Molinero
dda950b6e4 Test 2024-07-15 16:05:31 -03:00
Martin-Molinero
9b3400e9d1 Delete google9161359af9633398.html 2024-07-12 16:50:37 -03:00
Martin-Molinero
162d3cbca2 Add files via upload 2024-07-12 16:43:24 -03:00
Martin-Molinero
53c2a214a1 Improve indicator warmup (#8192)
* Improve indicator warmup

- Allow indicator warmup to handle multiple symbols, used for option
  greeks. Adding regression test
- Improve indicator history to handle specific T types. Adding unit test
- Remove period, and historical underlying volatility, from IV so
  simplify warmup behavior

* Address review, fix minor issues
2024-07-11 16:16:49 -03:00
FemtoTrader
8136a73801 Implements new indicator IBS - Internal Bar Strength (#8151)
* Implement new indicator IBS

* remove using System

* typo

* doc fix

* Implement new indicator IBS

* remove using System

* typo

* doc fix

* inherit TradeBarIndicator and return 1m when High=Low

* duplicate spy_with_ibs

* returns 0.5 when High=Low
2024-07-11 16:13:31 -03:00
Ricardo Andrés Marino Rojas
554a82527f Fix minor warnings (#8190)
* Fix CA1847 warnings and some CA1307 warnings

* Fix CA1823 and CS0169

* Fix CA1820 warnings

* Address requested changes
2024-07-10 14:17:27 -03:00
Ricardo Andrés Marino Rojas
8b312efd0c Fix CA1829 warning (#8188)
* Fix CA1829 warning

* Fix failing test
2024-07-10 14:08:28 -03:00
FemtoTrader
fcb33d8ba3 implements McGinleyDynamic (#8189) 2024-07-10 11:41:56 -03:00
Ricardo Andrés Marino Rojas
a7efcfe9d5 Fix CS1570 and CS1572 warnings (#8187)
* Fix CS1570 and CS1572 warnings

* Address requested changes
2024-07-10 11:16:16 -03:00
Ricardo Andrés Marino Rojas
5a7a162d34 Fix warnings CA1574 (#8186) 2024-07-09 17:52:07 -03:00
Martin-Molinero
268285e2b3 Minor fix for Mis-Aligned Timestamps from IndicatorHistory (#8185)
* Minor fix for Mis-Aligned Timestamps from IndicatorHistory

- Minor fir for mis-Aligned Timestamps from IndicatorHistory. Adjusting
  unit test to reproduce issue.

* Add another assert to indicator history tests
2024-07-09 17:09:12 -03:00
FemtoTrader
db1f63bae7 Add ZLEMA to MovingAverageTypeExtensions.cs and MovingAverageType.cs (#8177)
* add ZLEMA to Indicators/MovingAverageTypeExtensions.cs and Indicators/MovingAverageType.cs

* add new MA (ZLEMA) to test suite
2024-07-09 17:07:59 -03:00
Ricardo Andrés Marino Rojas
99a949586c Fix warnings part 12 (#8182)
* First part of the warnings

* Second half of the changes
2024-07-09 11:08:42 -03:00
Jhonathan Abreu
e0c90e8c04 Minor changes in option chain fetching algorithms (#8175) 2024-07-09 10:55:45 -03:00
Martin-Molinero
12644f8b2a Minor fixes for IndicatorHistory and IV (#8174)
* Minor fixes for IndicatorHistory and IV

- Minor fix for IndicatorHistory, use ScaledRaw data normalization mode
  for option indicators. Adding unit test
- Expand the IV expected upper range to 400%, given values can be higher
  than previous value of 200%
- Adjust IV to use smoothing function only when both option calculations
  succeed

* Updating regression algorithm expected greeks, minor change
2024-07-09 10:54:55 -03:00
FemtoTrader
28f9db194e fix naming (#8168) 2024-07-08 12:32:40 -03:00
Martin-Molinero
6c30157fab Remove universe selection on extended market dates (#8160)
- Remove universe selection on dates with extended market hours only
- Updating regression algorithms
- Expand date & time rules API to support specifying whether extended
  market hours only dates are desired or not
2024-07-08 11:58:50 -03:00
FemtoTrader
014ec7f626 Implement new indicator - ZLEMA - Zero Lag Exponential Moving Average (#8148)
* Implement new indicator ZLEMA

* Add script to generate reference data from talipp

* Some review fixes

* description

* use isReady

* use Delay(...)

* simplify ComputeNextValue

* Minor tweaks addressing review

* replace DateTime.UtcNow for specific date time instances

* remove unused imports

---------

Co-authored-by: Martin Molinero <martin.molinero1@gmail.com>
2024-07-08 11:58:05 -03:00
Roman Yavnikov
2941210d20 fix: lock of place first part of cross zero order (#8157) 2024-07-05 16:52:31 -03:00
Louis Szeto
6185a4c6a4 Option Strategy Filters for Jelly Roll and Ladder (#8150)
* add option filter strategy

* unit test

* regression test
2024-07-05 16:31:38 -03:00
Ricardo Andrés Marino Rojas
16a737ee26 Fix most of CA1725 warnings (#8154)
* Fix CA1725 warning

* Address requested changes
2024-07-05 16:19:56 -03:00
Martin-Molinero
ee35c75e62 Minor indicator test suite improvements (#8153)
* Minor indicator test suite improvements

- Simplify and improve indicator test suite assertions
- Reduce indicator suite run time

* Fix DividendYieldProviderTests dependency
2024-07-05 15:10:12 -03:00
Ricardo Andrés Marino Rojas
0a0c012ae9 Fix second half of the CA1051 warnings (#8140)
* Fix second half of the CA1051 warnings

* Address requested changes
2024-07-05 13:54:03 -03:00
Ricardo Andrés Marino Rojas
574eafd00d Add missing endpoint in C# API Client (#8143)
* Add C# API ReadBacktestInsights()

* Address reviews

* Address requested changes
2024-07-05 13:53:27 -03:00
Martin-Molinero
eff8b6f2fb Improve indicator history data update (#8141)
- Do not lose data symbol on indicator update during IndicatorHistory
  call. Adding unit test reproducing issue
2024-07-03 17:59:41 -03:00
Ricardo Andrés Marino Rojas
5fd021996a Fix half of the CA1051 warnings (#8137)
* Fix half of the CA1051 warnings

This warning is about not declaring visible instance fields. There are
something about 500 warnings in the solution, mostly in the QuantConnect and QuantConnect.Algorithm.CSharp projects. I aim to fix one of them in this PR and the other half of them in a second one. To fix it, I'm changing the visible instancce fields for properties.

* fix bugs

* Addressing minor reviews

* More minor fixes

---------

Co-authored-by: Martin Molinero <martin.molinero1@gmail.com>
2024-07-03 15:43:17 -03:00
Martin-Molinero
ee1a6ef87b Add missing terminal link brokerage name (#8135) 2024-07-02 14:11:21 -03:00
Martin-Molinero
3d17e0e122 Minor thread safety interest rate provider fix (#8119)
- Fix race condition in interest rate provider, we were updating the
  private static variable instance before it was ready, causing
  explosions
2024-07-02 13:19:04 -03:00
Martin-Molinero
9229ddbef0 Fix micro gold expirations (#8117)
- Minor fix for micro gold expected expirations. Updating unit tests
2024-07-01 14:12:20 -03:00
Louis Szeto
409f93a3aa Option Strategy Filter Universe (#8088)
* add 1-2 contracts universes

* Add unit tests for 1-2 contract strategies

* refactor

* Call/Put Butterfly

* Iron Butterfly/Condor & Box Spread

* Refactor and bug fixes

* Add regression algorithms

* use AllSymbols

* refactor on peer review, update unit tests

* update regression tests

* update assertion

* update

* remaining assertion

* order hash update

* use helper method on assertion

* fix bug

* Address reviews. Some cleanup and refactor

---------

Co-authored-by: Martin Molinero <martin.molinero1@gmail.com>
2024-07-01 13:58:30 -03:00
Martin-Molinero
25c635d846 Add indicator helper methods for base Algorithm (#8076)
* Add indicator helper methods for base Algorithm

- Add indicator helper methods for base algorithm. Adding new unit tests

* Expand indicators helper methods

- Expand indicators helper methods, adding support for C# and custom
  indicators too. Adding unit tests
- Expand indicators helper methods to support multiple symbols as input.
  Adding unit tests
- Improve conversion of symbol enumerable from python to C# adding unit
  tests

* Address reviews

- Keep old QB.Indicator methods for backwards compatibility
- Rename new API to IndicatorHistory, matching
  FutureHistory/OptionHistory
- Add new regression algorithms
- Minor improvement to DynamicData so it supports snake name access
2024-07-01 13:27:47 -03:00
Roman Yavnikov
1911cda7b1 Refactor: Handle OrderStatus with Cross Zero Order Collection (#8114)
* empty

* refactor: orderType for SecondCrossZeroOrder

* refactor: handle some specfic orderStatus in CrossZeroOrder process

* refactor: Handle specific OrderStatus in SecondPartCrossZeroOrder

* refactor: handle order status
revert: convertOrderType of CrossZeroSecondPart

* fix: use right collection when removing cross zero order class
2024-06-28 12:05:19 -03:00
Ricardo Andrés Marino Rojas
a2b420cb0a Fix warnings part 8 (#8113)
* Fix CA1819 and CA1002 warnings

Changed the type of Languages statistic in regression tests from
Language[] to List<Language>. By doing that, the warning CA1819 was
removed but then the warning CA1002 was raised. However, this warning
was expected to be excluded from QuantConnect.Algorithm.CSharp.

* Improve implementation

* Simplify code

* Fix bugs
2024-06-28 10:10:30 -03:00
Louis Szeto
cd1aad657d OptionStrategies for Iron Butterfly (#8072)
* Define Iron Butterfly and its buying power model

* Add unit tests

* Add regression test

* Address peer review

* Add short iron butterfly and short iron condor

* Add unit tests on short strategies

* add regression algorithms

* Invert direction of iron butterfly
2024-06-28 10:07:39 -03:00
Louis Szeto
aae6d617fb Option Strategy: Jelly Roll & Ladder (#8092)
* Define Jelly Roll

* Margin Model

* Add universe filter

* unit tests

* add regression tests

* add definitions

* universe filter

* margin model

* unit tests

* bug fix

* unit tests

* regression tests

* typo

* peer review

* peer review 2

* bug fix, address peer review

* minor fix

* Fixes `middleStrike` Parameter Description

The "middle strike" instead of "with higher/lower" to match the parameter description with name.

---------

Co-authored-by: Alexandre Catarino <AlexCatarino@users.noreply.github.com>
2024-06-27 15:58:06 -03:00
Ricardo Andrés Marino Rojas
621d1252b9 Fix label bug in QCAlgorihtm.Python.History() when requesting data for BaseCollection Datasets (#8093)
* First draft of the solution

* Fix bugs

* Fix bugs

* Fix another overloaded method

* Add new unit test

* Address requested changes

* Address requested changes

* Minor tweaks

---------

Co-authored-by: Martin Molinero <martin.molinero1@gmail.com>
2024-06-27 15:57:25 -03:00
Jhonathan Abreu
6392b5eed0 Minor changes in BaseSetupHandler. (#8112)
Making it able to update currency conversions for specific currencies.
2024-06-26 18:06:26 -03:00
Ricardo Andrés Marino Rojas
ba2d519910 Remove warnings from csproj files (#8108)
* Remove warnings from csproj files

* Leave just 2 warnings

* Nit change

* Leave just 2 warnings
2024-06-26 17:07:51 -03:00
Martin-Molinero
c8446ae26e Refactor AutomaticIndicatorWarmUp settings (#8111)
- Move EnableAutomaticIndicatorWarmUp as an algorithm setting named AutomaticIndicatorWarmUp
2024-06-26 17:02:48 -03:00
Roman Yavnikov
8a34d4a7a3 Refactor: Cross Zero Order event (#8110)
* refactor: reuse OrderEvent
test:refactor: CrossZeroOrder proccess Status update

* clean: extra paddings
2024-06-26 15:06:04 -03:00
Ricardo Andrés Marino Rojas
57f89620a1 Fix warnings part 6 (#8107)
* Fix half of the XML docs missing warnings

* Remove warnings from csproj files
2024-06-26 13:21:53 -03:00
Martin Molinero
47acbd66a2 Revert test breaking change 2024-06-26 10:18:35 -03:00
Ricardo Andrés Marino Rojas
56d36b97d5 Fix warnings part 5 (#8105)
* Add algorithm unit tests

* Add Brokerage unit tests

* Add Common unit tests

* Fix unit test bugs

* Add remaining unit tests

* Address requested changes

* Address requested changes

* Fix failing unit test

* Address requested changes
2024-06-26 10:11:36 -03:00
Roman Yavnikov
a8b106ae3e Feat: Brokerage Cross Position Order (#8051)
* feat: TryCrossPositionOrder
feat: helper methods to CrossPosition

* refactor: get rid CrossOrder +UTests

* feat: test simulator of cross zero orders request

* remove: callback from TryCrossPositionOrder
rename: TryCrossPositionOrder -> TryCrossZeroPositionOrder
feat: handle event of CrossZeroOrder
feat: new prop in CrossZeroOrderRequest
test:feat: write working test imitate of CrossZeroOrdering and assert different params

* feat: temp collection to keep CrossZeroOrder with Lean

* refactor: flag which indicate should we place crossZero order with LeanEvent or not

* refactor: change access modifier

* fix: CrossZero tests

* refactor: property collection instead of variable

* feat: lock context of CrossZeroOrder
feat: helper method for CrossZeroCollection

* refactor: test of cross brokerage ordering

* refactor: CrossZero Brokerage

* fix: lock area

* feat: Update CrossZero Ordering
refactor: CrossZeroOrders tests

* feat: additional test case for CrossZeroOrdering

* feat: Invalid OrderStatus when FirstPart of CrossZero ordering try to place
feat: message property in CrossZeroOrderResponse
refactor: CrossBrokerageTest a little bit

* feat: PossibleUpdateCrossZeroOrder

* refactor: UpdateCrossZeroOrder

* refactor: TimeOut for resetEvent

* refactor: crossZeroOrder change DateTime UtcNow on specific time
refactor: change action scenario for Filled FirstPart of CrossZeroOrder

* refactor: change firstPartQuantityproperty to link of FirstPartOfCrossZero order completely
fix: crossZeroOrder test put orderStatus internally

* feat: additional orderType in CrossZeroOrder tests

* test:remove: not use GetOrderCrossesZero()

* refactor: extra paddings

* rename: TryGetUpdateCrossZeroOrderQuantity instead of IsPossibleUpdateCrossZeroOrder

* refactor: CrossZeroOrder process and models

* remove: interface ICrossZeroOrderRequest

* feat: TradeStation NotSupportUpdate of CrossZeroOrder quantity

* feat: add license
remove: extra validation of variable

* refactor: add validation of quantity update in TradeStationBrokerageModel

* test:feat: canUpdate of TradeStationOrder

* refactor: reuse OrderEvent when we handle FirstPartCrossZeroOrder

* remove: assignment of filled quantity of FirstPartCrossZeroOrder
2024-06-26 10:06:25 -03:00
Jhonathan Abreu
8bd046a6b8 Add support for FTP notifications (#8097)
* Add support for FTP notifications

* Add optional parameters for SFTP notifications with private key

* Add optional "secure" parameter for FTP notifications.

Improve FTP notifications constructor and input checks.

* FTP notification improvements.

Add public key property.
Add multiple constructors and methods for FTP and SFTP notifications with either password or SSH keys.
Encode file contents.

* Address peer review

Add support for FTP notification with string contents

* Minor changes

* Minor changes

* Remove public key argument

* Fixes and minor changes
2024-06-26 10:03:35 -03:00
Alexandre Catarino
9e2b697792 Fixes AwesomeOscillator Helper Order Of Parameters (#8099)
The second and third parameter are `fastPeriod` and `slowPeriod`, but we had `slowPeriod` and `fastPeriod`, which is inconsistent with the class contructor and other indicators with `fastPeriod` and `slowPeriod` parameters.
2024-06-25 17:33:19 -03:00
Ricardo Andrés Marino Rojas
5699fa48fd Fix 4/4 of CA2201 warnings (#8103)
* Fix 4/4 of CA2201

* Remove warnings
2024-06-25 11:13:32 -03:00
Ricardo Andrés Marino Rojas
aa5ab68b47 Fix 3/4 of CA2201 warnings (#8102)
* Fix 2/4 of CA2201 Warnings

* Fix 3/4 of CA2201 warnings
2024-06-24 19:31:23 -03:00
Ricardo Andrés Marino Rojas
f8b169aa51 Fix 2/4 of CA2201 Warnings (#8101) 2024-06-24 17:00:38 -03:00
Ricardo Andrés Marino Rojas
b41df5b0f2 1/4 of the changes of RegressionTestException (#8100) 2024-06-24 15:23:33 -03:00
Jhonathan Abreu
5432c7c6d8 Fix dynamic SPDB unit tests taking too long (#8094)
* Fix dynamic SPDB unit tests taking too long

* Minor improvements in unit tests

* Minor improvements in unit tests

* Cleanup
2024-06-24 14:36:04 -03:00
Ricardo Andrés Marino Rojas
8c33536498 Add algorithm status statistic (#8095)
* First draft of the solution

* Fix bugs

* Fix bugs
2024-06-24 14:19:32 -03:00
Jhonathan Abreu
f0d02feb13 Rename AlgorithmSettings.DailyStrictEndTimeEnabled (#8098)
* Rename AlgorithmSettings.DailyStrictEndTimeEnabled  to DailyPreciseEndTime

* Minor fix
2024-06-24 14:10:11 -03:00
Ricardo Andrés Marino Rojas
0e0e6bd142 Add Tests for MaximumDrawdownPercentPortfolio (#8096)
* First draft of the solution

* Add more unit tests
2024-06-24 13:14:21 -03:00
Jhonathan Abreu
8424e85ade Reduce test files size (#8084) 2024-06-24 13:03:43 -03:00
Jhonathan Abreu
a159950117 Fix: refresh symbol properties using right type for security. (#8087)
Fix for live trading SPDB refresh
2024-06-11 13:50:33 -04:00
Ricardo Andrés Marino Rojas
4ca5cbca7e Add Yearly Date Rule (#8075)
* First draft of the solution

* Add improvements

* Nit changes

* Address requested changes
2024-06-07 15:48:53 -03:00
Jhonathan Abreu
6b963c735c Make SPDB dynamic with periodic updates (#8083)
* Dynamic spdb

* Minor changes and unit test

* Get MHDB and SPDB refresh period from config

* Add databases refresh period to algorithm settings

* Address peer review and add unit test
2024-06-07 15:48:27 -03:00
Ricardo Andrés Marino Rojas
62373ede5b Duplicate Futures.Energies (#8082)
* Duplicate Futures.Energies

* Nit change

* Add unit test
2024-06-06 19:39:05 -03:00
Martin-Molinero
7975a44d1c Revert "Duplicate "Energies" Futures Ticker Shortcut to Energy (#8067)" (#8081)
This reverts commit 23057f24c8.
2024-06-06 15:02:03 -03:00
Ricardo Andrés Marino Rojas
2823155311 Partial fix for bug (#8079) 2024-06-06 13:06:39 -03:00
Martin-Molinero
5f58254839 Minor improvement for python custom default brokerage message handlers (#8078) 2024-06-05 13:22:34 -03:00
Martin-Molinero
e78150aced Fix for custom streaming data live trading (#8077)
- Minor fix for custom streaming data in live trading. Adding unit test
  reproducing issue
2024-06-05 11:51:43 -03:00
Martin-Molinero
9ace77fb87 Fix consolidator scan determinism (#8074)
- Make sure we can scan consolidators deterministically. Adding
  regression algorithm reproduce reported issue
2024-06-04 11:59:09 -03:00
Martin-Molinero
1a3fedb36d Foundation library update (#8069)
* Foundation update

* Minor fixes
2024-06-04 11:57:04 -03:00
Ricardo Andrés Marino Rojas
23057f24c8 Duplicate "Energies" Futures Ticker Shortcut to Energy (#8067)
* First draft of the solution

* Add backwards compatibility

* Address requested changes
2024-06-04 11:52:58 -03:00
Martin-Molinero
529b24ed1b Live Collection unfolding data will skip old data (#8070)
- Minor tweak for live collection unfolding data will skip old data.
  Adding unit test
2024-06-04 11:52:33 -03:00
Louis Szeto
39bfbccd44 Add Protective Collar to Option Strategies (#8025)
* Add Protective Collar Option Strategy

* Add buying power model for Protective Collar

* Add unit test for Protective Collar

* Add regression test for Protective Collar

* Add unit test on position group buying power

* allow same strike for later abstraction

* minor bug fix

* Set up conversion option strategy

* add margin requirement

* add unit tests

* Add regression test

* add reverse conversion definition

* add reverse conversion and refactor conversion/collar margin model

* added/modified unit tests for conversion/reverse conversion

* minor bug fix on unit test, add regression test

* Address peer review

* update new set of IB testing data
2024-06-03 12:38:52 -03:00
Martin-Molinero
ab24ac4ac8 By default reject brokerage side created orders (#8066) 2024-05-31 14:36:17 -03:00
Martin-Molinero
250ba842ba Minor tweak for split (#8068) 2024-05-31 14:35:50 -03:00
Louis Szeto
79a8c66b39 Box Spread Option Strategy (#8041)
* Add box spread definition

* Add box spread margin model

* Add unit tests

* Add regression tests

* minor nit peer review
2024-05-30 11:41:20 -03:00
Ricardo Andrés Marino Rojas
d76c2bfc7d Add FuncTimeRule and FuncDateRule constructors for PyObject (#8061)
* Initial draft of the solution

* Add more unit tests
2024-05-28 17:35:02 -03:00
Martin-Molinero
158df4434c Update readme.md 2024-05-28 15:57:25 -03:00
Martin-Molinero
88d7380a53 Use SPY as default dividend yield for Index/Future greeks (#8056)
- Index and FOPs will use SPY as the default dividend providers, adding regression algorithms for them
2024-05-28 15:48:21 -03:00
Ricardo Andrés Marino Rojas
0f785372f6 Add unit test (#8060) 2024-05-28 15:39:35 -03:00
Martin-Molinero
0acfdbb9e5 Update readme.md 2024-05-28 10:10:15 -03:00
Jhonathan Abreu
40cfcfc336 Fix: Insight constructors not setting correct values (#8058) 2024-05-24 19:02:59 -03:00
Martin-Molinero
9c1824cccf Enhance GetFilePath subdirectory handling (#8057)
- GetFilePath will create subdirectories assuming the last piece of the
  requested path is a leaf. Expanding unit tests
2024-05-24 18:27:57 -03:00
Jhonathan Abreu
f0286c936d Fix: allow non-standard header values in Api.Download API (#8055) 2024-05-24 18:07:23 -03:00
Martin-Molinero
c87693d883 Update readme.md 2024-05-24 15:44:37 -03:00
Jhonathan Abreu
b6e35468db Update pythonnet to 2.0.38 (#8052) 2024-05-24 14:38:53 -04:00
Martin-Molinero
bb675bdddb Improve DQH handling of exceptions (#8054)
- Improve DataQueueHandlerManager handling of exceptions in the used
  data queue handlers. Adding unit tests
2024-05-24 15:29:14 -03:00
Martin-Molinero
d3b5bbaa1b Avoid duplicate data on FF resolution change (#8053) 2024-05-24 11:58:27 -03:00
Martin-Molinero
3a99e0b47c Fix fill forward resolution adjustment on removal (#8049)
* Fix fill forward resolution adjustment on removal

- Fix fill forward resolution adjustment on subscription removal. Adding
  regression algorithm reproducing issue

* Minor fix for undeterminism behavior on security removals and FF res change

* Further improvements and determinism

- Improve regression algorithm add, remove and readd future, asserting
  FF resolution changes
- Adjust universe selection to be deterministic and avoid unnecessary
  FF resolution changes
2024-05-24 10:15:26 -03:00
Martin-Molinero
5f3cd203d3 Fix for live FF enumerator (#8047)
- Adjust live FF enumerator to rely on the base FF enumerator logic and
  just filter out results based on the frontier. Adding unit tests
2024-05-22 13:39:52 -03:00
Martin-Molinero
2c6074bfdb Limit 'forward only indicator' error log (#8046) 2024-05-21 19:15:53 -03:00
Ricardo Andrés Marino Rojas
ad663ded2c Fix bug in FrontMonth() option filter (#8044)
* First draft of the solution

* Nit changes

* Fix bugs

* Nit changes

* More nit changes
2024-05-20 20:04:31 -03:00
Roman Yavnikov
fe2110de96 Feature: Implementation Trade Station Brokerage (#8031)
* refactor: make public futuresMonth Collection

* feat: TradeStation brokerage

* feat: PositionSide for Option in TradeStationOrderProperties

* feat: missed market TradeStation name

* feat: missed config TradeStation

* remove: extra TradeStation code

* remove: pragrma warning

* feat: implement TradeStationFeeModel
2024-05-20 17:58:44 -03:00
Martin-Molinero
549979f84b Update readme.md 2024-05-20 17:32:58 -03:00
Martin-Molinero
d4e7f584f6 Daily data time adjustment (#8001)
* Daily data Time & EndTime Improvement

- Adjust daily data Time & EndTime to actually reflect the time of the
  data used, for example US Equity from 9.30 to 4PM. Adding new unit and
  regression tests

* Refactor solution to use enumerator

- Refactor daily strict end times solution to be through enumerator
  usage, so it applies for history providers too

* Minor fixes

* Revert fill forward enumerator change

- Revert FillForward enumerator causing stats changing, enhancing unit
  tests

* Some cleanup

* Improve handling of live trading FF enumerator

- Improve handling of live trading FF enumerator, by adding support for
  bars to arrive with a delay so we can handle auction close/option
  prices or data providers which might have some delay making the data
  available. Adding new unit tests asserting the behavior
2024-05-20 17:28:03 -03:00
Ricardo Andrés Marino Rojas
c30ea9d293 Handle order types with unsupported security types in IB Brokerage Model (#8029)
* HandleUnsupportedOrderTypesForSecuritiesInIB

* Nit changes

* Nit changes
2024-05-15 22:56:05 +01:00
Jhonathan Abreu
56cfc51f10 Round combo order prices (#8024)
* Round combo order prices

* Combo limit order round fix: use smallest security min price variation

* Minor unit test change

* Improvements and unit tests

* Minor change

* Cleanup
2024-05-15 14:57:30 -04:00
Ricardo Andrés Marino Rojas
cc3c97a814 Improve exception message when generating Annual Performance Statistic (#8022)
* Improve exception message

* Nit changes
2024-05-15 11:45:12 -03:00
Jhonathan Abreu
c82573a2bc Update Pythonnet version (#8021)
* Update regression algorithm to reproduce GH issue #8011

* Update pythonnet version to 2.0.37
2024-05-15 09:11:52 -04:00
Ricardo Andrés Marino Rojas
b147c7ccfd Api Clean up, Documentation and Standarization part five (#8016)
* Update endpoints and add tests

* Remove JsonProperty tags

* Enhance unit tests

* Add live/insights/read/response

* Add missing class

* Remove old insights property

* Improve read live insights unit test

* Nit change

* Fix failing unit tests

* Revert "Fix failing unit tests"

This reverts commit a2b7c1d34e.

* Add Insights.Ticker back

* Nit change

* Address requested changes
2024-05-13 18:14:40 -03:00
Alexandre Catarino
ddea4ec380 Fix Summary for CancelPending (#8020) 2024-05-13 18:09:55 -03:00
Martin-Molinero
1c32144963 Some refactor and cleanup (#8014)
* Some refactor and cleanup

- Some refactor and cleanups
- Improve live trading CI tests speed

* Minor tweak for live trading data feed log
2024-05-10 12:27:00 -03:00
Martin-Molinero
061d5a9971 Update SPX MHDB to match Options (#8013)
- Update the SPX index MHDB entry to match the spx index options, for
  daily resolution selection support
2024-05-10 11:46:29 -03:00
Jhonathan Abreu
7e7fd4d791 Skip security initializer for benchmark security (#8012) 2024-05-09 18:09:34 -04:00
Jhonathan Abreu
b079d32522 Bug python type comparison (#8008)
* Reapply "Python consolidator removal directly from Python (#7995)" (#8006)

This reverts commit f5f2da3f96.

* Reapply "Fix: interface property implementation in python models (#7987)" (#8007)

This reverts commit 356b51f150.

* Fix: PyObject.TryConvert compares c# and py type by reference
2024-05-09 13:20:44 -04:00
Jhonathan Abreu
28baf03250 Improve PythonException stack trace parser (#8002)
* Improve PythonException stack trace parser

* Minor fix

* Minor improvements
2024-05-09 13:20:20 -04:00
Martin-Molinero
356b51f150 Revert "Fix: interface property implementation in python models (#7987)" (#8007)
This reverts commit ab40b5c0b6.
2024-05-09 10:06:07 -03:00
Martin-Molinero
f5f2da3f96 Revert "Python consolidator removal directly from Python (#7995)" (#8006)
This reverts commit bac3ec09b6.
2024-05-09 10:05:37 -03:00
Martin-Molinero
53fb9942d2 Minor optimization parameter json fix (#8005) 2024-05-08 20:05:47 -03:00
Martin-Molinero
e96e2d26a7 Update readme.md 2024-05-08 19:03:59 -03:00
Martin-Molinero
c13643f3ac Minor camelcase tweaks (#8004) 2024-05-08 18:08:57 -03:00
Martin-Molinero
6915a65900 Further camel case cleanup (#8003) 2024-05-08 17:28:47 -03:00
Martin-Molinero
d40ec77379 Refactor to use camel case (#7981)
* Camel case results

- Camel case lean results and streamed packets

* Update packets to camel case
2024-05-08 12:58:33 -03:00
Louis Szeto
bb7a7f26a7 Bug fix on Option Indicator calculation (#7999)
* Handle expired options

* unit test

* Move Zero Checks to Single Location

---------

Co-authored-by: Alexandre Catarino <AlexCatarino@users.noreply.github.com>
2024-05-07 14:03:29 -03:00
Jhonathan Abreu
520e6046ac Update vsdbg version to be supported in the base ubuntu (#8000) 2024-05-07 09:31:51 -04:00
Ricardo Andrés Marino Rojas
a1b6277492 Api Clean up, Documentation and Standarization part four (#7989)
* Update C# response classes for optimization endpoints

* fix bugs

* Fix bugs

* Fix bug

* More tests, API response classes and updates

* Partially revert wrong changes

* Missing file

* Improve unit tests and solve bugs

* Improve implementation

* Minor tweak

---------

Co-authored-by: Martin Molinero <martin.molinero1@gmail.com>
2024-05-06 20:33:31 -03:00
Jhonathan Abreu
bac3ec09b6 Python consolidator removal directly from Python (#7995)
* Fix: python consolidator reference lost when wrapped

* Make BasePythonWrapper equatable depending on the PyObject underlying reference

* Fix: TryConvert PyObject instances for generic C# types

* Minor unit tests fixes

* Address peer review and add unit tests
2024-05-06 14:44:04 -04:00
Derek Melchin
d6ff16f9da Add new crisis events (#7991)
* Add new crisis events

* Add new enum values
2024-05-06 14:44:07 -03:00
Roman Yavnikov
9fad556903 Remove: log ETA calculation (#7994)
* remove: ETA in data download provider

* remove: log of ETA calculation

* remove: test with ETA downloader
2024-05-03 14:25:10 -03:00
Jhonathan Abreu
021e507ef0 Holdings price adjustment after split (#7985)
* Fix: properly adjust prices after a split

* Minor fixes

* Minor: Adjust cached data on split

* Minor change

* Expand regression algorithms assertions
2024-05-01 17:42:43 -04:00
Jhonathan Abreu
ab40b5c0b6 Fix: interface property implementation in python models (#7987) 2024-05-01 13:58:02 -03:00
Roman Yavnikov
ef23d7b6fe Add Group Symbol and Total Time Execution Logging for Downloading Canonical Data (#7984)
* refactor: modifier static to parse enum and ignore warning

* feat: group symbol when download cannonicial data
feat: log total time execution of download provider
test: right keeping of cannonicial data

* feat: parameter ctor in DataDownloadConfig

* test:feat: additional assertion of wrote data in file

* feat: static FilterGroupDownloadDataBySymbol

* refactor: extract downloader folder path

* try: map file false

* feat: get rid of dataCacheProvider in DownloaderDataProvider

* refactor: get rid mapFile flag

* CI test fix

---------

Co-authored-by: Martin Molinero <martin.molinero1@gmail.com>
2024-05-01 13:39:34 -03:00
Ricardo Andrés Marino Rojas
17ba9f8b5d Api Clean up, Documentation and Standarization part three (#7982)
* Updates to data/prices C# response

* Update data, account and organization API responses

* remove unnecessary changes
2024-04-29 20:35:51 -03:00
Martin-Molinero
b527a3dd86 Minor fixes (#7980)
- Minor test improvement
- Adjust DownloaderDataProvider to follow the pattern
2024-04-26 14:37:47 -03:00
Ricardo Andrés Marino Rojas
cce8945fe8 Api Clean up, Documentation and Standarization part two (#7964)
* Add improvements

* Add improvments and unit tests

* Add XML comments

* Nit changes

* Add unit tests for OrderJsonConverter

* Improve unit tests

* Address requested changes

* Fix bugs

* Fix bugs

* Fix bugs and self-review

* Fix bugs

* Address requested changes

* Fix unit test bug

* Fix bugs

* Improve unit tests

* Solve bugs
2024-04-26 13:17:34 -03:00
Jhonathan Abreu
9755f8c916 Sourcing remote zipped custom data (#7976)
* Fix: source custom data from remote CSV zipped file

* Fix: Custom data sourcing zip entry names from remote locations

* Address peer review

* Add unit tests

* Minor fix

* Address peer review

* Minor fixes

* Return byte array in IApi.DownloadBytes

* Allow sourcing custom data from specific csv entry in a zipped remote file

* Minor change
2024-04-26 12:15:01 -04:00
Martin-Molinero
2ac435b117 Minor Config.Write Improvement (#7978) 2024-04-25 19:54:11 -03:00
Roman Yavnikov
74d95f1611 Implement Download Project in Lean (#7975)
* feat: init Download proj

* feat: update docker file to copy download proj

* feat: parsing in cmd arguments

* feat: DataDownloadConfig model
feat: add config file
refactor: logic of parsing config

* feat: overrid ToString in DataDownloaderGetParameters

* remove: not used argument command

* feat: calculate downloading % (without ETA time)

* fix: dockfile copy path for DownloaderDataProvider proj

* feat: additional Property in .csproj

* remove: DataProviderFullName prop from DataDownloadConfig

* remove: extra package (ref from Configuration proj)

* feat: ETA calculation of downloading data

* Minor tweak

* rename: namespace of downloaderDataProvider to generic style format

* test: ETA from DownloaderDataProvider

* fix: calculate ETA like real downloading process

---------

Co-authored-by: Martin Molinero <martin.molinero1@gmail.com>
2024-04-25 19:53:58 -03:00
Jhonathan Abreu
55b056588d Fix option assignment not processed because of existing open order (#7974)
* Fix: option assignment not processed because of existing open order

* Minor change

* Fix unit test
2024-04-24 10:42:41 -04:00
Martin-Molinero
6d9609799a Calling CSharp releases the GIL (#7970)
- Make sure calling CSharp methods, fields, properties releases the GIL,
  this was not hapenning for fiels & properties, adding unit test
  reproducing the issue
2024-04-23 12:46:50 -03:00
Martin-Molinero
8d2ced945b Minor fundamental properties typos (#7971) 2024-04-23 11:48:20 -03:00
Jhonathan Abreu
b8e49a94ad Python models conversion to PEP8 (#7969)
* Python models conversion to PEP8

* Python models conversion to PEP8

* Minor fix
2024-04-23 10:45:36 -04:00
Martin-Molinero
efd90f7ed9 Fundamental pep8 typos ValuationRatios (#7967) 2024-04-22 16:49:07 -03:00
Martin-Molinero
bec6faef9a CashFlowFromInvestingGrowth & CashFlowFromFinancingGrowth Typos (#7966) 2024-04-22 14:18:22 -03:00
Jhonathan Abreu
6bfe45dbcf PEP8 algorithms conversion (#7962)
* PEP8 algorithms conversion

* PEP8 unit tests algorithms conversion

* Minor fixes
2024-04-22 13:59:50 -03:00
Martin-Molinero
8fa824b19e Rename DebttoAssets to DebtToAssets (#7961) 2024-04-22 12:14:44 -03:00
Martin-Molinero
3e4ad661e2 Update readme.md 2024-04-19 19:41:29 -03:00
Louis Szeto
fa886eba79 pep8 conversion of python algos #12 (#7954)
* pep8 conversion

* PEP8 updates/fixes

* Update pythonnet version to 2.0.35

---------

Co-authored-by: Jhonathan Abreu <jdabreu25@gmail.com>
2024-04-19 16:55:48 -04:00
Ashutosh
b64ad5f68a pep8 conversion of python algos (#7957) 2024-04-19 17:24:37 -03:00
Louis Szeto
08a3de9e2d pep8 conversion of python algos #13 (#7955)
* t status
pep8 conversion

* Minor tweaks and rebase

* Various minor fixes

---------

Co-authored-by: Martin Molinero <martin.molinero1@gmail.com>
2024-04-19 16:14:12 -03:00
Louis Szeto
d2669fb0c2 pep8 conversion of python alphas and benchmark algos (#7956)
* pep8 conversion of alphas

* pep8 conversion of benchmarks

* Various fixes and rebase

---------

Co-authored-by: Martin Molinero <martin.molinero1@gmail.com>
2024-04-19 14:50:59 -03:00
Louis Szeto
279a7ef235 pep8 conversion on python algos #10 (#7951)
* pep8 conversion

* PEP8 updates/fixes

---------

Co-authored-by: Jhonathan Abreu <jdabreu25@gmail.com>
2024-04-19 12:59:02 -03:00
Louis Szeto
979bd9baef pep8 conversion of python algos #11 (#7952)
* pep8 conversion

* Minor tweak

---------

Co-authored-by: Martin Molinero <martin.molinero1@gmail.com>
2024-04-19 12:54:50 -03:00
Ashutosh
3c30e255fe pep8 conversion of python algos (#7948)
* pep8 conversion of python algos

* adding 10 more pep8 converted algos

* PEP8 updates/fixes

---------

Co-authored-by: Jhonathan Abreu <jdabreu25@gmail.com>
2024-04-19 10:06:48 -04:00
Jhonathan Abreu
77591f90c7 PEP8 python algorithms conversion (#7950)
* PEP8 python algorithms conversion

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

* Convert portfolio models to PEP8
2024-04-18 19:43:48 -03:00
Alexandre Catarino
d1796bd77e Copies RiskParityPortfolioOptimizer to Output Directory (#7949) 2024-04-18 19:19:19 -03:00
Louis Szeto
4a1f30bd96 pep8 conversion of python #7 (#7945)
* pep8 conversion

* PEP8 updates/fixes

---------

Co-authored-by: Jhonathan Abreu <jdabreu25@gmail.com>
2024-04-18 16:12:36 -03:00
Louis Szeto
7e5b8d6243 pep8 conversion of python algo #8 (#7946)
* pep8 conversion

* Minor tweaks

---------

Co-authored-by: Martin Molinero <martin.molinero1@gmail.com>
2024-04-18 16:08:34 -03:00
Louis Szeto
e8362c12a3 pep8 conversion (#7947) 2024-04-18 16:04:22 -03:00
Louis Szeto
c2ad893f32 pep8 conversion of python algos #5 (#7943)
* pep8 conversion

* Fix: detect python object of python classes derived from c# classes

* Minor PEP8 updates/fixes

---------

Co-authored-by: Jhonathan Abreu <jdabreu25@gmail.com>
2024-04-18 15:53:32 -03:00
Louis Szeto
5eb236834f pep8 conversions of python algos, #6 (#7944)
* pep8 conversions

* Address review. Fix PythonIndicator

* Minor CSharp algo fix

---------

Co-authored-by: Martin Molinero <martin.molinero1@gmail.com>
2024-04-18 15:15:18 -03:00
Ashutosh
1cae47ab25 pep8 conversion of python algos (#7942)
* pep8 conversion of python algos

* adding 10 more pep8 converted algos
2024-04-18 15:14:56 -03:00
Louis Szeto
ed351c8726 pep8 conversion of python algorithms #3 (#7934)
* raw pep8 conversion

* Minor fixes

---------

Co-authored-by: Martin Molinero <martin.molinero1@gmail.com>
2024-04-17 19:28:04 -03:00
Louis Szeto
6d5f5dce58 pep8 conversion of python algorithms #4 (#7935)
* pep8 conversion

* PEP8 updates/fixes

* Minor update

---------

Co-authored-by: Jhonathan Abreu <jdabreu25@gmail.com>
2024-04-17 19:27:00 -03:00
Ashutosh
c97c7a3317 pep8 conversion of python algos (#7938)
* pep8 conversion of python algos

* Minor tweak

---------

Co-authored-by: Martin Molinero <martin.molinero1@gmail.com>
2024-04-17 19:23:54 -03:00
Louis Szeto
ed7f3ebbbf pep8 conversion of python algos #1-25 (#7926)
* pep8 conversion of python algos

* address peer-review

* PEP8 updates/fixes

* More fixes

---------

Co-authored-by: Jhonathan Abreu <jdabreu25@gmail.com>
2024-04-17 17:02:32 -04:00
Louis Szeto
784e497691 pep8 conversion on python algorithms #2 (#7933)
* pep8 conversion

* more

* Minor fix

* Fix related regression algorithm

---------

Co-authored-by: Martin Molinero <martin.molinero1@gmail.com>
2024-04-17 17:36:53 -03:00
Kristiyan Michaylov
c2bea3c173 Feature 1076 implementing an indicator derivative oscillator (#7884)
* Initial boilerplate code

* Fix build failure

* Initial iteration for the code for Derivative Oscillator code

* Add foundation for unit tests

* Add reset method for test

* Add test case

* fixed test cases, all tests pass

* Put placeholder for IsReady change

Not implemented, as test cases fail when change is uncommented

* Update documentation and change class name

* Change names for Derivative Oscillator to more meaningful

* Add DO extension to create the indicator

* Provide variable definitions with var, replace old test file with new

* Use chaining for indicators creation

* Add test based on external data

* Change test file

* Fix WarmUp test + alphabetical order + rename indicator class

* Make all tests run except for external data tests

* Fixed warmup period and fixed the ResetsProperly test case

* Removed unused directives

* Add output directory for Derivative Oscillator test

* Minor tweaks

---------

Co-authored-by: HaentjeGH <l.m.j.haenen@student.tue.nl>
Co-authored-by: ivkozlov <ivkozlov@ozon.ru>
Co-authored-by: DanielVanRijswijk <d.j.v.Rijswijk@student.tue.nl>
Co-authored-by: Martin Molinero <martin.molinero1@gmail.com>
2024-04-17 16:34:57 -03:00
Martin-Molinero
b1a2f8f06c Bybit SPDB update (#7940)
- Bybit SPDB update
2024-04-17 16:06:31 -03:00
oussamanahdi
a83809c122 Update readme.md (#7939)
Fixed logo link
2024-04-17 15:21:05 -03:00
Jhonathan Abreu
17ba1088bd Pythonnet PEP8 fixes (#7931)
* Improve python exception message for cases when derived class uses member names already defined in base C# classes

* Update pythonnet version to 2.0.33

* Update error message

* Pythonnet version bump to 2.0.34. Minor unit test fix

* Enhance pythonnet overload tests

---------

Co-authored-by: Jared <jaredbroad@gmail.com>
Co-authored-by: Martin Molinero <martin.molinero1@gmail.com>
2024-04-17 14:25:25 -03:00
oussamanahdi
3da1afb2fe Update readme.md (#7937)
dark/light mode algoseek logo / link to https://www.algoseek.com/lean.html
2024-04-17 14:23:06 -03:00
Martin-Molinero
dfbe85ca85 PythonData Pep8 Support (#7936)
- Improve PythonData to support pep8 method names if available. Adding
  unit tests
2024-04-17 13:29:14 -03:00
Martin-Molinero
38c90d5a98 Fix CurrentSlice python wrapper (#7932)
- Fix algorithm current slice, to be a python slice wrapper. Updating
  regression algorithmst status
2024-04-16 18:38:53 -03:00
Jared
318701964c Update readme.md (#7927) 2024-04-16 17:34:49 -03:00
Jhonathan Abreu
93bc7a9dc1 Update pythonnet version to 2.0.32 (#7923) 2024-04-15 19:48:54 -03:00
Martin-Molinero
4e39100fa9 Pep8 Python Base Selection Models Update (#7920)
* Pep8 Python Selection Models Update

- Update python selection models to pep 8, keeping backwards
  compatibility support

* Address reviews, further pep8 renames
2024-04-15 19:22:20 -03:00
Martin-Molinero
0e58c4c694 Adjust GoodTilDate Pep8 (#7921)
- Pep8 adjustment for GoodTilDate, so it behaves like `Expiry` static
  readonly funcs which will be binded to both snake case and upper
  constant format, `good_til_date` & `GOOD_TIL_DATE`
2024-04-15 19:02:59 -03:00
Martin-Molinero
2ff13ea8fc Remove unrequired, unused universe DQH call (#7914)
- Remove unrequired, unused DQH subscription call to universe
  subscription
2024-04-15 13:50:30 -03:00
Martin-Molinero
dc1748f4ae Fix composer deadlock (#7917)
- Fix deadlock in composer creating a type like IBDownloader which gets
  the map file provider instance using the composer
2024-04-15 12:32:53 -03:00
Martin-Molinero
e06931c423 Make MorningStart codes readonly (#7919) 2024-04-15 12:32:41 -03:00
Martin-Molinero
f25029b0fe Update readme.md 2024-04-12 17:30:46 -03:00
Jhonathan Abreu
2ddf40b8e9 PEP8 style algorithm API (#7909)
* feat: support snake-case style Python QCAlgorithm implementations

* feat: add unit tests and minor fixes

* feat: implement new BasePythonWrapper class for python wrappers.

Used to cache methods and contains invoke functionality

* feat: make python wrappers implement the new base class for pep8 style support

* feat: keep overriden methods in Algorithm Python Wrapper

* feat: add unit tests for custom models algorithms with PEP8 style

* Bump pythonnet version to 2.0.30

* fix bugs and address peer review

* Address peer review

* Minor revert

* feat: StubsIgnoreAttribute for ignoring members or classes by the stubs generator

* Minor fixes

* Minor fix

* Minor fix

* Bump pythonnet version to 2.0.31

* Added Greeks.Lambda_ alias of Lambda for python compatibility.

Remove unused method
2024-04-12 17:29:15 -03:00
Martin-Molinero
90f09a1d60 Add TerminalLink Execution Instruction (#7916)
- Add optional TerminalLink execution instruction order properties
2024-04-12 15:10:12 -03:00
Ashutosh
94d33a50c4 Correction: Mapping tickSize to minimum_price_variation (#7910)
* Update symbol-properties-database.csv

* Update symbol-properties-database.csv
2024-04-11 12:37:25 -03:00
Martin-Molinero
bf741a155f Minor tweak for Live Synchronizer (#7912) 2024-04-11 10:43:41 -03:00
Martin-Molinero
c42cc841b2 Adjust API project file to accept a nullable id (#7911) 2024-04-10 15:19:38 -03:00
Martin-Molinero
fa9f10bebf Add support for auxiliary data history request (#7906)
* Add support for auxiliary data history request

- Add support for split/dividends/margin interest history requests.
  Adding regression algorithms

* Expand auxiliary history regression tests
2024-04-10 12:59:32 -03:00
Ricardo Andrés Marino Rojas
dc02ac7c84 API Clean Up, Documentation, Standardization (#7893)
* First draft of the update

* Add improvements

* Nit changes

* Add improvements

* Add improvements

* Remove unnecessary files

* Improve unit tests

* Add missing file

* Add new unit tests to CI

* Fix bug

* Fix unit tests

* Address changes

* Nit changes

* Nit changes

* Add fix for list backtest response

* Nit change

* Add changes in ListBacktest

* Fix failing unit test

* Improve API.GetObjectStore method

* Improve Api.GetObjectStore()

* Add C# models for object/get and object/properties

* Improve API methods and tests for object store

* Nit changes

* Nit change
2024-04-10 10:53:05 -03:00
Martin-Molinero
d238a8132e Python fundamental history request fix (#7905)
- Fix python fundamental pandas history request, where properties
  wouldn't change due to cache. Expanding regression test to assert
  issue
2024-04-09 09:55:20 -03:00
Martin-Molinero
7f7011edc0 Minor TZ fix for Scheduled Universe (#7903)
- By default Time rules yield times in UTC TZ, already correctly handled
  by 'ScheduledUniverseSelectionModel' but this wasn't fixed in ScheduledUniverse
2024-04-08 19:03:55 -03:00
Martin-Molinero
bb5c0eb54e Minor api improvements (#7901)
* Minor api improvements

- Adding Universe.Selected to hold the current set of selected symbols.
  Adding regression tests
- Adjusting TimeRules and DateRules to fallback to the MHDB if the
  security hasn't been added. Updating existing regression tests

* Expand regression test assertion
2024-04-05 17:43:25 -03:00
Jhonathan Abreu
314673534c Options/Index Options hour/daily resolution required data only download (#7898)
* fix: download year file data only for hour and daily resolutions for options and index options

* minor fix: index options regression tests expected status

* Minor change

* minor: update regression algorithms stats
2024-04-04 18:18:33 -03:00
Martin-Molinero
d24f665ee4 Adding new algorithm data handling options (#7897)
* Adding new algorithm data handling options

- Adding new QCAlgorithm data handling method options to override.
  Adding Py/C# regression tests
- Removing old OnData Type specific invoker methods

* Address reviews. Remove old OnData C# only methods
2024-04-04 15:38:50 -03:00
Martin-Molinero
3eec4a0090 Add example of scheduled universe selection with custom data (#7896)
- Add example of scheduled universe selection with custom data.
 See https://github.com/QuantConnect/Lean/pull/7895
2024-04-04 13:21:35 -03:00
Martin-Molinero
3aff0ce958 Add Scheduled Universe Selection (#7895)
* Add Scheduled Universe Selection

- Adding `UniverseSettings.Schedule` that will allow users to
specify a custom selection schedule which is independent of the
underlying data frequency
- Adding unit and regression tests

* Add live trading schedule time shift
2024-04-04 12:21:51 -03:00
Martin-Molinero
b65f253d42 Api read order and events handling (#7877)
- Adjust SerializedOrderEvent json format. Adding unit tests
- Removing unused SerializedOrder and it's converter
2024-04-02 18:56:05 -03:00
Martin-Molinero
529841ea77 Add labels to docker foundation files (#7890) 2024-04-02 16:36:08 -03:00
Jhonathan Abreu
6965dc9842 Option style parameter for parsing OSI option tickers (#7889)
* Get option style in OSI option ticker parsing method

* Keep previous SymbolRepresentation.ParseOptionTickerOSI overload

* Minor fix
2024-04-02 15:04:43 -03:00
Roman Yavnikov
0d430e2718 Revert: destination-dir param in Toolbox (#7885)
* revert: destination-dir param in Toolbox

* feat: test case on destination-dir param
2024-04-01 10:50:35 -03:00
Martin-Molinero
8bcd491fc3 Update readme.md 2024-03-28 16:33:13 -03:00
Ashutosh
f5cd9262b5 Added Forex CFD for IB (#7878) 2024-03-28 10:36:24 -03:00
Alexandre Catarino
f5db8788a0 Fixes Typo In Porfolio.Invested (#7876) 2024-03-27 15:44:53 -03:00
Martin-Molinero
0fa7f53539 Update blacklisted-tickers.txt (#7872) 2024-03-27 11:39:28 -03:00
Martin-Molinero
95000c5c29 Fix TF cuda support (#7874) 2024-03-26 17:51:57 -03:00
Martin Molinero
1120d7f050 Fix research CI expected output 2024-03-26 15:02:45 -03:00
Martin-Molinero
1cb262476d Minor python update related CI test fixes (#7873) 2024-03-26 14:42:07 -03:00
Martin Molinero
abadc543a4 Free space in GH CI 2024-03-26 14:06:37 -03:00
Martin-Molinero
9e04371f0b Update gh-actions.yml 2024-03-26 13:58:52 -03:00
Martin-Molinero
4eb16f3456 Update gh-actions.yml 2024-03-26 13:57:27 -03:00
Martin-Molinero
fe2420b9d4 Update readme.md 2024-03-26 13:09:04 -03:00
Martin-Molinero
78647d3a1d Update libraries and python 3.11 (#7856)
* Update python 3.11

* Update ARM foundation image and minor improvements
2024-03-26 12:57:56 -03:00
Jhonathan Abreu
78b49a1d11 Update InteractiveBrokers market symbols in SPDB (#7870)
* Update InteractiveBrokers market symbols in SPDB

* Update IB cfds in MHDB in SPDB

* Update IB index CFDs lot size
2024-03-26 10:44:16 -04:00
Roman Yavnikov
14f94923e1 Remove: old / not used part in ToolBox (#7871)
* remove: ref #6383

* remove: fxcm, ref #5505

* remove: not used pckg in ToolBox

* remove: fxcm downloader mention, ref #5505
2024-03-26 10:10:47 -03:00
Jhonathan Abreu
01eb907f98 Add CFD support for IB brokerage model (#7861)
* Support CFDs in IB

* Add new currency pair util method

* Minor changes to IB fee model and tests

* Add CFD USA market hours

* Add new Market interactivebrokers for cfds

* Add sample algorithm illustrating manually adding market hours to MHDB

* Update MHDB and SPDB
2024-03-25 16:58:17 -04:00
Roman Yavnikov
22dafee9c6 remove: IVolatilityEquity Converter (#7866) 2024-03-25 17:17:03 -03:00
Ricardo Andrés Marino Rojas
6259ee1d91 Remove BaseLiveAlgorithmSettings (#7862)
* Remove BaseLiveAlgorithmSettings

* Fix IB unit test

* Add Python unit test

* Add more unit tests
2024-03-25 15:54:06 -03:00
Ricardo Andrés Marino Rojas
ead2efe6b9 Add Starting and Ending KPI's (#7811)
* First draft of the solution

* Add missing changes

* Remove the new KPI's from report

* Fix bugs

* nit change

* Add improvements

* Fix regression tests

* Solve bugs in the regression algos

* Fix regression tests bugs

* Expand unit tests and add minor changes
2024-03-25 15:40:38 -03:00
Roman Yavnikov
ca99f329dd remove: Dukascopy Downloader (#7865) 2024-03-25 15:39:46 -03:00
Roman Yavnikov
3338c9a332 remove: CryptoIQ Downloader (#7867) 2024-03-25 11:10:10 -03:00
Roman Yavnikov
229caf485c remove: NseMarketDataConverter (#7863) 2024-03-25 11:08:19 -03:00
Roman Yavnikov
82b327b2b9 remove: Kraken Data Downloader from ToolBox (#7860) 2024-03-19 19:17:17 -03:00
Roman Yavnikov
aca30a896c Remove: Yahoo Data Downloader (#7859)
* remove: missed of QBDL PR:#6110

* remove: Yahoo(YDL) mention in proj
2024-03-19 11:40:46 -03:00
Martin-Molinero
3eedde9b6e Normalize ETF constituents universe (#7858)
- Normalize ETF constituents universe data. Adding new tests and
  assertions
2024-03-19 11:28:17 -03:00
Roman Yavnikov
c0d909c72c TryParsePath ignores DateTime (#7857)
* feat: logic of create Symbol with parsed Date

* fix: additional validation that date has value
2024-03-19 11:27:40 -03:00
Roman Yavnikov
7e568bf4ac Feature: find different Ticker data download parameters (#7845)
* refactor: map files in lean/data folder

* feat: Indexers in MapFile

* feat: extension for mapFile and downloader param

* refactor: getAllTickers from MapFiles

* feat: addition out variable in TryParsePath
fix: tests with new variable

* refactor: DownloadDataProvider with getting all ticker with different DateTime Ranges
feat: test

* revert: "refactor: map files in lean/data folder"

This reverts commit 41fa26eb8627446028d4f2d4c536511ea82a9a48.

* revert: "feat: addition out variable in TryParsePath"
refactor: some actual changing

This reverts commit 9de482bd6490eecd1eeee83e035dfc1ece8d6415.

* revert: "feat: Indexers in MapFile"
fix: actual changes

This reverts commit 393181c6316a354a8cdcbfb093707cb545383a8a.

* remove: high performance Any validation
feat: validation on ticker start with specific sign
fix: option test

* feat: validation on mapping
refactor: when resolution less hour
test: new test cases + validation of SecurityType

* refactor: add additional day when return date range from MapFile
fix: FirstTicker instead of Permtick when generate new Equity
feat: validation of request Date in DownloaderDataProvider
refactor: by style proj DownloaderDataProvider
test:fix: starting Date in TestCases

* remove: duplicate code

* fix: check of income data.Time with requested Start/End-Date

* test:fix: download test cuz we can not get/write future data

* remove:  extra Symbol Create mthd

* test:feat: validate of TryParse returns correct symbol

* remove: excess if condition

* test:remove: extra chaning
connected # 3a62adf54c

* refactor: split big method to small ones (add readability)

* fix: typo in xml description

* refactor: get the correct symbol value

* refactor: use local time instead of Utc in download Param extension
refactor: use struct instead of class

* test:fix: convert time to Utc from local time
2024-03-18 14:43:11 -03:00
Ashutosh
ee52ce4676 Update blacklisted-tickers.txt (#7854) 2024-03-18 11:52:07 -03:00
Martin-Molinero
a8280e1452 Minor fix for universe history (#7852)
- Do not cache universe collection data. Adding unit test
2024-03-14 16:20:28 -03:00
Ricardo Andrés Marino Rojas
934a8e0a61 Handle Windows reserved filenames (#7784)
* Add ToValidPathMethod

* Nit change

* Add more unit tests

* Improve implementation

* Enhance implementation

* Add more unit tests

* Enhance implementation

* Improve unit tests

* Improve implementation

* Nit changes

* Adjust reading/writing methods

* Fix bugs

* Add Windows OS flag

* Fix unit tests

* Fix unit tests

* Fix unit tests

* Change FileStream() to SafeFileStream()

* Fix bugs

* Fix bugs

* Nit changes

* Nit changes

* Add improvements

* Missing file

* Address requested changes

* Address requested changes

* Add missing test
2024-03-13 19:05:57 -03:00
Alexandre Catarino
44c7dbd698 Adds Rebate and Fee Rates to Shortable Provider (#7840)
* Adds Rebate and Fee Rates to Shortable Provider

If the provider does have this information, the rates are zero.

* Adds Helper Methods to QCAlgorithm

- Improve summaries.
- Express values as rates instead of percentages.
- Adds headers to files to emulate real data

* Clarify the Data Format

* Removes Helper Methods from QCAlgorithm

* Removes `Shortable` and `ShortableQuantity` from Example

Algorithms should prefer getting the information from the `Security.ShortableProvider`.
2024-03-13 16:04:33 -03:00
Jhonathan Abreu
b89d7d65b2 Fix live trading MHDB update (#7848)
* Add schedule manager unit tests

* Add schedule manager unit tests

* Fix overriding security exchange hours

* Minor comments changes

* Minor change

* Add SecurityExchangeHours.Update method to set without changing the reference

* Minor change
2024-03-13 12:09:15 -04:00
Ricardo Andrés Marino Rojas
09a3b61df8 Fix bug for NQX index options (#7824)
* First draft of the solution

* Add Improvements

* Update python version of the algo

* Update other classes

* Add regression algo

* Add missing data

* Fix bug

* Fix bug

* Nit change

* Clean implementation

* Nit change

* Nit change

* Improve implementation

* Nit change

* Nit change

* Solve bugs

* Improvements

* Address required changes

* Nit change

* Address changes

* Nit changes

* Nit changes

* Rename regression test
2024-03-13 11:42:55 -03:00
Martin-Molinero
516befe0b5 Backwards compatibility research universe history (#7849)
- Add backwards compatibility for research universe history api, adding
  unit tests
2024-03-13 11:20:02 -03:00
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
Jhonathan Abreu
6109ac8f1b Candlestick charts (#7425)
* Candlestick charts base implementation

* Series and Candlestick series json serialization

* Some cleanup

* Add AddPlot method for candlestick series to QCAlgorithm

* Remove Values property from ISeriesPoint

* Add candlestick QCAlgorithm.Plot trade bar methods

* Implement candlestick series re-sampling

* Add more SeriesSampler unit tests

* Add examples of candlestick charts usage to exisiting charting algorithm

* Address peer review

* Address peer review

* Derive Candlestick from Bar

* Sampler changes

* Add new series types from the cloud

* Add more candlestick series sampler tests

* Minor cleanup

* Minor changes
2023-08-08 17:52:46 -03:00
Ricardo Andrés Marino Rojas
aae4771b7e Fix Overflow bug in RandomDataGenerator (#7423)
* First attempt to fix the bug

* Allow the splitFactor to change over time

- Add unit test

* Nit change

* Address required changes

* Address required changes

* Adjust upper bound
2023-08-08 16:40:01 -03:00
Jhonathan Abreu
76b19161cb Fix updating StopLimitOrder.StopTriggered flag globally (#7407) 2023-08-08 16:37:47 -03:00
Henrik Strand
6e9df75d32 Replace chat badge (Slack -> Discord) (#7420) 2023-08-08 12:07:42 -03:00
Arthur Asenheimer
aae3f8b4d9 Fix minimum price variation for LE future (#7421)
* Adds IndicatorBatchUpdate

* Revert "Adds IndicatorBatchUpdate" (#3)

* Update symbol-properties-database.csv (#4)

Minimum price fluctuation for LE is supposed to be 0.00025 according to CME. (See also: https://www.cmegroup.com/markets/agriculture/livestock/live-cattle.contractSpecs.html)
2023-08-08 12:07:23 -03:00
Martin-Molinero
04bb2b503f Update readme.md 2023-08-04 15:54:57 -03:00
Martin-Molinero
df13e34e9e Update readme.md 2023-08-03 11:04:32 -03:00
Martin-Molinero
4976fc9a99 Revert breaking plotly update (#7415) 2023-08-03 10:57:22 -03:00
Ricardo Andrés Marino Rojas
aa1ebd0e65 Bug parameters in report bug (#7413)
* Solve bug in the parameters of the Report

Before, when the number of keys were odd a part of the raw template was
shown in the report generated. Additionally, the user couldn't define
the number of columns of the parameters table

* Add unit tests

* Enhance unit tests

* Nit change
2023-08-02 15:28:48 -03:00
Martin-Molinero
d1b8c13318 Dependency update and cleanup (#7411)
- Update Math.Numerics & QLNet to latest
- Remove unused old FSharp core causing issues
2023-08-01 19:26:20 -03:00
Martin-Molinero
a139aac522 Update readme.md 2023-08-01 14:46:37 -03:00
Ricardo Andrés Marino Rojas
3338486b52 Enable Report generator to use custom HTML template (#7410)
* Add support for custom HTML file in Report

* Add support for custom crisis HTML template

* Revert "Add support for custom crisis HTML template"

After considering this option carefully, the QC team has decided to
add this functionality in a different way.

This reverts commit aead1ff850.

* Get parameters and crisis HTML custom templates

* Move parameters html template to a file

* Nit change

* Remove template.crisis.html and add unit tests

* Nit change

* Nit change

* Add unit tests for the fail cases
2023-08-01 12:55:14 -03:00
Martin-Molinero
0c0eedf547 Update readme.md 2023-07-28 20:19:05 -03:00
Martin-Molinero
e8c1b0df48 Fix for CI python stubs (#7405) 2023-07-28 20:13:03 -03:00
Martin-Molinero
ed1362c8b0 Update readme.md 2023-07-28 18:56:46 -03:00
Jhonathan Abreu
906ab20bee Trailing stop orders (#7402)
* Add trailing stop orders base implementation

* Handle trailing stop order prices rounding

* Implement trailing stop orders fill logic

* Minor fill model changes

* Add ApplySplit to fill model interface for models that might need to be aware of splits.

Filling trailing stop orders require keeping track of min/max prices, which need to be split adjusted.

* Add brokerage order updated event for communicating certain order types prices changes

* Add order update event args class for brokerage side order updates

* Revert IFillModel.ApplySplit

* Add trailing stop orders regression algorithm

* Updated order ticket demo algorithm to include trailing stop orders

* Some cleanup

* Support trailing stop orders in IB brokerage model

* Some cleanup

* Fix failing tests

* Fix failing regression algorithm

* Address peer review

* Add trailing stop price calculation unit tests

* Minor changes

* Minor change
2023-07-28 17:49:58 -04:00
Jhonathan Abreu
10a9f31d65 Return valid default value for indicator Previous property (#7404) 2023-07-28 18:36:13 -03:00
Ricardo Andrés Marino Rojas
0817101bcd Include AlgorithmConfiguration.Parameters in the report generated and allow to override stylesheet (#7401)
* Add algorithm configurations to Report

* Add just Parameters section in the Report

* Revert "Add just Parameters section in the Report"

This reverts commit 775255127a212db81fc1cc1e23a35b7c60214eac.

* Include just AlgorithmConfiguration.Parameters

* Create ParametersReportElement

* Generate parameters into HTML dynamically

* Enable the user to modify CSS content throu

* Enable CSS override file to be passed through cmdline

* Check CSS Override file exists

* Fix bugs

* Address required changes

* Address required changes

* Address required changes
2023-07-28 18:33:24 -03:00
Ricardo Andrés Marino Rojas
3e9fc57bb0 Implement RangeConsolidator (#7385)
* Implement RangeConsolidator

It turned out that the behavior of RangeConsolidator was similar to
ClassicRenkoConsolidator. Then, some of the ClassicRenkoConsolidator
methods, were abstracted to new class called BaseTimelessConsolidator.cs,
from which both RangeConsolidator and ClassicRenkoConsolidator could
inherit, therefore resusing code. The following tasks were done:

- Create RangeConsolidator.cs
- Create RangeBar.cs
- Create BaseTimelessConsolidator.cs
- Create RangeConsolidatorTests.cs
- Modify ClassicRenkoConsolidator.cs

* Allow intermediate/Phantom RangeBar's

- Enhance unit tests
- Nit changes
- Allow intermediate/Phantom RangeBar's on RangeConsolidator

* Nit changes

* Create ClassicRangeConsolidator and more changes

- Add regression tests
- Enhance unit tests

* Address required changes

* Address requested changes

* Address requested changes

* Add regression tests with Tick Resolution

* Address required changes

* Increase Range for RangeConsolidatorWithTickAlgo

* Add more unit tests and solve bugs

* Nit change
2023-07-27 10:02:02 -03:00
Martin-Molinero
e442586a0d Test CI workaround (#7399)
- Replace default container gh ci support for custom action to enable
  cleaning up host
2023-07-24 19:23:16 -03:00
Arthur Asenheimer
adca9ea5b3 Fixed minimum price variation for Futures LE and HE (#7394)
* Adds IndicatorBatchUpdate

* Revert "Adds IndicatorBatchUpdate" (#3)

* Fixed minimum price variation for Futures ZL and HE
2023-07-24 11:15:23 -03:00
Martin-Molinero
947a3fc93b Delete mounted tools (#7396) 2023-07-21 13:40:39 -03:00
Jhonathan Abreu
b1b9680880 Handle API backtest charts read null requests (#7395) 2023-07-21 13:40:26 -03:00
Martin-Molinero
7aabea102b Update readme.md 2023-07-20 20:29:36 -03:00
Jhonathan Abreu
2522a14050 Fix naked index option margin requirement percentage (#7391) 2023-07-20 19:29:02 -03:00
Jhonathan Abreu
69eea5419c Make symbol-count optional and dependent on tickers in random data generator (#7390) 2023-07-20 19:23:50 -03:00
Martin-Molinero
a6283b0ab7 Fix unsupported configuration warnings filter (#7386) 2023-07-19 12:10:10 -03:00
Martin-Molinero
2a941e73e2 Add warning for unsupported live configurations (#7383)
- Add warning for unsupported live configurations
2023-07-18 16:18:56 -03:00
Martin-Molinero
1c3180b681 Do not transition from canceled to invalid order (#7382)
- Minor adjustment not to transition from canceled to invalid order
  status, which can happen in some cases in live trading as a race
  condition. Adding unit test
- Make sure open order status is set to submitted if none provided,
  adjusting existing test
2023-07-18 16:16:08 -03:00
Martin-Molinero
ffcfb4eeb2 Adjust debugger version for pycharm 2023.1.4 (#7381) 2023-07-18 16:15:58 -03:00
Martin-Molinero
e2ee42a0e2 Respect minimum time in universe always (#7379)
- Always respect the minimum time in universe even if we haven't gotten
  any data point yet. This is specially useful for live trading options
  which are illiquid
2023-07-17 14:57:29 -03:00
Lehonti Ramos
026ba6ed5b Modernization of syntax used in argument check exceptions (#7380)
* Changed argument exceptions so that they used the nameof() operator for parameter names

* Update IQSocket.cs

---------

Co-authored-by: John Doe <john@doe>
Co-authored-by: Martin-Molinero <martin@quantconnect.com>
2023-07-17 14:53:17 -03:00
Martin-Molinero
3a3dbe29ea Bug chain selection improvements (#7376)
* Contract chain selection improvements

- Adjust contract chain selection behavior for futures and options so we
  are sure to use the correct local time when filtering expirations.
  Adding unit test reproducing issue

* Update futures regression algorithms

* Address reviews
2023-07-13 20:34:45 -03:00
Martin-Molinero
663d0ff094 Remove expire check for live universe subscriptions (#7377)
- Remove expiration check for live universe subscription causing errors
2023-07-13 20:33:24 -03:00
Ricardo Andrés Marino Rojas
bfca56c4a8 Improve Tradier Brokerage Model (#7373)
* Check the TimeInForce in Tradier orders is not GTD

* Add unit tests

* Nit changes
2023-07-13 13:00:26 -03:00
Martin-Molinero
28fe8a1e7c Fix contract security filter universe (#7374)
* Fix contract security filter universe

- Fix for contract security filter universe which would would use .Time
  to filter expirations which could be yesterdays time at midnight
  localtime. Adding unit tests reproducing issue

* Update regression algorithms
2023-07-12 20:46:17 -03:00
Martin-Molinero
492490e2c5 Fix download CI unit test (#7372) 2023-07-12 19:59:18 -03:00
Ricardo Andrés Marino Rojas
bfb820c617 Update MHDB CME Group Futures on Good Friday (#7368)
* Update MHDB CBOT Futures on Good Friday

* Update MHDB CME Futures on Good Friday

* Update MHDB CBOT Futures on Good Friday

* Update MHDB CME Futures on Good Friday

* Update MHDB comex and nymex futures on good friday

* Revert "Update MHDB comex and nymex futures on good friday"

Since all nymex and comex futures had a holiday on Good Friday, it's
better to add the holiday on `Future-nymex-[*]` and `Future-comex-[*]`

This reverts commit e111c8e461.

* Remove Good Friday holiday for cme and cbot futures

- Remove Good Friday holiday from `Future-cme-[*]` and `Future-cbot-[*]`
- Add Good Friday holiday for specific cme and cbot futures

* Add unit tests and update MHDB

- Add unit tests asserting LEAN reads correctly Good Friday holidays and
  early closes for CME Group Futures
- Update the holidays for other CME group Futures on MHDB

* Fix bugs

* Enhance unit tests
2023-07-12 16:04:22 -03:00
Martin Molinero
bdfe9399da IB gateway Typo 2023-07-12 13:50:10 -03:00
Martin-Molinero
240e84dd3d Revert to IB 10.19.2a (#7371) 2023-07-12 13:43:42 -03:00
Martin-Molinero
62fb61929f Update readme.md 2023-07-11 20:49:03 -03:00
Jhonathan Abreu
72e7dca7af Bump Pythonnet version to 2.0.21 (#7367)
* Add security dynamic properties unit and regression tests.

These assert that dynamic properties that are instances of python classes that inherit c# classes keep their python object references.

* Minor change

* Bump pythonnet version to 2.0.21

* Fix security dynamic properties cast from PyObject

* Minor change
2023-07-11 20:43:49 -03:00
Martin-Molinero
1ea0cd9d82 Check continuous future mapped symbol is not expired in live (#7364)
- In Live trading check the continuous future mapped symbol is not expired
  before subscribing to the data queue handler. Adding unit tests
2023-07-11 20:43:36 -03:00
Martin-Molinero
a099b9fb71 Minor tweaks to avoid CI tests random failures (#7370)
* Minor tweaks to avoid CI tests random failures

- Increate timeout of research start test, using default value
- Minor tweaks for rate gate to improve performance

* Clean up rategate tests
2023-07-11 20:43:22 -03:00
Martin-Molinero
54413e99b4 Live Option Chain Source Fix (#7369)
- Fix live option chain sources handling
2023-07-11 20:43:11 -03:00
Ricardo Andrés Marino Rojas
03df6c5ccb Update MHDB with 3rd/4th July Holiday hours (#7366)
* Update MHDB with NYSE and ICE holiday hours

- Update holidays and early closes for ´Equity-usa-[*]´
- Update holidays for certain products from Ice Futures US

* Add missing holiday hours in MHDB for CME-G Futures

- The missing holiday hours were from 3 July 2023

* Remove duplicates
2023-07-11 15:21:51 -03:00
Martin-Molinero
329ce54ca9 Update readme.md 2023-07-11 12:12:45 -03:00
Martin-Molinero
2f21a27023 Revert trade builder api change (#7365)
- Revert trade builder api change, add SecurityManager setter, to be
  called by the algorithm
2023-07-11 10:54:29 -04:00
Jhonathan Abreu
e562b8c99c Fix IsExchangeIpen bar check in FillModel and EquityFillModel (#7363)
* Fix market-open bar checks for non-daily resolutions in fill models

* Address peer review

* Minor change
2023-07-10 18:41:17 -03:00
Ricardo Andrés Marino Rojas
f8b79b8d6b Make indicators work with RenkoBars and VolumeRenkoBars (#7360)
* Address JB comment

* Remove repeated fields in BaseRenkoBar

- Add new unit test to all indicators that inherit from
  IndicatorBase<TradeBar>. This test asserts the indicators can receive
  RenkoBar's as input

* Add Regression test and improve unit tests

- Change `Volume` property from `RenkoBar.cs` since RenkoBar's don't
  have Volume. Now it throws an error when accessed

* Address required changes

* Add Python regression test and enhance unit tests

* Enhance unit and regression tests

* Assert indicator current value at the end

* Allow more indicators to use Renko/VolumeRenkoBar
2023-07-10 11:27:03 -03:00
Martin-Molinero
9dbeb3255d Update python debuggers (#7361)
- Update python debuggers
2023-07-10 10:55:50 -03:00
Martin-Molinero
7e81693d3c Add UnrealizedPnLPercent to holdings (#7358) 2023-07-10 10:55:00 -03:00
Jhonathan Abreu
bc05aa03f9 Fix win/loss count statistics for options assignments (#7354)
* Add ITM option assignment trade as win in trade statistics

* Add TradeStatistics unit tests

* Add unit tests

* Add OptionTrade class to abstract IsWin method

* Keep track of winning/losing trades

* Add more unit tests

* Change Trade.IsWin to a property calculated by the trade builder

* Improve regression algorithm

* Handle ITM option sell win/loss statistics

* Update regression algorithms statistics

* Revert accidental unwanted changes

* Address peer review

* Keep track of winning and losing transactions for portfolio statistics

* Add more SecurityPortfolioModel unit tests

* Fix failing unit tests

* Minor changes

* Address peer review

* Minor fix
2023-07-10 10:20:29 -03:00
Martin-Molinero
c75d0d8a6d Update readme.md 2023-07-07 12:12:19 -03:00
Martin Molinero
4c9a455a08 Delete data folder before generating stubs in CI 2023-07-06 19:51:41 -03:00
Martin-Molinero
f17a8e4d92 Update readme.md 2023-07-06 15:19:52 -03:00
Martin-Molinero
6ccafe9640 Minor fix for invalid update events (#7357)
- Handler brokerage invalid update order event once the order has
  already been filled by the brokerage. Adding unit test reproducing the
  issue
2023-07-06 15:13:03 -03:00
Martin-Molinero
ddbc654d53 Update readme.md 2023-07-05 19:21:27 -03:00
Martin-Molinero
c86b005564 Add exchange post fix for wolverine order properties (#7355) 2023-07-05 19:17:43 -03:00
Martin-Molinero
0303cf079f Remove Capacity from Runtime Statistics (#7353) 2023-07-05 11:23:59 -03:00
Martin-Molinero
626f64e37d Update IB gateway to 1023 (#7351) 2023-07-04 14:05:35 -03:00
Martin-Molinero
1ca007faa3 Update readme.md 2023-07-03 14:49:46 -03:00
Jhonathan Abreu
d39a9420d5 Fix Security.IsMarketOpen for cases outside regular MH and last bar (#7343)
* Fix Security.IsMarketOpen for cases outside regular MH and last bar

* Minor changes

* Move bar check of IsMarketOpen into FillModel

* Minor changes

* Minor changes

* Minor changes
2023-07-03 14:40:31 -03:00
Martin-Molinero
240d7db8e2 Update readme.md 2023-07-03 11:00:34 -03:00
Martin-Molinero
49b6c56fe8 Fix for stack tracer code cleaner null reference (#7346) 2023-07-03 10:56:38 -03:00
Jhonathan Abreu
af0de8d2e9 Deployment target and running mode algorithm properties (#7337)
* Add algorithm's mode and deployment target properties source from job packet

* Address peer review

* Add Python regression algorithm
2023-07-03 09:55:21 -04:00
Ricardo Andrés Marino Rojas
b47619e7b9 Remove EnableAutomaticWarmUp and IIndicatorWarmUpPeriodProvider impl from RVA (#7344)
* Remove EnableAutomaticWarmUp for RVA indicator

* Remove `IIndicatorWarmUpPeriodProvider` impl
2023-06-30 16:15:27 -03:00
Martin-Molinero
092dcda143 Adding new packet types (#7341) 2023-06-30 16:14:03 -03:00
Ricardo Andrés Marino Rojas
e029b96229 Fix bug in VolumeWeightedAveragePriceIndicator (#7336)
* Fix bug

- Add `ResetHandler()` and `IsReset` field in `CompositeIndicator.cs`
- Modify `CompositeIndicator.Reset()` to invoke the IsReset event
- Modify `VolumeWeightedAveragePriceIndicator.Reset()` method to reset
  its composite indicator
- Modify `IndicatorExtensions.WeightedBy()` to register an event to the
  returned composite indicator `IsReset` field

* Enhance implementation

* Address Requested changes

* Nit changes

* Nit change

* Nit change

* Address chages

- Make ResetCompositeIndicator inherit from CompositeIndicator and
  override `Reset()` method
- Add ResetCompositeIndicator unit tests
- Modifiy IndicatorExtensions to keep returning the same type in
  `WeightedBy()` method

* Avoid modify other IndicatorExtensions methods

* Nit changes

* Reset inner indicators and add more unit tests
2023-06-30 13:36:44 -03:00
Martin-Molinero
25d664e349 Update readme.md 2023-06-30 11:23:01 -03:00
Martin-Molinero
7952db992b Revert IB gateway update (#7345) 2023-06-30 11:18:27 -03:00
Martin-Molinero
936350cf45 Feature update foundation (#7342)
* Update foundation image

* Update python packages tests

- Fix bug in python initializer path priority for virtual envs

* ARM foundation update
2023-06-29 18:06:28 -03:00
Martin-Molinero
d173c5d65e Update DockerfileLeanFoundation 2023-06-28 10:03:24 -03:00
Jhonathan Abreu
a02309f2c6 Fix indicator name generation method (#7335)
* Fix indicator name generation method

* Minor change

* Add period to Beta indicator name
2023-06-27 16:03:43 -03:00
Jhonathan Abreu
956428b7bf Security cache dynamic collection for custom properties (#7327)
* Dynamic security properties for quick objects storage

* Documentation and other minor changes

* Add Security indexer to access custom properties

* Address peer review

* Minor changes

* Improve regression algorithms

* Bumped pythonnet to version 2.0.19

* Bumped pythonnet to version 2.0.20

* Address peer review
2023-06-27 10:39:20 -04:00
Martin-Molinero
df935aa608 Avoid research CI timeouts (#7334) 2023-06-23 11:17:18 -03:00
Ricardo Andrés Marino Rojas
4fd58ce180 Fix bug in Insight Weighted PCM (#7333)
* Fix bug and add unit tests

- Modify `InsightWeightingPortfolioConstructionModel.cs/py` to take the
  absolute value in its `GetValue()` method
- Modifiy `InsightsReturnsTargetsConsistentWithDirection()` unit test to
  consider also the case where the direction is Down and the weight is
  negative

* Nit changes
2023-06-23 10:08:45 -03:00
Martin-Molinero
96b56f06d5 Minor Packet type addition (#7332) 2023-06-22 13:42:32 -03:00
Martin-Molinero
05ab723b63 Update readme.md 2023-06-21 15:42:32 -03:00
Ricardo Andrés Marino Rojas
14b256846d Handle potential Error Code returned by CrunchDAO (#7330)
When a user tries to get its last submission ID with an empty API key,
CrunchDAO returns an Error Code, therefore we need to handle that case
2023-06-21 15:27:17 -03:00
Derek Melchin
c4c66c2aba Update crunchdao demo algorithm (#7292) 2023-06-21 15:27:06 -03:00
Ricardo Andrés Marino Rojas
1996498af5 Modify DonchianChannel.cs and spy_with_don50.csv (#7329) 2023-06-21 15:26:58 -03:00
Martin-Molinero
e22565c849 C# stacktrace exception normalization (#7328)
- Following the Py pattern of exception handling we will normalize stack
  traces for C# too, adding unit test
2023-06-21 10:51:17 -03:00
Jhonathan Abreu
177531651c QCAlgorithm.BrokerageName property (#7325)
* Add QCAlgorithm.BrokerageName property

* Add QCAlgorithm.BrokerageName property in python algorithm

* Address peer review

* Address peer review

* Address peer review
2023-06-20 11:24:27 -04:00
Ricardo Andrés Marino Rojas
a309322ae5 Fix CustomPartialFillModelAlgorithmFails.cs/py (#7321)
* Fix bug

The algorithm `CustomPartialFillModelAlgorithm.cs` was not working as
expected with short orders because in its Fill model, the variable
`absoluteRemaining` instead of decrease was being increased since
the `FillQuantity` in each call to this method was negative. Therefore
when this amount was substracted to `absoluteRemaining`, instead of
substract, it was added. Hence the method created more partial orders
than expected, specifically: 580 short orders for SPY with Quantity -10.

* Fix `CustomPartialFillModelAlgorithm.py`

* Address required changes

* Nit change

* Address required changes
2023-06-20 09:46:11 -04:00
Jhonathan Abreu
5ddc8c3766 Add unit tests to assert pandas dataframe multiindex slicing support (#7324) 2023-06-19 17:52:25 -03:00
Jhonathan Abreu
5d6110f38c Make summary statistics available to algorithms at runtime (#7320)
* Make statistics available at runtime to algorithms

* Re-calculate statistics on every call

* Housekeeping

* Add regression algorithms

* Address peer review

* Support for custom summary statistics at runtime

* Minor changes

* Address peer review

* Address peer review

* Minor changes

* Minor changes
2023-06-19 17:34:59 -03:00
Ricardo Andrés Marino Rojas
eeb512fac6 Fix RenkoConsolidator (#7317)
* Fix bug and add unit tests

The bug was raised because rounding the first point inserted in the
RenkoConsolidator didn't get the closest y-multiple of the given number
x, where y is the bar-size. In order to compute the first y-multiple of
the given number x, we need to first compute x mod y := x - y*Floor(x/y),
once we get this number we divide it by y to know if we should round x
to minimum y-multiple greater than x, or should round x to the maximum
y-multiple smaller than x. If (x mod y)/y < 0.5 we round down, otherwise we round up (the amount (x mod y)/y is always less than one and higher than 0). See the Art of Computer Programming, Vol I. Donald E. Knuth.

- Add `GetClosestMultiple()` method in `RenkoConsolidator.cs`
- Add more unit tests

* Nit change

* Add XML docs

* Address required changes and add more unit tests
2023-06-16 18:36:56 -03:00
Martin-Molinero
2547af1ccc Update readme.md 2023-06-15 12:42:27 -03:00
Martin-Molinero
b21fcc98be Add language model packet types (#7318) 2023-06-15 12:38:39 -03:00
Jhonathan Abreu
60aba9efa4 Make order ticket available from order event (#7316)
* Make order ticket available from order event

* Add regression algorithms

* Address peer review

* Address peer review
2023-06-15 11:11:06 -04:00
Jhonathan Abreu
94572f571c Fix Equity MOO and MOC orders fill for tick subscriptions (#7315)
Properly selecting the official open/close and opening/closing prints
trade condition flags from trade ticks.
2023-06-15 11:02:55 -04:00
Jhonathan Abreu
501dc01399 Indicators history rolling window (#7314)
* Implement indicator history through a rolling window

* Minor changes and extend unit tests

* Add regression algorithms

* Minor changes

* Update regression algorithms examples

* Move resizing logic from IndicatorBase to RollingWindow

* Add unit tests and other minor changes

* Minor fix

* Add unit tests and other minor changes

* Add unit test
2023-06-13 15:07:09 -03:00
Martin-Molinero
d1171500e3 Update readme.md 2023-06-13 10:51:47 -03:00
Jhonathan Abreu
d32bf13b4d Option strategy position group buying power calculation for single securities (#7308)
* Fix position group BP calculation

* Fix position group BP calculation

* Extend option startegy buying power unit tests

* Fix option strategy buying power calculation to account for order direction
2023-06-13 10:34:08 -03:00
Martin-Molinero
4d55493000 Future and option universe selection improvements (#7313)
* Normalize universe selection future and option creation

- Normalize universe selection future and option creation to include
  canonical securities enabling continuous future support

* Update existing regression algorithms

* Self review

* Address review

* Extra regression test check
2023-06-13 10:32:26 -03:00
Martin-Molinero
24820fe92c Minor future margin model improvements (#7306)
- Refresh margin requirements daily
- Refactor margin requirements so they are fetch once per future symbol
2023-06-12 10:46:41 -03:00
Martin-Molinero
73c71c6913 Add missing GC future auxiliary data (#7312)
* Add missing GC future auxiliary data

- For improved testing add missing GC comex future auxiliary data.
  Updating regression tests

* Update regression algorithm expected data points
2023-06-09 19:43:34 -03:00
Ricardo Andrés Marino Rojas
3c9f9aae20 Fix bug in MarketProfile indicator (#7310)
* Fix bug, add unit tests and nit changes

The bug was raised because if two inputs points with repeated close values were inserted,
and the second one had 0 volume, when the first one is removed from
_oldDataPoints, as the reamaining value of it in _volumePerPrice is
zero, that entry is removed from _volumePerPrice. Therefore, when
the second input point is removed from _oldDataPoints, this entry
is not found in _volumePerPrice. Then the changes made were:

- Modify MarketProfile.Add() method to check every removed data point is
  still in _volumePerPrice
- Add unit tests to covert this change
- Nit changes in VolumeProfileTests.cs

* Fix bugs and add more unit tests

- The Fill Forward bars shouldn't be considered in the calculations as
it's not real data.

- If bar inserted is not FF but has zero volume, it could remove a price
  value from VolumePerPrice and leave this sorted list empty, then each
  time we access that list we need to first check it's not empty

* Enhance ComputeNextValue() and add more unit tests
2023-06-09 19:14:45 -03:00
Martin-Molinero
ff47ede36c Minor fix for automatically added option underlying (#7311)
- Lean engine will automatically add an options underlying if not
  present, but in most cases the option chain will select the underlying
  too, so let's make sure the configurations match. Previous to this
  change 'fill forward' setting could be different causing the
  underlying to be duplicated in the data stack
2023-06-09 19:03:35 -03:00
Martin-Molinero
1a3138d0cd Update readme.md 2023-06-08 17:57:37 -03:00
Jhonathan Abreu
756a61b8e0 ShortCallCalendarSpread and ShortPutCalendarSpread strategies helper factory methods (#7304)
* Add ShortCallCalendarSpread and ShortCalendarPutSpread strategies helper factory methods

* Housekeeping
2023-06-08 15:22:45 -04:00
Jhonathan Abreu
b479300587 Add IronCondor strategy helper factory methods (#7305) 2023-06-08 14:48:24 -04:00
Martin-Molinero
d2d3cdcc0f Update readme.md 2023-06-08 13:37:11 -03:00
Martin-Molinero
bae69aaa0a Add ARM foundation image (#7299)
- Readding ARM foundation image without Interactive brokers support
2023-06-08 13:29:42 -03:00
Martin-Molinero
ee3cea805e FactorFiles bases live auxiliary events (#7293)
- Adjusting live stack to emit live auxiliary events based on factor files.
    Updating existing tests
  - Minor improvements for map & factor file provider daily refresh time.
    Adding unit tests
2023-06-08 13:27:55 -03:00
Jhonathan Abreu
ad6046fea5 ShortButterflyCall and ShortButterflyPut strategies helper factory methods (#7302)
* Add ShortButterflyCall and ShortButterflyPut strategies helper factory methods

* Reduce duplication by adding the base OptionStrategyFactoryMethodsBaseAlgorithm algorithm class

* Housekeeping
2023-06-08 11:55:48 -03:00
Martin-Molinero
cc9a061cb1 Fix python Interpret unit test (#7301) 2023-06-07 18:05:16 -03:00
Jhonathan Abreu
90a2c06a4c Add ShortStaddle and ShortStrangle strategies helper factory methods (#7300) 2023-06-07 16:55:47 -03:00
Jhonathan Abreu
615827f259 NakedCall and NakedPut strategies helper factory methods (#7298)
* Add NakedCall and NakedPut strategies helper factory methods

* Housekeeping
2023-06-07 10:43:01 -04:00
Ricardo Andrés Marino Rojas
b64169fd20 Fix Beta chart in Report (#7295)
* Fix bug in Beta statistics

- Beta in Report was calculated using equity points and not daily
  performance points, as it's done in Backtest
- Performance points were not being divided by 100, as it's done in
  StatisticsBuilder
- Benchmark points were not being converted into a percentage daily
  performance of the benchmark, as it's done in StatisticsBuilder

* Improve implementation and add unit tests

* Enhance implementation and add more unit tests

* Enhance implementation

* Nit change

* Nit changes
2023-06-07 11:10:10 -03:00
Jhonathan Abreu
cb0661c79e Add CoveredPut and ProtectivePut strategies helper factory methods (#7297) 2023-06-07 10:01:49 -04:00
Jhonathan Abreu
5d148683b7 CoveredCall and ProtectiveCall strategies helper factory methods (#7296)
* Add CoveredCall strategy helper factory method

* Add ProtectiveCall strategy helper factory method

* Housekeeping
2023-06-06 18:22:30 -03:00
Jhonathan Abreu
0df6366301 Options premium in margin calculations (#7294)
* Make maintenance margin zero for long options

* Use OptionIntialMargin in OptionMarginModel

* Add naked call and put strategies unit tests

* Minor fix
2023-06-06 13:07:32 -03:00
Jhonathan Abreu
bdcb6d9474 Account for premium in options strategies margin (#7290)
* Account for premium in option strategies margin

* Minor fixes

* Add OptionInitialMargin class to separate strategies margin and premium

* Minor fix

* Minor fix

* Cleanup, docs and other minor changes

* Minor changes

* Minor changes

* Minor changes

* Address peer review
2023-06-05 12:58:48 -03:00
Ricardo Andrés Marino Rojas
b14bda2dc0 Add SetAccountCurrency() override (#7284)
* Add SetAccountCurrency overload

- Add SetAccountCurrencyOverload to allow the user to set also account
  currency quantity
- Add regression and unit tests to cover the changes

* Add regression algos

* Simplifiy SetAccountCurrency implementation

* Minor changes

* Minor changes
2023-06-01 17:44:45 -03:00
Martin-Molinero
1283f52de1 Add multi symbols tick history warning (#7289)
- Add warning message when using the multi symbol tick type history
  algorithm api
2023-06-01 17:42:40 -03:00
Martin-Molinero
64d0eaefab Update readme.md 2023-05-31 20:07:56 -03:00
Martin-Molinero
e42d84319d Support overriding position group margin requirements (#7286)
* Add support for Null SecurityPositionGroupModel

- Add support for algorithms to set the null security position group
  model which will not group securities together but rather return the
  single group buying power model. Adding regression algorithms

* Add Null Margin python regression & cleanup

- Add python regression algorithm & minor regression algorithms clean up
2023-05-31 19:53:50 -03:00
Martin-Molinero
cc73f5bca8 Add missing MHDB 'holidays' entry for backwards compatibility (#7287) 2023-05-31 17:58:26 -04:00
Jhonathan Abreu
0ff3622d1e Fix position group HasSufficientBuyingPowerForOrder (#7285)
* Fix position group HasSufficientBuyingPowerForOrder

Comparing computed delta BP -- which already considers every impacted
group -- with the right available buying power (the remaining margin)

* Minor changes
2023-05-31 13:14:14 -03:00
Martin-Molinero
ef01980b07 Python history improvements (#7283)
* Pandas frame include all ticks

- Pandas data framde history response will include all ticks. Updating
  existing and adding new tests

* Python pandas converter performance improvement
2023-05-31 10:22:21 -03:00
Jhonathan Abreu
82b3468ab7 Add naked single-option strategies (#7231)
* Handle liquidating option position with an option strategy

* Handle liquidating option position with an option strategy

* Minor changes

* Minor fix in default margin model margin call order generation
2023-05-30 15:59:28 -03:00
Martin-Molinero
bce3fb41bb Update readme.md 2023-05-30 13:51:08 -03:00
Ricardo Andrés Marino Rojas
7f6da62e5d Add TriggerPrice field when applying a split (#7279)
* Add TriggerPrice field when applying a split

If one stock is split in k parts, the new TriggerPrice in an order for that stock should be also scaled by a factor of k/10. It was made:
- Modify `DefaultBrokerageModel.ApplySplit()` to adjust `TriggerPrice` field
- Regression and unit test was added

* Check Limit Price for LimitIfTouched

* Nit change
2023-05-30 13:36:49 -03:00
Martin-Molinero
9aa9f715ec Minor MHDB Concurrent Usage Fix (#7281)
- Fix race condition with multiple threads creating the MHDB
2023-05-30 13:35:29 -03:00
Martin-Molinero
c33ce2f8c3 MHDB Merge Common Holidays, LateOpens & EarlyCloses (#7278)
* MHDB will merge common entry

- The MHDB will merge the market and security common entry holidays,
  early closes and late opens

* Normalize & reuse future US holidays

- Normalize & reuse future US holidays

* Update existing unit tests expected stats
2023-05-30 11:54:28 -03:00
Martin-Molinero
383acc06d2 Update readme.md 2023-05-26 18:58:49 -03:00
Jhonathan Abreu
5c5201944a Fix position group order quantity calculation for delta/target buying power (#7230)
* Fix PositionGroupBuyingPowerModel quantity for delta calculation

The model was calculation the order size that required a margin equal to
the given delta. This fix makes it so that it calculates the position
group order quantity required to get the given buying power delta,
taking into account the holdings for the existing position group in the portfolio.

* Fix PositionGroupBuyingPowerModel quantity for delta calculation

* Add unit tests

* Add unit tests

* Add unit tests

* Housekeeping

* Housekeeping

* Adapt unit tests and move messages to Messages class

* Improve quantity calculation for target BP loop

- PositionGroup.Quantity is now always positive.
- Added PositionGroupExtensions.Closes method and use it to check if reducing a position in PositionGroupBuyingPowerModel.GetPositionGroupBuyingPower. This is necessary since now a PositionGroup side is always "long" (see first bullet point).

* Improvements

* Improvements and new PositionGroup unit tests

* Unit tests improvements

- HasSufficientBuyingPowerForOrder test cases were completely updated to
  make it accurate in terms of Lean's margin calculation.
- BuyingPowerForPositionGroupCalculation test was fixed in order to get
  the correct expected result.

* Fixes for failing tests

* Added additional check to OptionStrategyMarginCallEventsAlgorithm

* Improve documentation comments

* Fix option strategies BuyingPowerForPositionGroupCalculation unit test

* Fix PositionGroupBuyingPowerModel.GetPositionGroupBuyingPower

Also address peer review

* Minor changes

* Update unit tests for new inverse strategies

Also fixed PositionGroupExtensions.WithQuantity to resolve inverse
strategy

* Minor fix

* Allow target/delta to go to the opposite direction of the position group

* Housekeeping

* Handle quantity for target/delta BP request for different reference position group

* Revert removal of PositionGroupBuyingPowerParameters.Direction

* Minor changes

* Peer review

* Minor tweaks on the position group buying power model

* Minor fix
2023-05-26 17:22:58 -04:00
Martin-Molinero
410956bf9f FreePortfolioValuePercentage Trailing Behavior (#7272)
* Implement Trailing FreePortfolioValue

- Implement Trailing FreePortfolioValue by default, users will be able
  to set it to a fixed number if desired. Adding regression algorithm
- Setting the default 'MinimumOrderMarginPortfolioPercentage' from 0 to
  0.1% of the TPV to avoud tiny trades by default

* Update existing regression algorithms

* Address reviews

- Send warning message to the user if a trade does not happen due to the
  default setting of the minimum order margin percentage value

* Address reivews

* Rename TotalPortfolioValueLessFreeBuffer

* Update new regression algorithm
2023-05-25 18:48:04 -03:00
Martin-Molinero
2147d868d8 Minor fix CrunchDAO Symbology (#7276)
* Minor fix CrunchDao Symbology

- Minor fix for CrunchDao Symbology. Updating existing tests

* Add missing symbol mapping

- Add IAlgorithm.Ticker(Symbol) functionality which will return the
  latest ticker for the requested symbol at the current algorithm time
- SignalExporters will use Ticker to get the current symbol ticker

* Rename SecId GetTicker to Ticker
2023-05-25 17:51:40 -03:00
Martin-Molinero
1e70673e00 Replace QC500 for SPY ETF (#7277)
- Replace manual QC500 universe for SPY ETF universe
2023-05-25 17:44:45 -03:00
Martin-Molinero
4823cca7ef Multiple Symbol Selection Universe (#7273)
- Add support and example algorithms for multiple symbol selection universe
 including custom data types.
2023-05-25 15:23:18 -03:00
Martin-Molinero
46d5d46aca Remove Alpha Licence References (#7275) 2023-05-25 12:51:33 -03:00
Ricardo Andrés Marino Rojas
3712786301 Enable custom Python optimizer in C# MeanVarianceOptimizationPortfolioConstructionModel (#7274)
* Solve bug and add regression test

The bug was raised because, when trying to use C#
MeanVarianceOptimizationPortfolioConstructionModel from a Python
algorithm, there wasn't a constructor that accepted a portfolio optimizer
as a PyObject. Additionally, there wasn't also a Python Wrapper to wrapp
that portfolio optimizer.

- Add PortfolioOptimizerPythonWrapper.cs
- Add constructor in
  MeanVarianceOptimizationPortfolioConstructionModel.cs that accepts
  portfolio optimizer as a PyObject
- Add regression algorithms to cover the changes

* Improve constructor overload implementation

* Change implementation to follow API pattern

* Enhance implementation and add unit tests

* Enhance implementation and add more unit tests

* Enhance implementation
2023-05-25 10:15:56 -03:00
Martin-Molinero
97489dfc57 Implement UnregisterIndicator helper method (#7271)
* Implement Unregister helper method

- Implement Unregister helper method, each indicator which hold a
  reference to the consolidators updating it. Adding regression
  algorithms

* Fix for QuantBook indicators

* Address reviews
2023-05-24 17:35:02 -03:00
Martin-Molinero
278401cfcf Custom data universe selection market hours (#7270)
- Custom data universe selection market hours. Adding regression test
  asserting the behavior. Updating existing tests due to market hours
  change, triggering selection always, even the 4th of July 2018
2023-05-24 13:50:43 -03:00
Jhonathan Abreu
6e7b69da44 Short call/put calendar spreads (#7269)
* Add short call calendar spread strategy and review margin calculation

* Add short Put calendar spread strategy and fixed naked short options margin calculation

* Minor changes

* Minor changes

* Minor changes
2023-05-24 13:09:31 -03:00
Martin-Molinero
b5ced1635e Chain Providers will filter expired (#7267)
- Future and option chain providers will always filter expired contracts
  from their result. Update existing tests
2023-05-23 18:33:07 -03:00
Martin-Molinero
f01ac9be3a Fix NDX index data timezone (#7268)
- Fix for NDX index data timezone
2023-05-23 17:24:21 -03:00
Jhonathan Abreu
2b045bfd35 Short straddle and strangle strategies (#7264)
* Add short straddle and strangle strategies

* Minor unit tests fixes
2023-05-23 13:39:41 -03:00
Jhonathan Abreu
96f8a89c0d Butterfly call/put spreads margin unit test review (#7266) 2023-05-23 13:35:28 -03:00
Martin-Molinero
da706dbd8e Add QuantBook memory recycle (#7263)
- Add QuantBook memory recycle timer to avoid managed memory creep
2023-05-23 10:02:54 -03:00
Martin-Molinero
c5790f3e20 Fix Collective2 future & option symbology (#7262)
* Fix Collective2 future & option symbology

- Fix collective2 future & option symbology. Adding unit tests &
  updating existing

* Minor fixes after live test
2023-05-22 19:11:45 -03:00
Jhonathan Abreu
794835772a Minor bear/bull call spreads unit tests fixes (#7260) 2023-05-22 16:03:51 -03:00
Ricardo Andrés Marino Rojas
a043313004 Change misleading error message while registering an indicator in Python (#7257)
* Solve the bug and add unit test

- The bug was raised because if something went wrong trying to register an indicator with a C# or a custom consolidator the exception raised was lost, because the catch sentence didn't return it with another exception

- A unit test was added asserting a exception with a related message was raised each time something went wrong with the consolidator

* Fix bugs and enhance unit tests

* Fix bug
2023-05-22 15:07:04 -03:00
Ricardo Andrés Marino Rojas
c9dde8a0df Improve Tradier Brokerage Model (#7256)
* Handle unsupported orders and add unit tests

- Capture more Tradier Brokerage order limitations
- Add unit tests to cover this changes

* Enhance implementation and add more unit tests

* Enhance implementation and add unit test

* Remove IsMarketOrderGTC condition

* Remove error message MarketOrderIsGtc
2023-05-22 14:59:44 -03:00
Martin-Molinero
5eb6026180 Covered and protective call put (#7258)
* Covered and Protective Call and Put

- Improve covered call and put margin requirements based on IB
- Add missing protective call and puts strategies (inversion of a
  covered call). Adding unit tests

* Fixes

* Add missing tests
2023-05-22 11:21:12 -03:00
Martin-Molinero
bbe2e31cb8 Revert "Improve Tradier Brokerage Model (#7249)" (#7254)
This reverts commit 014ec3453d.
2023-05-18 18:59:01 -03:00
Alexandre Catarino
fd76171604 Expire Instead of Clear Insights In Base PCM In OnSecuritiesChanged (#7251)
* Expire Instead of Clear Insights In Base PCM In OnSecuritiesChanged

* Fixes Regression Test

The regression was incorrect because `_removedSymbols` didn't retain the removed symbols from previous `OnSecuritiesChanged` calls, and the algorithm relances once per month. E.g. On day 1, SPY and FB were removed, on day 3 AAPL and IBM were removed and `removedSymbols` would only include AAPL and IBM.

We should hve fixed this problem before with:

```csharp
if (_removedSymbols == null) _removedSymbols = new List<Symbol>();
_removedSymbols.AddRange(changes.RemovedSecurities.Select(x => x.Symbol));
```

However the change to use Expire fixes the issue.

* Removes Unused List of Removed Symbols
2023-05-18 11:20:17 -03:00
Ricardo Andrés Marino Rojas
a1d5b1bd31 Change misleading message when order is not large enough for Binance brokerage (#7252)
* First attempt to fix the bug

* Enhance Message returned and unit tests

* Enhance implementation and unit tests

* Nit change
2023-05-18 10:38:28 -03:00
Martin-Molinero
dba6a04196 Improve handling of invalid order update & cancel (#7247)
- Avoid exceptions when updating or cancelling an invalid order. Adding
  unit tests reproducing the issue
2023-05-18 10:37:03 -03:00
Ricardo Andrés Marino Rojas
014ec3453d Improve Tradier Brokerage Model (#7249)
* Handle unsupported orders and add unit tests

- Capture more Tradier Brokerage order limitations
- Add unit tests to cover this changes

* Enhance implementation and add more unit tests

* Enhance implementation and add unit test
2023-05-18 10:21:54 -03:00
Ricardo Andrés Marino Rojas
0db0f10ee9 Fix potential bug in KrakenOrderProperties (#7248)
* Fix potential bug and add more docs

As FeeInBase and FeeInQuote are mutually exclusive, if one was set to true, the other one should be set to false. It was added information about where it's used and how fee currency selection works in Kraken.

* Nit change

* Simplify XML docs
2023-05-15 19:19:31 -03:00
Martin-Molinero
1a22f20340 Avoid expiring insights twice (#7243)
- Avoid expiring insights twice. Adding unit test
2023-05-15 10:01:07 -03:00
Martin-Molinero
5c078cd2a9 Remove 'data-directory' usage (#7241) 2023-05-12 18:24:12 -03:00
Martin-Molinero
08e1f31271 Minor live logging improvements (#7240) 2023-05-12 18:13:37 -03:00
Ricardo Andrés Marino Rojas
7f15202dfc Fix bug in LeastSquaresMovingAverage (#7238)
* Fix bug and fix unit test

* Enhance unit test

* Simplify LSMA.ComputeNextValue()
2023-05-11 14:55:27 -03:00
Ricardo Andrés Marino Rojas
4e56af487c Fix bug in RandomDataGenerator for Option data at Minute resolution (#7237)
* Fix the bug and add unit tests
- The bug was raised by different conditions.

First, the tick created in tick generator for Open Interest was not of type Open Interest.

Second, TickAggregator.cs was made to use daily resolution for OpenInterest always.

Third, the RandomValueGenerator, generated a random friday as expiration date for the option created but this one needed first two underlying data points, so if the expiration date was before the start date plus 3 days, RandomDataGenerator just generated OpenInterest data for the option.

* Add docs
2023-05-11 12:54:45 -03:00
Vinh Hung Nguyen
3bb390779b Add Missing Python Version of TickDataFilteringAlgorithm (#7219) (#7222)
* Add Missing Python Version of TickDataFilteringAlgorithm (#7219)

* Change to SecurityDataFilter

* Modify PR #7222

* Address reviews

* Minor improvement

---------

Co-authored-by: Ricardo Andrés Marino Rojas <47573394+Marinovsky@users.noreply.github.com>
Co-authored-by: hungv <hungv@compatibl.com>
Co-authored-by: Martin-Molinero <martin@quantconnect.com>
2023-05-10 19:48:54 -03:00
Jhonathan Abreu
f12bcb39a6 Unit tests for OptionStrategyPositionGroupBuyingPowerModelTests (#7234)
* Add option strategy position group BPM tests

Tests added for calculating order quantity for a delta buying power

* Add option strategy position group BPM margin calculation tests

* Add option strategy position group BPM margin calculation tests

* Add option strategy position group BPM margin calculation tests

* Add option strategy position group available BPM calculation tests

* Add option strategy position group impact buying power calculation

* Housekeeping

* Unit tests improvements

* Unit tests improvements

* Add more unit tests

* Address peer review
2023-05-10 19:47:26 -03:00
Derek Melchin
17639c399d Update Numerai Demo Algorithms (#7233)
* Update Numerai Demo Algorithm

* Remove Numerai demo algorithms that use portfolio state

* Address review
2023-05-03 20:16:34 -03:00
Martin-Molinero
fbca273807 Add forward data only fill model example (#7232)
* Add forward data only fill model example

- Add forward data only custom fill model C# & PY example.
- Minor adjustment for 'MarketOrderFillTimeout' to be zero always in
  backtesting

* Address reviews
2023-05-03 16:16:03 -03:00
Martin-Molinero
e838319a56 Update readme.md 2023-05-02 16:24:22 -03:00
Martin-Molinero
884bfe4482 Add support for brokerage side new orders (#7228)
* Add support for brokerage side new orders

- Add support for brokerage side new order events for liquidation cases

* Minor cash delta fix

* Improve account cash logging

* Fix null reference exception for open orders
2023-05-02 16:21:19 -03:00
Ricardo Andrés Marino Rojas
416d38271b Solve bugs in BrokerageModelPythonWrapper.cs (#7229)
* Implement ShortableProviderPythonWrapper.cs

- Modify AllShortableSymbolsCoarseSelectionRegressionAlgorithm.cs and ShortableProviderOrdersRejectedRegressionAlgorithm.cs to use ShortableProvider from Security and not from the Brokerage model
- Add SetShortableProvider() overload method in Security.cs to set a custom shortable provider from Python
- Remove AllShortableSymbols() method from LocalDiskShortableProvider.cs
- Remove DefaultShortableProvider class
- Add regresion algorithms in C# to cover the changes done

* Revert "Merge process"

This reverts commit 775a4b8ec1, reversing
changes made to bcc3e790f6.

* Revert "Revert "Merge process""

This reverts commit aa18fb40ee.

* Solve bugs

- Solve bugs in DefaultMarkets, CanUpdateOrder() and CanSubmitOrder() methods from BrokerageModelPythonWrapper.cs
- Add regression algos in both Python and C# to cover the changes

* Catch potential errors and add unit tests

* Add more unit tests

* Nit change

* Enhance implementation, add more unit tests
2023-05-02 15:09:16 -03:00
Martin-Molinero
b657365da7 Add IndexOptionPriceVariationModel (#7227)
* Add IndexOptionPriceVariationModel

- Add IndexOption price variation model to handle price based minimum
  price variation. Adding unit tests

* Minor improvements for VIX & VIXW
2023-05-02 11:23:20 -03:00
Louis Szeto
991ac4595f Improves Export Signal Algorithms (#7210)
* Update Collective2PortfolioSignalExportDemonstrationAlgorithm

* Update Collective2SignalExportDemonstrationAlgorithm

* Update CrunchDAOPortfolioSignalExportDemonstrationAlgorithm

* Update CrunchDAOSignalExportDemonstrationAlgorithm

* Update NumeraiPortfolioSignalExportDemonstrationAlgorithm

* Update NumeraiSignalExportDemonstrationAlgorithm

* Address peer review

* Add logic to handle warm up

* Update unit test statistics
2023-05-01 12:14:54 -03:00
Martin-Molinero
a7516b80ea Daily future cash settlement (#7226)
* Refactor settlement mode api

- Add new Scan method on ISettlementModel API. To be used by
  futures settlement model mark to market handling
- Use 'Parameters' classes for 'ISettlementModel'

* Address reviews

* Daily future settlement

- Implement daily future settlement. Adding unit & regression tests

* Address reviews

* Assert cash balance every day
2023-05-01 11:25:37 -03:00
Martin-Molinero
8b2eb5bd68 Refactor Settlement Model API (#7225)
* Refactor settlement mode api

- Add new Scan method on ISettlementModel API. To be used by
  futures settlement model mark to market handling
- Use 'Parameters' classes for 'ISettlementModel'

* Address reviews
2023-05-01 11:23:31 -03:00
yuriyarabskyyPro
6ce418ca5c Add missing side multiplier in returns per trade chart (#7224)
* Add missing side multiplier

* Minor build fix

---------

Co-authored-by: Yuriy Arabskyy <yuriy.arabskyy@gmail.com>
Co-authored-by: Martin-Molinero <martin@quantconnect.com>
2023-05-01 11:16:41 -03:00
Jhonathan Abreu
c61b8da167 Add contractDepthOffset parameter to History methods (#7213)
* Add contractDepthOffset parameter to every history api method overload

* Address peer review
2023-04-27 14:31:42 -03:00
Jhonathan Abreu
c8890c3da9 Multiple option position groups liquidation (#7221)
* Fix multiple option strategies liquidation

When holding multiple position groups of the same underlying, reverting
one of the groups was not possible because of the presence of the other
position groups, which caused no matching groups to be formed for the
order.

* Make OptionStrategyPositionGroupResolver not group single position

* Revert make OptionStrategyPositionGroupResolver not group single position
2023-04-27 14:29:30 -03:00
Louis Szeto
baf2dbcefa Add example algorithm on brokerage activities (#7214)
* Add example algorithm on brokerage activities

* Add brokerage activities event handlers on live feature algorithm

* add boolean flag
2023-04-27 14:17:58 -03:00
Ricardo Andrés Marino Rojas
4d5e0fb73a Modify OpenInterestFutureUniverseSelectionModel to work with Python (#7220)
* Implement ShortableProviderPythonWrapper.cs

- Modify AllShortableSymbolsCoarseSelectionRegressionAlgorithm.cs and ShortableProviderOrdersRejectedRegressionAlgorithm.cs to use ShortableProvider from Security and not from the Brokerage model
- Add SetShortableProvider() overload method in Security.cs to set a custom shortable provider from Python
- Remove AllShortableSymbols() method from LocalDiskShortableProvider.cs
- Remove DefaultShortableProvider class
- Add regresion algorithms in C# to cover the changes done

* Revert "Merge process"

This reverts commit 775a4b8ec1, reversing
changes made to bcc3e790f6.

* Revert "Revert "Merge process""

This reverts commit aa18fb40ee.

* Solve bug

- Add new constructor overload in OpenInterestFutureUniverseSelectionModel.cs that accepts future chain symbol selector as PyObject
- Add a private static method in OpenInterestFutureUniverseSelectionModel that converts Python lambda function to Func<DateTime, IEnumerable<Symbol>>
- Add a regression algorithm in Python to cover changes. In these case, add Python version of OpenInterestFuturesRegressionAlgorithm.cs

* Nit changes

* Nit change

* Minor docs tweak

---------

Co-authored-by: Martin-Molinero <martin@quantconnect.com>
2023-04-27 10:04:10 -03:00
Oleksii Rychko
3122edcaf9 RBI brokerage setup (#7216)
* Added RBIBrokerageModel, RBIFeeModel

* added RBIOrderProperties, added RBI to BrokerageName, config.json

* feature: changed config.json

* fix: changed config.json and UnsupportedOrderType message

---------

Co-authored-by: m00nler <91968598+m00nler@users.noreply.github.com>
Co-authored-by: raideNNdev <raideNNdev@proton.me>
2023-04-27 10:03:04 -03:00
Martin-Molinero
1965a2868d Update readme.md 2023-04-26 10:03:31 -03:00
Ricardo Andrés Marino Rojas
3e86712c1a Implement ShortableProviderPythonWrapper.cs (#7209)
* Implement ShortableProviderPythonWrapper.cs

- Modify AllShortableSymbolsCoarseSelectionRegressionAlgorithm.cs and ShortableProviderOrdersRejectedRegressionAlgorithm.cs to use ShortableProvider from Security and not from the Brokerage model
- Add SetShortableProvider() overload method in Security.cs to set a custom shortable provider from Python
- Remove AllShortableSymbols() method from LocalDiskShortableProvider.cs
- Remove DefaultShortableProvider class
- Add regresion algorithms in C# to cover the changes done

* Implement ShortableProviderPythonWrapper.cs

- Modify AllShortableSymbolsCoarseSelectionRegressionAlgorithm.cs and ShortableProviderOrdersRejectedRegressionAlgorithm.cs to use ShortableProvider from Security and not from the Brokerage model
- Add SetShortableProvider() overload method in Security.cs to set a custom shortable provider from Python
- Remove AllShortableSymbols() method from LocalDiskShortableProvider.cs
- Remove DefaultShortableProvider class
- Add regresion algorithms in C# to cover the changes done

* Solve bugs and nit change

* Address review

---------

Co-authored-by: Martin-Molinero <martin@quantconnect.com>
2023-04-25 19:55:44 -03:00
Jhonathan Abreu
8943dc6535 Add dataNormalizationMode parameter to every history api method overload (#7208) 2023-04-25 17:19:39 -03:00
Vinh Hung Nguyen
c8a646c0f0 Feature 7182 missing python version crypto future algorithms (#7206)
* Solve Report Generation Conversion Rate Error bug (#7183)

* Solve bug

Remove if sentence that checked if Portfolio contained securities that
needed a conversion, like Forex, Crypto or Cfd. It didn't take into
account CryptoFutures so when the backtest result used that kind of
security types it never found a conversion for them. Making a git blame
for Report.PortfolioLooper constructor it was found the if sentence was
not needed so it was removed and then different reports were made for
algorithms that used security types different than Forex,Crypto,Cfd and
CryptoFutures to check everything was still working as expected.

* Solve bug

Remove if sentence that checked if Portfolio contained securities that
needed a conversion, like Forex, Crypto or Cfd. It didn't take into
account CryptoFutures so when the backtest result used that kind of
security types it never found a conversion for them. Making a git blame
for Report.PortfolioLooper constructor it was found the if sentence was
not needed so it was removed and then different reports were made for
algorithms that used security types different than Forex,Crypto,Cfd and
CryptoFutures to check everything was still working as expected.

* Missing Python Version of Crypto Future Algorithms - Issue 7128

* Address reviews

---------

Co-authored-by: hungv <hungv@compatibl.com>
Co-authored-by: Martin-Molinero <martin@quantconnect.com>
2023-04-24 11:27:38 -03:00
Jhonathan Abreu
0b81cf0218 Add dataMappingMode parameter to History methods (#7204)
* Add dataMappingMode parameter to every history api method overload

* Minor unit tests fixes

* Update regression algorithm stats

* Minor changes

* Minor changes
2023-04-21 17:24:14 -03:00
Louis Szeto
6b1f859f5a Fixes bug in Hilbert Transform indicator (#7203)
* Fix bug on calculation, renew test data from correct TV script

* Add comment to explain changes
2023-04-21 12:01:52 -03:00
Martin-Molinero
6fb9cf8521 Cache folder usage improvements (#7200)
- Validate cache folder exists before using it
- Avoid duplication fetching factor & map files path
- Adding helper method to check if directory is empty. Adding unit tests
2023-04-20 11:24:19 -03:00
Ronit Jain
0d6abf5dde Add optimization-id for optimization backtests (#7202)
* add organizatin-id in backtests

* self review
2023-04-20 10:49:04 -03:00
Ricardo Andrés Marino Rojas
6b7be767f5 Implement SecurityDataFilterPythonWrapper.cs (#7201)
- Create `SecurityDataFilterPythonWrapper.cs`
- Modifiy `Security.cs` to set a data filter, whether is a C#, Python derivative or custom data filter custom
- Add Python and C# regression algorithms to assert the changes
2023-04-20 10:45:59 -03:00
Jhonathan Abreu
3888896ed4 Add extendedMarket parameter to History methods (#7191)
* Add extendedMarket parameter to every history api method overload

* Rename extendedMarketHours parameter

New name is extendedHours as in the History API to standarize parameters naming

* Update generic history overloads to use every matching subscription

* Update regression algorithms stats

* Centralize period-based history error for tick resolution

* Rename extended market hours parameter to extendedMarketHours

* Minor changes

* Minor changes

* Minor unit tests changes

* Minor unit tests changes

* Minor changes

* Minor unit tests changes

* Minor unit tests changes
2023-04-20 10:41:32 -03:00
Martin-Molinero
fb383dc73c Minor foundation update (#7196)
* Added PyStan Library in DockerfileLeanFoundation

* Add new libraries and unit tests

---------

Co-authored-by: Ivan Radigales Creus <ivanrdgc@gmail.com>
2023-04-19 15:19:07 -03:00
Louis Szeto
5891f44312 Implement Hilbert Tranform indicator (#7197)
* Implement Hilbert Transform Indicator

* Assign proper names to variables

fixes
https://github.com/QuantConnect/Lean/pull/7148#discussion_r1152325967
https://github.com/QuantConnect/Lean/pull/7148#discussion_r1152328259

* Add license

fixes https://github.com/QuantConnect/Lean/pull/7148#discussion_r1152336946

* Change `_v1` computation to operation instead of `FunctionalIndicator`

and more related changes
fixes https://github.com/QuantConnect/Lean/pull/7148#discussion_r1152332642

* Replace `updatesCount` with `Samples` field

* Implement `inPhase3` and `_quadrature2` as `Delay` indicators

* Minor fix to `WarmUpPeriod`

* Add descriptive names to indicators

* Reset all indicators

https://github.com/QuantConnect/Lean/pull/7148#discussion_r1152338785

* Minor fix

* Rename rest of parameters

* Implement helper method

* Renaming for LEAN's pattern

* Update 3rd party data source

* Refactor and fix bug on HT calculation

* Fix unit test's logic

---------

Co-authored-by: Alexander Myltsev <alexander.myltsev@gmail.com>
2023-04-19 14:41:05 -03:00
Martin-Molinero
841e6f12c2 Update readme.md 2023-04-18 19:14:27 -03:00
Martin-Molinero
afabedbfda Update readme.md 2023-04-18 18:30:59 -03:00
Ricardo Andrés Marino Rojas
02e54d0242 Implement OptionExerciseModelPythonWrapper.cs (#7193)
* Implement `OptionExerciseModelPythonWrapper.cs`
- Modifiy `Option.cs` to set the automatic exercise model, even if it's a python custom option model exercise model
- Add `QuantConnect.Orders.OptionExercise` in `AlgorithmImports.py`
- Add regression algorithms in C# and Python showing how to specify a custom option exercise model

* Address required changes

- Remove unnecessary constructor in
´CustomOptionExerciseModelRegressionAlgorithm.cs´
- Change `.Dispose()` in `OptionExerciseModelPythonWrapper.OptionExercise(9` to ´using´ keyword
- Change `Option.SetOptionExerciseModel()` XML docs

* Minor tweaks

* Update CustomOptionExerciseModelRegressionAlgorithm.cs

---------

Co-authored-by: Martin-Molinero <martin@quantconnect.com>
2023-04-18 16:54:53 -03:00
Martin-Molinero
430b30b2ac Update readme.md 2023-04-18 15:09:23 -03:00
Martin-Molinero
c3cdeea0ee Update readme.md 2023-04-18 14:11:25 -03:00
prasom
a4f2c03015 Python ConstantAlphaModel Constructor is Missing an Argument (#7189)
* Python ConstantAlphaModel Constructor is Missing an Argument #7185

* Minor tweak

---------

Co-authored-by: Martin-Molinero <martin@quantconnect.com>
2023-04-17 20:03:49 -03:00
Martin-Molinero
d1a2b95ddc Update reserved chart names (#7190) 2023-04-17 20:02:27 -03:00
Jhonathan Abreu
f1076020af Add fillForward parameter to History methods (#7180)
* Add fillForward parameters to every History method

* Remove conflicting Python history method

* Undo removing conflicting Python history method

* Minor changes

* Minor changes

* Minor changes

* Add fillForward and extendedMarket parameters to history request factory

* Minor changes

* Minor changes

* Minor changes

* Minor changes

* Minor unit tests changes

* Rename fillForward parameter in History API

New name if fillDataForward as in the Add*Security API to standarize
parameters naming

* Rename fillForward parameter

Using the shorter fillForward in every API
2023-04-17 16:42:13 -03:00
prasom
cd88806e93 Start research returns permission denied when run inside a devcontainer in VS Code (#7139) (#7188) 2023-04-17 10:45:55 -03:00
Ricardo Andrés Marino Rojas
b5087bf42a Solve Report Generation Conversion Rate Error bug (#7183)
* Solve bug

Remove if sentence that checked if Portfolio contained securities that
needed a conversion, like Forex, Crypto or Cfd. It didn't take into
account CryptoFutures so when the backtest result used that kind of
security types it never found a conversion for them. Making a git blame
for Report.PortfolioLooper constructor it was found the if sentence was
not needed so it was removed and then different reports were made for
algorithms that used security types different than Forex,Crypto,Cfd and
CryptoFutures to check everything was still working as expected.

* Solve bug

Remove if sentence that checked if Portfolio contained securities that
needed a conversion, like Forex, Crypto or Cfd. It didn't take into
account CryptoFutures so when the backtest result used that kind of
security types it never found a conversion for them. Making a git blame
for Report.PortfolioLooper constructor it was found the if sentence was
not needed so it was removed and then different reports were made for
algorithms that used security types different than Forex,Crypto,Cfd and
CryptoFutures to check everything was still working as expected.
2023-04-13 14:43:56 -03:00
Martin-Molinero
4ad0288110 Add missing optimizer launcher reference (#7181) 2023-04-12 19:35:02 -03:00
Martin-Molinero
35469154c4 Update readme.md 2023-04-12 15:39:32 -03:00
Martin-Molinero
9c893e83a2 Minor optimizer improvement (#7179)
- Handle optimization backtest name
- Allow configurable optimizer for Optimizer.Launcher project
2023-04-12 15:35:54 -03:00
Jhonathan Abreu
8134b099fa Updated EMA indicator description (#7178) 2023-04-11 18:58:35 -03:00
Jhonathan Abreu
8d54438eac Add support for iterating FutureHistory and OptionHistory (#7176)
This adds support for accessing the history slices in research
environment
2023-04-11 18:54:58 -03:00
Martin-Molinero
b23bc870e2 Minor regression test update after EMA merge (#7177)
- Minor regression test update after EMA merge
2023-04-11 18:26:48 -03:00
Ricardo Andrés Marino Rojas
9e51f10b77 Add Feature Signal Exports feature (#7145)
* Add Collective2SignalExportClass
Add SignalExportTarget interface

* Collective2SignalExport test working

Add SignalExportManager
Add draft of CrunchDAOSignalExport

* Modify SignalExportManager

Instantiate SignalExportManager in QCAlgorithm constructor
Draft of CrunchDAOSignalExport

* Improve SignalExportManager

- Add regression tests SignalExportDemonstrationAlgorithm in C# and
  Python

* Improve SignalExportDemonstrationAlgorithm

Address requested changes in Collective2SignalExport, SignalExportManger and SignalExportTargetTests.cs

* Add CrunchDAOSignalExport.cs

Add CrunchDAOSignalExport unit tests in SignalExportTargetTests.cs

* Add NumeraiSignalExport.cs

Modify SignalExportDemonstrationAlgorithm.cs to test NumeraiSignalExport
Add unit test in SignalExportTargetTests to test NumeraiSignalExport

* Address required changes

- Add BaseSignalExport.cs
- Add SignalExportParameters.cs
- Add PortfolioSignalExportDemonstrationAlgorithm.cs/py
- Improve Error handling in SignalExport provider classes
- Collective2SignalExport now gets the correct number of shares for each holding
- SignalExportManager now computes the correct holding percentage of each portfolio target
- SignalExportManager now takes into account if the algorithm is in live mode
- Demonstration algorithms now are more simple

* Address last required changes

- PortfolioSignalExportDemonstrationAlgorithm.cs/py now inherits from SignalExportDemonstrationAlgorithm.cs/py
- Add more unit tests to assert SignalExportManager gets the correct percentage quantity for each holding
- Change Collective2SignalExport, CrunchDAOSignalExport and NumeraiSignalExport Send() method to return true if there was no error while sending the signals and false otherwise
- Nit changes

* Remove exceptions thrown

- Add more unit tests and more test cases
- Enhance BaseSignalExport.Dispose() method

* Add Collective2SignalExportClass
Add SignalExportTarget interface

* Collective2SignalExport test working

Add SignalExportManager
Add draft of CrunchDAOSignalExport

* Modify SignalExportManager

Instantiate SignalExportManager in QCAlgorithm constructor
Draft of CrunchDAOSignalExport

* Improve SignalExportManager

- Add regression tests SignalExportDemonstrationAlgorithm in C# and
  Python

* Improve SignalExportDemonstrationAlgorithm

Address requested changes in Collective2SignalExport, SignalExportManger and SignalExportTargetTests.cs

* Add CrunchDAOSignalExport.cs

Add CrunchDAOSignalExport unit tests in SignalExportTargetTests.cs

* Add NumeraiSignalExport.cs

Modify SignalExportDemonstrationAlgorithm.cs to test NumeraiSignalExport
Add unit test in SignalExportTargetTests to test NumeraiSignalExport

* Address required changes

- Add BaseSignalExport.cs
- Add SignalExportParameters.cs
- Add PortfolioSignalExportDemonstrationAlgorithm.cs/py
- Improve Error handling in SignalExport provider classes
- Collective2SignalExport now gets the correct number of shares for each holding
- SignalExportManager now computes the correct holding percentage of each portfolio target
- SignalExportManager now takes into account if the algorithm is in live mode
- Demonstration algorithms now are more simple

* Address last required changes

- PortfolioSignalExportDemonstrationAlgorithm.cs/py now inherits from SignalExportDemonstrationAlgorithm.cs/py
- Add more unit tests to assert SignalExportManager gets the correct percentage quantity for each holding
- Change Collective2SignalExport, CrunchDAOSignalExport and NumeraiSignalExport Send() method to return true if there was no error while sending the signals and false otherwise
- Nit changes

* Remove exceptions thrown

- Add more unit tests and more test cases
- Enhance BaseSignalExport.Dispose() method

* Fix failing regression tests

* Fix failing unit tests

* Nit changes

* Nit change

* Nit change

* Fix failing unit tests

* Changes required

- Break regression algos `SignalExportDemonstrationAlgorithm.cs/py` nad `PortfolioSignalExportDemonstrationAlgorithm.cs/`y` into three ones, one for each signal export provider
- Change SignalExportManager constructor to receive current algorithm as a parameter
- Fix bug in `SignalExportManager.GetPortfolioTargets()`, now it computes the correct percentage for each holding
- Make `BaseSignalExport.DefaultAllowedSecurityTypes` overrdible
- Handle case were `Collective2SignalExport.ConvertPercentageToQuantity()` returns null
- Clean unnecessary code in `Collective2SignalExport()`, `CrunchDAOSignalExport()` and `NumeraiSignalExport()`

* Nit change

* Nit change

* Minor tweaks after review

* Remove indexes from signal exports

* Required changes
- Change EMA indicators period from 200, 300 to 10,100 in regression algorithms
- Remove Indices from regression algorithms
- Add more XML documentation to regression algorithms
- Change `Log.Error` to `_algorithm.Error` in Signal export providers. Besides, fix error message format
- Change default value for `platformId` parameter in `Collective2SignalExport.cs` constructor
- Solve small bugs in SignalExportProvider when verificating the amount of porfolio targets is greater than zero and each portfolio target is allowed
- Handle case when `PortfolioTarget.Percent()` returns null in `Collective2SignalExport.ConvertPercentageToQuantity()`
- Handle error format message from Collective2 API
- Check every ticker signal is between 0 and 1 (inclusive) in `CrunchDAOSignalExport.cs`
- Modifiy `NumeraiSignalExport.cs` constructor to take into account filename given in the arguments
- Fix small bug with the return value of `ConvertTargetsToNumerai()` method in `NumeraiSignalExport.cs`
- Modify `SignalExportManager.cs` to return true when the algorithm being ran is not in live mode
- Remove indices from CrunchDAO unit tests

* Enhance ´CrunchDAOSignalExport.cs´ implementation

---------

Co-authored-by: Martin-Molinero <martin@quantconnect.com>
2023-04-11 17:45:07 -03:00
Jhonathan Abreu
ed92e6653b Fix EMA first value calculation (#7173)
* Fix EMA indicator first value calculation

As done by TALib and TradingView, the first EMA value after warmup is
the SMA of the first period.

* Update TSI indicator test data

Data was exported from TradingView

* Update TRIX indicator test data from TradingView

* Update AccumulationDistributionOscillator indicator test data from TradingView

* Update Double EMA indicator test data from TradingView

* Update McClellanSummationIndex indicator test data

* Update SchaffTrendCycle indicator test data

* Update TripleExponentialMovingAverage indicator test data from TradingView

* Update stats for algorithms using EMA

* Update failing unit tests
2023-04-11 17:43:25 -03:00
Martin-Molinero
08a1f84f91 Fix continuous futures back month contracts (#7175)
- Fix continuous futures back month contracts setting which was ignored.
  Updating regression algorithms
2023-04-11 17:42:46 -03:00
Jhonathan Abreu
8e54918378 Account for time zone on MOC orders time buffer check (#7174)
* Use UTC times when checking if MOC order is not past the allowed buffer

* Add unit test
2023-04-11 17:42:34 -03:00
Martin-Molinero
fcab09effb Update LiveTradingDataFeedTests.cs
See https://github.com/QuantConnect/Lean/pull/7169/files
2023-04-10 17:31:10 -03:00
Jhonathan Abreu
5436c72fad Handle margin call orders for position groups (#7137)
* Handle position group margin calls

* Minor changes

* Update regression algorithms

* Minor changes

* Minor changes

* Added regression algorithm

* Peer review

* Peer review

* Peer review

* Peer review

* Minor changes

* Minor changes

* Add unit test

* Allow sufficient buying power when closing position group

* Add unit test

* Improve regression algorithms
2023-04-10 12:42:08 -03:00
Martin-Molinero
f152652f5b Fix api account deserialization (#7172)
- Fix API account deserialization. Adding unit test
2023-04-10 12:38:38 -03:00
Martin-Molinero
f9bbec1e16 Remove internal subscriptions from future chain (#7169)
- Remove internal subscription from slive future chain collection.
  Adding regression algorithm reproducing the bug
2023-04-05 18:23:04 -03:00
Ricardo Andrés Marino Rojas
20c92b0350 Fix bug: Report Color Map Does Not Include Crypto Futures (#7168)
* Fix ReportCharts color_map bug

- Add ´CryptoFuture´ entry in `color_map` dict using color #E55812
- Make ´ReportCharts.py´ color_map a class attribute
- Change ´ReportChartsTests.cs´ to use color_map dict from ´ReportCharts.py´
- Add unit test that fails every time a new SecurityType is added

* Improve unit test

* Nit change

* Nit change
2023-04-05 17:51:16 -03:00
Jhonathan Abreu
375af2ebd2 Updated MHDB and CME currencies futures expiry functions (#7166)
* Updated MHDB and CME currencies futures expiry functions

Some expiry functions needed to take into consideration the security
holidays

* Add more holidays to CME securities in MHDB
2023-04-05 14:49:42 -03:00
Jhonathan Abreu
daae49cc4f Updat AlphaVantageDataDownloaderTests to make it time independent (#7167) 2023-04-05 13:00:54 -03:00
Martin-Molinero
227ade63ed Refactor automatic option assignment (#7165)
- Refactor automatic option assignment to allow overriding behavior.
  Adding & updating existing tests
2023-04-04 17:40:31 -03:00
Jhonathan Abreu
9524f48a33 Fix maximum lots calculation methods in SecurityPositionGroupBuyingPowerModel (#7163)
One of the methods was multiplying the resulting quantity times the lot
size, which is not accurate.
2023-04-04 17:29:22 -03:00
Louis Szeto
d977eb2181 Refactor MACD Alpha Model (#7140)
* Update regression test to check number of insights

* Update model to have insight manager ref and cancel insight when signal goes flat

* Update unit tests and regression tests

* Address peer review: using Insights.Clear
2023-04-04 17:22:15 -03:00
Martin-Molinero
e15614a18f Add live log limit to controls (#7162) 2023-04-04 13:57:38 -03:00
Jhonathan Abreu
2e20b4803d Accounting for the position quantity in margin requirements (#7161)
* Invalidate option strategies orders when short selling over margin

When shorting an option strategy with margin requirements that cannot be
met, the order should be invalidated. The buying power model is now able
to detect said situation and result in unssuficient buying power.

The OptionsMarginModel now uses the parameters instance values instead
of the security holdings to compute margin requirements. This fixes the
situation when calculation buying power for a first time position with
no holdings.

* Add and fix unit tests

* Update regression algorithms

* Peer review
2023-04-03 18:51:05 -03:00
Martin-Molinero
cb0c7b0814 Update KeyStringSynchronizerTests.cs 2023-04-03 14:24:41 -03:00
Martin-Molinero
645e1ca88c Downloader Data Provider Improvements (#7159)
* Downloader data provider fixes

- Fix stored data time zone, which is expected in data time zone
- Minor logging improvements
- LeanData Parse handles etf universes path. Adding unit test
- LeanDataWrite will only map if there's something to map to

* Fix download data provider synchronization

* Synchronization improvements after more testing

- KeyStringSynchronizer will handle reentrancy. Adding unit tests
- Define a unique Synchronizare for downloading data, since not related
  to disk reading & writting
2023-03-31 18:29:55 -03:00
Martin-Molinero
84bb72fddb Remove unrequired csharp debugger (#7156)
- Remove unused & outdated csharp debugger netcoredbg
2023-03-30 19:05:31 -03:00
Martin-Molinero
4d32119576 Unzip to folder from byte[] (#7152)
- Unzip data to folder from a given byte[]. Adding unit tests
2023-03-29 16:06:42 -03:00
Martin-Molinero
c836c62945 LeanDataWriter can handle mapping (#7150)
* LeanDataWriter can handle mapping

- Adjust LeanDataWrite so that it can handle symbol mapping if required.
  Adding unit tests

* Fix Lean Data path parsing
2023-03-29 16:04:23 -03:00
Alexandre Catarino
2069833361 Updates HistoricalReturnsAlphaModel to Cancel Insights Not Emit Flat (#7151)
* Updates Regression Algorithm to Assert the Number of Insights

* Updates HistoricalReturnsAlphaModel to Cancel Insights Not Emit Flat

We expect fewer insights after this change, but no changes to any regression algorithm.

* Updates Regression Algorithm

Assert the new expected number of generated insights.

* Use InsightCollection Clear Method
2023-03-29 16:03:27 -03:00
Alexandre Catarino
b46b50fa50 Adds HistoricalReturnsAlphaModelFrameworkRegressionAlgorithm (#7149) 2023-03-28 16:08:47 -03:00
Derek Melchin
4d77431ae1 Refactor RsiAlphaModel (#7125)
* Update regression tests to check consolidators are removed

* Update model

* Address review
2023-03-28 16:07:08 -03:00
Alexandre Catarino
1bce9bcb71 Improves Validates_SetEndTime Test (#7147)
Uses the "Now" in algorithm default timezone, since that's how `EndDate` is initialized in QCAlgorithm.
2023-03-28 11:01:04 -03:00
Martin-Molinero
2dc40f0477 Update readme.md 2023-03-27 19:34:09 -03:00
Martin-Molinero
403814d64f Handle error sending notification (#7146) 2023-03-27 15:31:53 -07:00
Martin-Molinero
384ec3dbad Update readme.md 2023-03-27 17:10:30 -03:00
Martin-Molinero
708d38d4e5 Update readme.md 2023-03-27 16:49:52 -03:00
Martin-Molinero
03bc23ed8c Add project id for api notification (#7144) 2023-03-27 15:59:51 -03:00
Shukri
73c26ee7ec Fix some typos (#7138)
* Fix typo

who often -> how often

Signed-off-by: hsm207 <hsm207@users.noreply.github.com>

* Fix typo

sometimes bug -> sometimes be buggy

Signed-off-by: hsm207 <hsm207@users.noreply.github.com>

* Correct number of options to run research nbs

Signed-off-by: hsm207 <hsm207@users.noreply.github.com>

---------

Signed-off-by: hsm207 <hsm207@users.noreply.github.com>
2023-03-27 10:29:52 -03:00
Martin-Molinero
ce33c393e6 Update Extensions.cs 2023-03-24 09:40:50 -03:00
Louis Szeto
279a306758 Update TrailingStopRiskManagementModel model to cancel insights (#7131)
* Update risk model to cancel insight

* Updates Regression Tests

---------

Co-authored-by: Alexandre Catarino <AlexCatarino@users.noreply.github.com>
2023-03-23 15:29:04 -03:00
Alexandre Catarino
0247b95edd Adds TrailingStopRiskFrameworkRegressionAlgorithm (#7132)
Replaces old `TrailingStopRiskFrameworkAlgorithm` for `TrailingStopRiskFrameworkRegressionAlgorithm` that inherits from `BaseFrameworkRegressionAlgorithm` as a member of the framework regression tests.
2023-03-23 13:43:09 -03:00
Jhonathan Abreu
d47e073d90 Use data end time to timestamp fundalmental data dictionaries (#7126)
* Use data end time to timestamp fundalmental data dictionaries

* Peer review
2023-03-23 13:41:03 -03:00
Louis Szeto
6d75aee0ce Add regression test for MaximumSectorExposureRiskManagementModel (#7123) 2023-03-23 12:37:30 -03:00
Martin-Molinero
bbbf6f3a74 Minor downloader data provider improvements (#7130)
- Improve start time request for daily/hour files
- Skip custom data since it's not supported by the LeanDataWriter
2023-03-23 12:27:34 -03:00
Louis Szeto
3362a976fa Avoid Invalid historical data piping in StandardDeviationExecutionModel (#7086)
* Remove invalid historical warm up in STD Execution

* refactor

* peer review

* Use `Consolidator.InputType`

* Update regression test
2023-03-23 12:24:42 -03:00
Louis Szeto
f684940a7c Update MaximumUnrealizedProfitPercentPerSecurity model to cancel insights (#7121)
* Update regression test

* Update model to expire insights

* Avoid remove insights

* Update regression test

* Use InsightManager Cancel to Expire All Insights

* Update CompositeRiskManagementModelFrameworkAlgorithm

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

---------

Co-authored-by: Alexandre Catarino <AlexCatarino@users.noreply.github.com>
2023-03-23 12:23:42 -03:00
Derek Melchin
9c92a67510 Update MaximumDrawdownPercentPortfolio model to cancel insights (#7105)
* Remove OnEndOfAlgorithm and update expected trades

* Update models to cancel insights

* Update expected results

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

* Remove `Remove` method call

* Update to use the new `Cancel` method
2023-03-23 12:02:04 -03:00
Derek Melchin
b401fde07e Update MaximumDrawdownPercentPerSecurity model to cancel insights (#7103)
* Remove OnEndOfAlgorithm and update expected trade count

* Update models to cancel insights

* Update expected results

* Remove `Remove` method call

* Update to use the new `Cancel` method
2023-03-23 11:11:27 -03:00
Martin-Molinero
7db8df3f8d Add Insight expiration helper methods (#7127)
- Add InsightManager expiration helper methods. Adding unit tests
2023-03-22 19:15:47 -03:00
Alexandre Catarino
7feb46fec5 Fixes time zone (#7128)
If we use `.astimezone(dt.tzinfo)`, the new time was convering the timezone from local (e.g. PST) to GMT (dt.tzinfo). In this case, we only want to remove the timezone to enable the operation.
2023-03-22 19:02:11 -03:00
Martin-Molinero
1c81f5d028 Update readme.md 2023-03-22 17:43:50 -03:00
Alexandre Catarino
3b2e165254 Adds BaseFrameworkRegressionAlgorithm and New Regression Algorithms (#7116)
* Renames and Updates BaseAlphaModelFrameworkRegressionAlgorithm

The `BaseFrameworkRegressionAlgorithm ` will be used for multiple framework regression tests

* Updates and Renames EmaCrossAlphaModelFrameworkAlgorithm

Adds "Regression" to inform that it's a regression algorithm.

* Updates and Renames MaximumPortfolioDrawdownFrameworkAlgorithm

Adds "Regression" to inform that it's a regression algorithm, and use the model name: `MaximumDrawdownPercentPortfolio`

* Adds New Regression Algorithms
2023-03-22 11:21:30 -03:00
Martin-Molinero
44d1454ed7 Handle downloader data provider no MHDB entry (#7115)
* Handle downloader data provider no MHDB entry

* Address review: log once
2023-03-21 17:26:09 -03:00
Martin-Molinero
a58f6b679d Minor fake data queue handler fixes (#7114)
- Minor fake data queue handler fixes. Adding unit tests
2023-03-21 15:10:03 -03:00
Alexandre Catarino
761ea2571a Adds BaseAlphaModelFrameworkRegressionAlgorithm (#7107)
* Adds BaseAlphaModelFrameworkRegressionAlgorithm

`BaseAlphaModelFrameworkRegressionAlgorithm` will be used to validate Alpha Model regression algorithm with the same universe.

- HistoricalReturnsAlphaModelFrameworkAlgorithm
- EmaCrossAlphaModelFrameworkAlgorithm
- MacdAlphaModelFrameworkAlgorithm
- RsiAlphaModelFrameworkAlgorithm
- BasePairsTradingAlphaModelFrameworkAlgorithm

* Addresses Peer-Review
2023-03-21 13:22:34 -03:00
Jhonathan Abreu
0b661e70c1 Fix combo order direction determination (#7066)
* Fix fill quantity using group order quantity for combo orders

* Add Order's ComboQuantity property

* Add Order's ComboDirection property

* Minor changes and regression algorithms update

* Minor changes

* Update algorithms stats

* Minor changes and regression algorithms update

* Store the full quantity for each combo order leg in Quantity property instead of the ratio

* Minor changes and regression algorithms update

* A few fixes after pair programming

* Handle grouping position reduction

---------

Co-authored-by: Martin-Molinero <martin@quantconnect.com>
2023-03-21 12:26:50 -03:00
Alexandre Catarino
f1d55c3b0b Improves MinimumVariancePortfolioOptimizer Values Handling (#7106)
* Improves MinimumVariancePortfolioOptimizer Values Handling

The C# version of the `MinimumVariancePortfolioOptimizer` generated NaN resulting in unit tests failing.
If the solver returns NaN for an item, we set it to zero. if all items are NaN or Zero, we return the initial guess, since the sum cannot be zero.

* Fixes `RiskParityPortfolioConstructionModelTests`

We need to add insights to insight manager before we call `CreateTargets`.
2023-03-21 11:24:58 -03:00
Alexandre Catarino
497ac8497a Fixes Consolidator Removal from Subscription Manager in Python Algorithms (#7102)
* Adds Unit Test

Asserts that we can remove a consolidator that was previously added.

* AddConsolidator Method Only Wraps Non-C# Consolidators

This behavior was implemented in `QCAlgorithm.RegisterIndicator` to avoid wrapping an object unnecessarily.
2023-03-21 11:08:49 -03:00
Martin-Molinero
1877d59daa Improve aggregation helper methods (#7100)
- Improve LeanData aggregation helper methods to use shared consolidator based implementation
- Adding Tick to tradeBar aggregation
- Adding more unit tests
2023-03-20 16:08:25 -03:00
Martin-Molinero
56881e64fe Expand result state attributes (#7097)
- Add order, insight & log count into result algorithm state
2023-03-20 15:00:57 -03:00
Martin-Molinero
52de357b27 Terminal Link Minor Fixes (#7093)
- Fix data-queue-handler configuration initialization using paper brokerage
- Fix for downloader data provider request times
- Fix null reference exception in live result handler if algorithm is
  null
2023-03-20 12:24:16 -03:00
Derek Melchin
70acb30546 Test EmaCrossAlphaModel (#7081) 2023-03-17 18:08:43 -03:00
Alexandre Catarino
7c68e3f37a Refactor Portfolio Construction Models to Use Insight Manager (#7077)
* Asserts Number of Insights In One PCM Regression Test

If the `EqualWeightingPortfolioConstructionModel` interacts with the `QCAlgorithm.Insights`, the number of elements in the collection should not the sum of emitted insights.

* Refactor Portfolio Construction Models to Use Insight Manager

`PortfolioConstructionModel` will use `QCAlgorithm.Insights" instead of class property `InsightCollection` to manage the insights. It no longer adds insights to the collection, but it removes them if they expire or the securities are removed from the universe.

Updates PCMs that were affected by the change.

* Updates Unit Tests

We need to add the insights to the insight manager before we call `PortfolioConstruction.CreateTargets`
2023-03-17 18:00:43 -03:00
Louis Szeto
8a087f2166 Change python optimizer to Newton, added unit tests and regression test (#7085) 2023-03-17 15:23:31 -03:00
Martin-Molinero
a9c88ad25c ResultHandler state file improvements (#7078)
- Adjust start/end time string format
- In live trading will store the status file at the start, every 10 min
  and at the end
2023-03-16 18:24:49 -03:00
Martin-Molinero
bc6ac5470b Minor IndexOption underlying TZ fix (#7072)
* Minor IndexOption underlying TZ fix

- Fix for option universe chain underlying TZ which might not match the
  options one, bug affected IndexOption specifically.

* Update affected regression tests
2023-03-15 18:41:52 -03:00
Martin-Molinero
06bec5fb8e Add more logs for regression tests (#7073)
- Add holdings & cashbook logs from regression result handler, useful
  for debugging & developing
2023-03-15 18:25:26 -03:00
Martin-Molinero
d6f894eb3b Fix fill forward unit tests (#7070)
- Fix for some fill forward unit tests that were failing when run
  individually due to cache state in the
  TextSubscriptionDataSourceReader.
2023-03-15 12:45:04 -03:00
Martin-Molinero
8ed5f69ea6 Minor fill forward enumerator fix (#7068)
- Make sure the fill forward enumerator does not fill forward beyond the
  subscription end time. Adding tests
2023-03-15 10:18:43 -03:00
Alexandre Catarino
1c6be6438d Removes Cash Account Restriction for Framework Algorithms (#7067)
The user will be responsible for chosing/using models that fit the brokerage account type.
2023-03-14 19:25:20 -03:00
Martin-Molinero
2f03c92e30 Fill forward runtime adjustment (#7065)
- Fix for fill forward adjustment at runtime since the data stack runs
  async, we will remove and readd afected subscriptions.
2023-03-14 18:00:22 -03:00
Martin-Molinero
069246dda5 Performance Improvements (#7064)
* Performance Improvements

- Remove Immutable collection from position groups to improve
  performance. Adding more tests
- Remove ConcurrentDictionary from PortfolioTargetCollection &
  DataManager. Adding more tests
- Add Securities enumerator keys & values cache

* Add test for PortfolioTargetCollection remove by reference
2023-03-14 12:00:42 -03:00
Jhonathan Abreu
fbf8ffd924 Handle price discontinuity on volatility models (#7058)
* Apply splits and dividends to volatility models

* Apply splits and dividends to volatility models using history requests

* Add new ScaleRaw data normalization mode

Handling the new mode in the price scale enumerator.

* DataNormalizationMode.ScaledRaw history requests

* Minor changes

* Minor changes

* Disable new normalization mode in AddSecurity methods and other minor changes

* Peer review

* Minor changes

* Peer review

* Minor changes

* Peer review

* Peer review

* Peer review

* Add scaled raw history regression algorithm

* Add more regression algorithms

* Add more regression algorithms

* Add Slice.TryGet unit tests

* Peer review

* Peer review

* Peer review

* Peer review

* Peer review

* Update algorithms stats

* Peer review

* Peer review
2023-03-13 13:11:30 -03:00
Martin-Molinero
c6322956d9 Live trading holdings key (#7043)
* Fix live trading holdings uniqueness

- Fix live trading holdings key uniqueness

* Fix existing & add new test
2023-03-13 09:51:00 -03:00
Alexandre Catarino
aab5391d80 Fixes Limit Price Above/Below Open Case (#7060)
* Adds Unit Test For Limit Price Above/Below Open

See `LimitOrderFillsAtOpenWithFavorableGap`

* Fixes Limit Price Above/Below Open

If we place a buy/sell limit order below/above the current market price in TWS it fills immediately, so we model this behavior by filling with the opening price of the first trade bar.

* Updates Regression Tests

The number of trades did not change as expected. The fills are better because orders are filling with the open price when the new condition is met.
2023-03-10 14:23:45 -03:00
Martin-Molinero
bbbab6d9a8 Refactor alpha statistics phase I (#7055)
* Refactor alpha statistics

- Refactor alpha statistics, cleaning up and simplifying no longer required calculations and scoring
- Adding new InsightEvaluator abstraction, adding C# & PY regression
  algorithms

* Optimization backtest result json converter update

* Address reviews

- Remove IAlphaHandler, move insight storage responsability to IResultHandler
  and centralizing insight collection on the QCAlgorithm.Insights to be
  reused by the framework models
- Fix portfolio turnover single day backtests and duplicate time
  sampling handling. Updating regression algorithms

* Add InsightCollection tests and minor fixes

* Adding more & improved tests
2023-03-10 13:12:23 -03:00
Alexandre Catarino
4c909f33b9 Reuse Code To Find Best Effort TradeBar (#7057)
The `LimitFill`, `LimitIfTouchedFill` and `StopMaketFill` methods require `TradeBar` data to test price levels. We create a method to serve these methods as well other methods that will require this information.

Removes `Price > 0` check for `TradeType.Trade` data. Unecessary check, since a tick price cannot be less or equal to zero.
2023-03-09 11:06:26 -03:00
Martin-Molinero
e07c6265df Run TensorflowProbability Test Alone (#7056)
- For stability run TensorflowProbability test by itself
2023-03-08 17:18:58 -03:00
Alexandre Catarino
9069246519 Fixes EquityFillModel.StopMarketFill (#7042)
* Adds Unit Tests for Stop Market Fill

These unit tests covers new scenarios:
- Cannot trigger on quote data (QuoteBar or TickRype.Quote);
- Adds missing test for tick data (TickType.Trade)
- Unfavorable gap (see QuantConnect#4545)

* Fixes EquityFillModel StopMarketFill

Use the entire tick history to find the trigger price
Fill price is the stop price, unless there is an unfavorable gap (see #4545).

* Update Regression Tests

All regression tests keep the total trades. The difference are due to the time that the stop market orders are triggered and the prices that are filled. The `StopLossOnOrderEventRegressionAlgorithm` and the `UpdateOrderRegressionAlgorithm` observe the unfavorable gap case.

* Addresses Peer-Review

* Updates Regression Test

New `OrderListHash` because of the change in the fill on open case message.
2023-03-08 16:49:34 -03:00
Louis Szeto
0ed6d7e8b0 Remove annualization in MeanVarianceOptimizationPCM (#7053)
* remove annualization

* Update python optimizer to best fit in convex problem

* rerun test

* test metric

* Add comment to explain using simple return

* Add unit test on PR
2023-03-08 14:13:38 -03:00
Louis Szeto
11c182ed16 Add McClellanOscillator & McClellanSummationIndex Indicator (#7038)
* Add `McClellanOscillator` Indicator

* Add helper class in QCAlgorithm.Indicator

* Add `McClellanSummationIndex` indicator

* typo

* Fix MSI implementation

* Address peer review

* free `MOSC` in `MSI`

* fix bug

* Minor tweaks. Addressing review

---------

Co-authored-by: Martin-Molinero <martin@quantconnect.com>
2023-03-07 16:19:24 -03:00
Martin-Molinero
a5586ba562 Enqueable Enumerator Performance Improvement (#7049)
- Refactor enqueable enumerator not to require read lock most of the
  time
2023-03-06 15:40:55 -03:00
Martin-Molinero
1393ce4c5d Performance Securities & CashBook Collections (#7050)
- Improve performance of Securities & CashBook collections
2023-03-06 15:39:32 -03:00
Alexandre Catarino
694ffbbb80 Removes PythonTools from Solution (#7044)
* Removes PythonTools from Solution

Missing removal from #6967.
It results in a runtime error if we use dotnet to list the packages:
`dotnet list ../Lean/QuantConnect.Lean.sln package`

* Update QuantConnect.Lean.sln

---------

Co-authored-by: Martin-Molinero <martin@quantconnect.com>
2023-03-06 12:44:02 -03:00
Martin-Molinero
642fe96fde Update Binance Symbol Properties DB (#7040)
- Update Binance SPDB
- Minot fix for ExchangeInfoUpdater
2023-03-03 19:41:53 -03:00
Martin-Molinero
c4433098c3 Refactor Framework Statistics (#7041)
* Refactor framework statistics

* Further insight chart cleanup
2023-03-03 19:40:29 -03:00
Martin-Molinero
38f5a9c60c Bump to pythonNet 2.0.18 (#7036) 2023-03-03 13:11:03 -03:00
Louis Szeto
f4827f2f22 Modify advance decline indicators (#7032) 2023-03-02 15:48:20 -03:00
Jhonathan Abreu
81d1bb5095 Sample exposure for non invested portfolio (#7030) 2023-03-02 15:23:10 -03:00
Jhonathan Abreu
cdcd8fdacd Apply splits to TradeBuilder (#7020)
* Apply splits to TradeBuilder

* Minor tests changes

* Minor changes

* Add regression algorithm
2023-03-02 15:15:40 -03:00
Martin-Molinero
eebe0425d8 Rollback base image to focal (#7033)
* Rollback base image to focal

* Python env blame hang & crash
2023-03-02 12:43:23 -03:00
Martin-Molinero
caadaf62b2 Update readme.md 2023-03-01 20:12:05 -03:00
Louis Szeto
19df3e1e48 Normalization of Minimum Variance Optimizer's output weight (#6999)
* Update Optimizers to use absolute total weight for budgeting

* Update regression test

* address peer review

* added remarks
2023-03-01 17:20:58 -03:00
Martin-Molinero
66c016b284 Feature foundation update (#7028)
* Foundation Update

* Adding more foundation packages

* Update existing libraries

* Further package updates

* Image cleanup

- Update base image to ubuntu 22.04
- Some clean up on dockerfile
- Remove ARM base image

* Test updates

- Minor docker file tweaks
- Update existing python environment tests

* Add more tests & fix Julia

* Remove jupyter-dash

* Remove R from foundation

* Remove Julia

* Remove Tensorforce
2023-03-01 16:30:46 -03:00
Jhonathan Abreu
0c77be0ba8 Allow closed orders tag update (#7016)
* Allow closed orders tag update

* Minor changes
2023-02-27 18:42:24 -03:00
Wayne Adams
47bfdae372 docs: updates python version in vs instructions (#7014) 2023-02-27 10:19:02 -03:00
Jhonathan Abreu
3a2cae037f Fix UniverseDefinitions.ETF|Index overloads (#7006)
* Fix UniverseDefinitions.ETF|Index methods call ambiguity

* Minor changes
2023-02-24 16:35:35 -03:00
Martin-Molinero
b9e6781c96 Add missing exchanges (#7011)
* Add missing exchanges

- Add missing exchange definitions

* Fix and add more tests
2023-02-24 16:31:51 -03:00
Alexandre Catarino
2a6771c1c0 Fixes Liquidate Existing Holdings Behavior for SetHoldings for Multiple Targets (#7009)
* Adds Regression Test

The new regression test asserts that the total trades is 2.

* Fixes Liquidate Existing Holdings Bug

Liquidate existing holdings before open new postions.

* Addresses Peer-Review
2023-02-24 14:46:12 -03:00
Martin-Molinero
56270464cc IsOption Use Underlying Holidays and Early Closes if Empty (#7007)
* IsOption uses underlyings holidays

- Option assets will use underlyings holidays, early closes and late
  opens if their own are not defined

* Update regression algorithms
2023-02-24 12:49:51 -03:00
Alexandre Catarino
8bcd588602 Fixes EquityFillModel.FillModel (#7005)
* Adds Unit Tests

The `LimitFill` method should not fill using `QuoteBar` or `Tick` with `TickType.Quote` type.
Adds missing test for tick data (`TickType.Trade`).

* Fixes EquityFillModel.FillModel

Use `Tick` with `TickType.Trade` or `TradeBar` information to fill limit orders.

* Update Regression Test Expected Statistics

The regression tests changed because of different fills.
The `ExtendedMarketTradingRegressionAlgorithm` has different number of trades because of an extra fill on the 4th order generated by TradeBar with a Low lower than than the QuoteBar.Ask Low:

> 20230222 13:56:24.251 TRACE:: Log: Time: 10/10/2013 12:01:00 OrderID: 4 EventID: 2 Symbol: SPY Status: Filled Quantity: 10 FillQuantity: 10 FillPrice: 143.8998 USD

> asset.Cache.GetData<QuoteBar>().ToString()
"SPY: Bid: O: 144.2457 Bid: H: 144.2629 Bid: **L: 144.2457** Bid: C: 144.2629 Ask: O: 144.2543 Ask: H: 144.2889 Ask: **L: 144.2543** Ask: C: 144.2889 "

> asset.Cache.GetData<TradeBar>().ToString()
"SPY: O: 144.2543 H: 144.4532 **L: 143.4156** C: 144.2716 V: 75423"

* Improves Tick Resolution Unit Test

* Fixes Tick Resolution Case Handling

`master` only considers the latest trade, missing possible fills in the batch of trades.

* Adds Unit Test for Gap

See https://github.com/QuantConnect/Lean/issues/963

* Addresses Fill Optimistic Assumption

If we have a bar that gaps in our favor, we accept the limit price to avoid optimitic fills.

* Fixes Regression Tests

All regression tests with limit orders have worst performance after we remove the optimitic assumption, and use the limit price instead.
2023-02-24 10:35:34 -03:00
Alexandre Catarino
9cd05e9f1f Fixes BasePairsTradingAlphaModel (#7003)
* Updates the PearsonCorrelationPairsTradingAlphaModelFrameworkAlgorithm

Change the `PearsonCorrelationPairsTradingAlphaModelFrameworkAlgorithm` logic to show that it doesn't remove the consolidators used in the Alpha Model's indicators.

* Fixes `BasePairsTradingAlphaModel`

The `BasePairsTradingAlphaModel` will create indicators with class constructors and register them to consolidators that will be removed when the security is removed from the universe.

* Addresses Peer-Review
2023-02-24 10:20:01 -03:00
Jhonathan Abreu
40bff6efb7 Oanda trading hours update (#6998)
* Update Oanda's Forex and Metals CFDs trading hours in the MHDB

* Fix failing unit tests

* Update regression algorithm statistics

* Fix failing unit tests

* Minor changes
2023-02-24 10:14:55 -03:00
Jhonathan Abreu
f5e8966eea Uset GoodTilDate TIF for MOO and MOC orders (#7001)
* Uset GoodTilDate TIF for MOO orders

* Uset GoodTilDate TIF for MOC orders

* Add one-time warning for TIF validation
2023-02-23 17:38:44 -03:00
Ronit Jain
1596ed9846 remove force breakpoint (#7004) 2023-02-23 12:41:52 -03:00
Martin-Molinero
c1c4114dca Newtonsoft & Protobuf & RecyclableMemoryStream Updates (#7002)
* Dependency updates

- Update Newtonsoft to 13.0.2, protobuf to 3.2.0, RecyclableMemoryStream
  to 2.3.1

* Downgrade protobuf to 3.1.33
2023-02-23 12:11:01 -03:00
abhi-kr-2100
6acbcf0832 Brokerage Models Order Supported Types Check (#6989)
* Fix Issue #6937

Some brokerage models don't check the order type in `CanSubmitOrder`.
As a result, unimplemented order types don't cause `CanSubmitOrder`
to return false as it should.

This commit fixes these issues for:
* `FTXBrokerageModel.cs`
* `InteractiveBrokersBrokerageModel.cs`
* `SamcoBrokerageModel.cs`
* `TradierBrokerageModel.cs`
* `ZerodhaBrokerageModel.cs`

Brokerage implementations can be found at
https://github.com/orgs/QuantConnect/repositories. For example, the
Zerodha Brokerage implementation is available at
https://github.com/QuantConnect/Lean.Brokerages.Zerodha.

Signed-off-by: Abhishek Kumar <abhi.kr.2100@gmail.com>

* Use HashSet instead of an array

Checking if an object is contained within a HashSet is faster than
checking the same in an array.

Signed-off-by: Abhishek Kumar <abhi.kr.2100@gmail.com>

* Minor adjustments and normalization

* Add missing OptionExercise for IB

---------

Signed-off-by: Abhishek Kumar <abhi.kr.2100@gmail.com>
Co-authored-by: Martin-Molinero <martin@quantconnect.com>
2023-02-21 13:11:04 -03:00
Jhonathan Abreu
5675e71a32 Handle prices getting stuck on data generation (#6995)
* Handle prices getting stuck on data generation

* Add more unit tests
2023-02-21 13:09:31 -03:00
Martin-Molinero
48914b08db Chart Series Settings Lost (#6997)
* Fix live trading chart series index

- Fix Series loosing their index when handled by the
  LiveTradingResultHandler
- Some clean up for Series.cs

* Fix SeriesSampler loosing Series settings
2023-02-21 13:07:56 -03:00
Martin-Molinero
852c963bbf Remove unsupported HKFE from MHDB (#6990)
* Remove HKFE from MHDB

- Remove unsupported HKFE from MHDB

* Update tests
2023-02-20 20:19:42 -03:00
Alexandre Catarino
99848a1221 Adds NullBuyingPowerModel (#6977)
* Adds NullBuyingPowerModel

The `NullBuyingPowerModel` considers that we have sufficient buying power for all orders.

Adds example using a bull call spread since a equity buy and hold would not show the impact of this model in the position group buing power model.

* Define NullBuyingPowerModel.GetMaintenanceMargin

The `NullBuyingPowerModel.GetMaintenanceMargin` returns a `MaintenanceMargin` of zero. It means the total margin used is always zero and margin calls will not be triggered.

This feature is inspired on the  `ConstantBuyingPowerModel`. We don't inherit from that class, because `ConstantBuyingPowerModel.GetInitialMarginRequirement` gives us very small initial margin that leads to a very large quantity if we use `SetHoldings` or `CalculateOrderQuantity`
2023-02-20 19:50:24 -03:00
Martin-Molinero
7178be4f55 Remove Yahoo auxiliary data generator (#6993)
- Remove yahoo auxiliary data generator and failing tests
2023-02-20 19:23:31 -03:00
Martin-Molinero
017837c5a5 Remove Oanda cash account support (#6994)
- Oanda only supports margin account types
2023-02-20 19:21:50 -03:00
Martin-Molinero
c7294adfe4 Fix OrderQuantityLessThanLotSize typo (#6991) 2023-02-20 19:21:25 -03:00
Martin-Molinero
61fb997f07 Delete unsupported AlgoSeek Option Converter (#6992)
- Delete unsupported algoseek option converter
2023-02-20 19:21:15 -03:00
Alexandre Catarino
7cc6e31c43 Fixes Insight Period Calculation (#6978)
The calculations of `CloseTimeUtc` are correct and consistent: if the exchange is closed when the insight expires, `CloseTimeUtc` is the next open.

However, the definition of the `Period` was not consistent. Normally, it is defined by the different between `CloseTimeUtc` and `GeneratedTimeUtc`, but when we create an Insight with the Resolution and bar count overload, the period was defined by them:

```csharp
insight.Period = Resolution.ToTimeSpan().Multiply(BarCount);
```

which is incorrect, since it doesn't take the days the exchange is closed into account. The `ComputePeriod` method enforced consistency between the Resolution and bar Count overload and the `DateTime` overload, so the period for this overload was also incorrect.
2023-02-20 16:23:13 -03:00
Alexandre Catarino
b5ca1ac461 Removes UncorrelatedUniverseSelectionModel (#6976)
Framework models must have a C#, and Python implementation and algorithms that use them.
2023-02-20 16:21:53 -03:00
Jhonathan Abreu
2a54da9e2c Custom data type history API usage in Python (#6971)
* Custom data type history request in python

* Potential solutions

* Minor changes

* Use Slice.Get(Type) for getting python custom data history

* Minor changes

* Add unit tests

* Add unit tests

* Udpdate regression algorithms

* Peer review

* Peer review

* Add research regression tests

* Minor changes

* Minor changes

* Minor tweaks

---------

Co-authored-by: Martin-Molinero <martin@quantconnect.com>
2023-02-20 16:21:37 -03:00
Martin-Molinero
6fd1a002fe Adjust index option data timezone (#6970)
* Fix index option data timezone

- Fix index option data timezone which was 1 hour late than expected

* Update existing index option tests

- Update existing index option tests.
- Disable index option daily resolution support
2023-02-16 17:35:10 -03:00
Martin-Molinero
ace1a1f20d Define MaximumContractDepthOffset (#6969) 2023-02-16 17:23:56 -03:00
Martin-Molinero
75f86f555e Delete unused PythonToolbox (#6967) 2023-02-16 17:23:38 -03:00
Martin-Molinero
20655b334b Update readme.md 2023-02-15 15:16:55 -03:00
Martin-Molinero
3507c91640 Fix future daily price scale factor update (#6963)
* Fix future daily price scale factor update

- Fix future daily price scale factor update which was happening 1 day
  late due to data and exchange time zone differences.
  Adding regression algorithm reproducing and asserting it.

* Address review
2023-02-14 20:09:59 -03:00
Jhonathan Abreu
ebb31d0fb4 Unsettled cash conversion rate update (#6961)
* Update unsettled cashbook cash conversion rates

Also moved conversion rate holding from Cash to the CurrencyConversion
instance

* Minor fixes

* Peer review

* Minor fixes

* Minor fixes

* Minor fixes
2023-02-14 18:19:25 -03:00
Ronit Jain
dcd60d0551 Add support for HTML reports conversion to PDF (#6960)
* add wkhtmltopdf to lean image

* convert html to pdf

* avoid black stripts at bottom of each page

* address reviews

* address review

* address reviews

* self review

* address review
2023-02-14 15:50:19 -03:00
Martin-Molinero
dc2c68c754 Fix security cache reset (#6959)
* Fix security cache reset

- Fix security cache reset so it only happens when no universe has it as
  a member. Adding regression algorithm reproducing issue

* Avoid non deterministic FillForward behavior
2023-02-14 12:09:27 -03:00
Jhonathan Abreu
2791765c94 Make Consolidate Calendar overload with tick type public (#6957) 2023-02-13 16:01:30 -03:00
Martin-Molinero
f270f25eca Fix default future chain universe selection (#6958)
* Fix default future chain universe selection

- Fix default future chain universe selection that should always return
  empty, no selection. In some cases it would allos some contracts
  though. Adding regression algorithm reproducing issue.

* Address review
2023-02-13 15:56:48 -03:00
Martin-Molinero
8235de42a0 Minor debugging improvements (#6954)
* Minor debugging improvements

- Improve exception message if user provides empty/null ticker
- Log margin information on algorithn initialization
- Add unit test asserting option strategy position groups resolve
  correctly for existing holdings

* Symbol Lazy SecurityDefinitionSymbolResolver

- Symbol will have a lazy SecurityDefinitionSymbolResolver instance
  resolution
2023-02-13 10:49:10 -03:00
Martin-Molinero
c2e21df18b Fix combo order prechecks (#6953)
- Apply combo order prechecks before submitting orders. Adding unit test
2023-02-10 19:11:45 -03:00
Jhonathan Abreu
35dfcd73ab Index options MHDB review (#6890)
* Index options MHDB review

* Update MHDB

* Update regression algorithms stats

* Update regression algorithms stats

* Add index and index options holidays

* Peer review

* Update algorithms stats
2023-02-10 14:37:44 -03:00
Jhonathan Abreu
3783900eef Move Brokerages namespace's messages to Messages folder (#6915) 2023-02-10 13:49:15 -03:00
Jhonathan Abreu
9fea859323 Symbol to industry-standard security identifier conversion (#6893)
* Implement SecurityDefinitionSymbolResolver backwards conversion (symbol -> standard id)

* Peer review

* Peer review

* Peer review
2023-02-10 13:12:13 -03:00
Jhonathan Abreu
6e2744af7c Move Securities namespace's messages to Messages folder (#6922)
* Move Securities namespace's messages to Messages folder

* Rebase related fixes

---------

Co-authored-by: Martin-Molinero <martin@quantconnect.com>
2023-02-10 11:31:11 -03:00
Martin-Molinero
962b91fc12 Fix Messages namespace collision 2023-02-10 10:50:03 -03:00
Louis Szeto
cf00d3c9f3 OptionStrategies for put calendar spread index weeklies example (#6951) 2023-02-10 10:44:47 -03:00
Louis Szeto
8af5c8b6f2 OptionStrategies for put butterfly index weeklies example (#6950) 2023-02-10 10:42:40 -03:00
Louis Szeto
1fcef8c024 OptionStrategies for Index Option Call Butterfly (#6949)
* OptionStrategies for call butterfly index weeklies example

* fix typo
2023-02-10 10:42:07 -03:00
Jhonathan Abreu
a912638496 Move QuantConnect namespace's messages to Messages folder (#6924) 2023-02-10 10:41:05 -03:00
Jhonathan Abreu
5611b5508a Binance crypto futures fee models (#6874)
* Add Binance Futures and Binance Coin Futures fee models

* Add unit tests

* Add unit tests

* Minor changes

* Peer review

* Peer review
2023-02-09 19:25:27 -03:00
Jhonathan Abreu
b3bd15d3c2 Move Notifications, Optimizer and Python namespaces' messages to Messages folder (#6931) 2023-02-09 19:23:39 -03:00
Jhonathan Abreu
25ab8bdacc Move small namespaces' messages to 'Messages' folder (#6930)
* Move Benchmarks, Exceptions and Indicators namespaces' messages to Messages folder

* Move Command namespace's messages to Messages folder
2023-02-09 19:17:40 -03:00
Jhonathan Abreu
38c5ef3e2b Add CME Ether futures to symbols database (#6884)
* Add Ether futures to symbols database

* Change ETH futures exchange time zone to US/Central

* Add new contracts FuturesExpiryFuntions

* Remove BTIC Micro BTC and BTIC Micro Ether securities

* Add Ether futures IB fees and price multiplier entry

* Update Ethereum price multiplier
2023-02-09 18:42:19 -03:00
Jhonathan Abreu
194f01e621 Move Algorithm namespace's messages to Messages folder (#6916) 2023-02-09 18:35:29 -03:00
Martin-Molinero
61b5231c50 Research GetOptionHistory Weekly Index Improvement (#6946)
- Improve research GetOptionHistory weekly index option support. Adding
  unit test
2023-02-09 18:35:20 -03:00
Louis Szeto
4a06fcdda0 OptionStrategies for Index Option Bull Put Spread (#6945) 2023-02-09 16:10:14 -03:00
Louis Szeto
8325fd18ca OptionStrategies for Index Option Bull Call Spread (#6944) 2023-02-09 16:07:43 -03:00
Louis Szeto
2bc8783082 OptionStrategies for Index Option Bear Put Spread (#6943) 2023-02-09 16:07:00 -03:00
Louis Szeto
0d9f011758 OptionStrategies for Index Option Bear Call Spread (#6942) 2023-02-09 16:06:12 -03:00
Jhonathan Abreu
6dfc6c710c Add algorithm parameters to result (#6878)
* Add algorithm parameters to result's AlgorithmConfiguration

* Peer review
2023-02-09 12:55:30 -03:00
Jhonathan Abreu
e30232e21b Portfolio.UnsettledCashBook update when quote currency is not the account currency (#6871)
* Tracking unsettled cash for non-USD account currency

* Add unit tests

* Peer review

* Move and rename CashBook.UpdateType to Globals
2023-02-09 12:53:52 -03:00
Louis Szeto
8730eeb8a9 Volume Renko Consolidator & Bar (#6888)
* Volume Renko Consolidator & Bar

* address peer review

* Minor fix on tests

---------

Co-authored-by: LouisSzeto <hke0073@hotmail.com>
2023-02-09 10:46:02 -03:00
Jhonathan Abreu
914485c595 Rename SubscriptionRequest.TradableDates to TradableDatesInDataTimeZone for clarity (#6892)
Usages were reviewed to make sure all of them expect it to be in data
time zone instead of exchange time zone
2023-02-08 20:28:37 -03:00
Jhonathan Abreu
02f085ee9e Validate date on security identifier generation (#6897) 2023-02-08 20:26:37 -03:00
Martin-Molinero
f4cf7b6733 Fix SPXW option strategies (#6939)
- Fix SPXW option strategies. Adding regression algorithm
2023-02-08 20:24:30 -03:00
Jhonathan Abreu
d427970762 Check minimum Forex limits in IB Brokerage Model (#6881)
* Checking both min and max forex order size limits in IB brokerage model

Also updated the limits table

* Address peer review
2023-02-08 16:40:18 -03:00
Jhonathan Abreu
66ff14b3bd Patch for missing tick data in history call (#6932)
* Patch for missing tick data in history call

* Update TODO comment to include info on the proposed solution
2023-02-06 13:50:59 -08:00
Jhonathan Abreu
a7a4af6b70 Add Security.SetMarginInterestRateModel methods and its python wrapper (#6879) 2023-02-06 07:57:55 -08:00
Alexandre Catarino
b1a6aa686c Replace Nodes Endpoint in SDK (#6899)
* Adds `project/nodes` Endpoint to SDK

* Removes `nodes` Endpoint from SDK

* Fixes Documentation for `ProjectNodesResponse`
2023-02-05 09:35:11 -08:00
Louis Szeto
14b10f5e81 Add example of bull/bear call spread using index option (#6889)
* Add example of bear call spread using index option

* consistency

* Add bull call spread

* peer review

* peer review

* address peer review

* bug fix

* fix filter

* Address peer review
2023-02-02 13:01:47 -08:00
Louis Szeto
4d85f27f00 Add bull/bear put spread sample algorithms for index weeklies (#6914)
* bear put spread

* bull put spread
2023-02-02 12:34:26 -08:00
Louis Szeto
c2efa65048 Add Call/Put Butterfly sample algorithms for index weeklies (#6913)
* Add index weeklies' Call/Put Butterfly sample algo

* Address peer review
2023-02-02 12:34:04 -08:00
Louis Szeto
75eaf21e43 Add example algo of call & put calendar spread with SPXW (#6907)
* Add example algo of call calendar spread with SPXW

* Add similar example for put calendar spread

* Refine

* consistency

* address peer review

* fix bug

* bug fix

* update

* Improved efficiency

* Address peer review
2023-02-02 12:33:17 -08:00
Louis Szeto
72a6ea9d31 Add SPXW Iron Condor example algorithm (#6880)
* Add SPXW Iron Condor example algorithm

* review

* peer review

* Address peer review
2023-02-02 12:26:34 -08:00
Jhonathan Abreu
2b9662c12e Fix quote tick python consolidate call (#6876) 2023-01-26 18:22:34 -08:00
Jhonathan Abreu
98314d98ed User-facing messages organization (first phase) (#6912)
* Move user-facing order-related messsages to the Messages class

* Group Messages by class

* Move more orders messages

* Minor changes and docs
2023-01-26 16:14:57 -08:00
Jhonathan Abreu
a860cfc32f Combo orders reduced size validation (#6864)
* Combo order legs ratio validation

* Minor changes and unit tests

* Minor changes

* Minor changes

* Minor changes

* Minor changes
2023-01-16 21:11:08 -03:00
Martin-Molinero
6563d6e394 Use any resolution for chain provider (#6860)
* Use any resolution for chain provider

- Use any data resolution available to source symbols for the file based
  chain provider. Adding unit test

* Fix selection timezone bug

- Fix universe selection timezone bug. Updating regression algorithms
2023-01-16 16:10:07 -03:00
Martin-Molinero
11cc062628 Combo limit orders price calculation (#6858)
* Fix limit price calculation for combo limit orders fills

* Update regression algorithms

* Address reviews

* Fix thread race condition

Co-authored-by: Jhonathan Abreu <jdabreu25@gmail.com>
2023-01-13 18:02:25 -03:00
Alexandre Catarino
e8b95b80e1 Polygon Handles Data Subscriptions with One Security Type (#6855)
* Handles Data Subscriptions with One Security Type

Polygon sells data subscriptions for security types separately, so we should not test whether the users have all three subscriptions, Equity, Forex, and Crypto. Users just need the type they will use.

Adds new crypto markets, and unit tests for them. Adapt unit test.

* Fixes ToolBox Downloader

Adds `--api-key` argument.
Closes #6687

* Address reviews

Co-authored-by: Martin-Molinero <martin@quantconnect.com>
2023-01-12 17:37:29 -03:00
Martin-Molinero
a52822853d Expand Index option support (#6849)
* Expand Index option support

- Adjust APIs so that the same underlying can be used
  for different options, adding support for SPX weekly options. Adding
  regression tests

* Fix IndexOption.IsStandard

* Add IndexOption test
2023-01-12 16:39:02 -03:00
ChadBett
73e46cc9ae TensorFlow Placeholder Fix (#6852)
Fixed this error from happening when running this code:

tf.placeholder() is not compatible with eager execution.
  at placeholder
    raise RuntimeError("tf.placeholder() is not compatible with "
 in array_ops.py: line 3341
  at NetTrain
    xs = tf.compat.v1.placeholder(tf.float32 in /QuantConnect/backtesting/./cache/algorithm/project/main.py: line 57
2023-01-11 11:18:47 -03:00
Ronit Jain
a9c4d29776 Feature add algorithm state information in result packets (#6839)
* add state to backtesting result packets

* self review

* add state in live results

* set runtime error in algorithm

* set hostname in job packets

* Set state when algorithm is null

* address review

* address reviews

* set runtime error when algorithm is not available during runtime
2023-01-11 10:54:38 -03:00
Jhonathan Abreu
6ed8cb5cae Backtest progress calculation (#6847)
* Fix backtest progress calculation

* Backtest progress monitor class

* Minor changes

* Lazy calculating the processed days count

* Minor changes

* Minor changes
2023-01-11 10:33:38 -03:00
Jhonathan Abreu
1d1dc07dfb Set DataNormalizationMode on AddSecurity method (#6845)
* Set DataNormalizationMode on AddSecurity method

* Minor changes
2023-01-10 13:03:00 -03:00
Jhonathan Abreu
bddebe279d Algorithm asserting options stategy orders with large quantities (#6843) 2023-01-09 14:21:16 -03:00
Martin-Molinero
81a334c525 Add Leg.Create method (#6842)
- Add Leg.Create method for sugar syntax, specially for python
2023-01-09 14:20:32 -03:00
Martin-Molinero
af26b66481 Update readme.md 2023-01-06 21:10:08 -03:00
Martin-Molinero
d7ead851a1 Update readme.md 2023-01-06 19:27:32 -03:00
Martin-Molinero
f428398900 Update readme.md 2023-01-06 19:22:07 -03:00
Martin-Molinero
19483702f8 Update readme.md 2023-01-06 18:36:42 -03:00
Martin-Molinero
146be2d0ba Update readme.md 2023-01-06 18:09:40 -03:00
Jhonathan Abreu
b54281b262 Combo orders (#6813)
* Feature combo orders

- Add support for combo orders

* Make fill model wait for all grouped orders to emit fills

* Add ComboFill to model multiple fills for combo orders

* Fill combo limit orders

Add some regression algorithms

* Add fill implementation for combo leg limit orders

* Add IFill as common interface for Fill and ComboFill

* Refactor combo orders removing IGroupOrder interface

Move the group order manager to the base Order class

* Update algorithms

* Handle combo order events atomically

* Refactor brokerage transaction event handler

* Refactor combo fill models

* Process fills in batch

* Combo orders fill model tests

* Combo leg limit orders algorithm

* Regression algorithms cleanup

* Fill and combo fill classes cleanup

* Housekeeping

* Refactor equity fill model to derive from base fill model

* Address review changes request

* Handling the new types of orders in the OrderJsonConverter

* Add regression algorithm to test combo orders update/cancel

* Add regression algorithm to test combo orders update/cancel

* Housekeeping

* Address review changes request

* Minor changes

* Security transaction handler method for setting order request id

* Extend public interface for placing combo orders

* Combo order tickets demo algorithm python version

* Tweaks and updates

* Minor fixes

* Minor changes

* Minor fixes

* Address reviews minor fixes

* Minor fixes

Co-authored-by: Martin-Molinero <martin@quantconnect.com>
2023-01-06 17:58:43 -03:00
Martin-Molinero
f12e8fc08e CryptoFutures adjustments (#6836)
* CryptoFutures adjustments

- Address reviews of CryptoFutures:
- Add new Slice MarginInterestRates collection
- Add new regression tests asserting funding rate application behaves
  the same no matter the resolution
- Add auxiliary data by type into the security cache
- Revert BuyingPowerModel changes

* Make interest rate application time deterministic
2023-01-05 18:07:01 -03:00
Alexandre Catarino
6b6ca5b460 Saves Dividend Payments to Security Holdings (#6830)
* Saves Dividend Payments to Security Holdings

Saves information about dividend payments to `SecurityHoldings`. This information will be used to factor in dividend payments to the `Profit` and `NetProfit`.
Adds `SecurityPortfolioManager.TotalNetProfit` to sum all the `SecurityHoldings.NetProfit`.

Adds regression and unit tests.

* Addresses Peer-Review

Improves Regression Test.
2023-01-03 18:37:00 -03:00
Martin-Molinero
ab4c3bf55e Live margin interest rate bug (#6833)
* Fix for live MarginInterestRate

* Add unit tests
2023-01-03 14:13:11 -03:00
hsm207
9c69ee5536 Update link to Lean CLI getting started (#6832) 2023-01-02 11:14:06 -03:00
Alexandre Catarino
89493b1546 Adds Pre-Market for LBS (#6831)
The lumber pre-opening window is from 6am to 9am Chicago.
https://www.cmegroup.com/trading-hours.html#foi=F&search=Lumber
2022-12-30 18:00:07 -03:00
Martin-Molinero
ee683933a3 Feature Perpetual Crypto Futures (#6807)
* WIP

* Add base currency cash

* Symbol properties and data processing

* Add basic template algorithm

* Add hourly crypto future algorithm

* Minor fixes after live trading testing

* CoinApiDataQueueHandler CryptoFuture support

* Address reviews

* Fix regression algorithms after update
2022-12-30 13:58:11 -03:00
Martin-Molinero
e87c98def8 Update readme.md 2022-12-28 15:39:59 -03:00
Martin-Molinero
239406ef5c Update ib gateway to latest (#6819) 2022-12-28 15:35:52 -03:00
Martin-Molinero
e13066273c Update readme.md 2022-12-26 17:25:34 -03:00
Martin-Molinero
7677b99bf6 Handle OnOptionNotification race condition (#6821)
- Handle OnOptionNotification race condition to take into account sell
  orders too. Updating unit tests
2022-12-26 17:21:51 -03:00
Ronit Jain
c21dd716ed use data channel property (#6826) 2022-12-26 15:23:18 -03:00
Martin-Molinero
f87eb88f27 Update holidays Christmas New Years 2022/23 (#6824) 2022-12-26 13:58:05 -03:00
Martin-Molinero
1d363e2c35 Fix brokerages tests order id update (#6822)
- Fix for brokerage test brokerage order id update handling
2022-12-22 20:02:35 -03:00
Martin-Molinero
98273097e5 Update readme.md 2022-12-22 10:43:39 -03:00
Martin-Molinero
cbdf25d713 Update readme.md 2022-12-21 21:19:44 -03:00
Martin-Molinero
dcfdbd8c82 Add OnOrderIdChangedEvent (#6816)
* Add OnOrderIdChangedEvent

- Add OnOrderIdChangedEvent so that brokerages can change the brokerage
  order ids on the original order directly

* Fix bug
2022-12-21 20:53:39 -03:00
Louis Szeto
b5b317f490 Basic template algorithm for continuous futures rollover (#6803)
* Basic template algorithm for continuous futures rollover handling

* update regression metric

* Update to multi-contract versions

* SymbolData implementation

* minor bug

* peer review

* order hash

* more abstraction
2022-12-20 11:37:32 -03:00
Martin-Molinero
0eecf5d139 Update gh-actions.yml 2022-12-20 11:12:43 -03:00
Alexandre Catarino
bc513ce0e7 Changes Crumb Location from Yahoo Downloader (#6812)
Yahoo has changed the location from the crumb which is no longer located in "CrumbStore",
2022-12-20 10:33:52 -03:00
Roman Yavnikov
019ce5aa76 TDAmeritrade brokerage fix (#6806)
* remove: support SecurityType.Future

* add SecurityType.Index and IndexOption
fix: error message in orderType support

* Update TDAmeritradeBrokerageModel.cs

Co-authored-by: Martin-Molinero <martin@quantconnect.com>
2022-12-16 19:47:03 -03:00
Martin-Molinero
c4329c4132 More resilient object store file read (#6800) 2022-12-13 15:25:47 -03:00
Roman Yavnikov
9618c376bf Feature tdameritrade brokerage setup (#6791)
* TDAmeritrade LEAN integration

* feature: update order model for TDAmeritrade brokerage
fix: typos

* fix: typo in license

* refactor: remove extra multiple op

* refactor: TDAmeritrade naming api-key

* remove: extra configs

* fix: PR comment

* Rename file

* feature: add to config `SubscriptionDataReaderHistoryProvider`

* remove: extra logic

* Address review

Co-authored-by: Martin-Molinero <martin@quantconnect.com>
2022-12-12 18:14:21 -03:00
Alexandre Catarino
3aabb11315 Allows Market-On-Close Orders Outside Buffer Period (#6769)
* Allows Market-On-Close Orders Outside Buffer Period

Market-On-Close orders can be submitted before and after the buffer period from 15:45 to 16:00 (Tested with TWS) meaning that we can submit MOC when the market is closed and, consequently, use daily resolution data.

* Adds Regression Test with Extended Market Hours

- Removes `nextMarketClose > Time` condition since it's unnecessary. If the algorithm Time is greater than the close of that day, `nextMarektClose` refers to the next day.

* Updates Unit Test

Updates `OrderQuantityConversionTest` because the MOC orders are submitted. They are placed at 7 pm and invalid before this pull request.

* Updates Summary of new Regression Tests
2022-12-08 19:46:58 -03:00
Jhonathan Abreu
4d2723f851 Update CME options scaling factors (#6774) 2022-12-06 16:41:04 -03:00
Jhonathan Abreu
86b74e0a09 Add IB weekly restart time entry to config file (#6773) 2022-12-06 14:52:46 -03:00
Jhonathan Abreu
41a730bc68 OTM option excerise orders improvements (#6767)
* Set fill price to zero in OTM exercise orders.

Improved the OTM exercise orders message.

* Update regression algorithms and unit tests

* Add IsInTheMoney property to OrderEvent

* Update SerializedOrderEvent

* Properly setting the option exercise order price to strike price or zero

* Minor changes

* Minor changes
2022-12-06 14:30:40 -03:00
Jhonathan Abreu
6b2dfb6b8c Update equity default settlement days (#6766) 2022-11-28 13:26:56 -03:00
Jhonathan Abreu
7a4ca7898e Add estimate option to optimizer for optimization estimate (#6763)
* Add 'estimate' option to optimizer launcher

* Add 'estimate' option to optimizer launcher

* Unit tests and minor tweaks

* Minor tweaks
2022-11-25 19:08:28 -03:00
Mathieu Paquette
60028ad48a fix(ToolBox/IQFeed): increase default buffer size (#6762)
fixes #6761
2022-11-25 10:40:52 -03:00
Derek Melchin
e9d690b35a Add missing </summary> tag (#6760) 2022-11-23 10:20:27 -03:00
Alexandre Catarino
db2cb57a3f Handles NaN or Infinity from QLNet Calculations (#6757) 2022-11-18 18:25:13 -03:00
Jhonathan Abreu
3c784e5b04 Revisit futures contract multipliers (#6753) 2022-11-18 18:24:45 -03:00
Jhonathan Abreu
31f8561330 Allow optional selector in classic renko consolidator in Python and C# (#6755) 2022-11-18 17:14:03 -03:00
Martin-Molinero
38b87d941a Update readme.md 2022-11-18 14:36:51 -03:00
Alexandre Catarino
83d59b5f9a Removes Volatility Model Warm Up Requirement (#6752)
* Fixes Regression Algorithm Testing No Warm Up Requirement

* Removes Volatility Model Warm Up Requirement

If the volatiliy model is not ready, we will use the Brenner and Subrahmanyam (1988) approximation (BS88).
Lean will not set the volatility model if the user doesn't, since the BS88 can handle the null model case.
2022-11-18 14:34:56 -03:00
Martin-Molinero
f19d8cb700 Add missing exchanges (#6754)
* Add missing exchanges

* Add missing conversion handling
2022-11-18 14:11:13 -03:00
Martin-Molinero
fcee43b56e Update readme.md 2022-11-17 14:38:14 -03:00
Martin-Molinero
7898e74148 Update readme.md 2022-11-17 13:50:31 -03:00
Louis Szeto
b34cea4458 Calculate Option Greeks with Implied Volatility (#6720)
* Using IV to calculate Greeks, and remove single-step stochastic approximation

* Correct calculation for theta, vega, rho

* Add calculation from Black Calculator and peer review

* Address peer review and added unit test

* Update some tests and correct vega/eho

* Fix Unit Test and Improve Comments

Fixes `IndexOptionCallITMGreeksExpiryRegressionAlgorithm` since `Vega` was really non-zero.

* Fix regression test and add IV calculation

* refactor and bug fixing on peer review

* refactor and bug fixing on peer review

* for rerun test

* add warning on IV estimation not coveraged and edit speed unit test to not exceed 2s per 1000 iteration

* update logging

* update logging and description

* Add default option pricing models and unit tests

* address review

* Added Fed interest rate as risk-free rate with unit tests and set as default for option greeks calculation, added regression algorithms, addressed peer review

* refactor structure of interest rate

* Skip Saturday and Sunday

* regression test fix

* peer review

* Fixes Interest Rate Provider Logic

* Minor tweaks

* Fix start date

* Minor test tweak

* Update interest rates

* Fix unit tests

* Add minor log

Co-authored-by: Alexandre Catarino <AlexCatarino@users.noreply.github.com>
Co-authored-by: Martin-Molinero <martin@quantconnect.com>
2022-11-17 13:35:42 -03:00
Jhonathan Abreu
e9edb8ac29 Fix IndicatorExtensions for Python indicators (#6748)
* Fix using python custom indicators with extensions

* Minor changes to the algorithm

* Address PR comments
2022-11-16 18:36:46 -03:00
Jhonathan Abreu
33c57bbde4 Use selector on indicator warm up (#6746) 2022-11-15 19:59:59 -03:00
Jhonathan Abreu
94b9b13530 Make PlotIndicator able to receive IndicatorBase (#6745)
* Make PlotIndicator able to receive IndicatorBase

* Minor changes
2022-11-15 11:49:55 -03:00
Jhonathan Abreu
682b9aa760 Restrict index and cash-settled options exercise in IB brokerage (#6744)
* Limit exercise in IB brokerage for limit and cash-settled options

* Add regression algorithm

* Assert that index option is automatically exercised in regression algorithm
2022-11-15 11:03:43 -03:00
Jhonathan Abreu
98c6023748 Forbid european options exercise before expiry (#6734)
* Forbid european options exercise before expiry

* Minor tweaks

* Minor tweaks to tests
2022-11-11 19:32:44 -03:00
Martin-Molinero
dacc679d42 Wolverine brokerage setup (#6733)
* Wolverine LEAN integration

* Wolverine Lean integration - adjusting comments and restrict to Equity only

* fix 0.005$ per share fee

* remove PostOnly from Wolverine as its not needed

* AccountType.Margin and also removed check for USD only currency

* fix Market Wolverine -> USA

* change config

* Minor tweaks

Co-authored-by: Mark Virchenko <mark.virchenko@redduck.io>
2022-11-10 17:59:36 -03:00
Jhonathan Abreu
3e76716b07 Fix ppply options filter on market open only when using OnlyApplyFilterAtMarketOpen (#6731) 2022-11-10 12:46:09 -03:00
Jhonathan Abreu
55b09a1ea6 Data monitor (#6725)
* Data monitor (FIRST TEST)

* Calculate data request frequency in data monitor

* Detecting universe data usage in data monitor

* Json data monitor report generation

* Data monitor refactor

* Log and store data monitor report

* Data monitor report tests

* Clean up

* Clean up

* Address changes request

* Address changes request

* Wire data monitor only for backtest, not for live or research

* Minor tweaks

* Some minor tweaks

Co-authored-by: Martin-Molinero <martin@quantconnect.com>
2022-11-09 17:38:34 -03:00
Martin-Molinero
5539e27905 Fix tradier default config (#6727)
- Tradier brokerage is no longer a history provider, after refactor https://github.com/QuantConnect/Lean.Brokerages.Tradier/pull/7
2022-11-08 15:55:15 -03:00
Martin-Molinero
42ed7cf2a7 Update readme.md 2022-11-08 12:17:56 -03:00
Martin-Molinero
62d1321d74 Object Store Limit Validation (#6726)
- Minor object store limit validation on saving a new entry
2022-11-08 11:51:16 -03:00
Derek Melchin
0fa2ea19bc Reset trailing stop model highwater mark upon security liquidation (#6724)
* Fix trailing stop reset

* Add regression algorithm
2022-11-07 17:46:46 -03:00
Martin-Molinero
e155f620e1 Update readme.md 2022-11-03 11:23:15 -03:00
Alexandre Catarino
897e16c484 Changes SuperTrend Indicator Type from TradeBarIndicator to BarIndicator (#6717) 2022-11-01 10:19:13 -03:00
Martin-Molinero
6477b40661 Fix Options Strategies Names (#6715)
- Minor fix for options strategies names. Update regression algorithm
  order hash due to tag
2022-10-31 15:17:07 -03:00
Derek Melchin
5bfe2491c3 Add Sortino indicator (#6696)
* Add sortino indicator and helper indicators

* Address review

* Address review
2022-10-28 18:12:33 -03:00
Martin-Molinero
03f1bacd3f Update readme.md 2022-10-25 17:23:55 -03:00
Martin-Molinero
9849a11933 Update readme.md 2022-10-25 14:22:41 -03:00
Martin-Molinero
8e6dd5a338 Update readme.md 2022-10-25 12:45:15 -03:00
Martin-Molinero
2738c0f006 Refactor multi IDQH frontier (#6709)
* Refactor multi IDQH frontier

- Fix for multi IDQH frontier support, specially for IB + QC
- Adding new CompositeTimeProvide. Adding unit tests

* Adjust solution to fix new data available event
2022-10-25 11:59:21 -03:00
Martin-Molinero
a0c4d7b741 Update readme.md 2022-10-24 12:02:49 -03:00
Martin-Molinero
7095dc1559 Update gateway to 1019 (#6706)
- Update gateway to latest 1019
- Fix bug in IB data subscription limit, not applying when using
  multiple data queue handlers
2022-10-24 12:01:13 -03:00
Jhonathan Abreu
2d7afa798a Make NDAX use the same fill model as the other crypto brokerages (#6705) 2022-10-21 16:42:42 -03:00
Martin-Molinero
b8bcc4796f Create directory & replace link (#6704) 2022-10-21 15:55:10 -03:00
Martin-Molinero
0fc9555121 Update readme.md 2022-10-21 15:22:35 -03:00
Martin-Molinero
45e13bb35b Memory Related Performance improvements (#6700)
* Memory Related Performance improvements

- Make sure we cleanup & dipose of python related objects during pandas
  data generation.
- Disable memoizing enumerable use while creating pandas data frames,
  since we do not require it
- Reduce unrequired object creations
- Replace concurrentCollections for ordinary locks

* Decimal parsing typo fix
2022-10-21 15:11:18 -03:00
Martin-Molinero
5773d29419 Research Libraries Fixes (#6702)
- Replace old conda libc for OS version
- Remove unrequired LD_LIBRARY_PATH added for a mono issue at https://github.com/QuantConnect/Lean/pull/5380
2022-10-21 15:09:44 -03:00
Jhonathan Abreu
8f3bdcfe6c Fix adding Python additional paths in research (#6699)
* Add python additional paths for research

* Delegate adding additional paths to pythonpath to PythonInitializer

* Add new way to keep algorithm location at the beginning of pythonpath

* Add switch to disable BeginAllowThreads in PythonInitializer

* Add switch to disable BeginAllowThreads in PythonInitializer

* Address changes request
2022-10-21 12:11:10 -03:00
Alexandre Catarino
736e5d1fe0 Adds Support to Visual Studio Code Dev Container (#6680)
* Adds Support to Visual Studio Code Dev Container

Adds support and documentation to VSCode Dev Container.

* Address Peer Review

- Adds Dockerfile to install QuantConnect Stubs to enable Python autocomplete.
- Adds settings.json to enable Python autocomplete and LF line ending.
- Removes autobuilder task.
- Fixes Research Laucher

* Launcher and Task Impromevents

Fixes line endings issue
Fixes Launcher to point to right config.json file
Improve readme formatting

* Simplify Jupyter Notebook Deployment
2022-10-19 16:41:57 -03:00
Alexandre Catarino
c5e5de3416 Fixes Index Option Assignment Simulation (#6697)
Cash settlements do not open a position for the underlying, so we don't need to calculate the cost of closing the position.
2022-10-19 10:45:55 -03:00
Martin-Molinero
39735941ec FillForward delisting handling (#6692)
- In some rare cases the FillForwardEnumerator was missing to register
  the delisting date of an asset because it was the first data it got.
  Adding unit test reproducing issue
2022-10-14 20:29:40 -03:00
Martin-Molinero
fc6835cace Normalize time in universe behavior (#6693)
* Normalize time in universe behavior

- Normalize Option & Future chain universe behavior regarding their
  assets time in universe. They will now respect the universe settings
  time in universe value. Adding new regression algorithms asserting the
  behavior

* Address reviews & cleanup
2022-10-14 15:13:59 -03:00
Derek Melchin
dba0fd0824 Update description (#6691) 2022-10-13 20:21:52 -03:00
Martin-Molinero
a0fd2b193f Option greeks improvements (#6690)
- Update QLNet library to latest version from 6/2019 -> 11/2021
- Fix evaluation date which was using settlement date. Adding unit tests
  reproducing issue
2022-10-13 20:00:17 -03:00
Martin-Molinero
0fa471f4e5 Resource related improvements (#6683)
- Add resource controls logs
- Make sure the OS CPU performance counter thread is only created when
  desired, not in research
2022-10-12 17:25:56 -03:00
Martin-Molinero
b899aa4767 Make UserDefinedUniverse thread safe (#6682)
- Make UserDefinedUniverse thread safe. Adding regression test
2022-10-12 15:06:01 -03:00
Martin-Molinero
fed1b6e780 Add pyvinecopulib to foundation (#6679)
- Adding pyvinecopulib to foundation. Adding unit test
2022-10-11 16:30:57 -03:00
Martin-Molinero
f528c39700 Foundation update (#6677)
- Add new python packages to foundation images. Adding tests
2022-10-10 20:03:33 -03:00
Jhonathan Abreu
6a0fdd63a8 Add algorithm directory before any additional paths to pythonpath (#6674) 2022-10-06 20:04:47 -03:00
Alexandre Catarino
ca4187290b Normalize Algorithm EndDate Initilization (#6672)
Use `SetEndDate` to set `EndDate` in `QCAlgorithm` constructor. It will ensure that the `EndDate` is independent of the time the algorithm is executed if `SetEndDate` is not called in `Initilaize`.

Some users don't implement `SetEndDate` to run the algorithm to the latest datapoint, but this is not true if we run the algorithm during the day as the latest datapoint will be 24 hours before the execution time while there is data until the current day midnight.
2022-10-05 20:20:16 -03:00
Jhonathan Abreu
a0491a9b74 python-additional-paths config file setting (#6667)
* Add python-additional-paths setting in config file

* Configure python additional paths in JobQueue instead of PythonInitializer
2022-09-30 16:52:17 -03:00
Alexandre Catarino
abeb841a0c Adds Additional Condition to Parse SecurityIdentifier Properties (#6658)
* Adds Additional Condition to Parse SecurityIdentifier Properties

A string can pass the previous conditions and create an invalid `SecurityIdentifier` (e.g. "Sharpe ration").  If it is invalid, the Market is not supported (e.g. "378").

* Adds Unit Test to Pandas Indexing

* Log Only Once if TryParseProperties Cannot Parse

Use cache to increase speed and remove redundant logging
2022-09-29 10:13:45 -03:00
Martin-Molinero
783805ccf9 Allow running start from python (#6662)
* Allow running start from python

- Allow running start.py from python as well as IPython, so C# can be
  called. Adding unit test

* Address review
2022-09-28 12:57:47 -03:00
Alexandre Catarino
848d812bf2 Fixes Buying Power Model Selection for Cash Account (#6652)
`DefaultBrokerageModel` was selecting `CashBuyingPowerModel` for securities not supported by this model as it only supports Crypto and Forex.
2022-09-26 12:50:08 -03:00
Derek Melchin
96b07e6916 Add PyObject overload to ETFConstituentsUniverseSelectionModel (#6616) 2022-09-26 12:47:25 -03:00
Martin-Molinero
7796868da7 Fix research image typo (#6650)
Fix research image typo
2022-09-22 10:58:23 -03:00
Martin-Molinero
108bfa6c0a Enable debugging worker threads (#6647)
- Enable debugging worker threads in python
2022-09-21 16:29:37 -03:00
Martin-Molinero
7f44c3d605 Update readme.md 2022-09-19 19:34:02 -03:00
Martin-Molinero
59eae963be Fix order cancel using order ticket (#6640)
- If cancel request failed, allow user to retry. Adding unit test
  reproducing the issue
2022-09-19 18:36:51 -03:00
Louis Szeto
c48979e986 Remove alpha stream from docker image (#6638) 2022-09-19 17:48:07 -03:00
Martin-Molinero
e54fe3ae95 Pin clr loader version (#6641) 2022-09-19 17:04:24 -03:00
Martin-Molinero
ee685ea045 Add new python libraries to foundation (#6629) 2022-09-19 13:20:54 -03:00
Ryan Russell
11f13be75b docs(VixDualThrustAlpha): readability improvements (#6632)
* docs(VIXDualThrustAlpha): `determine` fixup

Signed-off-by: Ryan Russell <git@ryanrussell.org>

* docs(VixDualThrustAlpha): `unsubscribe` fixup

Signed-off-by: Ryan Russell <git@ryanrussell.org>

Signed-off-by: Ryan Russell <git@ryanrussell.org>
2022-09-19 13:17:18 -03:00
Ryan Russell
188506b5da docs(ShareClassMeanReversionAlpha): dollar-neutral fixup (#6631)
Signed-off-by: Ryan Russell <git@ryanrussell.org>

Signed-off-by: Ryan Russell <git@ryanrussell.org>
2022-09-19 13:17:10 -03:00
Ryan Russell
ca83e8443f docs(BasicTemplateIndiaIndexAlgorithm): readability fixups (#6633)
* docs(BasicTemplateIndia): `Prperties` -> `Properties`

Signed-off-by: Ryan Russell <git@ryanrussell.org>

* docs: `Intialization` -> `Initialization`

Signed-off-by: Ryan Russell <git@ryanrussell.org>

Signed-off-by: Ryan Russell <git@ryanrussell.org>
2022-09-19 13:16:54 -03:00
Ryan Russell
ac0cdb20f5 docs: formatted readability fix (#6627)
Signed-off-by: Ryan Russell <git@ryanrussell.org>

Signed-off-by: Ryan Russell <git@ryanrussell.org>
2022-09-16 17:32:44 -03:00
Ryan Russell
a131a4849a docs: automatic readability fixes (#6626)
Signed-off-by: Ryan Russell <git@ryanrussell.org>

Signed-off-by: Ryan Russell <git@ryanrussell.org>
2022-09-16 17:32:28 -03:00
Jhonathan Abreu
31b603593d Get history for a specific bar type in Python (#6611)
* Get history of a given bar type in python

* Separate GetDataFrame in sub methods to avoid dynamic type resolution

* Housekeeping and unit tests update

* Use all requests in python type method history method

* Address changes request

* Reverted some requested changes
2022-09-13 10:26:47 -03:00
Jhonathan Abreu
f62f110b1b Handle non-unique multi-index error in history dataframe creation (#6617)
* Handle non-unique multi-index error for Ticks in data frame creation

* Update unit tests

* Update unit tests and add comments

* Add regression algorithm
2022-09-08 19:40:57 -03:00
Derek Melchin
ede2991823 Add ETF universe selection model and example algos (#6604)
* Add ETF universe selection model and example algos

* Address review

* address peer review
2022-09-07 21:32:51 -03:00
Martin-Molinero
3b65f4b9a1 Fix micro crude oil future expiration (#6614)
* Fix micro crude oil future expiration

- Fix micro crude oil future expiration. Adding unit test

* Add MicroCL for ExpiriesPriorMonth
2022-09-07 21:06:28 -03:00
Alexandre Catarino
f755b91158 Fixes PythonData.EndTime (#6602)
* Fixes PythonData.EndTime

The `EndTime` property of `PythonData` didn't override the base implementation in `BaseData`. Therefore `EndTime` was always set as `Time`.

Fixes Regression Tests
- The C# version of `Bitcoin` class needs to implement `EndTime`-
- Fixes regression tests

* Minor tweaks and rebase

- Add support for python data types just setting EndTime. Adding unit
  tests for PythonData
- Fix for DynamicData EndTime property being fetched. Updating unit
  tests

Co-authored-by: Martin-Molinero <martin@quantconnect.com>
2022-09-07 14:53:05 -03:00
Martin-Molinero
7d1cd79618 Fix warmup live time zone (#6612)
- Fix live trading warmup timezone issue. Adding unit test
- Adding useful configuration values to main config.json
2022-09-02 18:30:46 -03:00
Martin-Molinero
a0ba23a7f0 Update readme.md 2022-09-02 17:24:35 -03:00
Jhonathan Abreu
4415468d96 Update CME futures market hours (#6607)
* Update CME futures market hours

* Update regression algorithms stats

* Update regression algorithms stats

* Update expected values in unit tests

* Additional mhdb updates

* Update mhdb
2022-09-02 12:33:50 -03:00
Louis Szeto
dff92ac85e Fix BlackLittermanPortfolioConstructionModel (#6603)
* Remove redundant dimension that throw error

* Fix bug

* Fix bug

* Add dimension test

* Fix test and bug

* Fix python bug

* Address peer review

* Update python workflow

* Update python and test
2022-09-01 16:43:23 -03:00
Martin-Molinero
dc4a903727 Fix ObjectStore limits enforcement (#6609)
- Fix object store limits enforcement. Adding unit tests
2022-09-01 13:52:11 -03:00
Martin-Molinero
5e7651f699 Update dotnet interactive (#6608) 2022-09-01 12:43:02 -03:00
Martin-Molinero
fcd48ecdbb Object Store Improvements (#6605)
- Fix for cache behavior, finer grained writting and loading
- Add Keys and Clear to the object store API. Adding tests
2022-08-31 20:50:00 -03:00
Martin-Molinero
8e8aa74fb0 Add project id to algorithm (#6600)
- Add projectId for algorithm usage
2022-08-30 20:56:28 -03:00
Jhonathan Abreu
548a6998e3 Report generation with non-default algorithm settings (#6589)
* Add algorithm settings to backtest results

* Use algorithm result settings in report generation

* Add unit tests

* Housekeeping

* Changes for live result report

* Housekeeping

* Housekeeping

* Housekeeping

* Add unit tests
2022-08-30 19:23:25 -03:00
Jhonathan Abreu
9a062e4b5d Include trades and quotes in tick history request (#6595)
* Include both quotes and trades in Tick history request

* Regression algorithm

* Housekeeping

* Housekeeping
2022-08-30 19:03:11 -03:00
Jhonathan Abreu
82f2aa7a63 Parsing all currencies in a number with currency (#6599)
* Correctly stripping out currency symbol from numbers with currency

* Fixes
2022-08-30 19:02:21 -03:00
Martin-Molinero
46aa62bd0c Improve object store key support (#6598) 2022-08-30 18:18:50 -03:00
Martin-Molinero
250230e79f Global object store (#6594)
* Refactor object store

* Address reviews

* Simplify implementation

- Remove base64 encoding
- Refactor object store api to allow a single path argument

* Fix bug

* Adjust storage controls

* Fix unit tests
2022-08-30 16:40:01 -03:00
Martin-Molinero
0be339d75f Update python install instructions (#6590) 2022-08-26 18:51:32 -03:00
Martin-Molinero
3eb2b94070 Minor logging improvements (#6588)
- Add virtual env name in init log
- Log account type with cashbook
- Consolidate job handlers log. Adding DataProvider
2022-08-26 14:18:28 -03:00
Louis Szeto
b655bd776e Addition of Risk Parity Portfolio Construction Model (#6577)
* /

* Models

* Models

* Partial test

* Complete test and fix bug

* Address peer review

* Address review and fix bugs

* Fix regression result

* Fix regression result
2022-08-26 12:23:31 -03:00
Martin-Molinero
2bc41e0e32 Websocket improvements (#6585)
* Dynamically set wait time on WS error

- Dynamically adjust wait time on websocket error

* Avoid subscribing multiple times to message events

- Avoid websocket subscription multiple times to message events during
  disconnection/connection cycle

* Add Dispose Brokerage WebSocket Subscription Manager
2022-08-26 10:53:28 -03:00
Martin-Molinero
d6d3514ae2 Live warmup resolution check (#6586)
- Add check for live warmup history request, making sure there is at
  least room for a single bar between start and end. Avoid sending
  start==end when rouded down by the resolution causing some history
  providers to fail
2022-08-26 10:50:02 -03:00
Martin-Molinero
575f17c6ec Order command improvements (#6584)
- Create SubmitOrderRequest method in algorithm API to reduce
  duplication of code and responsability.
- Add order command tests for different failure and success cases
- Fix null reference exception in equity fill model, when there is no
  data for an asset.
2022-08-25 15:53:11 -03:00
Jhonathan Abreu
3c6ae2f1e7 Fix report's exposure plot colors and other bugs (#6580)
* Use correct colors in report's exposure plot

* Add 12 month rolling sharpe to report plot

* Housekeeping

* Fix failing unit tests
2022-08-25 12:28:22 -03:00
Martin-Molinero
19f3d8b305 Fix python memory leak (#6579)
* Fix python memory leak

- Fix python memory leak. Adding unit test

* Update pythonnet to 2.0.17
2022-08-24 18:24:07 -03:00
Jhonathan Abreu
475f295ce0 Support market orders for futures and FOPs on extended hours (#6575)
* Allow market orders for futures and FOPs on extended market hours

* Update regression algorithms stats

* Add futures fill model to allow extended market hours

* Add unit tests

* Update regression algorithms stats

* Update regression algorithms stats

* Housekeeping
2022-08-24 11:04:52 -03:00
Martin-Molinero
7fdedbe98f Rename python environments (#6572)
* Rename python environments

* Rename to Foundation-Py/C#-Default
2022-08-23 19:06:19 -03:00
Martin-Molinero
24605c6788 Add missing PY.GIL when shutting down (#6571) 2022-08-23 17:40:20 -03:00
Martin-Molinero
c8a80e361c Update readme.md 2022-08-23 15:53:29 -03:00
Martin-Molinero
dc7b2faa6b Fix launcher potential null reference (#6567)
- Fix launcher potential null reference if the job is null
2022-08-22 19:03:32 -03:00
Ryan Russell
9cd38a388b chore(.NET 6): Update references from dotnet 5 to dotnet 6 #6560 (#6565)
* docs(dotnet6): `dotnet 5` -> `dotnet 6`

Signed-off-by: Ryan Russell <git@ryanrussell.org>

* `.Net 5` -> `.Net 6`

Signed-off-by: Ryan Russell <git@ryanrussell.org>

Signed-off-by: Ryan Russell <git@ryanrussell.org>
2022-08-22 17:51:24 -03:00
Martin-Molinero
04723df362 Fix ARM foundation image (#6566)
- Remove unsupported libraries
2022-08-22 17:50:11 -03:00
Martin-Molinero
3f42101f6d Update to python38 and libraries (#6558)
* Update to python38

- Update to python38
- Update libraries

* Create latest virtual environment. Add CI unit tests

* Further update python packages

* Virtual env fixes

- Refactor python virtual env setup
- Adding CI unit tests for python packages and virtual envs

* Adding more python packages

- Adding NBeats, Ax-platform, Riskfolio-Lib

* Rename pomegranate venv
2022-08-22 13:54:02 -03:00
Jhonathan Abreu
eddd28243b Show backtest and live runtime days in report (#6561)
* Show backtest and live runtime days in report

* Show live or backtest runtime days in report stats

* Housekeeping
2022-08-22 12:12:19 -03:00
Jhonathan Abreu
8e35155c40 Fix IB futures commission fees (#6557)
* Adapted futures commission fees for IB

* Unit tests

* Some cleanup

* Fix exchange fees

* Update regression algorithms stats

* Update unit tests
2022-08-18 18:35:49 -03:00
Ryan Russell
98fa4464ce docs: excersizing -> exercising (#6559)
* docs: `excersizing` -> `exercising`

Signed-off-by: Ryan Russell <git@ryanrussell.org>

* docs: fix `exercising for exercising`

Signed-off-by: Ryan Russell <git@ryanrussell.org>

* docs: `migth` -> `might`

Signed-off-by: Ryan Russell <git@ryanrussell.org>

Signed-off-by: Ryan Russell <git@ryanrussell.org>
2022-08-18 11:00:26 -03:00
Jhonathan Abreu
539011274c Support extended market hours for futures (#6522)
* Support extended market hours in AddFuture()

* Support extended market hours in AddFutureContract()

* Add C# regression algorithm

* Add Python regression algorithm

* Add regression algorithm for future contracts

* Add regression algorithm checking market hour ranges

* Fixed future regression algorithms to use extended market hours

* Fixed future regression algorithms to use extended market hours

* Fixed future regression algorithms to use extended market hours

* Fixed AddFutureOptionContractFromFutureChainRegressionAlgorithm to use extended market hours

* Update future market hours to include extended in market hours database

* Fixed AddFutureOptionContractDataStreamingRegressionAlgorithm to use extended market hours

* Fixed AddFutureOptionContractFromFutureChainRegressionAlgorithm to use extended market hours

* Fixed AddFutureContractWithContinuousRegressionAlgorithm to use extended market hours

* Fixed BasicTemplateContinuousFutureAlgorithm to use extended market hours

* Fixed BasicTemplateFuturesAlgorithm to use extended market hours

* Fix BasicTemplateFuturesDailyAlgorithm to use extended market hours

* Fixed BasicTemplateFuturesFrameworkAlgorithm to use extended market hours

* Fixed BasicTemplateFuturesHistoryAlgorithm to use extended market hours

* Fixed ContinuousBackMonthRawFutureRegressionAlgorithm to use extended market hours

* Fixed ContinuousFutureBackMonthRegressionAlgorithm to use extended market hours

* Fixed ContinuousFutureHistoryRegressionAlgorithm to use extended market hours

* Fixed ContinuousFutureLimitIfTouchedOrderRegressionAlgorithm to use extended market hours

* Fixed ContinuousFutureRegressionAlgorithm to use extended market hours

* Fixed DelistedFutureLiquidateRegressionAlgorithm to use extended market hours

* Fixed AutomaticIndicatorWarmupDataTypeRegressionAlgorithm to use extended market hours

* Fixed ConsolidateRegressionAlgorithm to use extended market hours

* Fixed DelistingFutureOptionRegressionAlgorithm to use extended market hours

* Fixed EqualWeightingPortfolioConstructionModelFutureRegressionAlgorithm to use extended market hours

* Fixed FutureContractsExtendedMarketHoursRegressionAlgorithm to use extended market hours

* Fixed FutureMarketOpenAndCloseRegressionAlgorithm to use extended market hours

* Fixed FutureMarketOpenConsolidatorRegressionAlgorithm to use extended market hours

* Fixed FutureOptionBuySellCallIntradayRegressionAlgorithm to use extended market hours

* Fixed FutureOptionCallITMExpiryRegressionAlgorithm to use extended market hours

* Fixed FutureOptionCallITMGreeksExpiryRegressionAlgorithm to use extended market hours

* Fixed FutureOptionCallOTMExpiryRegressionAlgorithm to use extended market hours

* Fixed FutureOptionDailyRegressionAlgorithm to use extended market hours

* Fixed FutureOptionHourlyRegressionAlgorithm to use extended market hours

* Fixed FutureOptionMultipleContractsInDifferentContractMonthsWithSameUnderlyingFutureRegressionAlgorithm to use extended market hours

* Fixed FutureOptionPutITMExpiryRegressionAlgorithm to use extended market hours

* Fixed FutureOptionPutOTMExpiryRegressionAlgorithm to use extended market hours

* Fixed FutureOptionShortCallITMExpiryRegressionAlgorithm to use extended market hours

* Fixed FutureOptionShortCallOTMExpiryRegressionAlgorithm to use extended market hours

* Fixed FutureOptionShortPutITMExpiryRegressionAlgorithm to use extended market hours

* Fixed FutureOptionShortPutOTMExpiryRegressionAlgorithm to use extended market hours

* Fixed FuturesAndFuturesOptionsExpiryTimeAndLiquidationRegressionAlgorithm to use extended market hours

* Fixed FuturesExpiredContractRegression to use extended market hours

* Fixed FutureSharingTickerRegressionAlgorithm to use extended market hours

* Fixed HistoryWithDifferentContinuousContractDepthOffsetsRegressionAlgorithm to use extended market hours

* Fixed HistoryWithDifferentDataMappingModeRegressionAlgorithm to use extended market hours

* Fixed HistoryWithDifferentDataNormalizationModeRegressionAlgorithm to use extended market hours

* Fixed LimitOrdersAreFilledAfterHoursForFuturesRegressionAlgorithm to use extended market hours

* Fixed OpenInterestFuturesRegressionAlgorithm to use extended market hours

* Fixed RegisterIndicatorRegressionAlgorithm to use extended market hours

* Fixed SetHoldingsFutureRegressionAlgorithm to use extended market hours

* Fixed WarmupFutureRegressionAlgorithm to use extended market hours

* Fixed AddFutureOptionSingleOptionChainSelectedInUniverseFilterRegressionAlgorithm to use extended market hours

* Fixed AlgorithmHistoryTests to use extended market hours for futures

* Fixed AlgorithmTradingTests to use extended market hours for futures

* Fixed BrokerageSetupHandlerTests to use extended market hours for futures

* Fixed TimeRulesTests to use extended market hours for futures

* Fixed FutureOptionMarginBuyingPowerModelTests to use extended market hours for futures

* Fixed FutureMarginBuyingPowerModelTests to use extended market hours for futures

* Fixed FileSystemDataFeedTests to use extended market hours for futures

* Fixed QuantBookHistoryTests to use extended market hours for futures

* Split BasicTemplateContinuousFutureAlgorithm to have an extended market version

* Fixed FutureMarketOpenAndCloseRegressionAlgorithm to use extended market hours

* Split BasicTemplateFuturesAlgorithm to have an extended market version

* Split BasicTemplateFuturesAlgorithm to have an extended market version

* Split BasicTemplateFuturesFrameworkAlgorithm to have an extended market version

* Split BasicTemplateFuturesHistoryAlgorithm to have an extended market version

* Revert AddFutureContractWithContinuousRegressionAlgorithm

* Revert AddFutureOptionContractDataStreamingRegressionAlgorithm and added data

* Revert AddFutureOptionContractFromFutureChainRegressionAlgorithm

* Revert AddFutureOptionSingleOptionChainSelectedInUniverseFilterRegressionAlgorithm

* Revert ConsolidateRegressionAlgorithm

* Revert Algorithm.CSharp/ContinuousBackMonthRawFutureRegressionAlgorithm.cs

* Revert ContinuousFutureBackMonthRegressionAlgorithm

* Revert ContinuousFutureHistoryRegressionAlgorithm

* Revert ContinuousFutureLimitIfTouchedOrderRegressionAlgorithm

* Revert ContinuousFutureRegressionAlgorithm

* Revert Algorithm.CSharp/DelistedFutureLiquidateRegressionAlgorithm.cs

* Revert EqualWeightingPortfolioConstructionModelFutureRegressionAlgorithm

* Split FutureMarketOpenAndCloseRegressionAlgorithm to have an extended market version

* Split FutureMarketOpenConsolidatorRegressionAlgorithm to have an extended market version

* Revert FutureOptionBuySellCallIntradayRegressionAlgorithm

* Revert FutureOptionCallITMExpiryRegressionAlgorithm

* Revert FutureOptionDailyRegressionAlgorithm

* Revert FutureOptionPutITMExpiryRegressionAlgorithm

* Revert FutureSharingTickerRegressionAlgorithm

* Revert FuturesAndFuturesOptionsExpiryTimeAndLiquidationRegressionAlgorithm

* Revert FuturesExpiredContractRegression

* Revert HistoryWithDifferentContinuousContractDepthOffsetsRegressionAlgorithm

* Revert HistoryWithDifferentDataMappingModeRegressionAlgorithm

* Revert HistoryWithDifferentDataNormalizationModeRegressionAlgorithm

* Revert OpenInterestFuturesRegressionAlgorithm

* Revert RegisterIndicatorRegressionAlgorithm

* Revert SetHoldingsFutureRegressionAlgorithm

* Revert WarmupFutureRegressionAlgorithm

* Revert AutomaticIndicatorWarmupDataTypeRegressionAlgorithm

* Some cleanup

* Address changes request

* Address changes request

* Add more Class III Milk data to fix DelistingFutureOptionDailyRegressionAlgorithm
2022-08-18 10:56:44 -03:00
Martin-Molinero
6f3208eded Python Virtual Environments Support (#6556)
- Add support to use a python virtual environment if defined in the
  algorithm job. Adding tests
2022-08-17 16:40:52 -03:00
Ryan Russell
62493f8986 docs: algorithm readability improvements (#6554)
docs: `algorthm` -> `algorithm`
2022-08-17 10:39:57 -07:00
Ryan Russell
35afe3da84 docs: portfolio readability fixes (#6553)
* docs: `portolio` -> `portfolio`

Signed-off-by: Ryan Russell <git@ryanrussell.org>

* docs: `porfoltio` -> `portfolio`

Signed-off-by: Ryan Russell <git@ryanrussell.org>

Signed-off-by: Ryan Russell <git@ryanrussell.org>
2022-08-17 10:23:40 -03:00
Jhonathan Abreu
b07680688f Fix FormatException on estimated capacity rendering during report generation (#6551)
* Fix FormatException on non-USD currency capacity in report generator

* Improve currency removal from capacity string

Applied this improvement to OptimizationBacktestJsonConverter.WriteJson

* Address changes request
2022-08-16 11:08:36 -03:00
Ryan Russell
e4647ea146 docs: epected -> expected (#6552)
Signed-off-by: Ryan Russell <git@ryanrussell.org>

Signed-off-by: Ryan Russell <git@ryanrussell.org>
2022-08-16 10:12:30 -03:00
Ryan Russell
052e20cbf4 refactor(Algorithm): readability improvements (#6547)
* refactor(Algorithm): Correct `Intrinino` -> `Intrinio` references

Signed-off-by: Ryan Russell <git@ryanrussell.org>

* refactor(Algorithm): Update `evemts` -> `events`

Signed-off-by: Ryan Russell <git@ryanrussell.org>

* refactor(BubbleAlgorithm): readability improvements

Signed-off-by: Ryan Russell <git@ryanrussell.org>

* refactor(OrderTicketDemoAlgorithm): readability improvements

Signed-off-by: Ryan Russell <git@ryanrussell.org>

Signed-off-by: Ryan Russell <git@ryanrussell.org>
2022-08-15 10:52:07 -03:00
Jhonathan Abreu
771cc11b3a Fix KeyError in report generator due to missing color mappings (#6546)
* Fix KeyError when rendering exposure chart in report with some security types

* Update exposure chart colors and add unit tests

* Updated json test file
2022-08-12 18:52:15 -03:00
Ronit Jain
0d882b8201 Refactor handle lean-cli commands for live deployments (#6527)
* handle multiple command files

* remove default useage

* add tests for verify files are read in order

* add comment

* change reuslt file name

* add comment

* liquidate using given symbol values

* remove redundant

* accept ticker, market, security type to build symbol, to be used by CLI commands

* use null leverage

* symbol can be null if ticker, market, security type values are provided

* reject the default value of security type

* cleanup

* cleanup

* check if status is not invalid

* cleanup

* abstraction to remove duplication

* fix name

* address reviews

* use counter

* add test to validate symbol/ticker agrumnets

* remove hardcoded values
2022-08-12 18:12:33 -03:00
Ryan Russell
95c1f752ac docs: Readability improvements (#6545)
Signed-off-by: Ryan Russell <git@ryanrussell.org>

Signed-off-by: Ryan Russell <git@ryanrussell.org>
2022-08-12 16:56:26 -03:00
Martin-Molinero
37dca9d458 Remove log packet aggregation (#6538)
- Remove log packet aggregation
- Clean up Queue api usage
2022-08-11 19:06:11 -03:00
Jhonathan Abreu
2dd3a0cb94 Fix 'GetParameter()' ambiguous call error when no default parameter is provided (#6541)
* Fix QCAlgorithm.GetParameter() ambiguous call error when no default parameter is provided

* Add unit tests

* Add regression algorithms
2022-08-11 18:45:00 -03:00
Jhonathan Abreu
aa8a3a241b GetParameter number conversion overloads (#6535)
* Add numeric conversion overloads to QCAlgorithm.GetParameter()

* Add unit tests

* Address changes request
2022-08-10 18:15:04 -03:00
Louis Szeto
cfa4a4c1c1 Update readme information in Equity data (#6536)
* Update readme

* Update equity readme

* Add quote info

* Fix typo

* Add back QuoteQuant as pre-2007 vendor

* Fix typo
2022-08-10 18:11:20 -03:00
Ronit Jain
3064c1ed4b update config value (#6537) 2022-08-10 18:10:02 -03:00
Jhonathan Abreu
9e7690754a Forbid tick resolution period-based history requests (#6533)
* Detect implicit tick resolution in period-based history requests and throw

* Add regression algorithms
2022-08-09 18:19:08 -03:00
Jhonathan Abreu
460ef10ff4 Add more info to python runtime error message (#6526) 2022-08-09 17:56:23 -03:00
Jhonathan Abreu
6f70606f3e Allow tick history request without tick subscription (#6534) 2022-08-09 17:51:25 -03:00
Louis Szeto
9eb71e1543 Mean Reversion Portfolio Construction Model (#6519)
* MRP

* Fix bug

* Rename

* Provide virtual `GetPriceRelative` function to override for any variants in future

* SymbolData class within model

* Address peer review

* fix bug

* revise unit test and fix bug in python model

* revise unit test and fix bug in model

* Revise regression statistics

* Revise regression statistics

* Revise regression statistics

* Revise regression statistics

* Revise regression statistics

* Address peer review

* Updated unit tests according to peer review

* Address peer review
2022-08-04 11:20:11 -03:00
Martin-Molinero
3f7d339463 Fix live result Handler null reference (#6521)
- Fix live result handler null reference, that could happen if the
  algorithm explodes mid initialization. Adding unit test
2022-08-03 19:57:03 -03:00
Martin-Molinero
3f2bcc1784 Add missing CancellationTokenSource dispose (#6512)
- Add missing CancellationTokenSource disposals to avoid memory leaks
2022-08-01 11:12:01 -03:00
Martin-Molinero
30d137e9cc Track CPU usage (#6520)
- Track CPU usage, useful for debugging
2022-08-01 11:10:52 -03:00
Martin-Molinero
ab9ad75c93 Update readme.md 2022-07-29 15:52:57 -03:00
Jhonathan Abreu
1440842d87 Fix LocalMarketHours.GetMarketClose for extended market hours (#6516)
* Fix LocalMarketHours.GetMarketClose to get the actual next market close time with extended market hours

The method was not properly considering gaps between regular hours close and extended market open

* Revert some changes to fix errors
2022-07-29 12:31:10 -03:00
Martin-Molinero
2df01c4d2e Update readme.md 2022-07-28 20:54:04 -03:00
Martin-Molinero
82aab246a8 Update readme.md 2022-07-28 20:43:32 -03:00
Martin-Molinero
f665d693b7 Update readme.md 2022-07-28 20:30:15 -03:00
Martin-Molinero
ef531e09bd Add Lean commands (#6513)
* Add Lean commands

- Add Lean commands to common project

* Address reviews

- Address reviews, refactor command interfaces and classes

* Rename FileCommandQueueHandler to FileCommandHandler
2022-07-28 16:44:40 -03:00
Jhonathan Abreu
3db470de52 Add fill forward and extended market parameters to QuantBook's history methods (#6515) 2022-07-28 15:29:15 -03:00
Martin-Molinero
a43bdaf1c7 Fix crypto hash leak (#6511)
- Fix crypto sha256 memory leak
- Minor improvements to reduce improve performance
2022-07-26 20:00:23 -03:00
Martin-Molinero
e0f483c46b Fix ARM IB gateway java version check (#6509)
- Fix for ARM IB gateway java version check.
  See https://github.com/QuantConnect/lean-cli/issues/114
2022-07-26 10:35:47 -03:00
Martin-Molinero
8093df31cc Update readme.md 2022-07-25 20:11:25 -03:00
Ronit Jain
9df9d76081 get value from config, default to local (#6502) 2022-07-22 11:08:46 -03:00
Jhonathan Abreu
ad844e9411 Fix checking market open for post market segments (#6500)
* Consider post-market segments when getting market open

* Consider post-market segments when getting market open

* Fixes and more unit tests
2022-07-22 10:57:01 -03:00
Derek Melchin
e7e9153fbf Update indicator source links (#6501) 2022-07-21 17:50:14 -03:00
Martin-Molinero
24627f5efa Fix optimization json converter (#6499)
- Fix optimization json converter, not handling correctly different
  account currencies. Updating unit test to reproduce issue
2022-07-21 17:43:14 -03:00
Martin-Molinero
440282c138 Update compare_benchmarks.py 2022-07-20 20:04:33 -03:00
Martin-Molinero
3d3f04abbc Update python autocomplete readme (#6498)
- Updating the python autocomplete readme to suggest adding
 `from AlgorithmImports import *`
2022-07-20 18:40:52 -03:00
Martin-Molinero
0a64462e50 Add performance gh action (#6497)
* Add performance gh action

- Add new performance github action, running python and csharp benchmark
  algorithms
- Adjusting algorithms length so they are not too long or too short

* Checkout master branch benchmark reference
2022-07-20 18:15:38 -03:00
Martin-Molinero
c43f472503 Fill model will use internal configurations (#6494)
- Fill model will take into account internal configurations, this is
  specially relevant for continuous future mapped contracts. Updating
  regression algorithms and unit tests.
- Allowing internal configurations to update trade builder information
2022-07-19 19:00:35 -03:00
Jhonathan Abreu
6c93af96a1 Disable MOO orders for futures out of regular market hours (#6480)
* Remove suppport for market orders and MOO orders for futures

* Add regression algorithm to assert that limit orders are filled on after hours for futures

* Remove suppport for market orders and MOO orders for futures in DefaultBrokerageModel

* Update regression algorithms stats

* Fixed regression algorithm and clean up

* Add unit tests

* Fix regression algorithms

* Address changes request
2022-07-19 16:18:06 -03:00
Martin-Molinero
b3cb24a16f Update readme.md 2022-07-19 14:39:14 -03:00
Jhonathan Abreu
38f7e72dbe Add delisted futures and FOP regression algorithms with daily resolution (#6493)
* Add regression algorithms for delisted futures with daily resolution

* Add regression algorithms for delisted futures options with daily resolution

* Updated documentation
2022-07-18 17:53:43 -03:00
Martin-Molinero
a9073396bd Add WarmUpResolution pass through (#6487)
- Add new WarmUpResoltuion pass through version for friendly
user experience. Adding unit test
2022-07-18 13:47:04 -03:00
Martin-Molinero
b7df632294 Correctly handle Polygon authentication sequence (#6485)
- Correctly handler Polygon data queue handler authentication sequence
2022-07-18 13:40:21 -03:00
Martin-Molinero
38772a5a89 Do not apply split during live warmup (#6488)
- Do not apply split during live warmup. Adding unit tests asserting the
  behavior for live dividends and splits during warmup and non warmup
2022-07-15 18:17:26 -03:00
Martin-Molinero
7540af454c Warmup resolution respected (#6467)
* Respect warmup resolution given

- The data feed will respect the warmup resolution given and override
  the resolution used by the algorithm when adding a subscription.
  Updating regression algorithm to keep previous statistics. Adding new
  regression algorithm asserting the desired behavior

* Testing improvements

- Add more unit tests and regresion test
- Add missing data for crypto
- Fix bug with FFed data crossing after the end time of the warmup
  request

* Add more Warmup resolution regression algorithms

- Adding more warmup resolution regression algorithms, using
  Settings.WarmupResolution and an option selection case

* Add more warmup regression tests

- Adding more warmup regression tests.
- Will no longer skip universe selection subscriptions from warmup
  resolution enforcement. Updating regression algorithms data points

* Fix bug with data rounding

- Fix data rounding bug when warmup resolution is set to a different
  value than the original configuration. Updating regression algorithms
  to assert the expected behavior

* Address reviews

- Revert regression algorithms changes to use Resolution during warmup.
  Updating their stats.
- Adding new regression algorithms asserting the behavior warming up
  using a timespan and no warmup resolution
- Fix bug where data used to warmup the 'normal' enumerator will make it
  through into the warmup time span. Updating tests

* Address reviews

- Add missing comments, explaning warmup algorithms time span
  calculations.
- Revert changes in existing `WarmupOptionTimeSpanRegressionAlgorithm`
  to reduce diff to minimum
- Adding new warmup unit tests asseting algorithm warmup start time, for
  different combinations of bar count, timespan, resolution
2022-07-15 13:05:06 -03:00
Derek Melchin
cd06e87493 Update data normalization mode comments (#6486)
* Update Data Normalization Mode enum descriptions

* Extend descriptions
2022-07-15 11:10:52 -03:00
Ricardo Andrés Marino Rojas
5200a9e593 Add ReadBacktestOrders() and ReadLiveOrders() methods (#6329)
* First commit

* Any change

* Add more unit tests

* Nit changes

* Changes requested

* Fix bugs and requested changes

* Requested changes

* More changes

* Check ongoing backtest orders

* Read ongoing backtest does not fail

* nit change

* Fixes for standarized API orders response

- Fixes for a standarized API read orders reponse

Co-authored-by: Martin-Molinero <martin@quantconnect.com>
2022-07-14 16:02:58 -03:00
Martin-Molinero
07aa5625e1 Avoid division by zero error in backtesting result handler (#6484)
* Minor improvements

- Avoid division by zero error in backtesting result handler. Race
  condition where the SetAlgorithm implementation would still be running
  and we try to loop through the update method
- Improvement nullreference exception message
- Cleanup resolution to timespan extension method

* Address reviews

- Cleanup data config fill forward conditional statement for tick
  resolution
2022-07-14 12:54:55 -03:00
Martin-Molinero
31fc7ac236 Do not generate Equity Quote Daily data (#6483)
- Fix for so the random data generator does not try to create daily
  equity quote data
2022-07-14 10:20:34 -03:00
Martin-Molinero
e6f8a7535e Fix live future and option universe selection daily resolution (#6482)
* Fix live future and option universe selection daily resolution

- Adding unit test reproducing issue for option and future universe
  chain using daily resolution, since was rounding down in UTC TZ the
  date might not change and it would re emit the same data point

* Address reviews

- Add more test cases
- Adding locks around RegisteredSecurityDataTypesProvider to allow it to
  be used by multiple threads at the same time without exploding
2022-07-13 19:10:13 -03:00
Martin-Molinero
778d436b94 Removed mapped futures contract is non tradable (#6479)
* Minor fixes for mapped futures contract

- Future security was never able to be non tradable
- Skip remove future contracts from live holdings. Adding unit test
  reproducing issue and regression algorithm

* Fix removal of continuous futures

- The canonical continuous future would leave behind an OpenInterest
  subscription when removed because of a different in the way the
  configurations were built, this will now be centralized in a single
  method. Adding unit tests reproducing issue
- FillForwarding setting of the continuous future was not being
  respected. Updating algorithm reproducing the issue to assert the
  behavior failing in master

* Address reviews

- Minor refactors addressing reviews
2022-07-13 15:36:24 -03:00
Martin-Molinero
36ddf1c618 Update config.json 2022-07-13 15:33:48 -03:00
Martin-Molinero
632833caaa Minor live related testing changes (#6481)
- The history provider manager will log the underlying instances it's using.
- Allow brokerage test suites to reuse the algorithm stubs class
2022-07-13 15:26:45 -03:00
Martin-Molinero
6200988ad5 Fix result handler live holdings (#6478)
* Fix result handler live holdings

- Live result handler live holdings will include future assets
  associated with continuous futures. Adding unit tests

* Fixed for live holdings price rounding

- Live holdings will use the SPDB minimum price variation for rounding.
  Adding unit tests
2022-07-12 18:31:35 -03:00
Martin-Molinero
826f2cbbf9 Minor refactor messaging handler (#6472) 2022-07-11 16:24:26 -03:00
Jared
e54cc3e948 Update readme.md 2022-07-08 11:32:05 -07:00
Louis Szeto
413a084254 Add Price in CoarseFundamental (#6464)
* Update CoarseFundamental.cs

* Fix typo

* Add virtual/override
2022-07-06 13:28:57 -03:00
Martin-Molinero
8c0b60cd2f Refactor work queue scheduling (#6465)
- Remove thread in charge of sorting and updating the queues weight.
  This will be handled by each worker thread instead. Avoid cases where
  the work count is so high that the sorting thread in master would not
  be able to update all the weights, causing data to be enqueued beyond
  the max prefetch limit. Adding benchmark algorithm reproducing issue
2022-07-06 12:13:32 -03:00
Martin-Molinero
64f0a9e0a2 Fix for ApiDataProvider (#6461)
- Avoid race condition while downloading data.
- Reused http client for downloads
2022-07-05 18:43:58 -03:00
Martin-Molinero
3f407cd80f Smaller live warmup history requests (#6455)
- Smaller live warmup history requests, will keep track of the last point
  we got from the file based enumerator and start our history enumeration from this point
2022-07-05 13:15:23 -03:00
Jhonathan Abreu
5758b65099 Added configuration parameters to Python QCAlgorithm.History() method that takes custom data source type (#6448)
* Add new Python QCAlgorithm.History() method with all parameters and type

* Add regression algorithms

* Using all parameters in History()

* Use private methods to reuse History() code

* Use private methods to reuse History() code

* Add unit tests for QCAlgorithm.Python.History()

* Add unit tests for QCAlgorithm.Python.History()

* Add unit tests for QCAlgorithm.Python.History()

* Add unit tests for QCAlgorithm.Python.History()

* Add unit tests for QCAlgorithm.Python.History()

* Add unit tests for QCAlgorithm.Python.History()

* Asserting history count
2022-07-05 13:14:08 -03:00
Louis Szeto
c1db23250e Update enum values in comments (#6460) 2022-07-05 10:29:28 -03:00
Martin-Molinero
b426483e1d Rebase org- branches on trunk (#6456)
- Adding github actions to automatically rebase org- branches on trunk
  when master get's a merge
2022-07-01 12:24:03 -03:00
Louis Szeto
30e47f3e8b Add basic template algorithm for Cfd and FutureOption (#6454) 2022-07-01 12:20:45 -03:00
Martin-Molinero
506e3a1c2c Add default value for GetParameter (#6452)
- Allow providing a default value for GetParameter. Updating regression
  test to use it
2022-06-29 18:58:09 -03:00
Alexandre Catarino
ab228e8eca Adds typing Import to AlgorithmImports (#6450) 2022-06-29 15:37:43 -03:00
Martin-Molinero
dc043f8c09 Fix future chain data normalization mode (#6445)
- Similar to the OptionChainUniverse, the future chain universe should
  also add it's contracts using the raw data normalization mode. Adding
  regression algorithm reproducing issue
2022-06-28 15:15:09 -03:00
Martin-Molinero
05bfad729c Fix custom fine universe selection model (#6447)
- For for custom fine universe selection model so it can return
  Universe.Unchanged. Adding regression tests
2022-06-28 15:11:04 -03:00
Martin-Molinero
5c6a779f4d Period consolidator adjusments (#6444)
- Replace logic to convert TimeSpan based PeriodConsolidator into count
  based, by an override of the 'potentialStartTime' in the case we could
  be falling into a look ahead consolidated bar end time
2022-06-27 19:17:20 -03:00
Martin-Molinero
630503bf9c Remove deprecated inspect.getargspec (#6443)
- Remove deprecated python `inspect.getargspec` usage, replace for new
  `getfullargspec`. Adding unit tests reproducing issue
2022-06-27 18:49:46 -03:00
Martin-Molinero
18eec48a3d Avoid PythonNet runtime stash on shutdown (#6441)
* Can't relesase the GIL after shutdown

* Bump version to pythonnet 2.0.16
2022-06-27 13:04:01 -03:00
Jhonathan Abreu
e9409bf207 Add contractDepthOffset parameter to QCAlgorithm.History() (#6438)
* Add contract depth offset parameter to big History() methods

- Added unit tests
- Added little more ED daily data

* Add C# regression algorithm

* Add Python regression algorithm

* Update regression algorithms stats

* Address changes request
2022-06-27 10:04:33 -03:00
Martin-Molinero
867682c923 Set default object store settings from config (#6437)
- Will set default object store settings from config like research
2022-06-24 18:44:00 -03:00
Martin-Molinero
59ac2f57ed Shutdown python manually (#6439) 2022-06-24 18:43:44 -03:00
Martin-Molinero
4c3afa6ff1 Add OpenInterestAnnual (#6436)
- Adding OpenInterestAnnual where the contract maps when any of the back month
  contracts of the next year have a higher volume that the current front month.
- Add support for backwards compatible data mapping mode additions
- Updating ES map and factor files. Adding a little daily data too
2022-06-23 19:22:24 -03:00
Jhonathan Abreu
9128ce1260 Add data normalization mode parameter to QCAlgorithm.History() (#6435)
* Add data normalization mode parameter to big History() methods

* Add C# regression algorithm

* Add Python regression algorithm
2022-06-23 17:02:50 -03:00
Jhonathan Abreu
505ef17565 Add data mapping mode parameter to QCAlgorithm.History() (#6415)
* Add dataMappingMode parameter to QCAlgorithm.History()

* Add C# regression algorithm

* Add Python regression algorithm

* Cleanup

* Add data mapping mode parameter only to big History() methods

* Fix regression algorithms and add required data

* Fix unit test

* Update regression algorithms stats
2022-06-22 19:25:30 -03:00
Martin-Molinero
a12a43c1ef Update VX futures market hours (#6417) 2022-06-22 17:25:18 -03:00
Alexandre Catarino
e3313c7c45 Fixes Contract Multiplier for Treasury Futures (#6418) 2022-06-22 17:25:00 -03:00
Martin-Molinero
f0b59a72fd Fix Train method during warmup (#6416)
- During warmup period the algorithms initial time might not be a rounded date
  value, so it's important to take into account hours/minutes. Adding
  regression algorithm reproducing and asserting issue
2022-06-21 10:05:27 -03:00
Martin-Molinero
a42a53671f Add missing Py.Gil in base PCM (#6414)
- Add missing python Py.Gill in base PortfolioConstructionModel. Adding
  unit test reproducing issue, seg fault
2022-06-20 19:44:31 -03:00
Martin-Molinero
bb0c27fefd Period timespan consolidation improvements (#6408)
* Period timespan consolidation improvements

- If user is trying to consolidate a period providing data of a bigger
  period we will now throw an exception. Adding tests
- If both consolidated and given data share the same period, gently
  adjust the consolidator into a data count of 1. Adding tests
- Fixing bug in QuoteBarConsolidator period double accounting. Adding unit tests

* Add Period and Count regression algorithm
2022-06-20 15:14:44 -03:00
Martin-Molinero
299cb79832 OnWarmupFinished always called (#6413)
* OnWarmupFinished always called

- Always call OnWarmupFinished. Adding regression tests

* Assert method called with counter
2022-06-20 14:24:12 -03:00
Martin-Molinero
8fb188d567 Add missing Juneteenth holiday (#6412)
- Add missing Juneteenth holida. Reference https://www.timeanddate.com/holidays/us/juneteenth
2022-06-20 10:42:37 -03:00
Martin-Molinero
740b40ff11 Fix QuoteBar Non Time Based Consolidator Period (#6409)
* Fix QuoteBar NonTimeBased Consolidator Period

- Fix QuoteBar non timebased consolidator period, that was accounting
  twice for the initial bar period. Updating unit tests

* Improve QuoteBarConsolidator assertion

- Assert quote bar consolidated time and endtime in unit tests
2022-06-17 19:44:37 -03:00
Jhonathan Abreu
e736b28568 Add data normalization mode parameter to AddEquity method (#6407)
* Add DataNormalizationMode parameter to QCAlgorithm.AddEquity method

* Add regression algorithm

* Add Python regression algorithm

* Style changes

* Fix test error
2022-06-17 18:27:06 -03:00
Martin-Molinero
b007d9f962 Fix intermittent ZipMapFile cache test failure (#6406)
- Fix for intermittent ZipMapFile cache test failure and reducing test length
2022-06-16 15:30:20 -03:00
Martin-Molinero
4d7d7def63 Add Log.Error at OptionSymbol.IsOptionContractExpired (#6405)
- Add error log at OptionSymbol.IsOptionContractExpired in the case we
  detect an unexpected expiration time. That could be related to
  Symbol.ID.Date being incorrect
2022-06-16 15:10:17 -03:00
Jhonathan Abreu
09c4a53f95 Fix greeks all being zero on expiration date (#6401)
* Fix option price and greeks always beign zero on the expiration date

* Fix option price and greeks always beign zero on the expiration date

* Updated documentation

* Style and performace changes

* Address changes request

* Fix QL.Settings.includeReferenceDateEvents not being set on every thread

* Updated code documentation
2022-06-16 12:29:51 -03:00
Derek Melchin
714042bb69 Fix remark typos to match docs (#6404) 2022-06-16 12:00:17 -03:00
Martin-Molinero
a8e7a8b27e Reconcile the Market Opening for Futures and Scheduled Events (#6397)
- Changes taken from https://github.com/QuantConnect/Lean/pull/6227
- Rebased + a few more tweaks and added tests
2022-06-15 13:47:00 -03:00
Ronit Jain
182ee51389 Bug handle order status race condition for brokerage tests (#6400)
* update order status from event handler

* choose easy limits to less liquid markets

* increase waiting time for fill for less liquid markets
2022-06-14 17:32:34 -03:00
Jhonathan Abreu
4a41c2ea90 Detect unsupported option style in option price model (#6388)
* Add indicator for allowed option styles to QL option price models

* Add and update option price model tests

* Update option price models methods sumary to indicate allowed option styles

* Add regression algorithms for option price models for different option styles

* Update OptionPriceModel regression algorithms to use Lean local data

* Add Python regression algorithms for option price models for different option styles

* Update OptionPriceModel regression algorithms to assert that greeks are valid

* Address changes request

* Address changes request

* Update OptionPriceModel regression algorithms to check both call and put contracts

* Update OptionPriceModel regression algorithms to use correct test data

* Update OptionPriceModel regression algorithms to throw in OnData

* Address changes request

* Update OptionPriceModel regression algorithms to assert greeks are not all zero
2022-06-13 16:21:20 -04:00
Ronit Jain
c1dc981403 Feature use minimum price variation for roundoff (#6398)
* make thread safe

* use use minimumPriceVariation for roundoff

* cleanup, remove duplication
2022-06-13 11:42:59 -03:00
Martin-Molinero
15e399c96b Live T-1 selection warmup (#6395)
* Live T-1 selection warmup

- Only use BaseDataCollection class
- Reuse collection enumerator
- Remove FuturesChainUniverseSubscriptionEnumeratorFactory
- Universe selection will use Cache providers
- Add null reference check
- Add more tests
- Fixes for warmup fill forwarding. Add more tests

* Address reviews. Add missing comments
2022-06-10 17:25:20 -03:00
Martin-Molinero
3fb267f4ad Update readme.md 2022-06-10 11:24:54 -03:00
Martin-Molinero
a3f4dff299 Refactor chain providers (#6394)
* Refactor chain providers

- ChainProviders will use quote, open interest and trade information,
  which ever is first. Updating regression algorithm changing contract
  being added.
- Add base BacktestingChainProvider for shared logic, reducing
  duplication.
- ChainProviders will now use the given IDataCacheProvider and
  IMapFileProvider
- If Providers are called for a date the exchange is closed they will
  search for the previous available date where the exchange is open.
  Adding unit tests.

* Address reviews. Logging improvements
2022-06-10 11:24:09 -03:00
Martin-Molinero
cbfdd85cef Live Internal Subscription Start Time (#6392)
- Live Trading internal subscription start time will be after warmup.
  Adding unit tests.
2022-06-09 17:28:32 -03:00
Martin-Molinero
223066d6d9 Disable live trading warmup plotting (#6393)
- Disable live trading warmup plotting during warmup
2022-06-09 17:27:55 -03:00
Martin-Molinero
25871497e9 Update readme.md 2022-06-09 12:49:15 -03:00
Martin-Molinero
3ad4695354 Update readme.md 2022-06-09 12:42:46 -03:00
Ronit Jain
1c644297df Extract Tradier brokerage files and dependencies (#6387)
* use research-object-store-name key from config while creating object store for research notebooks

* remove files
2022-06-09 12:33:34 -03:00
Ronit Jain
60c9162b11 Extract Gdax brokerage files and dependencies (#6391)
* use research-object-store-name key from config while creating object store for research notebooks

* initial removal

* remove reference

* move test to private repo containing downloaders
2022-06-09 12:32:27 -03:00
Alexandre Catarino
6e32f46068 Adds Missing UpdateTriggerPrice Method (#6385)
Since there is `UpdateStopPrice`, `UpdateLimitPrice`, `UpdateQuantity` and `UpdateTag` method to make it easier to update the `OrderTicket`, we include `UpdateTriggerPrice` to cover the `LimitIfTouched` case.
Also, updated the docs or the arguments for these methods.

Updates LimitIfTouchedRegressionAlgorithm:
- Adds `UpdateTriggerPrice` call that rounds down the `TriggerPrice`.
2022-06-08 10:35:47 -03:00
Martin-Molinero
564d8507c7 Update readme.md 2022-06-07 15:58:45 -03:00
Ronit Jain
c11e24c5b2 Extract Oanda brokerage files and dependencies (#6383)
* use research-object-store-name key from config while creating object store for research notebooks

* remove oanda files
2022-06-07 14:07:24 -03:00
Martin-Molinero
f8c65d886c Update readme.md 2022-06-07 11:26:10 -03:00
Ronit Jain
c162e75bbc Extract bitfinex brokerage files and dependencies (#6382)
* use research-object-store-name key from config while creating object store for research notebooks

* remove bitfinex files

* remove redundant ref

* move test to private repo
2022-06-07 11:07:28 -03:00
Louis Szeto
ca64dd74d5 Update XML documentation comment of LimitPrice (#6381)
* Update OrderField.cs

* Typo
2022-06-07 09:57:37 -03:00
Jhonathan Abreu
5fa9dbad3d Fix Engine not running algorithm when calling Error() from Initialize() (#6379) 2022-06-06 19:33:27 -03:00
Martin-Molinero
3a00b6963c Avoid sending expired symbols to IDQH (#6378)
- Avoid sending expired symbols to the IDQH. This can happen during
  warmup period. Adding unit tests
2022-06-06 19:30:04 -03:00
Martin-Molinero
cde9be8d16 Fix 'OnWarmupFinished' callback (#6377)
- Fix missing 'OnWarmupFinished' callback for python. Adding regression
  algorithms
2022-06-06 11:56:02 -03:00
Louis Szeto
aa1883a140 C# Version of CustomVolatilityModelAlgorithm (#6373) 2022-06-03 19:47:39 -03:00
Martin-Molinero
0c0ee829a2 Warmup state minor fixes (#6367)
* Warmup minor fixes

- Result handler fix
- Centralize and normalize status update during warmup

* Address reviews

* Minor adjustments

* Add console message during warmup period

* Fix warmup percentage update
2022-06-02 18:20:02 -03:00
Jhonathan Abreu
9af7d4a1dc Extended currencies dictionary (#6368)
* Default Currencies.GetCurrencySymbol to the ticker and add ADA symbol

* Extended Currencies dictionary

* Fix failing tests
2022-06-02 17:31:38 -03:00
Martin-Molinero
cabbcf6d81 Move debugpy init log (#6366) 2022-06-02 12:13:13 -03:00
Jhonathan Abreu
df308cc2a7 Make PandasConverter.GetIndicatorDataFrame accept Python dictionary (#6365)
* Overload PandasConverter.GetIndicatorDataFrame to accept a Python dict

* Shared implementation code for PandasConverter.GetIndicatorDataFrame overloads

* Added documentation for private shared methods used by PandasConverter.GetIndicatorDataFrame

* Added unit tests for PandasConverter.GetIndicatorDataFrame

* Added unit tests for PandasConverter.GetIndicatorDataFrame Dictionary overload

* Address change requests

* Address change requests
2022-06-01 19:57:51 -03:00
Ricardo Andrés Marino Rojas
8f3ced7639 Fix bug with Coinbase Pro Stable Pairs (#6362)
* First Commit

* Change Unit tests
2022-06-01 17:19:41 -03:00
Martin-Molinero
e0b9a2735f Warmup fixes (#6293)
* Add regression test reproducing issue

* WIP

* Update regression algorithms

* Improvements

* Cleanup and more fixes

- Clean up BaseDataExchange

* RealTimeHandler fixes

* Address reviews

* More comments, tests and minor tweaks

* Avoid false test failures

* Fixes

* Minor improvements

* Scheduled Event start time fix

* Add warmup option regression algorithm and fix

* Add WarmupFutureRegressionAlgorithm

* Normalize backtesting and live future selection
2022-05-31 10:03:56 -03:00
Martin-Molinero
895dfedf81 User Account currency symbol for fees and capacity (#6359)
* User Account currency symbol for fees and capacity

* Update expected currency symbol stats
2022-05-27 16:36:44 -03:00
Jhonathan Abreu
69dd4fc638 Fixed bug for trailing stop model tracking original security price (#6356)
* Reproduce TrailingStopRiskManagementModel bug with test case

* Fix TrailingStopRiskManagementModel to make it relative to max price

* Adapted old TrailingStopRiskManagementModel test to new implementation

* Fix TrailingStopRiskManagementModel Python version

* Fixed TrailingStopRiskFrameworkAlgorithm regression tests data

* Handling both long and short positions in TrailingStopRiskManagementModel

* Traking holdings value instead of unrealized profit in TrailingStopRiskManagementModel

* Checking for position side change in TrailingStopRiskManagementModel

* Handling immediate liquidation in TrailingStopRiskManagementModel
2022-05-26 19:50:54 -03:00
Ronit Jain
fd20b5377d use research-object-store-name key from config while creating object store for research notebooks (#6355) 2022-05-26 18:12:13 -03:00
Ricardo Andrés Marino Rojas
e78c3e1eb7 Solve bug when plotting Python indicators (#6347)
* First commit

* Add unit test

* Change implementation

* Add unit tests

* Nit change

* nit change

* Remove unnecessary methods

* Add more unit tests

* Revert "Add more unit tests"

This reverts commit 1ba2ab7454.

* Add more unit tests

* Add more unit tests

* Improve Implementation

* Change unit tests

* Remove unit tests

Remove unit tests from AlgorithmRegisterIndicatorTests.cs
2022-05-26 13:03:42 -03:00
Martin-Molinero
0fbbc0e612 Revert "Coarse fine flag improvement (#6349)" (#6353)
This reverts commit fb90f118c9.
2022-05-25 16:51:33 -03:00
Martin-Molinero
fb90f118c9 Coarse fine flag improvement (#6349)
* Coarse fine flag improvement

- Coarse will check global data folder for fine existance if it's
  different than the given path to check

* Update readme.md
2022-05-24 19:46:37 -03:00
Derek Melchin
d7558406c8 Set default constructor values to match those in Python (#6348)
The Python implementation of this Alpha model sets some default values for `lookback` and `resolution`.
aaba566954/Algorithm.Framework/Alphas/PearsonCorrelationPairsTradingAlphaModel.py (L23-L24)
2022-05-23 21:31:48 -03:00
Martin-Molinero
00dd3dbd2c Bump to pythonNet 2.0.15 (#6342) 2022-05-18 13:09:45 -03:00
Martin-Molinero
cb2062debd Expand GetSecondUnevenWait usages (#6340)
* Reduce Live CPU usage

* Address selfreview
2022-05-16 20:12:22 -03:00
Martin-Molinero
4b86c78df0 Add unit test showcasing feature (#6339) 2022-05-13 20:21:08 -03:00
Jhonathan Abreu
17d57cb578 True Strength Index indicator (#6332)
* TrueStrengthIndex indicator

* TrueStrengthIndex indicator signal line

* Address change requests
2022-05-13 15:55:28 -03:00
Martin-Molinero
284b26a9bd Performance improvements and fixes (#6330)
* Reuse GUID

* Reduce Lean task usage

* Reduce CPU usage

* Address reviews
2022-05-13 15:04:09 -03:00
Martin-Molinero
0bc087954e Fix for arm image research (#6333) 2022-05-12 12:42:38 -03:00
Martin-Molinero
f5dd997ca0 Minor fix for FuncPeriodSpecification (#6334)
- Minor fix for FuncPeriodSpecification so it always uses the same
  DateTime to assert the given function. Improve documentation and
  exception message being thrown
2022-05-12 12:37:08 -03:00
Martin-Molinero
33616a44b0 Avoid coding with exceptions (#6327)
- Avoid relying on exception throwing for coding logic.
2022-05-09 10:34:50 -03:00
Derek Melchin
9bd6b46160 Fix CustomIndicatorAlgorithm (#6324) 2022-05-09 10:19:31 -03:00
Martin-Molinero
eb995b86ea Update to pythonNet 2.0.14 (#6322)
* Update to pythonNet 2.0.14

* Add unit test reproducing issue
2022-05-06 17:29:55 -03:00
Martin-Molinero
59a3912f68 Update recyclable memory nuget (#6321) 2022-05-06 11:04:19 -03:00
Martin-Molinero
1be6cccbd4 Update readme.md 2022-05-05 14:45:46 -03:00
Martin-Molinero
a658beb31e Update readme.md 2022-05-05 13:03:17 -03:00
Martin-Molinero
8cf6e073af Update readme.md 2022-05-04 16:43:01 -03:00
Martin-Molinero
2f39ac7d83 Fix research test setup (#6318) 2022-05-03 18:55:48 -03:00
Martin-Molinero
ea25e76faa Update readme.md 2022-05-03 12:18:55 -03:00
Martin-Molinero
b7a21ce4be Update to net6 (#6311)
* Update to net6

* Bump pythonNet to 2.0.13
2022-05-03 11:45:55 -03:00
Martin-Molinero
b9d3d99917 Bump pythonNet version 2.0.12 (#6310)
* Updates after pythonNet rebase

* Bump pythonNet version 2.0.12

* Fix exception types being thrown
2022-05-02 14:38:50 -03:00
Martin-Molinero
64125668db Catch expected test exception (#6317) 2022-05-02 12:44:18 -03:00
Martin-Molinero
06228a8de8 Improve python stack trace parsing (#6316)
- Improve python stack trace parsing removing base Lean path directory.
  Adding unit test
2022-05-02 11:42:36 -03:00
Martin-Molinero
813412afb2 Persist and order runtime statistics (#6314) 2022-04-29 20:59:40 -03:00
Ricardo Andrés Marino Rojas
e0d29e1da7 Charge correct fees for Coinbase Pro stable pairs (#6312)
* First commit

* Improve implementation

* Improve implementation
2022-04-29 16:29:21 -03:00
Ronit Jain
41b7ff58cf consider null cases for cloud brokerageData (#6308) 2022-04-28 13:42:11 -03:00
Ricardo Andrés Marino Rojas
6d181cc452 Fix bug with SetBenchmark() using custom data (#6304)
* First commit

* Solve the easy case

* Solve bugs

* Solve bugs

* Requested changes

* Requested changes
2022-04-27 13:58:10 -03:00
Ronit Jain
b8c8460c7a Update Tradier sandbox config as string with backwards compatibility for bool (#6306)
* add new config

* make case in-sensitive

* use string.IsnullOrEmpty
2022-04-27 13:58:00 -03:00
Louis Szeto
9fe018390e Update OrderResponseErrorCode.cs (#6303) 2022-04-26 10:36:02 -03:00
Nicholas Konovalenko
427f2a70fe Relative Moving Average Indicator (#6297)
* RelativeMovingAverage Indicator #5958

* RelativeMovingAverage #5958

Creation of the RelativeMovingAverage (RMA) indicator, based on the following equation: https://www.hybrid-solutions.com/plugins/client-vtl-plugins/free/rma.html

* Address self review

* Fix unit test

Co-authored-by: Martin-Molinero <martin@quantconnect.com>
2022-04-25 13:13:20 -03:00
code-review-doctor
32f49f1f92 Fix issue probably-meant-fstring found at https://codereview.doctor (#6301) 2022-04-25 10:48:58 -03:00
Martin-Molinero
b3c2303111 Zip data cache provider improvements (#6296)
- Throw on failure to store. Add unit test
- Fix handle leak
2022-04-22 13:52:30 -03:00
Martin-Molinero
fc008fe906 Update readme.md 2022-04-21 16:48:12 -03:00
Martin-Molinero
bbcf5d71a2 Update readme.md 2022-04-20 12:48:25 -03:00
Martin-Molinero
482d86a44a Update readme.md 2022-04-20 12:42:00 -03:00
Martin-Molinero
6eab53f619 Update readme.md 2022-04-19 15:04:29 -03:00
Ricardo Andrés Marino Rojas
f617d25af9 Add missing StableCoins pairs in Crypto Exchanges (#6259)
* Add missing stablecoins

* Fix bugs

* Remove MIMUSD stablecoin pair

That pair is already in the SPDB

* Add more stablecoins pairs

- Add SUSD and IDRT

* Fix bug

* Requested changes

The algorithm posted in the GH was failing because when finding a conversion between currencies BTC to USD, it wasn't taking into account BTCUSDT and that USD = USDT because is a stablecoin

* Solve bugs

* Nit changes and more tests

* Requested changes

* Nit changes

* Requested changes

* Nit change
2022-04-12 18:10:37 -03:00
Martin-Molinero
a8e104f696 Allow LeanDataWriter to merge existing ticks if desired (#6284)
* Allow DataWriter to merge existing ticks if desired

- Optionally allow lean data writer to merge new ticks with existing
- Adjust ZipStreamWriter
- Fix bug in compression lib that was leaving files open. Reproduced by
  added tests.

* Address reviews

- Define new WritePolicy to configure the behavior of the LeanDataWriter
  regarding how it should handle writing to a file: merge, overwrite,
  append
2022-04-08 18:20:23 -03:00
Ronit Jain
d1ff914e5a fix docs (#6285) 2022-04-08 17:44:01 -03:00
Martin-Molinero
574d685647 Update readme.md 2022-04-07 15:55:51 -03:00
Martin-Molinero
fbd12c7eb1 Update readme.md 2022-04-07 15:29:26 -03:00
Ronit Jain
49562c712f Extract IB brokerage files and dependencies (#6283)
* make public safe to expose test properties

* extract ib files

* remove dependencies

* refactor to use ib reference as string

* remove un-used dependencies

* remove redundant refrences
2022-04-07 14:48:10 -03:00
maciek231
73fa0461ed Added checking if algorithm is stopped in initialize method (#6282)
* Added checking if algorithm is stopped in initialize method

* Quit on initialize adjusment

- Minor adjustments to solution. Adding more regression algorithms

Co-authored-by: Martin-Molinero <martin@quantconnect.com>
2022-04-06 19:56:18 -03:00
Martin-Molinero
6cf537b26f Tradier handle unsupported order durations (#6281)
- Tradier will correctly handle closed orders with unsupported order
  durations. Adding unit test
2022-04-04 18:36:22 -03:00
quantify-cflynn
a374ce9b6e Update Tick.cs Time parsing (#6280)
* Update Tick.cs Time parsing

* Adjust equity tick millisecond read

* Fix tick sub millisecond precision

- DateTime.AddMilliseconds will rount to the nearest integer. So instead
  use AddTicks

* Avoid sporadic test failure

Co-authored-by: Martin-Molinero <martin@quantconnect.com>
2022-04-04 17:36:57 -03:00
Ronit Jain
ad34429014 Refactor changes required for brokerages extraction (#6279)
* set price currency for open orders from brokerage setup handler, remove setters from brokerage

* order already has price currency being set by brokerage transcation handler

* remove as overwritten by BrokerageSetupHandler.GetOpenOrders

* refactor because can't use internal setters in private repos

* refactor, use ctor to set attributes

* remove redundant broker dependency

(cherry picked from commit 57b071eb174ca9fe857021ebffa7a546834e86f7)

* check limit price for limit order instead for checking price

* add price agrument for MarketOrder

* remove, not required anymore

* AddUnrequestedSecurity should not return null

* assert string in not null cases
2022-04-04 17:01:36 -03:00
Martin-Molinero
cc1c305432 Update readme.md 2022-04-01 20:09:46 -03:00
Martin-Molinero
caaa506c56 Update readme.md 2022-04-01 18:45:14 -03:00
kulaj
29e426c2b6 Add localization for CSV export delimiters in CoarseUniverseGeneratorProgram (#6228) (#6275)
* Add localization for CSV export delimiters (#6228)

* Use invariant string decimal for coarse

Co-authored-by: Martin-Molinero <martin@quantconnect.com>
2022-04-01 18:12:47 -03:00
Ricardo Andrés Marino Rojas
368cfe0f5d SecurityExchangeHours::GetMarketHours(DateTime) check early closes and late opens (#6278)
* Update GetMarketHours()

* Nit changes

* Requested changes

* Fix bug

* Add more unit tests

* Address reviews

* Minor tweak

Co-authored-by: Martin-Molinero <martin@quantconnect.com>
2022-04-01 18:02:41 -03:00
Martin-Molinero
06c05c4274 Fully reset security cache (#6277)
- Fully reset the security cache when it's finally removed from the algorithm.
   Adding regression algorithm reproducing issue
- Updating regression algorithms which would trade based on data
  previously available
2022-04-01 15:00:29 -03:00
Ricardo Andrés Marino Rojas
cde4743ca7 Warm up EmaCrossAlphaModel indicators (#6270)
* Warm up EmaCrossAlphaModel

Warm Up EmaCrossAlphaModel indicators

* Fix regression test bug

When using the default `EmaCrossAlphaModel()` the period of both indicators to be ready is bigger than the difference between the start date and the end date of the algorithm. Then, as the algorithm didn't warm up the data both indicators of EmaCrossAlpha never were ready, but now as the model warms up the data both indicators are ready so we get different statistics

* Requested change

* Fix unit tests

As there wasn't items in `AddedSecurities`, when trying to remove the items in ´RemovedSecurities´ there was nothing to remove because there was never a security in `_symbolDataBySymbol`. That's why, in order to test, the behavior of `EmaCrossAlphaModel` when removing a security we need to first add one to then remove it.

* Requested changes in Python

- Requested changes in Python
- Nit changes

* Nit change

* Requested Changes

* Add RemoveConsolidators() method in Python version
2022-04-01 12:15:35 -03:00
maciek231
58e89872c1 Fix HttpClient request timeout (#6273)
* Fix HttpClient request timeout

* Update LiveOptionChainProvider.cs

Remove unrequired accepted encoding specification

Co-authored-by: maciej.tromiczak <maciej.tromiczak@96volt.com>
Co-authored-by: Martin-Molinero <martin@quantconnect.com>
2022-03-30 17:34:02 -03:00
Ricardo Andrés Marino Rojas
85eb1fca9a Add History method overload For Python (#6265)
* Add requested History overload

* Add more regression tests

* Revert "Add more regression tests"

This reverts commit 71b279e917.

* Add more regression tests
2022-03-30 16:18:36 -03:00
Jovad Uribe
cc18e47cd6 Added get/set and tests (#6258)
Co-authored-by: Jovad Uribe <jovuribe@gmail.com>
2022-03-18 10:47:55 -07:00
Ronit Jain
15066ae5e1 Feature improve regression tests (#6245)
* add data count properties

* 'add history count property

* assert data counts

* update missing override

* consider override/virtual cases

* implement data count

* add message handler for regression tests

* use regression test message handler

* set algorithm manager for regression test message handler

* update data count

* check if stats are present, check if algo manager is not null

* update

* add c# algo

* make same as c# algo

* use new line

* logic shifted to RegressionTestMessageHandler

* cleanup

* auto cleanup

* skip non deterministic data count

* change data count

* use inheritance

* improve stats

* update couht

* add sma indicator to c# and customSMA to python

* call base method before executing further

* skip test

* revert to original

* add duplicate sma

* skip regression test
2022-03-15 16:51:15 -03:00
Jovad Uribe
1dc118304f Feature #6233 adds super trend getter (#6251)
* Updates SuperTrend and tests

* Requested Changes

* Address selfreviews

Co-authored-by: Jovad Uribe <jovuribe@gmail.com>
Co-authored-by: Martin-Molinero <martin@quantconnect.com>
2022-03-14 15:01:07 -03:00
Martin-Molinero
de57cedc5a Make continuous future untradable (#6252)
* Make continuous futures untradable

- To match live trading behavior. Adjust continuous futures securities
  to be untradable

* Set ContinuousFuture as non tradable

- Set continuous futures as non tradable. Update regression algorithms
- Fixes for symbol capacity calculation
2022-03-14 14:23:26 -03:00
Louis Szeto
6273671eb7 Update readme.md (#6250)
Enclose the opened string
2022-03-11 11:44:24 -03:00
Louis Szeto
cece811cce Remove extra ; at Python files (#6248)
Co-authored-by: LouisSzeto <hke0073@hotmail.com>
2022-03-10 11:09:33 -03:00
Alexandre Catarino
0c9c8c45e5 Fixes WarmUpIndicator Overload Inconsistency (#6246)
`WarmUpIndicator` for Python indicators doesn't return the indicator anymore after #6027. So all overloads should return `void`.

Fixes `SmaCrossUniverseSelectionAlgorithm` [C# and Py].
2022-03-10 10:59:16 -03:00
Ronit Jain
7e64bd0265 add end date (#6242) 2022-03-07 19:24:16 -03:00
Ronit Jain
48a7ba77ef Feature support CI of research environment for LEAN (#6237)
* initial commit

* temp commit

* checkout master

* update files

* copy to output directory

* checkout master

* automatically update expected output

* revert

* use correct dotnet interactive version

* clean escape char before assert

* add remark

* update namespace

* remove pythonnet

* use GetExportedTypes

* update notebook result during test run

* remove dispensable escape sequences from expected output

* change location

* update summary

* docs

* docs

* update paths

* use multiple lines for output

* update paths

* suport different python location

* check if notebook are run

* update comment

* remove

* help proper debugging

* assert output first

* add comment
2022-03-04 17:40:41 -03:00
Martin-Molinero
b6de0e7222 Update readme.md 2022-03-04 16:23:57 -03:00
Martin-Molinero
7732a27c1b Nugets will copy content files to output (#6239) 2022-03-04 16:18:46 -03:00
chriscdev
adb6afc4f1 Feature 6208 add nyseliffe exchange to interactive brokers (#6209)
* Added NYSELIFFE exchange support to Interactive Brokers brokerage.

* Fixed unit test AddSecurityWithSymbol by adding market hours for Equity-nyseliffe-[*], Index-nyseliffe-[*], Option-nyseliffe-[*].

* Added NYSELIFFE exchange support to Interactive Brokers brokerage.

* Fixed unit test AddSecurityWithSymbol by adding market hours for Equity-nyseliffe-[*], Index-nyseliffe-[*], Option-nyseliffe-[*].

* Added NYSELIFFE exchange support to Interactive Brokers brokerage.

* Fixed unit test AddSecurityWithSymbol by adding market hours for Equity-nyseliffe-[*], Index-nyseliffe-[*], Option-nyseliffe-[*].

* - Added NYSELIFFE futures to Futures.cs
- Added method GetGoodFriday() to calculate Good Friday to FuturesExpiryUtilityFunctions.cs.
- Added unit tests for GetGoodFriday().
- Added NYSELIFFE futures expiries to FuturesExpiryFunctions.cs which uses GetGoodFriday() instead of hardcoding the date of Good Friday in the market-hours-database.json.
 - Added unit tests for NYSELIFFE futures expiry.
- Added NYSELIFFE to Exchange.cs
- Removed Equity-nyseliffe-[*] and Index-nyseliffe-[*] from market-hours-database.json
- Updated Option-nyseliffe-[*] to FutureOption-nyseliffe-[*] on market-hours-database.json
- Added the supported NYSELIFFE futureoptions to symbol-properties-database.csv.

* Removed blanks after India tuple

* Added the dates for 2022 and 2023 to the market-hours-database.json.
Removed "FutureOption-nyseliffe-[]" from market-hours-database.json.
Added to FuturesOptionsSymbolMappings.cs:
{ "YG", "OYG" },
{ "ZG", "OZG" },
{ "ZI", "OZI" }

* Minor tweaks for nyseliffe FOPs

Co-authored-by: Chris Coetzee <chris@polidata.ai>
Co-authored-by: Martin-Molinero <martin@quantconnect.com>
2022-03-04 15:24:17 -03:00
Martin-Molinero
29588095ed Remove Atreyu order exchange destination (#6232)
- Remove Atreyu order exchange destination no longer supported. Updating
  regression test
2022-03-04 15:22:29 -03:00
Martin-Molinero
e7043bfc7e Re add ptvsd python debugger (#6236) 2022-03-01 22:11:23 -03:00
Colton Sellers
a44d7b2f92 VSCode Project Changes (#6129)
* Deprecate breakpoints

Drop Watchlist

Remove breakpoints from lean

Prep install of NetCoreDbg

Cleanup

* Install NetCoreDbg

* Update Research Images with Newer Jupyter
2022-03-01 17:41:44 -03:00
Adalyat Nazirov
18b99338fc Implement Binance US exchange (#6222)
* Binance.US base changes

* biniance exchange info update

* Binance US uses same fee rates as main Binance

* binance us brokerage model tests

* use base implementation of GetBuyingPowerModel method
2022-02-22 13:32:59 -03:00
Ronit Jain
f129ab1a09 Feature implement ExchangeInfoDownloader (#6213)
* add gdax exchange info downloader

* add downloader method to program]

* fetch currency description

* change definition to include headers

* use extension method to make request

* remove log from test

* replace WebRequest

* cleanup

* use relevant name

* implement IExchangeInfoDownloader for bitfinex, initial commit

* add default values

* use default market value

* use correct attribute for lotsize

* don't skip missing values

* handle multiple downloaders

* add gdax and bitfinex exchange downloader

* follow LEAN data directory structure

* update SPDB

* order tickers

* order tickers

* add exchange info downloader test template

* delete files

* update SPDB

* use currency mapping

* update bitfinex symbols

* update currency mapping

* sort result after old currency symbols are used

* use market of the respective brokerage

* no more unknown symbol

* change minimum order size value

* direct conversion possible

* update bitfinex symbols

* change user-agent

* add test for indirect conversion

* update stats
2022-02-22 13:00:54 -03:00
Ronit Jain
f86926bf7a Fixes HistoryProviderManager slice merging by using algortime for all slices (#6226)
* remove un-used

* use utc time for slice sync

* use utc time

* refactor

* add regression test

* use utc time

* use utc time

* make utctime required parameter

* add utcTime in slice creation

* assert warm up complete

* check if algorithm is still warmingup

* use exchange tz
2022-02-18 20:43:33 -03:00
Louis Szeto
68c046fc7b Update SamcoFeeModel.cs (#6220)
* Update SamcoFeeModel.cs

https://www.samco.in/charge-list-equities-and-equity-derivatives

* Update SamcoFeeModelTests.cs

Co-authored-by: Martin-Molinero <martin@quantconnect.com>
2022-02-17 20:05:31 -03:00
Alexandre Catarino
3e52816f6e Fixes GetBuyingPowerModel Method of DefaultBrokerageModel (#6215)
`CashBuyingPowerModel`, which reflected on `AlphaStreamBrokerageModel`, a margin-only brokerage.

It also didn't consider the account type, so `InteractiveBrokersBrokerageModel` was using the margin model even if `AccountType.Cash` was selected.

Removes `GetBuyingPowerModel` method from other Brokerage Models when their cases are covered by `DefaultBrokerageModel`

Fixes some typoes in `TradierBrokerageModel`

Fixes unit and regression tests. For the regression tests, we have explicitly set the brokerage model.
2022-02-17 19:41:55 -03:00
Jasper van Merle
c598a8d260 Add support for array history-provider values to QuantBook (#6219) 2022-02-17 11:24:20 -03:00
Martin-Molinero
e63bfc9127 Adjust virtual position in margin accounts (#6214)
- The BrokerTransactionHandler will also adjust virtual positions for
  margin accounts when fees are in base currency and the asset is a
  crypto or forex pair. Adding new regression tests reproducing issue
2022-02-16 15:25:47 -03:00
Martin-Molinero
e316f12394 Refactor MarginRequirementEntry. Update margins (#6210)
* Fix master

* Refactor MarginRequirementEntry to it's own file

* Update margin files

* Remove duplicate dates cases

* Update margins after fix
2022-02-15 20:24:28 -03:00
Martin-Molinero
306298a16f Update HistoryProviderManagerTests.cs 2022-02-15 12:34:00 -03:00
Adalyat Nazirov
e8160f33d5 Binance extraction (#6193)
* extract binance brokerage

* remove binance tools from main toolbox app

* modify OrderTestParameters constructor

* fix BinanceBrokerage ref config.json

* update symbol properties

* move BinanceFeeModel tests to the right place
2022-02-15 12:05:47 -03:00
Ronit Jain
ce3cb8e1a3 fix max leverage (#6207) 2022-02-14 16:42:05 -03:00
Ronit Jain
2d644d7879 Feature handle multiple history providers (#6187)
* initial commit

* get history from data providers

* merge history from history providers

* merge slice

* Add merge function in slice

* Update test

* merge aux data

* add data points in _data

* append new data points in original list

* Add test suite for HistoryProviderManager

* reduce complexity

* setup once

* add fake history provider

* doesn't count aux data

* add tests for options

* style changes

* add custom data

* merge rawDataList

* use array of history providers

* optimize

* fix formatting error

* add comment

* add tests

* simplify

* use list

* use abstraction

* split tests

* add test

* use abstraction to create generic enumertor class

* refactor

* accept list of type T

* sync history slices

* use SubscriptionDataReaderHistoryProvider for live

* rename test file

* return empty

* add tests

* cleanup

* address reviews

* optimize

* Fix method definition

* use initial time for basedata

* refactor

* re-use collection

* inherit HistoryProviderBase

* always return HistoryProviderManager

* add tests

* update rawDataList

* reset composer

* consider null elements

* add tests for binary search method

* Follow lean coding style

* revert

* remove binary search method

* convert to field
2022-02-14 11:58:00 -03:00
Colton Sellers
b80e274d4f Rename OptionsPositions.None -> Empty (#6204) 2022-02-11 19:11:30 -03:00
Martin-Molinero
9a355c9be5 Adjust INR/USD micro future scale to usd dollars (#6203) 2022-02-11 17:01:01 -03:00
Kieran Anderson
303b95ab50 Fix typo (#6201)
"buisness" --> "business"
2022-02-10 21:16:18 -03:00
Colton Sellers
d826d267f4 Update CI script with fixes for using env var (#6200) 2022-02-10 20:13:39 -03:00
Ricardo Andrés Marino Rojas
eb55311052 Feature 5157 micro futures update (#6190)
* Update MHDB and SPDB

Update MHDB and SPDB with micro futures

* Fix bugs

* Add more FutureExpiryFunctions

* Requested changes

* Nit changes

* Nit changes

- Fix some future values in SPDB
- Test LastFriday() method
- Apparently Micro CHF/USD Futures(MSF) refers to the micro of Swiss Franc Futures (6S). The same happens with Micro JPY/USD (MJY) Futures and Japanese Yen Futures (6J)

* Fix bugs

* Micro futures MultipleFactor

* Fix some futures MultipleFactor
2022-02-10 17:45:07 -03:00
Colton Sellers
27d18fa2e8 Include DataSource repos in stub generation (#6195)
* Include DataSource repos in stub generation

* Remove C# import from AlgorithmImports

* Directly import the Algorithm.CSharp namespace

* Update ci_build_stubs.sh

Case-sensitive typo

Co-authored-by: Jasper van Merle <jaspervmerle@gmail.com>

Co-authored-by: Jasper van Merle <jaspervmerle@gmail.com>
2022-02-10 15:09:08 -03:00
Adalyat Nazirov
bb0c671e7c Accept OrderSubmissionData in constructor (#6194)
* modify OrderTestParameters constructor

* add other types
2022-02-08 19:27:22 -03:00
Martin-Molinero
c8dc343c13 GetLastKnownPrices python data (#6191)
* Adding unit tests reproducing issue.

* Fix a couple of minor bugs

- IsMarketOpen will work correctly when used with daily and hourly
  resolution.
- slice.Get will work correctly with python custom data
- ExtendedDictionary will be able to dinamically access methods,
  required for python and private C# data types

* Refactor solution. Add more tests

* Remove unrequired import statement
2022-02-08 15:37:05 -03:00
Alexander Myltsev
b6815d22de Exante Brokerage initial setup (#6018)
* Exante Brokerage initial setup

* Minor exante adjustment. Address review

* Add comments to Exante config section

* Exante `GetLeverage`: handle `SecurityType.Forex`

* Exante `GetLeverage`: return 1.0 for the default case

* Cover Exante `BrokerageModel` and `FeeModel` with tests

* Add missing configurations at config.json

Fixes https://github.com/QuantConnect/Lean/pull/6018#discussion_r799527521

* Fix spaces typos

https://github.com/QuantConnect/Lean/pull/6018#discussion_r799528112

Co-authored-by: Martin-Molinero <martin@quantconnect.com>
2022-02-07 19:53:22 -03:00
Martin-Molinero
459f60603b Fees is base currency subtracted from quote currency (#6188)
* WIP

* Fix fees in base currency not being subtracted

- Fix fees in base currency not being subtracted from the quote currency
  for crypto cash accounts. Updating regression tests to assert
  portfolio, cashbook state and holdings state.

* Fix unit test race condition
2022-02-07 14:57:40 -03:00
Martin-Molinero
1aaaa20c61 Fix daily auxiliary data points emission time (#6186)
* Use GC server mode for tests

* Fix daily auxiliary data points emission time

- Due to fillforwarding, in some cases with daily resolution symbol
  change events (generically any auxiliary data) would arrive late.
  Updating regression test to reproduce the issue. Adding unit test
- Some refactoring and logging improvements

* Address reviews

* Remove old xml docs param
2022-02-04 21:06:45 -03:00
Adalyat Nazirov
07b6572bf9 Support Binance Margin trading (#6173)
* change BinanceBrokerageModel

* supply spot vs margin endpoint as parameter

* wip

* send margin order for margin account

* "NEW" means that the order has been accepted by the Binance engine.

* fix cash balance

* use JsonConverters for account parsing

* unit tests

* fixup

* lazy connect

* fix connection

* allow api client to be null if DQH only

* make method private

* more unit tests

* fix Dispose

* fix tests

* fix IsConnected condition

* run test as additional

* add some comments

* improve unit tests

* improve null checks

* tidy up the code
2022-02-04 17:30:39 -03:00
Ricardo Andrés Marino Rojas
a675aca7e5 Refactor GetFilePath() (#6164)
* Refactor `GetFilePath()`
Add also useful methods to use with this one

* Nit changes

* Requested changes

* Requested changes

* Restore SaveString()

* Nit changes

* Address self review

* Test improvements

* Adjust example KerasNeuralNetworkAlgorithm

* Minor tweak for KerasNeuralNetworkAlgorithm.py

Co-authored-by: Martin-Molinero <martin@quantconnect.com>
2022-02-04 16:58:25 -03:00
Martin-Molinero
87db3fe379 Performance improvements (#6182)
- User server mode for GC
- Remove SecurityType cache type check
2022-02-02 19:52:45 -03:00
Ricardo Andrés Marino Rojas
74321d1727 Update CME future holidays and early closes in MHDB (#6181)
* CME Futures update in MHDB

* Fix indent spaces nit errors

* Revert "Fix indent spaces nit errors"

This reverts commit 6ebb8614c0.

* Fix tabs errors

* Update MHDB with 2022 holidays

* Fix bugs

* Remove earlyOpens
2022-02-02 19:28:21 -03:00
Martin-Molinero
9fd50a302e Update or remove SharpZipLib dependency (#6180) 2022-02-02 13:28:24 -03:00
Martin-Molinero
fc0b2f3fa4 Fix for Add & Remove option contract case (#6172) 2022-01-28 14:13:21 -03:00
Martin-Molinero
c4a2d6eef4 Crypto base currency fees handled correctly (#6166)
* Binance fees deducted from fill quantity accordengly

- For Binance cash accounts while buying, if fees are from the base
  currency of leans virtual position, we need to deduct the fee from the
  fill quantity, else we can end with a position bigger that it actually
  is and not be able to liquidate

* Refactor solution

- Refactor solution into a more generic approach solving fees in base
  currency at the BrokerageTransactionHandler level, covering all
  brokerages that require it. Adding regression algorithm reproducing
  issue.
- Update Bitfinex and Binance fee models to correctly reflact reality

* Log fill quantity adjusment once
2022-01-28 13:02:58 -03:00
Martin-Molinero
c2b60e4e48 Fix empty parameter set deserialization (#6171)
- Fix empty ParameterSet deserialization. Adding unit test
2022-01-27 20:18:47 -03:00
Martin-Molinero
ca9e55fda6 Add null check for Tradier GetQuotes (#6170)
- Fixing bug where tradier GetQuotes could return null in cases where
  the provided symbol would not match any. Adding unit test.
2022-01-26 19:55:27 -03:00
Martin-Molinero
b698641c90 Minor tweak for ApiDataProvider to support India (#6169)
- Minor tweaks for the ApiDataProvider to better support India market
2022-01-24 21:27:22 -03:00
Ronit Jain
e5c709ee29 Extract zerodha brokerage out of LEAN (#6163)
* Remove zerodha brokerage

* use different brokerage for tests

* remove zerodha files with conflict

* remove redundant dependecies
2022-01-24 18:43:12 -03:00
Martin-Molinero
ca787d0a25 Add support for live price scaling (#6104)
* Add support for live price scaling

- Add support for live trading price scaling for continuous futures.
  Adding unit tests

* Move live price scale application. Updating unit tests

- Live trading application of price scaling will happen before fill
  forwarding and updating securities real time price. Updating unit
  tests to reproduce issue
2022-01-24 18:02:24 -03:00
Martin-Molinero
b1a1277eca Fix GetLastKnownPrices resolution usage (#6165)
- GetLastKnownPrices will no longer guess which resolution to use but
  rely on other methods implementation/
- Updating basic template future algorithms to warmup contracts and
  assert it
- Minor improvements for FunSecurityInitializer and FuncSecuritySeeder
2022-01-21 18:00:53 -03:00
Martin-Molinero
30d7fb042b Always reuse aggregator instance if any (#6161)
* Always reuse aggregator instance if any

- When fetching a IDataAggregator instance from the composer, do not
  enfore type name on existing instances

* Fix unit tests
2022-01-20 18:52:22 -03:00
Ronit Jain
d1bb70fbb7 Add account currency and IRegressionAlgorithmDefinition (#6159)
* Add account currency

* update stats

* use market order, same as c#
2022-01-19 18:25:57 -03:00
Ricardo Andrés Marino Rojas
0946bfc2fb Enable users to use symbol tickers when using Toolkit (#6158)
* If the market ticker has a ":" the user can use the symbol ticker

* Nit change
2022-01-19 15:42:21 -03:00
Ronit Jain
f34be8e3ff Feature add India index algorithms and data (#6145)
* add data

(cherry picked from commit 814011d89e5316d150f88ffca5f48d8d5f0ea7d9)

* update market hours for index

(cherry picked from commit edac40732c120eb84d27de00594b59eebb4983f5)

* add index algorithms

(cherry picked from commit b22d27b4fa98172c435f7c26de4a3a297c49a6b7)

* update statistics

* add cash

* Add india market

* add leverage for index

* can subscribe to index

* update format

* fix wrong cash

* fix ticker names

* update data

* update ticker and stats

* update docs
2022-01-19 12:14:48 -03:00
Martin-Molinero
e1d1e28bb8 Fix for Tick subscription history requests (#6156)
- Fix for history requests != Tick for existing subscriptions with Tick
  resolution. Adding unit test reproducing issue
2022-01-18 17:36:27 -03:00
Colton Sellers
5ea9f04b10 Deprecate PTVSD for DebugPy (#6153)
* Deprecate PTVSD for DebugPy

* Replace all references to PTVSD with debugpy

* Address review
2022-01-13 09:45:12 -03:00
Adalyat Nazirov
2529ba124d FTX API endpoint is cinfigurable (#6026)
* specify enpoint url of ftx api (can be FTX pr FTX.US)

* more metadata for ftxus

* tidy up code

* tests

* more tests

* fix tests

* fix us fee rates

* add account tier

* update symbol props

* typo

* typo-2

* update symbol properties

* use FTXUS fee model

* minor tweaks
2022-01-12 13:51:18 -03:00
Ricardo Andrés Marino Rojas
472f78cc53 Remove Quandl from LEAN (#6110)
* Remove Quandl from LEAN

* Nit changes and CustomLiveDataFeedTests.cs

* Resolve conflicts

* Remove files related with Quandl

* Fix bug

* Fix QuantBookHistoryTests.cs

* Fix bug

* Fix bug

* Fix unit tests

* Try fix regression tests

* Nit changes

* Fix bug

* Some of the requested changes

* The missing changes

* Requested changes

* Nit changes

* Revert "Nit changes"

This reverts commit 9800bc5c34.

* Nit changes

* Fix bug

* Requested changes

* Missing file using Quandl to be removed

* Nit changes

* Not applied nit change

* Nit change

* Nit change

* Add nasdaq-auth-code parameter in config.json

* Remove 'quandl-auth-token' from config.json

Co-authored-by: Martin-Molinero <martin@quantconnect.com>
2022-01-12 12:10:20 -03:00
Adalyat Nazirov
0c26d42561 Feature 2839 black scholes data generator (#6135)
* replace to local functions as they are more performant

* fix random generator upper bound

Next() includes minValue, but not maxValue, so we increment it +1

* introduce abstract layers

* refactoring

* fix tets

* adapt tests

* fixup

* implement blackschole price model for options

* use risk free rate

* use ql price model

* wip

* change interface

* fix

* tidy up the code

* wip

* iterate groupped symbols

* wip

* wip

* fix

* allow symbol of different types

* improve settings

* wip

* iterate full range

* fix issue with negative option

* fix

* fixup

* use StandardDeviationOfReturnsVolatilityModel

* re-use existing tick types per security type

* parametrize underlying security type

* use default option style

* dynamic option price model

* fix enumeration

* test

* fix unit tests

* refactor code

* remove unused file

* minor tweaks and refactoring

* rename symbol generator class

* fix interface

* add comments

* more comments and unit tests

* more tests

* add disclaimer

* more tests

* more comments and tests

* split tests into different files

* tidy up the code

* tidy up the code; more tests

* refactor TickGenerator => use security price directly on each iteration

* remove dupe; reuse main constructor

* use SecurityManager, refactor code

* bugfix: save ticks in history array

* check volatility warm up & tests

* more unit tests

* describe volatility period span in settings

* rename command line option

* Minor adjusments. Address review

- Use Lean log handler instead of writting directly to console
- Rename BlackShcolesPriceGenerator to generically OptionPriceModelPriceGenerator
- Minor format clean up & standarization
- Add support for specifying the option chain size

* Rename TickGenerator private fields

* Fix unit tests

* fix tests class name

* Support tickers being specified

Co-authored-by: Martin-Molinero <martin@quantconnect.com>
2022-01-10 17:21:03 -03:00
Martin-Molinero
4b94f50754 Option selection improvements (#6144)
- Zip entries will be sourced from cache provider
- Option underlying will use SubscriptionDataSource to fetch it's data.
  Fixing bug where it would let through an old data point, or miss
  sending data through.
2022-01-10 11:18:28 -03:00
Martin-Molinero
5bdc60b137 Fix for warmup history requests when internal subscriptions present (#6146) 2022-01-10 11:10:44 -03:00
Ronit Jain
3837c32b36 Add India market local data and regression algorithm (#6088)
* Add india market data

* use local data for algo

* Add India market regression algo

* update india market data

* Update readme

* add python algo for BasicTemplateIndiaAlgorithm

* Add India data regression python algo

* data india data files

* update tickers

* Fix algo template

* remove data

* fix stats

* update stats

* remove unused data
2022-01-06 18:24:32 -03:00
Ronit Jain
0e298edcb2 use compression library (#6142) 2022-01-05 15:19:41 -03:00
Martin-Molinero
7a753bfa3f Live mapped subscription will clone the underlying (#6141)
- Live subscription enumerator will clone the underlying data set when
  live mapping is being done. To avoid issues where IDQH implementations
  could reuse a data point with same configurations. Adjusting unit test
  to reproduce issue
2022-01-05 13:45:52 -03:00
Martin-Molinero
8e2554b110 Add continuous futures MHDB always. Adding unit tests (#6139) 2022-01-04 20:31:31 -03:00
Martin-Molinero
bfa58b4692 Fix IB Hong Kong Future Exchanges fees (#6133)
* Fix IB HongKongFutureExchanges fees. Adding test

* Minor self review tweak
2021-12-28 20:12:59 -03:00
Martin-Molinero
e3375bc45e Pin conda and pip foundation versions (#6134) 2021-12-28 18:14:17 -03:00
Martin-Molinero
ac8b500ba2 Foundation update: Ray, H2o & IB (#6126)
* Foundation remove Ray update H2o

* Update IB version to 10.12.2d
2021-12-28 16:17:52 -03:00
Omid K. Rad
2557a36feb Bug: Config.TryGetValue returns true if key is not found (#6128)
* Fix typo

* Fix TryGetValue to return false if key is not found

* Revert "Fix TryGetValue to return false if key is not found"

This reverts commit b85b7b579a.

* Update documentation for TryGetValue
2021-12-28 12:19:46 -03:00
Martin-Molinero
55cb3bdaff ApiDataProvider Support Future map & factor files (#6132)
- Add support for the ApiDataProvider to handle future map and factor
  files downloads. Adding unit test
2021-12-27 21:52:51 -03:00
Martin-Molinero
10bb627fc2 Update to pythonNet 2.0.11 (#6131) 2021-12-27 15:49:24 -03:00
Alexandre Catarino
3d3733c0fb Adds Market.HKFE to InteractiveBrokersFeeModel (#6127)
Adds `Market.HKFE` to `InteractiveBrokersFeeModel` in the Futures Options case.
2021-12-22 19:32:07 -03:00
Martin-Molinero
1303ccf843 Update readme.md 2021-12-22 17:16:41 -03:00
Martin-Molinero
3b5f3fcf42 Update readme.md 2021-12-22 16:18:09 -03:00
Andreas Sundebo
e2de241c2b Feature 5090 add api optimization methods (#6108)
* Move Optimizer-related DTOs and JSON converters into Common/Optimizer

* Add REST methods for Optimization

* Move OptimizationStatus into Common

* Change optimizationId parameter type to string

* Update Optimization and add lightweight optimization object

* Rename lightweight optimization to BaseOptimization and remove unneccessary properties

* Remove snapshotId from Optimization, add ParameterSet to Backtest

* Add missing IApi.cs method signatures

* Move ParameterSet into Common

* Replace Backtest with OptimizationBacktest

* Update UpdateOptimization to not include null or empty name and layout params in the request

* Change Objective targetTemplate regex pattern from ['(.+)'] to (.+) to prevent escaping target strings without whitespace

* Return Estimate object when calling EstimateOptimization

* Use DefaultNamingStrategy when serializing constraint operators

* Revert "Change Objective targetTemplate regex pattern from ['(.+)'] to (.+) to prevent escaping target strings without whitespace"

This reverts commit fbe7de0fd7.

* Update Api method signatures

* Add unit tests

* Fix XML comment referring to the old class name

* Fix XML summary for OptimizationResponseWrapper

* Address review feedback
- Remove unused testOrganizationId
- Change NodeType from string to NodeType enum
- Clarify unit types for Estimate time and balance
- Simplify JsonConverter classes

* Add accessors to Common/Api classes

* Define performance metrics names in PerformanceMetrics class

* Remove unnecessary branching logic from GetSeriesValues method

* Add crefs and examples to XML comments in the Api class

* Revert "Change NodeType from string to NodeType enum"

* Remove layout param from UpdateOptimization method

* Backtest property ParameterSet should be of type ParameterSet

* Add asserts for deserialization in OptimizationBacktestJsonConverterTests

* Replace the three target-related properties with Criterion

* Add serialization and deserialization tests for Optimization

* Remove Optimization Serialization test

* Add EstimateDeserialization test

* Add asserts for integration tests

* Address self review

* Revert test case

* Update Nodes.cs

* Update Nodes.cs

* Set Aborted status when Optimization fails to start

* Add ParameterSetJsonConverter and ParameterSetJsonConverterTests

Co-authored-by: Martin-Molinero <martin@quantconnect.com>
2021-12-22 13:14:56 -03:00
Martin-Molinero
68e2a9170a Do not send internal SecurityChanges to Algorithm (#6118)
* Do not send internal SecurityChanges to Algorithm

- Will not send internal security changes to the Algorithm by default.
  Following custom security changes filter pattern. Updating regression
  algorithms to assert behavior.
- The universe member will know wether it was added with internal
  configurations or not

* Address reviews use a separate collection for internals

* Refactor solution. Adding security changes constructor class
2021-12-21 20:24:32 -03:00
Adalyat Nazirov
d395f704b3 Bug 6115 adjust dates (#6124)
* GH-6115: adjust dates

* fix

* use another approach

* Add lean data writter multiple days data unit test

Co-authored-by: Martin-Molinero <martin@quantconnect.com>
2021-12-21 17:33:36 -03:00
Martin-Molinero
4d1fc7e05a Handle security added and removed in the same loop (#6120)
* Handle security added and removed in the same loop

- Correctly handle adding and removing a security in the same loop.
  Adding regression test

* Adding comments
2021-12-21 11:59:45 -03:00
Martin-Molinero
e3a562d3c9 Add file and line number to documentation attribute (#6122) 2021-12-20 17:30:04 -08:00
Martin-Molinero
4fdd60d146 Use 64 when saving zips update dotnetZip (#6114) 2021-12-20 16:39:06 -03:00
Martin-Molinero
abbb50e209 Minor improvements for data reading and caching (#6113)
* Minor improvements for data reading and caching

* Address reviews

* Adjust zip cache error check
2021-12-16 19:58:37 -03:00
Alexandre Catarino
0e1cc288a6 Change Default Market of CFD to OANDA (#6107)
Oanda is currently the only provider.
2021-12-13 17:58:57 -03:00
Martin-Molinero
3b826535c7 Fix for ConcurrentDictionary Thread Safety (#6105)
- ConcurrentDictionary with OrderBy is not thread safe, adding thread
  safe extension method. Adding unit tests
2021-12-13 10:45:58 -03:00
Martin-Molinero
59da486e30 IB will correctly create non USD currency contract (#6103)
- IB will create contract based on SPDB entry for symbol. Adding unit
  test
2021-12-10 13:56:32 -03:00
Martin-Molinero
f42d7bb3a2 Align universe security and configuration TZ (#6102)
* Align universe security and configuration TZ

- Make sure universe security and configuration tz are aligned always.
  Adding unit test reproducing issue

* Address review UserDefinedUniverse will use UTC TZ
2021-12-09 15:53:56 -03:00
Martin-Molinero
87bd0d7792 CompositeDataQueueHandler handles duplicate configs (#6101)
* CompositeDataQueueHandler handles duplicate configs

- CompositeDataQueueHandler will handle duplicate subscriptions sharing
  the same config. Adding unit tests

* Refactor bug solution after review

- LiveSubscriptionEnumerator will not long perform any symbol mapping
  but will just trigger a new subscription call when remapped.
- CompositeDHQ will handling symbol mapping and keep track of these
  mapped configs to trigger unsubscribe accordengly. Adding unit tests

* Adjust solution after review

- To avoid breaking uniqueness of SubscriptionDataConfig will be adding
  a private `mapped` property that will change equality of mapped
  configs to avoid them clashing. Adding unit tests

* Rename IDQH subscription extension methods
2021-12-09 14:53:04 -03:00
Louis Szeto
8ca9258e70 API Reference for docs v2 (#6098)
API Reference for docs v2 

Co-authored-by: Alexandre Catarino <AlexCatarino@users.noreply.github.com>
2021-12-08 16:25:36 -08:00
Martin-Molinero
72105539fc Minor Exchanges cleanup (#6100) 2021-12-06 19:27:27 -03:00
Anuj Patel
589e8a9293 fix Kraken fee model (#6096)
* Update KrakenFeeModel.cs

* Update KrakenFeeModelTests.cs

Co-authored-by: Anuj Patel <91538343+anuj-mitul-patel@users.noreply.github.com>
2021-12-06 11:59:20 -03:00
Martin-Molinero
dd27a382f7 Composite data queue handler IUniverseProvider (#6097)
* Minor performance improvements

* CompositeDataQueueHandler is UniverseProvider

- CompositeDataQueueHandler implements the UniverseProvider interface.
  Adding unit tests
2021-12-06 10:27:18 -03:00
Jovad Uribe
62a8aee38c Kaufman Efficiency Ratio Indicator (#6050)
* Indicator

* Fixed logic error

* Removed old files, added KER into KAMA

* Removed old comments

* Added requested changes

* Minor clean up

* Refactors KaufmanEfficiencyRatio and KaufmanAdaptiveMovingAverage

Co-authored-by: Martin-Molinero <martin@quantconnect.com>
Co-authored-by: Alexandre Catarino <AlexCatarino@users.noreply.github.com>
2021-12-04 18:55:09 -03:00
Alexandre Catarino
7e7c27416b Updates KeltnerChannels to Update MiddleBand with EndTime (#6084)
* Updates KeltnerChannels to Update MiddleBand with EndTime

* Adds Unit Test

This unit test shows that the timestamp of the MiddleBand and the indication are aligned as expected.
2021-12-03 19:43:32 -03:00
Martin-Molinero
26f2f88c67 Add documentation attribute default value (#6095) 2021-12-03 18:47:47 -03:00
Martin-Molinero
c08c129860 Add documentation attribute (#6094) 2021-12-03 18:23:06 -03:00
Martin-Molinero
bae10389ae Update readme.md 2021-12-03 17:15:58 -03:00
Martin-Molinero
4301d7cead Update readme.md 2021-12-03 17:08:06 -03:00
Martin-Molinero
d49f1d0d6c Update readme.md 2021-12-03 16:34:47 -03:00
Ronit Jain
264c3c8374 Composite IDQH - Support multiple live data feeds (#6047)
* initial commit

* Follow IDQH implementation

* Expect a list of data handlers from LiveNodePacket

* Return null if can not subscribe

* refctor to add check for subscription

* initialze null

* Add tests

* Check subscribe retuns null/not-null

* cleanup

* Read all required IDQH credentails to job

* Use CDQH to handle all IDQH instances

* constructor abstraction to call from setjob

* use flag

* remove redundant because derived will call initialize on it

* abstract and initialize from setjob

* handle null enumerators

* get creds from data handlers

* handle single data handler value from data-queue-handler

* Fix to support a json array

* Fix missed constructor call

* change access modifier to access from Tests files

* Add test to get brokerageFactory from dataQueueHandler

* Fix init flag to handle all conditions

* Add docs

* initialize from setjob

* Check if websocket open before using

* change defination of initialzie to include tradier

* clean up

* change defination

* fix wrong api key name

* return empty enumerator

* check websocket open before sending request

* check connection before subscribing

* fix to include more cases

* check websocket open before sending request

* Minor refactoring

* reafctor and use IsConnected

* remove unused

* clean up

* Fix test cases

* reverse change

* include config changes

* connect to websocket from setjob

* check websocket connection from setjob

* clean up

* include condition for IDQH that are not brokerage

* Address review

* Add market check condition before subscribe

* Remove deprecated

* Minor fix for deserializing data queue handler

Co-authored-by: Martin-Molinero <martin@quantconnect.com>
2021-12-03 16:18:41 -03:00
Martin-Molinero
8a1f67edfc Minor fixes (#6093)
- Update Atreyu fees
- Remove redundant check in AlphaStreamBrokerageModel
- Fix option contract removal and second addition. Adding unit test
2021-12-03 12:54:49 -03:00
Martin-Molinero
5f434f2fa5 SetupHandlers will exit if errors on initialize (#6092)
- SetupHandlers will exit right away if detect errors on initialize.
  Adding unit tests
2021-12-02 19:24:51 -03:00
Martin-Molinero
e37f8ae878 Fix for adding continuous future and future contract at the same time (#6091)
- Fix for adding continuous future and manually adding contract at the
  same time. Continuous future was using the user defined universe
  symbol and caused clashes. Adding regression test reproducing the issue.
2021-12-02 18:13:52 -03:00
Martin-Molinero
b4e95209f6 Fix for IB Option position race condition (#6090)
- Fix for IB option position update race condition, where the BTH would
  incorrectly assume it should trigger an early option assignment. Adding unit tests
2021-12-02 17:09:50 -03:00
Martin-Molinero
ea65c61dc8 Minor InteractiveBrokers fix (#6089)
- IB needs to notify the `DefaultBrokerageMessageHandler` we have re
  connected else it might kill the algorithm
2021-12-01 19:26:25 -03:00
Ricardo Andrés Marino Rojas
6bf6ff1a6a Fix bug in ConsumeMultipleMinutes() test (#6083)
* Give `code()` more time per iteration

* Another proposed solution

* Revert "Another proposed solution"

This reverts commit 29bf5a7554.

* Add an AutoResetEvent field in `TimeConsumer()`

* Avoid change TimeMonitor implementation

* Remove changes in `TimeConsumer.cs`

* Requested changes

* Avoid re-implementation
2021-11-30 21:44:42 -03:00
Martin-Molinero
d1a35e6281 Continuous Futures Refactor. Live Mappings (#6076)
* Continuous Futures Refactor. Live Mappings

- Adding support for live mappings. LiveTradingDataFeed will handle any
  symbol mapping at the configuration layer and resubscribe through the
  IDQH
- Refactoring continuous futures adding ContinuousFutureUniverse that
  will select the currently mapped security

* Minor fixes

- Remove addition of configurations in UniverseSelection step, leave
  resposability for universe.
- LiveTradingDF future unit test will only assert slice data for non
  internal feeds.
- ContinuousContractUniverse will respect internal option interest
  subscription

* Address review
2021-11-30 21:38:50 -03:00
Martin-Molinero
fed1fa929b Fix low resolution index TradeBar parsing (#6081)
- Fix low resolution Index TradeBar parsing. Updating unit tests. Adding
  unit tests
2021-11-29 12:59:16 -03:00
Ricardo Andrés Marino Rojas
9e7962f5a2 Add Overload in SecurityTransactionManager Methods to Support Python Functions (#6068)
* Add PyObject overload

* Nit changes and unit tests

* Regression tests

* Nit changes

* Requested changes

* Requested changes

* Handle null parameter cases
2021-11-26 16:15:54 -03:00
Andreas Sundebo
3e66733413 Properly handle pending CancelOrderRequests during backtesting (#6021)
* Properly handle pending CancelOrderRequests

To avoid unneccessary "Insufficient buying power to complete order" errors showing up as Invalid orders we need to skip further processing of pending CancelOrderRequests in the BacktestingBrokerage and instead let them be properly removed during the next transaction handler run.

* Update BacktestingBrokerage.cs
2021-11-26 14:47:30 -03:00
Colton Sellers
c11a09e08a Feature Index Option Low Resolution Support (#6075)
* Activate Index and IndexOptions low res

* Add Index and IndexOption low res data

* Add IndexOption regressions

* Fix bug with IndexOption QuoteBar data not being scaled

* nit - update comment for _scaleFactor

* Update data and regressions to reflect fix in data

* Tweak regressions
2021-11-26 13:11:35 -03:00
Anuj Patel
f06bab944d fix incorrect Kraken and Coinbase Pro fee values (#6071)
* fix Coinbase Pro fee values

fee values changed to reflect most recent fee schedule, see 
* https://blog.coinbase.com/updates-to-coinbase-pro-fee-structure-b3d9ee586108
* https://help.coinbase.com/en/pro/trading-and-funding/trading-rules-and-fees/fees
* https://pro.coinbase.com/fees

* fix Kraken fee values

all fee values multiplied by 1/100 to correct inaccuracy, see
* https://www.kraken.com/features/fee-schedule#kraken-pro

* changes time to after latest fees have been set and replaces old expected values
2021-11-24 16:57:20 -03:00
Ricardo Andrés Marino Rojas
df63b6f5d6 Renaming requested changes (#6072) 2021-11-24 09:58:37 -03:00
Colton Sellers
1358bd8115 Future and FutureOption low res support (#6069)
* Fixes for FutureOptions support in LeanData

* Add CreateCanonicalOption() utility function for Symbol.cs

* Add aggregated Futures/FuturesOptions data to Lean

* Add FutureOptions regressions for daily/hourly data

* Allow Futures to be added with low resolution

* Add Future regressions using hour/daily data

* Nit - Python Class names

* Add reviews

* Add alias into CreateCanonicalOption
2021-11-24 09:53:21 -03:00
Martin-Molinero
40cc7a808a Skip subscribing to canonical symbols (#6070) 2021-11-22 21:00:45 -03:00
Martin-Molinero
e3a4fa1838 Update readme.md 2021-11-22 12:54:51 -03:00
bmello4688
1d8243ecac Add tick type to data downloader get (price data) call in order for a… (#6057)
* Add tick type to data downloader get (price data) call in order for api's with rate limits to handle not making an api call at all.

* Added DTO object to pass into data downloader get

* Added missing header for new file

* Address review. Minor tweaks

Co-authored-by: Martin-Molinero <martin@quantconnect.com>
2021-11-22 12:00:16 -03:00
Martin-Molinero
a8c81cad2a Fixes for continuous futures history requests (#6067)
* Fixes for continuous futures history requests

- Fixes for continuous future history requests and warmup. Adding
  regression test

* Address reviews
2021-11-19 20:52:15 -03:00
Martin-Molinero
5f95a9ba77 Bug fix python history requests enumerable data (#6066)
* Fix for python enumerable data history request

- Fix for python enumerable type data history request. Adding unit test.

* Add methods for adding data points into a baseDataCollection
2021-11-19 14:58:48 -03:00
Ricardo Andrés Marino Rojas
a9b914c9ef Fix: IB Subscribe Cannot Find HangSeng Futures (#6064)
* Fix Bug

* Nit change

* Change `LookupSymbols()` method implementation

* Nit change

* Revert "Nit change"

This reverts commit 7bad6d195d.

* Nit change
2021-11-18 20:56:22 -03:00
Martin-Molinero
5436275901 Remove comments from MHDB json file (#6065) 2021-11-18 20:41:02 -03:00
Martin-Molinero
0a315b0ae6 Update readme.md 2021-11-17 19:59:03 -03:00
Colton Sellers
33599b473d Refactor Delistings Processing (#6059)
* Move processing of delistings to Brokerage

* Deal with case that exchange is not open on OptionSymbol.ID.Date

* Refactor solution to use DelistingNotification event

* Adjust some regression expected liquidation time

* Mark some todos on deprecated functions

* Update expected liqudation time for Py regressions

* Update regressions that have been validated

* Use HandlePositionAssigned for assignment orders

* Update regressions

* Update some missed unit tests; remove one that is already covered by regression

* Cleanup deprecated backend functions

* nit - small cleanup adjustment

* Post rebase fix

* Address review

* Minor tweak to py regression
2021-11-17 17:43:35 -03:00
Jovad Uribe
325e788728 Super Trend Indicator (#6013)
* Super Trend Indicator #4653

* Updated test data

Previous test data was wrong

* Reduced if statement

* Updated tests

Replacing spy test data with dwac test data from trading view.

* Minor comment update

* Minor tweaks

Co-authored-by: Martin-Molinero <martin@quantconnect.com>
2021-11-17 12:19:26 -03:00
Martin-Molinero
57ac4d6497 Add import for System.Drawing (#6063) 2021-11-17 11:28:09 -03:00
Martin-Molinero
664dca2236 Tradier websocket bug fix (#6061)
- Tradier brokerage will use BaseWebsocketsBrokerage which handled
  websocket resubscription. Minor API changes
2021-11-16 18:44:38 -03:00
Ricardo Andrés Marino Rojas
5415fe6bc0 Beta indicator (#6042)
* First BetaIndicator prototype
- In construction

* Fist BetaIndicator version and unit tests

* More unit tests and regression test

* Nit change

* Requested changes

* Nit changes

* Requested changes

* Adjust beta formula slightly and nit changes

* Nit change
2021-11-15 15:57:24 -03:00
Martin-Molinero
b2517cbbb4 Fix DiskDataCacheProvider. Expanding unit test (#6058) 2021-11-15 15:57:09 -03:00
Martin-Molinero
b8b0d18993 Continuous futures (#6034)
* Continuous Future Contracts

* Mapping approach

* Tweaks WIP

* Live mapping

* Live mapping

- Add support for live mapping, refreshing mapfiles
- Fix future expiration functions
- Adding unit tests

* Update moq test package

* Continuous futures price scaling

* Refactor price factors scaling

* Factor file related renames

* Address reviews
2021-11-15 14:44:30 -03:00
Martin-Molinero
ad865e2a53 Add new CustomWeight, AlphaModel for AlphaStreams (#6052)
- Add new CustomWeight PCM for alpha streams
- Add new AlphaStreams AlphaModule that will handle security additions
  and removals, removing this logic from AlphaStreamsBasicTemplateAlgo
2021-11-15 14:33:16 -03:00
Martin-Molinero
57f0d17c5d Remove user plan enum (#6055)
* Remove user plan enum

- Get maximum order and runtime from job controls
- Remove user plan enum definitions

* Add log for BacktestingSetupHandler maximums
2021-11-12 19:37:23 -03:00
Ricardo Andrés Marino Rojas
d234d69abc Give timer more time (#6053) 2021-11-12 13:41:56 -03:00
Colton Sellers
dd4da7ba95 Feature Daily/Hourly Options Support (#6017)
* Create generic writing for LeanDataWriter, + notes on todos

* Make Options Daily/Hourly data store by year

* Refactor Generic Write

* Permit hour and daily resolutions for options

* Refactor writer to merge when needed with other files

* Cleanup redundancies, run write tasks in parallel

* Make needed classes/vars available

* Update tests to reflect new naming convention for daily hourly options data

* Add Byte[] overloads for ZipData functions in compression

* Implemented Store() for ZipDataCacheProvider

* Have LeanDataWriter use a DataCacheProvider

* ZipDataCacheProvider cleanup

* ZipDataCacheProvider tweaks, doesn't support storing non-zips

* Test adjustments

* Update LeanDataWriter to use Write instead of SaveDailyHourly/SaveMinuteSecond

* Implement tests to verify DownloadAndSave behavior

* Nit cleanup on DownloadAndSave tests

* Fix for options daily/hourly underlying equity subscription read

* Add daily/hourly options data and regressions

* Add missing open interest for hourly

* Fix writing of OpenInterest Daily/Hourly data

* Update data

* Fix Date typo in regression

* Use daily algorithm to test delisting

* Revisions part 1

* Expand test for DataCacheProviders; refactor DiskDataCacheProvider

* nit - test adjustments

* ZipDataCacheProvider test setup refactor

* Adjust multithreaded read/write test; fixes for ZipDataCacheProvider

* Move DiskDataCacheProvider to its own file and add write test

* Remove _appendToZips; always overwrite entry or create zip

* Add mapping regression for daily options

* nit - add license to regression

* Fix Tick write case where more than one data point for a DateTime

* Fix data issue

* Address review

* Tweaks for tests

* Stop Store() early if no entry name is given
2021-11-11 20:05:31 -03:00
Martin-Molinero
27f5223cd2 Pin dotnet interactive version for net5 (#6048) 2021-11-10 13:00:59 -03:00
Adalyat Nazirov
b3d3df3a3c rate limit is dependent on Account Tier, Tier1 by default (#6046) 2021-11-09 16:44:29 -03:00
Ricardo Andrés Marino Rojas
3c1ddb7b96 Enable Warm Up process in MacdAlphaModel (#6037)
* Warm up MACD indicators
- When a security is added in the MACD alpha model, it's warm up at once

* Add unit tests

* Nit change

* Code style and nit changes
2021-11-04 12:15:32 -03:00
Ronit Jain
926ac3879a Add try-catch and null check (#6038) 2021-11-03 20:07:47 -03:00
Martin-Molinero
0327b2012c Add default value for Exchange security types (#6032) 2021-11-01 12:05:15 -03:00
Martin-Molinero
cd5e1d9c54 Can serialize unknown exchange. Adding test (#6031) 2021-10-29 09:13:52 -07:00
Ricardo Andrés Marino Rojas
fc6ddc2120 Feature 5988 WarmUpIndicator() method for indicators written in Python (#6027)
* Implement IIndicatorWarmUpPeriodProvider
- Implement IIndicatorWarmUpPeriodProvider in PythonIndicator.cs
- Make a unit test to check whether the WarmUpPeriod is working as expected
- Make a regression test to check the new feature at a system level

* Nit change

* Change Period parameter for WarmUpPeriod parameter
- Change regression test to check if the new parameter keep backwards compatibility with indicators that do not set WarmUpPeriod

* Documentation change

* Fix tests bugs
- In CommonIndicatorTests.cs before finish the test it checks the period.value with the number of samples but for default the period.value was set to -1

* Change names

* Change WarmUp and RegisterIndicator methods
- Lean WarmUp indicator skip custom python indicators that don't define WarmUpPeriod parameter

* Call WarmUpIndicator manually
- Add a new "bridge" method called WarmUpIndicator in QCAlgorithm.Python.cs to set up everything to call WarmUpIndicator in QCAlgorithm.Indicators.cs
- Change the regression algorithm to warm up the indicators manually

* Remove unnecessary code and add more tests

* Nit change

* Revert "Nit change"

This reverts commit da411f59c9.

* Fix bugs

* Try fix bugs

* Add C# regression test
- More nit changes
- Fix bugs

* Requested changes

* Remove unnecessary code

* Requested changes

* Nit changes
- Add new Python class to check a custom indicator, which doesn't inherits from PythonIndicator, warms up properly

* Reduce redundant code

* Fix bug and add more unit and regression tests

* - Add more unit tests

* Nit change

* Test cleanup

Co-authored-by: Martin-Molinero <martin@quantconnect.com>
2021-10-28 20:29:22 -03:00
Ricardo Andrés Marino Rojas
013b9ea850 Set WarmUpPeriod value in MarketProfile constructor (#6029)
- Remove unnecessary attribute `_period` in MarketProfile
- Set the value of WarmUpPeriod to the period in MarketProfile constructor
- Fix unit test to check VolumeProfile and TimeProfile indicators are being warmed up properly and its WarmUpPeriod parameter isn't zero
2021-10-28 19:54:11 -03:00
Martin-Molinero
9f29e3bf4e Some performance improvements for IndexOptions (#6025)
- Some performance improvements for IndexOptions specially affects
  debugging C# algorithms.
2021-10-27 20:26:51 -03:00
Alexandre Catarino
4ecdf14ce8 Include Security Master Url to ApiDataProvider Error Message (#6023) 2021-10-27 14:58:15 -03:00
Martin-Molinero
ede2d4a5e4 Lazy loading of the SecurityDefinition file (#6024)
- Perform a lazy loading of the security definitions file. Adding unit
  tests
2021-10-27 14:57:50 -03:00
Martin-Molinero
8c71dbc8ba Revert "Feature 5988 IIndicatorWarmUpPeriodProvider for custom PythonIndicator (#5992)" (#6022)
This reverts commit 995f598999.
2021-10-26 22:07:22 -03:00
Martin-Molinero
d17865b2cf CoinApi read previous date file (#6019)
- If available, CoinApi converter will read previous date files to
  rescue initial midnight ticks for the processing date. Also make sure
  to drop ticks from tomorrow
2021-10-25 20:26:12 -03:00
Martin-Molinero
7b3b560dea Foundation update CVXPY 1.1.15 (#6020)
- Update cvxpy python package version to latest 1.1.15. To avoid
  installation issue `error in cvxpy setup command: use_2to3 is invalid`
2021-10-25 18:45:07 -03:00
Ricardo Andrés Marino Rojas
995f598999 Feature 5988 IIndicatorWarmUpPeriodProvider for custom PythonIndicator (#5992)
* Implement IIndicatorWarmUpPeriodProvider
- Implement IIndicatorWarmUpPeriodProvider in PythonIndicator.cs
- Make a unit test to check whether the WarmUpPeriod is working as expected
- Make a regression test to check the new feature at a system level

* Nit change

* Change Period parameter for WarmUpPeriod parameter
- Change regression test to check if the new parameter keep backwards compatibility with indicators that do not set WarmUpPeriod

* Documentation change

* Fix tests bugs
- In CommonIndicatorTests.cs before finish the test it checks the period.value with the number of samples but for default the period.value was set to -1

* Change names

* Change WarmUp and RegisterIndicator methods
- Lean WarmUp indicator skip custom python indicators that don't define WarmUpPeriod parameter

* Call WarmUpIndicator manually
- Add a new "bridge" method called WarmUpIndicator in QCAlgorithm.Python.cs to set up everything to call WarmUpIndicator in QCAlgorithm.Indicators.cs
- Change the regression algorithm to warm up the indicators manually

* Remove unnecessary code and add more tests

* Nit change

* Revert "Nit change"

This reverts commit da411f59c9.

* Fix bugs

* Try fix bugs

* Add C# regression test
- More nit changes
- Fix bugs

* Requested changes

* Remove unnecessary code

* Requested changes

* Nit changes
- Add new Python class to check a custom indicator, which doesn't inherits from PythonIndicator, warms up properly

* Reduce redundant code
2021-10-25 18:08:57 -03:00
Martin-Molinero
43c271a568 Atreyu template algorithm change traget SPY exchange (#6016) 2021-10-25 15:43:35 -03:00
IlshatGaripov
2e4252c92b LiveTradingResultHandler -> changes access modifier of SetNextStatusUpdate (#6015) 2021-10-25 11:17:35 -03:00
Adalyat Nazirov
0f189aa2b4 FTX brokerage rejects STOP order if market price missed (#6009)
* cannot submit stop orders with bad trigger price

* unit tests

* expect price data
2021-10-25 11:14:41 -03:00
IlshatGaripov
f55588e4c6 SecurityHolding -> impl. ToString() (#6014) 2021-10-25 11:07:34 -03:00
Martin-Molinero
58ccdee1b1 PythonNet version bump 2.0.10 (#6010) 2021-10-22 20:27:38 -03:00
Colton Sellers
6bd2859f64 Update to PythonNet 2.0.9 (#6004) 2021-10-21 20:06:38 -03:00
Alexandre Catarino
3ff7882dbf Round AverageLoss to Avoid Very Small Numbers (#6003) 2021-10-21 17:00:31 -03:00
Martin-Molinero
dace6d7ee1 Fix index live target exchange (#6000) 2021-10-20 17:26:25 -03:00
Colton Sellers
71d9eed07e BuyingPowerModel Fixes (#5996)
* Refactor error message for reproducability

* WIP Refactor GetMaximumOrderQuantityForTargetBuyingPower

* Additional tweaks and tests

* Address shorted margin case

* Reinstate tests with new modified function

* Update regression

* Some cleanup

* Expand test set

* Refactor solution

* Address review

* Final adjustments and cleanup

* Expand error message for GetAmountToOrder for safety and reproducibility

* Address reviews
2021-10-20 16:37:20 -03:00
Stas Kotykhin
c4a4550a66 Override History provider in kraken environment (#5998)
* add history-provider field to config.json

* Add comment
2021-10-20 16:36:34 -03:00
bmello4688
67081a8a05 Add virtual overrides for pivotpointshighlow computations (#5987)
* Add base class for pivotpointshighlow

* abstracts do not work well with python switch to virtuals and use pivotpointhighlow as base implementation

* added missing documentatino header

* moved reset back to original location
2021-10-19 21:45:18 -03:00
alexgallotta
a567053404 fix build command with dotnet (#5990) 2021-10-18 16:55:56 -03:00
Martin-Molinero
56b8ccc4b4 CoinApi log error on duplicate symbol (#5989) 2021-10-15 20:31:55 -03:00
Martin-Molinero
5f65677ede Add suuport for coinApi kraken ftx exchanges (#5985) 2021-10-15 11:24:30 -03:00
Ricardo Andrés Marino Rojas
def916aed1 Add IIndicatorWarmUpPeriodProvider for WindowIndicator.cs and Identity.cs indicators (#5984)
- Implement IIndicatorWarmUpPeriodProvider interface in both indicators
- Add test to check the new functionality is working as expected. To test WindowIndicator IIndicatorWarmUpPeriodProvider there was used WindowIdentity indicator tests because that indicator only inherits from it
2021-10-15 11:10:59 -03:00
Adalyat Nazirov
46ce138fa1 move methods for further usage across other brokerages (#5981) 2021-10-14 17:08:11 -03:00
Martin-Molinero
b8768ae274 Add FOPs price magnifier (#5979)
* Add FOPs price magnifier

* Improve unit tests
2021-10-14 11:57:48 -03:00
Ricardo Andrés Marino Rojas
db04b5e110 Feature 5930 price magnifier (#5977)
* Update SPDB with price magnifier parameter
- Add a new column for new parameter in symbol-properties-database.csv
- Change InteractiveBrokersBrokerage.cs implementation of GetContractPriceMagnifier() method in order to get the parameter directly from the SPDB
- Add test in SymbolPropertiesDatabaseTests.cs to check if the new parameter is loading properly

* Change GetContractPriceMagnifier() method name and implementation
- Change NormalizePriceToLean() and NormalizePriceToBrokerage() methods

* Nit change in GetSymbolPriceMagnifier() method

* Remove GetSymbolPriceMagnifier() method
- Remove redundant and unnecessary parameters in NormalizePriceToLean() and NormalizePriceToBrokerage()

* Requested changes and SPDB update
- Update SPDB with minimum order size parameter for futures in cents. The minimum order size parameter was extracted from the CME group API

* Address reviews. Adding unit test for failing case

Co-authored-by: Martin-Molinero <martin@quantconnect.com>
2021-10-14 11:16:23 -03:00
Colton Sellers
cff3640f15 Update to PythonNet 2.0.8 (#5978) 2021-10-13 20:19:06 -03:00
Martin-Molinero
b5574a7986 Do not emit zero quantity Exercise Order events (#5976)
- BrokerateTransactionHandler will not emit zero quantity Exercise order
  events. Updating unit tests
2021-10-12 19:38:37 -03:00
Martin-Molinero
c638f82337 Adjust Bitfinex currency fee error message (#5975) 2021-10-12 17:05:27 -03:00
Adalyat Nazirov
3a591c3a72 Fix Binance ExchangeInfo downloader (#5965)
* fix exchangeinfo downloader

* normalize data, update symbol properties

* min ordersize should be in base currency

* check min order size using quote currency price

* check order size in quote currency

* improve checks

* improve code; more unit tests

* more description

* fix failing test
2021-10-11 12:36:41 -03:00
Martin-Molinero
fdfb1b54c0 Add Binance debugging logs (#5974) 2021-10-11 11:55:12 -03:00
Adalyat Nazirov
7cfdd1243f FTX brokerage essentials (#5963)
* FTX config boilerplate

fixup

* required

* order props

* make orger props setter public

* add market props

* brokerage model

* deny modify order directly

* update markets

* unit tests

* fix market properties

* add comments

* return security benchmark

* fix fee calculation

* dont change access modifiers

* check brokerage CanSubmitOrder using min order quantity

* fix ticker values - use lean notation

* fix fee model

* fix error message
2021-10-08 19:16:38 -03:00
Stas Kotykhin
3fc042af33 Move bar aggregators to utils, add time overloads & add check of orderType for Kraken (#5969)
* Move Aggregate Quote and Trade Bars to utils

* Add decimal and long overload to UnixTimeStampToDateTime

* Add Kraken OrderType check in CanSubmitOrder

* PR !5969 review fixes
2021-10-08 17:59:32 -03:00
Martin-Molinero
1d6fed8843 Update python to 2.0.7 (#5968) 2021-10-08 12:55:14 -03:00
Colton Sellers
2109394060 Add subset test after dropping 'symbol' (#5966) 2021-10-06 18:21:33 -03:00
Colton Sellers
d2d99b1f10 Algorithm Sampling and Statistics Fixes (#5936)
* Implement scheduled event sampling solution

* Use UTC time, only update daily portfolio value once a day

* For daily resolutions sample chart always

* Cleanup

* Drop resample daily all together

* Force final sample

* Regression updates

* FIx LiveResultHandler to update portfolio and benchmark values outside of sampling event

* Name the daily sampling event

* Address review pt 1

* Drop force and use reference wrapper

* Adjust tests

* Fix warning for Benchmark Timezone Misalignment and also add test

* Fix for daily resolution orders and test adjustments

* Also warn on universe settings with daily resolution

* Update missed regression

* Fix reference wrapper use

* Update regression after rebase

* Add values back in for Daylight Algo

* Have statistics builder skip day 1 performance

* Regression adjustments

* Test adjustments

* Update regression unit test

* Adjust some regressions starts to show performance values

* Add hourly algorithm for beta comparison

* Address missing Python regression changes

* Remove null comment
2021-10-05 19:31:25 -03:00
Martin-Molinero
659735946a Bitfinex fees cash accounts (#5957)
* Bitfinex Fee adjustment

- Fix for bitfinex fee adjustment for cash account type only happen if
  the currencies are the expected ones, else log message.

* Adjust error handling to terminate algorithm

* Add bitfinex TESTBTCTESTUSD

* Minor improvements

- Add bitfinex test symbols to the SPDB
- Make SecurityDefinitionSymbolResolver log using trace
- Minor tweak for Bitfinex DQH lock contention
2021-10-04 18:15:32 -03:00
Stefano Raggi
29294cb1f4 Transaction handlers - minor updates (#5956)
- Move debug logging of order events from Brokerage to BrokerageTransactionHandler
- Override CurrentTimeUtc in BacktestingTransactionHandler
2021-10-01 19:09:08 -03:00
Ronit Jain
4546bbe9b1 Fix missing reference price when creating last entry (#5952)
* Fix code styling changes

* Cosmetic change

* Add reference price 1 for last entry

* Fix refernece price
2021-10-01 11:37:58 -03:00
Ricardo Andrés Marino Rojas
af958f0ce4 Bug 5904 minimum order size rejected order (#5949)
* - Update symbol-properties-database.csv, SymbolPropertiesDatabase.cs and SymbolProperties.cs with a new column for MinimumOrderSize parameter for Crypto type
- Change CanSubmitOrder() method implementation in GDAXBrokerageModel.cs to get the MinimumOrderSize from the security SymbolProperties directly
- Add CanSubmitOrder() method in Binance, Bitfinex and Kraken Brokerages models
- Add tests to check if CanSubmitOrder() method is working as expected in Binance, Bitfinex, Kraken and GDAX brokerages models
- Add tests to check if MinimumOrderSize parameter is loading correctly from symbol-properties-database.csv

* Revert "- Update symbol-properties-database.csv, SymbolPropertiesDatabase.cs and SymbolProperties.cs with a new column for MinimumOrderSize parameter for Crypto type"

This reverts commit e0fd66a5fa.

* Revert "Revert "- Update symbol-properties-database.csv, SymbolPropertiesDatabase.cs and SymbolProperties.cs with a new column for MinimumOrderSize parameter for Crypto type""

This reverts commit b0f37935fc.

* Requested changes in Crypto brokerage models
- Remove unnecessary commas in symbols-properties-database.csv
- Add TestHelpers class to reuse GetSecurity() method
- Add IsValidOrderSize() method in DefaultBrokerageModel class
- Remove unnecessary classes for brokerage models test helpers

* Nit change
- Remove unnecessary attribute from DefaultBrokerageModel.cs

* Nit change

* Nit changes and Regression test
- Add Bitfinex BTCUSD hourly data for 2 days
- Add regression test BuyBTCWithLessThanOneDollarAlgorithm.cs to test that the order size is taking into account when placing or updating an order
- Nit changes

* Change CanUpdateOrder() implementation
- CanUpdateOrder() now checks if the requested quantity value is valid

* Requested Changes
- Change regression algorithm BuyBTCWithLessThanOneDollar.cs name and implementation

* Nit changes
2021-09-30 18:30:04 -03:00
Stefano Raggi
6c42a266be IB brokerage - Update option positions at contract expiration (#5880)
* IB brokerage - Update option positions at contract expiration

* Add handling of live option expiration events

* Address review

- Nits

* Refactor option notification events [WIP]

* Add early exercise+assignment unit tests

* Fix sign bug in IB ExerciseOrder

* Address review

- log unexpected position
- add unit test cases for partial exercise/assignment
2021-09-30 13:48:41 -03:00
José Emiliano Cabrera Blancas
8b7da686ea Fix MovingAverageType in KeltnerChannels Indicator (#5954)
The Simple Moving Average was always used instead of the one passed to
the KeltnerChannels constructor.
2021-09-29 20:48:07 -03:00
Martin-Molinero
d3280c5e60 Move VX margin files (#5948) 2021-09-28 14:21:07 -03:00
Stas Kotykhin
fe1f22543f Add NonUpdateableLimitIfTouchedOrderTestParameters class (#5947) 2021-09-28 13:16:04 -03:00
Stefano Raggi
57ddbbbf05 IBAutomater updates (#5946) 2021-09-28 11:45:05 -03:00
Martin-Molinero
9579c4263b Fix history requests so they ignore internal subscriptions (#5945)
- Fix for history requests so that they ignore internal subscriptions
  accordengly. Adding regression test reproducing issue
2021-09-27 20:31:05 -03:00
Martin-Molinero
f082a40f34 Add missing comments (#5944) 2021-09-27 18:48:53 -03:00
Martin-Molinero
d739873daa Add aggregator reader (#5942)
* Add BaseDataCollectionAggregatorReader

- Add enumerable for BaseDataCollection
- Add BaseDataCollectionAggregatorReader
- Clean up CollectionSubscriptionDataSourceReader

* Address reviews

- Add new FileFormat that will be handled by the new Reader
- Adding unit tests for the new BaseDataCollectionAggregatorReader
- Some DataSourceReader duplication cleaning up

* Minor adjustment after some live trading tests
2021-09-27 17:25:23 -03:00
Martin-Molinero
0f7dfe8ec8 Fix live ETF universe selection (#5938)
- ETF live universe selection will behave the same as Coarse selection.
  Adding unit test
2021-09-23 15:11:35 -03:00
Alexandre Catarino
58968bf05f Adds Warnings to MOO and MOO using Tick Data (#5937)
Adds Warnings to MOO and MOO using Tick Data
These warnings are meant to let the user know that it was not possible to find ticks marked with the `OfficialOpen`, `OfficialClose`, `OpeningPrints` or `ClosingPrints` flags.
2021-09-22 19:17:18 -03:00
Stefano Raggi
627f280100 IB brokerage updates (#5933)
* Disconnect from IB API before waiting for restart

* Update IBAutomater to v2.0.62

* Update IBAutomater to v2.0.63
2021-09-22 18:52:00 -03:00
Alexandre Catarino
9ca57c2de9 Fixes Market On Close Fill of Equity Fill Model (#5913)
* Fixes Market On Close Fill of Equity Fill Model

Only use trade data (`Tick` with `TickTrade` type or `TradeBar`) to get the closing price, since MOC is filled with the closing price.

- Fix unit tests to show that the new implementation only fills with trade data from the current open market.
- Change regression tests to reflect the bug fix. All other changes are the consequence of using `TradeBar` instead of `QuoteBar`.

* Address Peer-Review

Fixes the logic with tick data: looking for the OfficalClose or ClosingPrints only apply if data from the extended market hours is included.
Adds additional logic to handle missing trade data.

* Refactors Timeout Logic and Adds It to MarketOnOpenFIll

-Refactors timeout logic to address peer-review and adds it to MOO fill too.
- Adds unit tests
2021-09-21 17:51:35 -03:00
Martin-Molinero
35c2951abb Tradier add retry logic. Clean up rate gate (#5935)
- Add Tradier retry logic in case of an unexpected execution failure
- Clean up rate gate logic to use RateGate class
2021-09-21 17:40:54 -03:00
Simon Judd
2c237b7f84 IB Brokerage - fix for futures contracts priced in cents (#5930)
* Fix IB futures prices where PriceMagnifier != 1

* Fix deadlock in GetOpenOrdersInternal by moving ConvertOrder call out of event handler;
Minor refactor to combine NormalizePrice and ConvertPrice methods

* IB future and future options price magnifier

* Address review. IB API clean up

Co-authored-by: Martin-Molinero <martin@quantconnect.com>
2021-09-20 16:17:25 -03:00
Martin-Molinero
4e6e0c85c6 Lean exchange improvements (#5932)
* Lean exchanges improvements

- Adding new Exchange class to avoid exchange code clash.
  Adding and updating unit test

* Add Market for MapFile API

* Self review
2021-09-20 13:50:15 -03:00
Colton Sellers
a2ac956d53 Move WickedRenkoConsolidator to RenkoConsolidator as Default (#5931)
* Rename Renko to ClassicRenko

* Rename WickedRenko to Renko

* Adjust tests and usages

* Backwards support WickedRenkoConsolidator

* Renames for consistency
2021-09-17 16:32:01 -03:00
Colton Sellers
5fecb77c8a Composite Indicator Fixes (#5929)
* Refactor for two types in composite indicator

* Fixes for unit tests

* Non generic indicator base

* Further seperate non-generic indicator base and generic input base

* Adjustments

* Remove generic CompositeIndicator

* Add test suite

* Make each method an individual case

* Address review

* Testing cleanup

Co-authored-by: Martin-Molinero <martin@quantconnect.com>
2021-09-16 17:58:10 -03:00
Stefano Raggi
3e8f15a62f Fix IB restarts during weekends (#5926)
* Fix IB restarts during weekends

* Address review

- Task.Delay usage
- update default delay from 10s to 5m
2021-09-15 19:16:34 -03:00
Martin-Molinero
0931ae868a Fix multiple coarse selection algorithms (#5927)
- Fix for live trading multiple coarse selections. Adding unit test
  reproducing issue.
2021-09-14 20:27:09 -03:00
Martin-Molinero
e13df5c901 Fix null reference loading existing holdings and cash balance (#5925) 2021-09-14 11:20:03 -03:00
Martin-Molinero
7be1b7db1a Algorithm Language can be case insensitive (#5924) 2021-09-13 10:31:31 -03:00
Gerardo Salazar
024d416ddd Adds support for getting a Lean symbol based on FIGI, CUSIP, ISIN, SEDOL (#5922)
* Adds support for getting a Lean symbol based on FIGI, CUSIP, ISIN, SEDOL

* Address review: bug fixes for mapping, improve docs, cleanup & refactor

  * Make LocalZipMapFileProvider and LocalZipFactorFileProvider only
    initialize if they haven't been initialized yet.

* Address review: makes ISIN, SEDOL, CUSIP case-insensitive

  * Cleans up map file provider in SecurityDefinitionSymbolResolver
  * Modifies some test cases to test for case-insensitivity

* Add null check for SecurityDefinitions

* Fix unit tests

Co-authored-by: Martin-Molinero <martin@quantconnect.com>
2021-09-10 19:16:18 -07:00
Martin-Molinero
eb2dbe2af7 Fix FuncSecuritySeeder for python (#5923)
- Fix funcSecuritySeeder for python. Adding regression algorithm
2021-09-10 19:28:49 -03:00
Colton Sellers
8358c394e1 Support all security types for benchmarks (#5919)
* Adjust benchmark subscription to dynamically determine best resolution

* Get types from SM

* Add red/green test set for security types
2021-09-10 16:58:31 -03:00
Stefano Raggi
d7c7adbd0d Update IBAutomater to v2.0.57 (#5920) 2021-09-10 12:36:34 -03:00
Martin-Molinero
1ab1f90e27 Add research import QuantConnect.AlphaStream (#5918) 2021-09-09 15:12:42 -03:00
Martin-Molinero
bf2ef35ada Update readme.md 2021-09-09 12:14:46 -03:00
Colton Sellers
2001f9a181 Tradier Options History Support (#5912)
* Implement options support for history requests

* Address review
2021-09-09 11:19:12 -03:00
Stas Kotykhin
8026785116 Feature kraken brokerage setup (#5896)
* Kraken Brokerage initial setup

* Fix naming in config

* Add license messages

* Add fees for stablecoins

* add kraken databases

* Review fixes, tests added

* Remove redundant field and using

* add CanUpdateOrder & summary

* Remove null

* Change to equal

* complete xml comments
2021-09-08 12:49:13 -03:00
Ronit Jain
5083433f68 Inital brokerage setup commit (#5905) 2021-09-07 22:05:36 -03:00
quantify-cflynn
5d4f428906 Add ValueAreaVolumePercentage Parameter (#5908)
* Add ValueAreaVolumePercentage Parameter

Remove hard coding of parameter and set it to optional parameter for the user.

* Update TimeProfile.cs to include valueAreaVolumePercentage parameter

* Update TimeProfile definition in QCAlgorithm.Indicators.cs
2021-09-07 12:17:23 -03:00
Ricardo Andrés Marino Rojas
da60daa60d Market profile indicator (#5891)
* Create Market Profile indicator.

* - Requested changes in MarketProfile indicator made it.
- TimeProfile and VolumeProfile created and tested.
- tp_datatest.csv and vp_datatest.csv extracted from https://github.com/bfolkens/py-market-profile

* Final potential Market Profile Indicator.
All unit test made it and the indicator is passing all of them
Test cases made it with python library from GH issue

* Code styling request changes

* Minor suggestions

* Minor renaming tweaks

Co-authored-by: Martin-Molinero <martin@quantconnect.com>
2021-09-03 20:18:44 -03:00
Martin-Molinero
7d88b5040b Update readme.md 2021-09-03 19:20:11 -03:00
Martin-Molinero
d76106b444 Fix foundation build failure (#5902) 2021-09-03 17:41:58 -03:00
Martin-Molinero
de09ec0933 Update readme.md 2021-09-03 17:27:36 -03:00
Martin-Molinero
c3874bc618 Mapping Extensions will try get custom data from symbol (#5901) 2021-09-03 17:08:02 -03:00
Stefano Raggi
0e1e497fbf Update IBAutomater to v2.0.56 (#5900)
* Update IBAutomater to v2.0.55

* Update IBAutomater to v2.0.56
2021-09-03 10:31:22 -03:00
Martin-Molinero
8eb023e854 Remove duplicate market hours segments (#5897) 2021-09-02 19:09:51 -03:00
Martin-Molinero
b251cffc2f Alpha Streams improvements (#5887)
* Few improvements

- Alpha Streams algorithm will add target securities right away
- If algorithm is warming up PortfolioTargetCollection will emit not
  insight
- Fix local disk factor file provider to use local cache instead of data
  folder
- EWAS PCM will not emit targets for securities which have not been
  added by the algorithm yet, to avoid runtime exception

* Fix GetLastKnownPrice default order adding more unit tests
2021-09-01 13:12:26 -03:00
Stefano Raggi
1d904e716c Add new Market.CFE (#5391)
As most brokers use separate exchange codes for CBOE and CFE, we added the new Market.CFE (previously Market.CBOE was used for both exchanges). This change also avoids hacky code in symbol mappers.
2021-08-31 19:34:14 -03:00
Ronit Jain
df57428bd7 Fix zerodha async order event (#5878)
* Fix zerodha async order event

consider fillQuantity as total filled quantity

cover edge case of fully filled

fix async events received from zerodha

indentation fix

* Fix coding style

* keep order in only CachedOrderIDs
2021-08-30 19:32:40 -03:00
Stefano Raggi
9d734c4d8f Update IBGateway install path (#5885) 2021-08-30 17:11:12 -03:00
Martin-Molinero
765ce87df1 Remove unrequired link library (#5884) 2021-08-27 21:45:30 -03:00
Martin-Molinero
8a5766fa39 Update foundation base image to ubuntu 20.04 (#5882)
- Update amd64 and ARM foundatio base image to ubuntu 20.04
2021-08-27 19:47:20 -03:00
Martin-Molinero
933e5ce6ca Alpha Streams improvements (#5876)
* Alpha Streams improvements

- Warmup added securities so we can trigger an order right away
- Fix bug where AddSecurity returned a security which was not the one
  being used
- Fix bug where EWAS PCM would remove from a dictionary while iterating
  over it

* Fix unit tests

* Add QCAlgorithm.GetLastKnownPrices API

- Add new GetLastKnownPrices that will return the last known data point
  for all subscribed data types.
- Fix for MHDB GetDataTimeZone which was using an invalid entry key
  format for custom data.
- Fix for using GetLastKnownPrice/s to seed a security during creation,
  when it's not added in the Algorithm.Securities collection

* Adding more unit tests for GetLastKnownPrice

* Address reviews

- Refactor GetLastKnownPrice/s to perform a single history request for
  all data types
2021-08-27 13:50:45 -03:00
Gerardo Salazar
dc433493b7 Add support for specifying CoinAPI market to process (#5877)
* Add support for specifying CoinAPI market to process

* Address review: improve CoinAPI stability by making inputted market lowercase
2021-08-27 13:26:55 -03:00
Martin-Molinero
9acf68ad19 Bump pythonNet to 2.0.6 (#5881) 2021-08-26 18:01:05 -03:00
Martin-Molinero
5ebf451fb3 Fix for python SetHoldings precision loss (#5879)
- After https://github.com/QuantConnect/Lean/pull/5872 trading API
  changes numpy float64 was not converted correctly by pythonNet and
  used an int. Reverting API changes and adding regression test. This
  should be fixed at pythonNet layer
2021-08-25 15:25:39 -03:00
Gerardo Salazar
a4d49c05ca Adds ETF(...) to UniverseDefinitions (#5873)
* Adds ETF(...) to UniverseDefinitions

  * Adds ETF constituents universe framework regression algorithm
    for C#/Python

* Address review: adds test cases for ticker/Symbol ETF universe additions

  * Fixes bug where null Market would result in null dereference exception

* Address review: add missing Index tests

* Address review: don't hardcode market when creating constituent universe

  * Uses Brokerage Model's default markets collection to determine
    the market for the given security type

* Address review: restore QC500 and DollarVolume.Top(...)

  * Restores algorithms related to both helper universe
    definition methods

* Address review: remove copy to output directory for python algos

* Add example algorithms for ETF constituent universes using custom RSI alpha model

* Address review: adjust algorithm to use cache + algo RSI & clean up code

* Address review: make ETF Constituent RSI Alpha Model algo a regression test

* Address review: increase trade count and remove single trade logic
2021-08-25 11:22:31 -03:00
Martin-Molinero
aaba566954 Alpha Streams Improvements. Python Imports (#5874)
* Order handling improvements

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

* Python Import fixes

- Add regression test for ImmediateExecutionModel minimum order margin
  check
2021-08-24 11:15:48 -03:00
Martin-Molinero
bf28a1d313 Add basic template Atreyu algorithm (#5872)
* Add basic template Atreyu algorithm

- Add C# and Python basic template atreyu algorithm. Show casing how to
  specify exchange to execute in different ways.
- Adjust trading API to allow specifying order properties to use

* Lean Exchange improvements

- Rename PrimaryExchange to Exchange
- OrderPropeties will use Exchange enum instead of string
- Adding BSE exchange value

* Regression tests fixes
2021-08-23 18:24:44 -03:00
Julio
85a4d3364b Add prefix "oanda-" to access-token (#5870)
Add prefix "oanda-" to account-id
2021-08-23 10:55:31 -03:00
IlshatGaripov
eccca2c029 Fix for Trailing Stop Risk Management Model (#5791)
* To fix the referenced issue

* Fixing up TrailingStopRiskManagementModel

* Fix-ups to address review

* Impl. tests + relevant improvements

* Minor logic improvement at first dictionary update

* Regression test small fix

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

* Use integer values in test cases

* Removes failing testcases in MaximumDrawdownPercentPerSecurityTests (!) & renaming

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

This reverts commit f9cd279f8c.

* Fix up for failing test cases
2021-08-20 15:14:36 -03:00
Martin-Molinero
b0314e1c7c Fix for alpha license (#5868)
* Fix organization read alpha license field

* Add import statement for python
2021-08-19 15:51:48 -03:00
Martin-Molinero
3410832ccf Alpha holdings state (#5770)
* Alpha holdings state

- Alpha result packet will optionally provide the algorithms portfolio
  state

* Rename

* Convert AlphaStreamsPortfolio to data source

* Improvements on AlphaStreams algorithm

* Fix regression tests

* Add unit tests for EW AS PCM and fixing bugs

* Protobuf AlphaStreamsPortfoliot staState

- Protobuf AlphaStreamsPortfolioState. Adding unit tests
- Add variable TPV tests for EW ASPCM

* Add alpha license to Organization response

* Improvements EW AS PCM respects free portfolio value

* Fixes

- Update tests expected statistics results affected by MHDB custom data timezone fix
- Fix for Extensions.IsCustomDataType

* Fixed and adding more regression tests

- Adding support and regression test with alpha consumer with different account currency
- Adding support and regression test of a universe adding custom data
  types
- Add support and regression test for algorithm alpha consumer with existing holdings

* Add AlphaStreamsOrderEvent data type
2021-08-19 13:56:18 -03:00
Stefano Raggi
d573a0f6c7 BrokerageTransactionHandler - handle OrderStatus.New in order update/cancel (#5867) 2021-08-19 12:01:38 -03:00
IlshatGaripov
7a3d8667c5 More logging for BinanceRestApiClient (#5846)
* More logging for BinanceRestApiClient

* Changing LogLevel to Debug for history providers : Binance, Polygon

* Minor fixes

Co-authored-by: Martin-Molinero <martin@quantconnect.com>
2021-08-18 11:25:51 -03:00
Martin-Molinero
c3543f844a Add paper trading for Binance (#5859)
- Adding paper trading support for binance
2021-08-18 10:57:45 -03:00
Martin-Molinero
1fdb36ee89 Improve object store logs (#5864) 2021-08-18 10:33:34 -03:00
Gerardo Salazar
cd9e451ead Adds Support for ETF Constituent Universes (#5862)
* Adds support for ETF constituent universes

  * Adds filtering for universe data if it doesn't match the
    universe subscription type

  * Update mapping for ALL underlying Symbols if
    `Symbol.UpdateMappedSymbol(...)` is called. Required to support
    constituent ETF universes that might have mapping events

  * Delistings of composite constituent universe Symbol will result in
    removal of universe securities.

  * Added regression algorithms for ETF constituent mappings (C#/Python),
    along with data required to run locally

  * Refactor universe delistings in SubscriptionSynchronizer -
    big thank you to @Martin-Molinero :)

* Address review: update regression algorithms and add explanatory comments

* Address review: add additional checks to delisting regression algorithms

  * Adds new regression algorithm testing the addition of a universe
    without calling AddEquity() and asserts same behavior
2021-08-17 19:54:29 -03:00
Stefano Raggi
b4f6b51ad1 Update IBAutomater to v2.0.52 (#5863) 2021-08-17 17:07:33 -03:00
Stefano Raggi
a5e395d298 Update IBAutomater to v2.0.50 (#5860)
* Update IBAutomater to v2.0.47

* Update IBAutomater to v2.0.48

* Update IBAutomater to v2.0.49

* Update IBAutomater to v2.0.50
2021-08-16 21:08:22 -03:00
Stefano Raggi
a40329c70c Update IBAutomater to v2.0.46 (#5852) 2021-08-12 11:32:14 -03:00
Alexandre Catarino
6546647e08 Get Best Effort Price For Fill Price (#5855)
`EquityFillModel` will use Trade Tick or TradeBar data if there is no L1 data available leading to filling to stale price.
2021-08-12 10:16:20 -03:00
Martin-Molinero
46829f0f01 Dependency clean up (#5834) 2021-08-11 12:39:00 -03:00
Colton Sellers
e722e72aaa Pandas Mapper Recursion Bug Fix (#5848)
* Adjust wrapper

* Adjustments

* Add red -> green unit tests

* Address review
2021-08-10 20:32:09 -03:00
Martin-Molinero
e92230a7fe Fix SubscriptionDataReader auxiliary data out of order (#5843)
* Fix SubscriptionDataReader auxiliary data out of order

- Fix for SubscriptionDataReader emitting auxiliary data out of order
  due to sparse that and enumerator refresh logic. Adding regression
  algorithm
- Minor tweaks for unit tests failing on and off

* Fix for SDR internal subscriptions

- Fix for SubscriptionDataReader enumerator refresh for internal
  subscriptions which were ignored. Adding regression test
- Updating custom data regression algorithms affected by the issue
	- DropboxBaseDataUniverse was emitting a custom data point being end time
	- UnlinkedTraderBarIconicType was emitting a single data point
	  of the underlying SPY minute data when if should of emitted
	  all data points
2021-08-10 18:57:23 -03:00
Ronit Jain
7881aeb3a5 Websocket-refactor for websocket message data as text and binary (#5833)
* websocket-refactor for websocket message  as text and binary

Initial commit

websocket support for text and binary messageData

code style fixes

test fix

* delete un-used file

* zerodha websocket textMessage parse

* messageData class abscration

* Empty

Co-authored-by: Martin-Molinero <martin@quantconnect.com>
2021-08-10 17:40:07 -03:00
Stefano Raggi
32fdb51ab5 Update IBAutomater to v2.0.45 (#5847) 2021-08-10 12:01:29 -03:00
IlshatGaripov
190fe012f1 Perform update (#5841) 2021-08-10 11:18:23 -03:00
IlshatGaripov
893ca2b41d Makes sure to create directory for results-destination-folder (#5842) 2021-08-09 17:39:57 -03:00
Stefano Raggi
c30bd32fb0 Fix IB history requests (#5832)
* Fix IB history requests

- Fix time zone bug causing incomplete results
- Use RegularTradingHours flag only for equities
- Second resolution data is now requested in 30 minute chunks (instead of 1 minute):
https://interactivebrokers.github.io/tws-api/historical_limitations.html

* Filter history result respecting market hours and IncludeExtendedMarketHours flag

* Add history unit tests
2021-08-09 16:57:12 -03:00
Martin-Molinero
e720147e50 Algorithm Manager will break when algorithm is deleted (#5840) 2021-08-09 15:42:13 -03:00
Martin-Molinero
b77f0122b2 Improve python exception parsing (#5831)
* Improve python exception parsing

- Improve python exception parsing adding support for line shift. Adding
  unit tests

* PythonException revert change

* Centralized and normalize algorithm runtime handling

* Adding support for C# line and file exception report
2021-08-06 20:11:54 -03:00
Colton Sellers
646adb9131 Remove Ray from ARM image (#5830) 2021-08-05 19:06:44 -03:00
Colton Sellers
e2ae173d99 Feature Python Library: Ray (#5824)
* Add Ray lib to both foundation images

* Update some version failing tests
2021-08-05 17:55:51 -03:00
Stefano Raggi
1cfc044034 Update Lean Foundation docker files to IBGateway v985.1j (#5828) 2021-08-05 17:55:30 -03:00
Alexandre Catarino
9b7af08b3e Fixes Market On Open Fill of Equity Fill Model (#5679)
* Fixes Market On Open Fill of Equity Fill Model

Only use trade data (Tick with Trade type or TradeBar) to get the open price, since MOO is filled with the opening action price. Ensure that this method doesn't use trade data from before the market opens for high-resolution data case.

Fix unit tests to show that the new implementation only fills with trade data from the current open market.

Change regression tests to reflect the bug fix.
In the `ExtendedMarketHoursHistoryRegressionAlgorithm`, MOO was filled with extended market hours.

* Fix Bug for Tick Resolution Case

For tick susbcription, the tick with the open price information is the the first valid (non-zero) tick of trade type from an open market.
Addresses peer-review by moving the if-condition for data belonging to the open market where the subscriscribed types are checked.

* Fix Bug for Low Resolution Edge Case

For the edge case where the order is placed after the trade bar is open, for example, order places at 1 pm with daily-resolution data. The fill model will not use the open of the bar that will close at midnight, since this value is prior to the order.

Adds unit test.

Change regression tests to reflect the bug fix.
In the `RegressionAlgorithm`, MOO was filled with open prior to the order. The algorithm now has one order less, since the last MOO would need to wait another day to be filled.

* Implements SaleCondition and Exchange Check For Tick

- Adds additional unit tests for MOO

* Fixes Regression Test in DataConsolidatorPythonWrapperTests

* Addresses Peer-Review

- Adds new unit test cases.
2021-08-05 12:53:04 -03:00
Stefano Raggi
1a02fbaae5 Add autorestart for Binance data connections (#5827) 2021-08-05 10:54:50 -03:00
Alexandre Catarino
ed835faf35 Change Binance Benchmark to BTCUSDC (#5823)
`BTCUSD` is not supported by Binance (see Symbol Properties Dabase)
2021-08-04 21:45:03 -03:00
Gerardo Salazar
5ea70e2a89 Adds support for CoinAPI Binance processing (#5819) 2021-08-03 21:17:23 -03:00
Martin-Molinero
2603694263 C# research will pre load all QC dlls (#5820) 2021-08-03 21:14:59 -03:00
Stefano Raggi
4a3a7a44f5 Update Lean Foundation docker files to IBGateway v985 (#5815)
* Update Lean Foundation docker files to IBGateway v985

* Add apt-get update for ARM foundation

* Update default value of IB gateway

Co-authored-by: Martin-Molinero <martin@quantconnect.com>
2021-08-03 19:13:38 -03:00
Martin-Molinero
76c930a035 Update readme.md 2021-08-03 11:47:27 -03:00
Martin-Molinero
12f70aab46 Add DataSource place holder (#5817) 2021-08-03 11:30:12 -03:00
Gerardo Salazar
650ce2e2b5 Removes References To Built-in Custom Data Implementations (#5793)
* WIP removal of custom data references & tests updates

* Regression algos updated and python algorithms moved to DataSource repos

* Fixes failing unit tests

* Add "LiveDataTypes" field to LiveNodePacket

* Adds Initialize() to IDataChannelProvider

  * Adds new extension method to convert
    HistoryRequest -> SubscriptionDataConfig

* Address review: Add protobuf definitions for Iconic data types

* Address review: re-adds DynamicSecurityDataAlgorithm as regression algo

  * Small adjustments to variable naming and documentation

* Move test files to respective DataSource repos
2021-08-02 19:24:45 -03:00
Martin-Molinero
ef4fea7592 Fix engine initialization (#5814) 2021-07-30 17:33:03 -07:00
Martin-Molinero
3cf9cc7d41 Update RestSharp to 106.12.0t (#5810) 2021-07-30 17:45:59 -03:00
Colton Sellers
a9b634b096 Pandas Dataframe indexing w/ list (#5813)
* Wrap df.__getitem__ to map all keys before indexing

* Add reproducing test case
2021-07-30 16:34:03 -03:00
Stefano Raggi
1793add749 Add support for IBGateway v985 (#5812)
* Add support for IBGateway v985

- Effective in TWS version 985 and later, for US stocks the bid, ask, and last size quotes are shown in shares (not in lots).

* Add missing error log in IB symbol mapper

* Trigger build
2021-07-30 13:55:26 -03:00
Martin-Molinero
41636c94c3 Common engine initialization (#5809)
- Create Lean common engine initialization class, which will be called
  by research and Lean launcher
- Fix backtest deserialization bug due to failing to handle decimal
  value
2021-07-29 21:14:17 -03:00
Stefano Raggi
2624b8c6f5 Update IBAutomater to v2.0.43 (#5807)
* Update IBAutomater to v2.0.42

* Update IBAutomater to v2.0.43
2021-07-29 20:53:38 -03:00
Colton Sellers
d8a86f182f Pandas Remapper Refactor (#5808)
* Refactor pandas mapper to support newer versions

* Clean up remapper

* Finalize deprecated tests and adjust those that should apply to new pandas

* Move mapper to its own file

* Add supporting Py tests and setup instructions

* Add license
2021-07-29 20:10:00 -03:00
Martin-Molinero
0da9d626dc Remove security from all universes holdings it (#5798)
- Calling RemoveSecurity() will remove the security from all the
  universes holdings it, there was a race condition here where it would
  just take the first universe and remove it from it.
  Adding regression test adding and removing an option contract and it's underlying
2021-07-28 18:03:09 -03:00
Jovad Uribe
9888081cc0 Relative Daily Volume Indicator (#5747)
* Relative Volume Indicator

* Requested changes and renamed indicator

* Made changes, included Resolution

* Added requested changes

* Update

* Update RelativeDailyVolumeTests.cs

* Update RelativeDailyVolume.cs

* Fixed Test Case File

* Update RelativeDailyVolume.cs

* Fixed IsReady flag
2021-07-28 18:02:34 -03:00
Martin-Molinero
611326b140 WebSocketClient improvements (#5799)
- Take lock to refresh client to avoid null reference
  exception
- Reduce gate rate
- Use extension methods to await tasks
- Avoid copying the data multiple times
2021-07-28 15:17:08 -03:00
Stefano Raggi
907a9f086c Update BinanceBrokerage to handle more than 512 symbols (#5773)
* Update BinanceBrokerage to handle more than 512 symbols

* Address review

- fetch symbol weights only if required
- remove code duplication

* Add rate limiting for new connections

* Update WebSocketMessage to include the websocket instance

* Handle resubscriptions on reconnect

* Address review

* Address review

* Remove unnecessary locking

* WebSocketClientWrapper updates

- remove allocation of receive buffer on each message
- add missing lock in Close method
- log message data when message type is Close
- fix race condition after unexpected websocket close

* Set WebSocketClientWrapper task to LongRunning

* Add missing check in GetHistory

* Fix exceptions with Binance downloader

- closes #5794
2021-07-28 11:10:40 -03:00
Stefano Raggi
0c4e577885 BitfinexBrokerage updates (#5787)
* Update BinanceBrokerage to handle more than 512 symbols

* Address review

- fetch symbol weights only if required
- remove code duplication

* Add rate limiting for new connections

* Update WebSocketMessage to include the websocket instance

* Handle resubscriptions on reconnect

* Address review

* Address review

* Remove unnecessary locking

* WebSocketClientWrapper updates

- remove allocation of receive buffer on each message
- add missing lock in Close method
- log message data when message type is Close
- fix race condition after unexpected websocket close

* Set WebSocketClientWrapper task to LongRunning

* Add missing check in GetHistory

* Fix exceptions with Binance downloader

- closes #5794

* Update Bitfinex symbols in symbol properties database

* Update BitfinexBrokerage to use BrokerageMultiWebSocketSubscriptionManager

* Address review

* Remove unnecessary locking

* Remove old channels on resubscription
2021-07-28 11:10:12 -03:00
Marco Grassi
e823dfdfb7 fix a typo, and remove all unnecessary semicolumns in Python (#5795) 2021-07-27 16:05:13 -03:00
Martin-Molinero
4469d18eb6 Set timezone for DateRules (#5796)
- If algorithm timeZone is changed Update DateRules timezone. Adding
  unit test
2021-07-27 15:34:11 -03:00
Ishant Jain
808ba17bff Indian Market Holidays & Early Open/Late Close Modified (#5792) 2021-07-26 11:14:22 -03:00
Ronit Jain
00f68b951f Zerodha - GetHistory DateTime Parse Correction (#5788)
* logging and kite connection retry

(cherry picked from commit 9845a2d79e86c338093cadcae7f41b29d897c78c)

* changed thread.sleep time for kite connection retries

* websresponse retry on error - coding style change

* datetome parse to convert time in utc

* indentation code-style fix

* zerodhaDownloader support for dataTimeZone

* removed code redundancy for single conversion without hardcoded TZ

* removed hardcode dataTimeZone and code refactor

* returns exchange TZ to lean and data TZ to local disk from downloader

* Kite historical candle timestamp TZ conversion

* added unit test for kite historical candle

* access modifier correection
2021-07-23 18:34:48 -03:00
Stefano Raggi
c07b643273 Filter Bitfinex currencies in Derivatives wallet (#5786) 2021-07-21 14:39:01 -03:00
Gerardo Salazar
95f199eae5 Bug fix: don't throw on unsupported exchanges in CoinApi converter (#5784) 2021-07-20 19:09:29 -03:00
Martin-Molinero
2cb239a330 Fix price left over split cash adjustment (#5780)
- After a split if there are left over shares we model them getting sold
  using the new price. Adding unit and regression test
2021-07-19 13:18:10 -03:00
Martin-Molinero
cb326788b3 Filter out small orders based on Setting (#5776)
* Filter out small orders based on Setting

- BuyingPowerModel will filter out small orders based on algorithm
  setting, a % of PTV, instead of hard coded 1 share value. Addin unit
  and regression tests
- Updating regression algorithms to use new setting, reduce order trades

* Update regression algorithms
2021-07-19 13:17:51 -03:00
Ronit Jain
e2e2b5f102 zerodhaDownloader support for new market convention - Market.India (#5775)
* zerodhaDownloader support for India Market

(cherry picked from commit c36272ef9c4c7eddfff77413d900faab3a2a8654)

* indenation styling fix

* zerodha donwloader

* Market.India support from zerodhaSymbolMapper

* code styling changes
2021-07-19 11:43:17 -03:00
Martin-Molinero
f75e81bd7d Add null check for API data folder (#5774)
- Api.Initialize will not throw for null data folder. Adding unit test
2021-07-16 18:27:42 -03:00
Ronit Jain
522fe14951 Zerodha ProductType customization for Fetching Positions&holdings and also while placing orders (#5766)
* re adding KiteProductType

* check kiteProductType per order and get all Product Type Account Holdings

* use WithLockedStream and remove lock unlock stream

* filter holding if config productType set otherwise fetch all

* improvements in styling and properties

* unionbank has less margin requirements, second always works
2021-07-16 11:43:14 -03:00
Martin-Molinero
9cf4075957 Send invalid orderEvent for non shortable order (#5772)
- TransactionHandler will see invalid OrderEvent for an order which
  tries to short an non shortable asset. Adding unit test, updating
  regression algorithm.
- Fix Api data price path normalization, found while testing with
shortable provider. Adding unit tests
2021-07-15 21:10:46 -03:00
Martin-Molinero
1ed390c5f7 Minor tweaks (#5771)
- Improve readme file, add nuget link, update Lean home page
- Increase 10min look back to 60 for setting currency conversion
- Replace error message for trace when minute resolution history request
  is empty
2021-07-15 13:03:46 -03:00
Jasper van Merle
f5224f8be9 Logging improvements (#5767) 2021-07-14 20:53:09 -03:00
Colton Sellers
8d11bbf0ba Update to PythonNet 2.0.5 (#5764) 2021-07-14 11:01:57 -03:00
Martin-Molinero
1dcdfe79b0 Add data paths to PriceEntry (#5761) 2021-07-13 14:56:20 -03:00
Stefano Raggi
e453635458 Update Binance symbols in symbol properties database (#5759)
* Update Binance symbols in symbol properties database

* Fix failing unit tests
2021-07-12 13:28:28 -03:00
Martin-Molinero
d84ad9ebfc Reduce research image size (#5758)
- Reduce research image size
- Increate BrokerageConcurrentMessageHandler unit test timeout
2021-07-12 09:58:11 -03:00
Martin-Molinero
f9adc6b136 Rename data permissions (#5753) 2021-07-09 22:59:14 -03:00
Jovad Uribe
e5f62fa4dd Feature Augen Price Spike Indicator (#5713)
* Added Augen Price Spike Files

* AugenPriceSpike Update

Adjusted indicator calculations and added test data from Trading View

* Requested Changes

* Minor changes
2021-07-09 20:07:15 -03:00
Colton Sellers
3430b46e6a BuyingPowerModel GetMaximumOrder Adjustments (#5756)
* Add reproducing unit test

* Apply fix to force adjustment if needed

* Adjust fee to correctly replicate original issue

* Adjust solution

* Update unit test to reflect the way this function is used

* nit - rename test

* Cleanup error message to improve reproducibility

* nit - Drop unneeded var

* Add in adjustment test cases as well, fixed
2021-07-09 19:37:48 -03:00
Colton Sellers
00ac4f33af Implement Python overload of Notify.Web for PyObject Headers (#5749)
* Implement Python overload of Notify.Web for PyObject Headers

* Address review + add unit tests
2021-07-08 21:07:19 -03:00
Colton Sellers
0d752abae6 Feature Telegram Notification (#5535)
* Lay telegram notification groundwork

* nit comments

* Implement in JSON converter, and add roundtrip test

* Update comment docs

* Implement configurable token in NotificationTelegram

* Rename to ID, due to @ handles not usable

* Address review + nits

* Nit comment fix
2021-07-07 21:06:45 -03:00
Martin-Molinero
2a77a8d3c0 Update readme.md 2021-07-07 19:50:23 -03:00
Martin-Molinero
49d6cb0021 QuantBook fundamental history request (#5743)
- Allow requiesting the entire FineFundamental object for a QuantBook
  history request. Adding unit test
2021-07-07 12:02:01 -03:00
Stefano Raggi
9a81414a94 IB Brokerage updates (#5744)
* IB Brokerage updates

- Update IBAutomater to v2.0.40
- Add config setting to enable export of IBGateway logs (default=false)
- Downgrade IB log level from Information to Warning

* Update IBAutomater to v2.0.41

* Trigger build
2021-07-07 11:26:09 -03:00
Martin-Molinero
3f85c9ab82 Update readme.md 2021-07-06 23:06:03 -03:00
Martin-Molinero
f062b54450 Update readme.md 2021-07-06 19:59:58 -03:00
Colton Sellers
64b95b2e8e MaximumOrderQuantity Error Log Expansion (#5741)
* Add more details to the log to improve insight into bugs

* Keep string formatting invariant
2021-07-06 19:26:49 -03:00
Martin-Molinero
7bcaaf8f23 Reduce dockerfoundation size (#5740)
- Clean files and conda after each docker build step
- Merge steps to reduce size
- Clear apt lists
2021-07-06 17:42:19 -03:00
bmello4688
8383163aae fixed problems with testcasesource (#5722) 2021-07-06 12:04:04 -03:00
bmello4688
04f3c850ba test fails sometimes from a race to check value (#5720)
* test fails sometimes from a race to check value

* add while limit
2021-07-05 19:03:12 -03:00
Martin-Molinero
5bd0675423 Fix minor race condition in brokerage message handler (#5736)
* Fix minor race condition in brokerage message handler

- Fix race condition where a message could be enqueued and
wait for a new call, not being processed ASAP

* Reduce BrokerageTransactionHandler logs
2021-07-03 19:46:31 -03:00
Jasper van Merle
6eb3822193 Fix coarse universe generator crashing on single processor (#5735)
* Fix coarse universe generator on single processor

* Make sure MaxDegreeOfParallelism value is not less than 1

Co-authored-by: Martin-Molinero <martin@quantconnect.com>
2021-07-03 19:08:55 -03:00
Martin-Molinero
12b62f6ec9 Add organization id to packet (#5733) 2021-07-02 20:59:59 -03:00
Martin-Molinero
8d2455b629 Add BrokerageConcurrentMessageHandler (#5731)
* Add BrokerageConcurrentMessageHandler

- Add Brokerage helper `BrokerageConcurrentMessageHandler` class to lock message stream
while executing an action, for example placing an order, adding unit tests.
- Binance will use new message handler

* Fix unit test
2021-07-02 19:11:25 -03:00
Colton Sellers
171f0f19d5 MaximumOrderQuantity Bug Fix (#5727)
* Implement solution with lightest changes possible

* Update regressions v1

* Adjust AlgorithmTradingTests

* Adjust PatternDayTradingMarginBuyingPowerModel tests

* Drop need to loop twice

* Adjust last unit test, with calculations included

* nit - comment fix

* Break out adjustment calculation to static function; add unit test

* Update Py regression

* Upgrade adjustment calculation to be smart enough to get us to target always

* nit - cleanup GetAmountToOrder

* Add license to test

* nit - comment fix

* cleanup GetAmountToOrder further

* Add additional test cases
2021-07-02 18:52:15 -03:00
Martin-Molinero
e5a50109b4 DownloaderDataProvider improvements (#5730)
- Ignore margin files requests. Only provided by ApiDataProvider
- Reduce noise by LeanData.TryParse() call on failure
2021-07-02 14:03:16 -03:00
Ronit Jain
c8d13080a8 Indian Market support for backtesting and live deploys through Zerodha (#5710)
* added symbolData class to store exchange and token values of tickers

* support for India Market

(cherry picked from commit 5f629dcb9e72426dc7b560e782cb1fae72861574)

* removed local vscode workspace file

* support for india market instead of nse and other exchanges

* changed hardcoded india values to Market.India

* changed zerodha getcash fromm available to net

* addded edge case handoing with expections

* support for market info (nse, bse) for india market

* exchange info for EmitQuoteTick

* basic testing with c#

* c# algo

* c# testing

* live orders during market open success

* support orderproperties for exchange value for order placement

* added exceptional handling cases

* fix xml descriptions for the files

* fix zerodha-product-type in DefaultOrderProperties

* add basic template for india market

* fix orderProperites for default values

* fix for local data, python implementation not available

* fix access modifiers of SymbolData

* fix variable name case

* fix single check for exchange, call to base

* fix styling, redundent code and access modifers

* fix non static not callable from static

* fix static
2021-07-02 11:06:47 -03:00
Rohan Sharma
8d352b6318 feat: Improve error message from ObjectStore (#5729) 2021-07-02 10:37:37 -03:00
Martin-Molinero
00cd8947a8 Update bitfinex channel Id (#5728) 2021-07-01 21:42:17 -03:00
Gerardo Salazar
c211d04798 Adjust AlgoSeek Futures price multipliers to quote/process prices in USD (#5725)
* Adjust AlgoSeek Futures price multipliers to quote prices in USD

* Revert changes to AUP scaling

  * After a second review, seems that this contract isn't scaled.
    The contract multiplier differs from the NYMEX Aluminum Index's
    contract multiplier, and so does the minimum price variation.
    The minimum price fluctuation seems consistent with CME's
    quoted prices, which also claims the contract is quoted in USD.

* Fix futures contract multipliers for some scaled contracts
2021-07-01 18:46:36 -03:00
Martin-Molinero
55195867a9 Reduce LTRH error log to debug (#5723) 2021-06-30 16:44:52 -03:00
Gerardo Salazar
c9a3ad35e1 Fix Futures SymbolRepresentation disambiguation of ticker with limited year information (#5715)
* Fixes bug where future converter processing includes invalid values

* Fix issue in SymbolRepresentation

* Fixup

* Empty commit

* Empty commit
2021-06-29 17:37:06 -03:00
Martin-Molinero
0d45bf5101 Add composite DataProvider (#5714)
- Add new CompositeDataProvider that will wrap multiple instance. Allows
  using for example the ApiDataProvider and a DownloaderDataProvider.
- Adjusting ProductJsonConverter after recent Modules addition
2021-06-29 12:40:31 -03:00
Martin-Molinero
66552b49bd Add new DownloaderDataProvider (#5709)
* Add new DownloaderDataProvider

- Moving LeanDataWrite and IDataDownloader to common project
- Add new BaseDataDownloaderDataProvider with concurrency helper method
- Add new DownloaderDataProvider which will use a IDataDownloader or
  IBrokerage implementation as data source

* Add support for downloading symbol chains data
2021-06-28 15:56:10 -03:00
Martin-Molinero
0642f58bda Fix SEC downloader (#5711) 2021-06-28 11:24:23 -03:00
Colton Sellers
c7e6c96933 Encode/Decode Extension Addition (#5708)
* Implement Encode/Decode Base 64

* Add unit test
2021-06-25 17:50:55 -03:00
Colton Sellers
5c10b2cb82 Move Encode to Extension Util (#5707)
* Move to extension util

* Move decode to extensions
2021-06-25 10:26:10 -03:00
Antoine Dray
4dd2ad85a9 Fix KrakenDownloader error on invalid pair format (#5703) (#5704)
The Kraken allow queries from pairs of format XBTUSD and XXBTZUSD but it will only return data with the XXBTZUSD causing errors when XBTUSD ticker is specified.
This commit adds a more meaningful error when KDL is called with XBTUSD format.
2021-06-24 19:42:13 -03:00
Martin-Molinero
10defd4928 Include IB CSharpAPI in brokerage nuget (#5706) 2021-06-24 18:59:14 -03:00
Martin-Molinero
891aeb87d3 Update readme.md 2021-06-23 18:17:25 -03:00
Stefano Raggi
2fa07561b1 Add missing IBGateway dependency library (#5696) 2021-06-23 17:12:50 -03:00
Stefano Raggi
148b9c8d45 IB Brokerage updates (#5695)
* Update IBAutomater to v2.0.39

* Downgrade IB logging level from Detail (5) to Information (4)

- The online documentation warns of performance overhead when setting logLevel=5
2021-06-23 11:34:33 -03:00
Jared
65cecef030 Update readme.md 2021-06-22 18:15:35 -07:00
Stefano Raggi
4fed304eb7 Update Lean Foundation docker files to IBGateway v984 (#5686) 2021-06-22 17:20:47 -03:00
Colton Sellers
a987e0231f Scheduled Events for Start/End Week/Month Fix (#5690)
* Apply fix for both start and end month cases

* Add unit tests for both cases

* Fix weekstart/weekend for same issue; add unit tests

* nit - rename tests

* Adjust logic
2021-06-22 14:20:00 -03:00
Colton Sellers
f47775338c Expand Lean Default Charts and Reduce Clutter (#5680)
* Update charts that are not empty and not default values

* Testing

* Filter final results

* Explicitly filter alpha charts if not needed

* Use filtered charts for Live results handler

* Refactor solution to manage alpha charts internally by creator

* nit comment fixes

* Implement drawdown as default chart

* Implement Capacity Estimate for backtest default chart

* Add default values to QC.Plotting

* Adjust drawdown calculation

* Only sample "Capacity" once a day

* Implement Volume chart

* Nit fixes

* Volume Chart adjustments and fixes

* Rename to "Assets Sales Volume"

* Implement Exposure Sampling

* Store algorithm currency symbol, round capacity to nearest 1k

* Add new plots to default charts

* nit change name

* Address reviews

* Reduce duplication and clean up exposure sampling

* Address reviews

* Improve sample exposure

* Address review

* Only enumerate holdings once

* nit - comments

* Post rebase fix

* Don't need to round anymore
2021-06-22 11:19:48 -03:00
Colton Sellers
fa1e97bc60 Round Capacity Estimate for Runtime Statistics (#5688)
* Refactor solution to deal with rounding in CapacityEstimate

* Use DiscretelyRoundBy + adjust regressions
2021-06-21 21:06:09 -03:00
Martin-Molinero
8fb649ceb4 SymbolJsonConverter improvements (#5683)
* SymbolJsonConverter improvements

- SymbolJsonConverter will be able to deserialize symbols expressed in
  user friendly format. Adding unit test
- Adding a couple of helper methods, removing duplicated code

* Fix FOPs expiration year parsing
2021-06-21 21:02:46 -03:00
Stefano Raggi
7d8754f33c Update IBAutomater to v2.0.38 (#5682)
* Update IBAutomater to v2.0.38

* Trigger build
2021-06-21 12:23:55 -03:00
Stefano Raggi
080511fa5a Add IResultHandler.BrokerageMessage (#5681)
* Add IResultHandler.BrokerageMessage

- Result handlers can receive notifications for brokerage message events

* Make LiveTradingResultHandler.RuntimeError virtual
2021-06-21 12:23:46 -03:00
Martin-Molinero
5146329c0f CoinApi: reduce thread contention by lock per symbol (#5677)
- Reduce thread contention in coinApi DQH by taking a lock per symbol
  versus a global lock.
- Improve tick creating by reducing object being wasted on empty
  constructor
2021-06-17 20:47:57 -03:00
Stefano Raggi
47fb4e64f2 Update IBAutomater to v2.0.37 (#5676) 2021-06-17 16:14:38 -03:00
Alexandre Catarino
5361f87dd1 Updates Equity Market Data (#5576)
* Updates Equity Market Data

* Updates Unit Tests

* Updates Regression Tests

In this commit we include regression tests with small changes (slightly different CAGR, Alpha, etc, but same number of trades) due to the data update.

* Updates Regression Tests 2

The following regression tests were adapt because of verification of hard-coded market data values:
- `AdjustedVolumeRegressionAlgorithm`
- `HistoryWithSymbolChangesRegressionAlgorithm`
- `OptionRenameRegressionAlgorithm`
- `RawDataRegressionAlgorithm`
- `SwitchDataModeRegressionAlgorithm`

The following regression tests have more trades since adjusted prices allowed more 1-2 shares trades that were rounded down to zero before:
- `AddUniverseSelectionModelCoarseAlgorithm` 23 -> 35
- `MeanVarianceOptimizationFrameworkAlgorithm` 12 -> 14
- `PortfolioRebalanceOnDateRulesRegressionAlgorithm` 298 -> 324
- `PortfolioRebalanceOnInsightChangesRegressionAlgorithm` 83 -> 86
- `ScheduledUniverseSelectionModelRegressionAlgorithm` 86 -> 90
- `SectorExposureRiskFrameworkAlgorithm` 17 -> 22
- `SetHoldingsMultipleTargetsRegressionAlgorithm` 8 -> 9
- `StandardDeviationExecutionModelRegressionAlgorithm` 196 -> 199
- `UniverseUnchangedRegressionAlgorithm` 11 -> 17
- `VolumeWeightedAveragePriceExecutionModelRegressionAlgorithm` 237 -> 238

Especial cases:
- `BlackLittermanPortfolioOptimizationFrameworkAlgorithm` 18 -> 17
 - BLM model sensibility
- `OptionChainedAndUniverseSelectionRegressionAlgorithm`

The following regression tests have different Capacity because of different volume from lowest capacity asset, except:
- `OptionEquityCoveredCallRegressionAlgorithm` New lowest capacity asset is underlying
- `OptionEquityCoveredPutRegressionAlgorithm` New lowest capacity asset is underlying

* Revert File Update for SPWR and SPWRA

* Fix Regression Tests

Temporarily removes python regression test for `MeanVarianceOptimizationFrameworkAlgorithm` as the `MeanVarianceOptimizationPortfolioConstructionModel` for each version are yeilding different results. If we use C# version in `MeanVarianceOptimizationPortfolioConstructionModel.py`, the results match.

* Changes Optimization Method in MinimumVariancePortfolioOptimizer [Py]

Uses `trust-constr`  method.
See https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.minimize.html
2021-06-17 14:04:51 -03:00
Jasper van Merle
72fb362f96 Fix futures not working with IQFeed (#5675)
* Fix futures not working with IQFeed

* Trim slash from value instead of using ID.Symbol
2021-06-17 08:46:03 -07:00
Martin-Molinero
24e3a71581 Coinapi improvements (#5672)
- Add centralized download extension helper method
- Update coinApi client
2021-06-16 20:30:51 -03:00
Colton Sellers
15555f710d Python Loading and Debugging Refactor (#5670)
* Use Python algorithms directly in their location; also refactor pythonpath additions to one method

* Update VSCode Launch options

* Drop issue these changes fixes

* Use AddRange
2021-06-16 20:30:33 -03:00
Martin-Molinero
3d13fb6935 Implement Atreyu fees (#5674)
* Empty

* Implement Atreyu fees
2021-06-16 19:43:27 -03:00
Colton Sellers
74f0c89499 Option Chain Provider Symbol Map Resolve (#5664)
* Use mapFileProvider to resolve symbol mapping

* Add reproducing unit test

* Only resolve mapping for types that require it

* address review
2021-06-16 19:42:38 -03:00
Martin-Molinero
0991f089d0 Reduce disk usage in the cloud (#5673) 2021-06-16 18:43:55 -03:00
Colton Sellers
424fa36703 Organization Product ID and ApiDataProvider Fix (#5671)
* Add ID to Organization Products

* Use Product ID to verify subscription
2021-06-16 15:01:53 -03:00
Colton Sellers
afbd058dad Add Site-Package Issue to Readme (#5668)
* Add information to Python and Research readme

* Adjust doc
2021-06-16 13:57:13 -03:00
Stefano Raggi
66d2f42d01 IBAutomater updates (#5669)
* Update IBAutomater to v2.0.36

* Trigger build
2021-06-16 12:52:43 -03:00
Martin-Molinero
11f8dc2958 Improvements for CoinApi subscription (#5666) 2021-06-15 19:49:14 -03:00
Martin-Molinero
03f56481d4 Refactor python algorithm import (#5657)
* Python research import improvements

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

* Centralize algorithm imports

* Add regression test GH action

* Unit test python import clean up

* Join research and main imports

* More python import clean up

* Fix failing skipped regression algorithm
2021-06-15 19:06:06 -03:00
Stefano Raggi
c367451c6d Update IBAutomater to v2.0.35 (#5663) 2021-06-15 16:58:31 -03:00
Alexandre Catarino
c4e6e7f8dc Changes VIXCentralContango.F9 to Nullable (#5662)
According to the data, the contract 8 months away from the front-month contract, `F9`, can be null.
2021-06-14 16:23:28 -07:00
Colton Sellers
ef5f7fbc50 QuantBook Provider and Composer Fix (#5660)
* Use Composer instance for QB so providers are the same across Lean; also initialize map and factorfiles

* Don't need map and file initialize
2021-06-14 19:17:53 -03:00
Colton Sellers
7f9d35f666 Research BollingerBands Value Error (#5656)
* Stop update when properties will fail to update

* Only enforce our case after the BB is ready

* Nit comment fixes

* Add unit test

* Use faster DateTime.UtcNow
2021-06-14 14:23:05 -03:00
Gerardo Salazar
be0fc9a879 Fixes case where crypto has short exposure in ReportGenerator in long-only strategies (#5655) 2021-06-11 21:40:49 -03:00
Colton Sellers
a882aadeef Research Fixes and Doc Updates (#5649)
* Updates to default notebooks

* Update readme

* Notebook adjustments

* Drop launch script support

* Use our cwd if no QC dlls are in AppDomain directory

* Modify Intialize.csx to use parent directory only if QC files are detected there

* Clean up some details after testing

* Adjustments

* nit, NullOrWhiteSpace
2021-06-11 16:06:47 -03:00
Stefano Raggi
02f7742878 Update IBAutomater to v2.0.34 (#5652) 2021-06-11 14:38:45 -03:00
Martin-Molinero
b7c18cbfe7 Update pythonNet to net5 (#5653)
- Csproj clean up legacy build print logs
- Update pythonNet to net5
2021-06-11 13:51:09 -03:00
Martin-Molinero
6e6a1631dc Enable loading crypto live virtual position tracking (#5651)
* Enable loading live virtual position tracking

- Enable GDAX paper trading configurations
- GDAX will optionally load existing holdings from live job package
- Bitfinex will try loading existing holdings from live job package for
  cash account type

* Binance live holdings loading
2021-06-10 20:05:23 -03:00
Gerardo Salazar
250ffa1fec Adds VIXCentralContango data, modifies cached alternative data sourcing in live mode (#5648)
* Adds VIXCentral Contango data

  * Refactor cached alternative data in live mode to
    use web endpoint if the data is not available locally

* Remove fallback to cache bucket for CBOE/FRED/EIA/VIXCentralContango

* Address review: force VIX as ticker for all VIXCentralContango data
2021-06-09 20:44:53 -03:00
Martin-Molinero
7e2678d0f6 Normalize live holdings initialization (#5647)
* Normalize live holdings initialization

* PaperBrokerage config based live state recovery

- Increase algorithm status storing sampling period
- Fix bug where duplicate cash entries could happen
2021-06-09 20:11:38 -03:00
Louis Szeto
9f15ca4c9c feature-<#5631>-<Create SpreadExecutionModel> (#5633)
* Create SpreadExecutionModel.py

* Update SpreadExecutionModel.py

* Update SpreadExecutionModel.py

* Update SpreadExecutionModel.py

* Update SpreadExecutionModel.py

* Update SpreadExecutionModel.py

* Update SpreadExecutionModel.py

* Update SpreadExecutionModel.py

* Create SpreadExecutionModel.cs

* Create SpreadExecutionModelTests.cs

* Update SpreadExecutionModelTests.cs

* Update SpreadExecutionModel.cs

* Update SpreadExecutionModelTests.cs

* Update SpreadExecutionModel.cs

* Update SpreadExecutionModel.cs

* Update SpreadExecutionModelTests.cs

* Update SpreadExecutionModel.cs

* Update QuantConnect.Algorithm.Framework.csproj

* Create SpreadExecutionModelRegressionAlgorithm.py

* Update SpreadExecutionModelTests.cs

* Update SpreadExecutionModelTests.cs

* Update SpreadExecutionModelTests.cs

* Update SpreadExecutionModelTests.cs

* Update SpreadExecutionModel.py

* Update SpreadExecutionModel.cs

* Address review

- Adding CSharp regression algorithm implementation
- Updating unit tests, minor format changes

* Address review. Add comment and Abs spread percent

Co-authored-by: Martin-Molinero <martin@quantconnect.com>
2021-06-09 14:55:00 -03:00
IlshatGaripov
d23ac25b67 Polygon IO limited aggregate bars per request. Fix. (#5363)
* Applies a fix

* Fixing the tests to cover downloader func. Fixing the queue handler

* this has to be removed

* -- Fixes -- [WIP]

* Implements the way to upload historical bars in async fashion. [ WIP ]

* Finishes GetEquityTradeTicks() impl.

* Do not break iteration if result is null

* Uses DisposeSafely and fixes a typo

* To use IEnumerable for return type in GetHistoryAsync

* Fixes GetEquityQuoteTicks()

* Removes GetHistoryAsync() and reverts the associated with it changes

* SubscriptionManager -> revert the changes

* PolygonDataQueueHandler -> use SIP timestamp as it keeps the order

* PolygonDataQueueHandler -> use Log.Trace for the no data {date} message

* Fixes GetForexQuoteTicks()

* Introduce ResponseSizeLimitAggregateData

* Fixes up GetCryptoTradeTicks()

* Small fixes for tick processing methods

* Removes launchSettings.json

* Refactor download data logic

- Replace WebClient for HttpClient
- Remove duplicated download logic and parsing for a single static
  method

* Update PolygonDataQueueHandler.cs

Remove commented code

Co-authored-by: Martin-Molinero <martin@quantconnect.com>
2021-06-09 10:43:34 -03:00
Colton Sellers
8f7f862563 Ignore Tests (#5646) 2021-06-09 10:25:07 -03:00
Colton Sellers
0f0eeaff82 DataProvider Updates & Refactoring (#5641)
* Use DataProvider for fetching Shortable and FutureMargins files

* Use data provider for AllShortableSymbols

* Refactor of NeedToDownload logic

* Adjustments

* nit - cleanup

* Expand test cases

* Create the directory if it doesn't exist
2021-06-08 22:11:21 -03:00
Martin-Molinero
e8cf002238 Live trading holding improvements (#5644)
- Store holdings at end of algorithm
- Warmup holding market price if 0
2021-06-08 21:55:17 -03:00
Stefano Raggi
e875b111d7 IB Brokerage updates (#5642)
* Add immediate logging for IB brokerage unit tests

* Filter brokerage message event for IB warning

- 10197 - No market data during competing live session.

* Update IBAutomater to v2.0.32

* Update IBAutomater to v2.0.33
2021-06-08 11:29:29 -03:00
Martin-Molinero
a231a7d47a Update python net to 2.0.3 (#5640)
* Update pythonNet version to 2.0.3

* Fix outputPath causing issues with nuget
2021-06-07 21:37:26 -03:00
Colton Sellers
37cce922d3 Api Data Request Path Format Issue (#5639)
* Address some format issues for data request paths

* Add reproducing test

* Drop logging for failure, let Api take care of it
2021-06-07 20:59:39 -03:00
Colton Sellers
5f9e4a6bca Option Exercise Quantity Fix (#5638)
* Use determined quantity for exercise order

* Add regression algorithm for issue

* Minor tweaks

Co-authored-by: Martin-Molinero <martin@quantconnect.com>
2021-06-07 18:51:52 -03:00
Martin-Molinero
42c58d6e53 Ensure data is downloaded only once (#5635)
- Ensure data is downloaded only once with the ApiDataProvider. Adding
  unit test
- Log invalid securityType ApiDataProvider requests once
- Assert Factor file and map file providers are compatible with the
  ApiDataProvider
2021-06-07 14:26:24 -03:00
Colton Sellers
ab6027723f Refactor Api (#5251)
* Use lean data key as param for request

* key -> filePath rename and some cleanup

* Refactor

* Add Organizations Endpoints

* Add some organization api wrapper objects

* Address namespace issue

* Reorganize Api Test into seperate files using one ApiTestBase

* Add Organization tests

* Use capitalized "API" test namespace to reduce amount of file changes

* Add License to test base

* Update /data endpoint functions and response objects

* Update ApiDataProvider Logic

* Handle deserialization of organization products

* Simplify converter

* Only throw for equity requests when not subscribed to map/factor files

* Add missing header

* Make arguement exception

* Api adjustments

* Add Zip factor and map file providers

- Common project will now reference Compression project and not the other way
  round.
- Adding Zip FactorFile and MapFile providers

* Refactor FactorFileProvider to use DataProvider to fetch files

* Use resulting MinimumDate in construction of FactorFile

* Nit FactorFile comments and arrangement

* Refactor MapFileProviders to use DataProvider for fetching files

* Refactor ZipFileProvider

* Clean up

* Refactor Backtesting Future/Option chain providers to use dataprovider

* Fixes for data/ endpoints and test adjustments

* Response objects adjustments/cleanups

* ApiDateProvider fixes and testing

* Add LocalZipFactorFileTests

* Update ApiDataProvider download test to verify stream is not null

* Implement posting of agreement summary and signed time

* Mark all Api related tests as explicit and document details on running

* Clarify default token on ApiTestBase

* Adjust summary

* Update Api responses for QCC, except org products which are sold in USD

* Implement cache expiration for zip MapFile and FactorFiles. Adding unit tests

* Fix multiple markets for ZipFactorFile provider

* Use Symbol as cache key

* Api.cs review

* Dispose of factorFileStream after reading

* Use zip.EntryFileNames

* Address a few reviews

* Few more fixes

* Address Api Review

* Add Job Org id to config

* Minor tweaks

* Compare with invariant culture

* Fixes Option Universe selection

* ZipEntryNameSubscriptionDataSourceReader will use IDataProvider

* Fix research

* Fix null reference exception

* Make duplicate log debug

Co-authored-by: Martin-Molinero <martin@quantconnect.com>
2021-06-07 11:37:44 -03:00
Alexandre Catarino
37473c4580 Fixes OverflowException in FuturesOptionsMarginModel (#5629) 2021-06-04 21:24:19 -03:00
Gerardo Salazar
677661766b Fixes filtering of CoinAPI raw data in CoinApiDataConverter (#5625)
* Fixes bug where raw data was incorrectly be filtered when ID was duped

* Filter CoinAPI raw data by distinct Symbol created from the SymbolMapper

* Fixes bug where only quotes or trades would be processed, not both

* Trigger rebuild
2021-06-04 13:53:47 -03:00
Martin-Molinero
c66a26e01d Fix build: Holding.Type is not setable (#5628) 2021-06-03 21:03:18 -03:00
Martin-Molinero
effa2da594 Avoid need for Holding Type update build status (#5623) 2021-06-03 20:21:18 -03:00
Stefano Raggi
572aa99743 IBAutomater updates (#5626)
* Update IBAutomater to v2.0.27

* Update IBAutomater to v2.0.28

* Update IBAutomater to v2.0.29

* Update IBAutomater to v2.0.30

* Trigger build
2021-06-03 19:04:54 -03:00
Gerardo Salazar
e77e202373 Adds support for LeanDataWriter minute/second/tick writing for files w/ more than 2GB uncompressed (#5620) 2021-06-02 18:29:50 -03:00
Martin-Molinero
f9c50e28ef Add data libraries into image (#5619) 2021-06-02 12:45:28 -03:00
Martin-Molinero
4c773c348c Update readme.md 2021-05-31 11:13:13 -03:00
Colton Sellers
41f9d9da94 Remove SecurityInitializer from Universe Selection (#5418)
* Attempt to remove SecurityInitializer from UniverseSelection stack entirely

* Fix broken Python Universe Selection model

* Remove mistake change (meant for another branch)
2021-05-28 14:53:13 -03:00
Martin-Molinero
5f6a40fd9c Update readme.md 2021-05-28 12:18:52 -03:00
Martin-Molinero
0335b49edf Update pythonNet to 2.0.2 (#5611) 2021-05-28 12:10:55 -03:00
Derek Melchin
1175c304e1 Fix live timestamp alignment in CustomDataBitcoinAlgorithm (#5603)
* Fix python version

* Make C# version match

* Revert c# changes, make python version use exchange timezone
2021-05-27 20:09:48 -03:00
Colton Sellers
6c42f58b68 VS Code Tasks and Python Debugging Fixes (#5601)
* ~Fix Python debugging and update docs

* Cleanup tasks
2021-05-27 16:34:04 -03:00
Alexandre Catarino
22a5378604 Reduce Leverage for Equity to 1 in Alpha Stream Brokerage Model (#5598)
All security type use 1 as leverage but Forex and CFD that are allow to use 10.
2021-05-27 15:31:34 -03:00
Martin-Molinero
2df6715301 Add hostname to initial log message (#5608) 2021-05-26 19:27:05 -03:00
Colton Sellers
459f812223 Duplicated Points in Custom DataFrame Fix (#5606)
* Don't add "value" to series twice

* Reproducing unit test
2021-05-26 18:44:13 -03:00
Martin-Molinero
22caf9ef2a FOPs margin as a curve (#5607)
* FOPs margin as a curve

- Adjust FOPs margin requirement so that it behaves like an 'S' curve
  for the contract strike, around the underlying price and it's margin requirement.
  Based on IB behavior. Adding unit tests for different future contracts
- Improve a couple of unit test cleanup

* Add ES Short Call unit test
2021-05-26 18:09:05 -03:00
Gerardo Salazar
94fb9293dc Adds filtering of negative ticks in CoinAPI converter consolidation (#5597)
* Adds filtering of negative ticks in CoinAPI converter

  * Tick data will remain the same, only aggregated data
    will have changes reflected in its output as a result

* Adds suspicious tick filtering to ticks

* Address review: Add Crypto Trade Tick suspicious test case
2021-05-25 19:38:53 -03:00
Stefano Raggi
59266d84bf IB Automater update (#5599)
* Update IBAutomater to v2.0.23

* Update IBAutomater to v2.0.24
2021-05-25 16:50:17 -03:00
Colton Sellers
8ee9432bda Wicked Renko Consolidator Fix (#5589)
* Round first value to Renko BarSize

* Add unit tests
2021-05-24 21:39:21 -03:00
Adalyat Nazirov
99088d6dd8 Atreyu Brokerage model (#5593)
* move AtreyuOrderProperties

* config

* make method public

* allow override base GetCashBalance test method
2021-05-24 21:09:39 -03:00
Stefano Raggi
15183cefe8 Update IBAutomater to v2.0.22 (#5592)
* Update IBAutomater to v2.0.22

* Add Sleep before restarting IBAutomater

Co-authored-by: Martin-Molinero <martin@quantconnect.com>
2021-05-24 20:09:50 -03:00
Martin-Molinero
9e96aeb440 Language update. Csproj clean up (#5590)
- Update CSharp language version to latest 9
- Remove old csproj build configurations
2021-05-24 11:10:03 -03:00
Colton Sellers
a2beeffcde Add Useful Error Message on TradingCalendar (#5588)
* Add warning when start and end are reversed

* Throw arguement exception; add unit test
2021-05-24 11:09:29 -03:00
IlshatGaripov
c384fe0e2a Implements PivotPointsHighLow indicator + tests (#5352)
* Implements PivotPointsHighLow indicator + tests

# Conflicts:
#	Tests/QuantConnect.Tests.csproj

* Some fixes

* Refactoring + Adds NewPivotPointFormed event

* Fixing tests

* Some fixes for the Get methods to not throw when points array is empty

* To address review + more fixes

* Fixing xml comments typos

* Implements separate rolling windows to calculate highs and low

* Makes the number of last stored indicator values as an input parameter

* Overrides Reset()

* Adds a helper method

* Change numerical return to Enum types

* Changes IsReady condition :

the indicator is ready and starts calculating the pivot point when any of the rollings is ready

* Address reviews

Co-authored-by: Martin-Molinero <martin@quantconnect.com>
2021-05-24 11:09:07 -03:00
Martin-Molinero
ee6631dd8a Update readme.md 2021-05-21 18:50:04 -03:00
Martin-Molinero
4fdb748b42 Add Alphas Streams SDK to Lean image (#5587) 2021-05-21 18:31:51 -03:00
Colton Sellers
ff0ecc7ed2 CFD Capacity Estimate (#5582)
* Use forex method of estimation for CFDs by hard setting volume

* Update regression

* Use a unique volume estimation factor for CFDs
2021-05-21 16:24:29 -03:00
Colton Sellers
dcdfc7fdb3 Update Oanda CFDs Lot Sizes and Market Hours (#5581)
* Update lot sizes on symbols

* Update some incorrect marketHours

* Update all Oanda CFD market hours

* unify rollover to next day endtime
2021-05-21 16:16:26 -03:00
Colton Sellers
a83eb7bf88 Update GDAX Brokerage MinimumOrderSizes (#5586)
* Update GDAX Brokerage MinimumOrderSizes

* Re-add XRP for historical purposes
2021-05-21 15:44:16 -03:00
Stefano Raggi
4e0ef94c97 Fix IBAutomater timeout error (part 2) (#5585)
* Update IBAutomater to v2.0.20

* Update IBAutomater to v2.0.21
2021-05-21 13:54:37 -03:00
Jasper van Merle
c4db451416 Increase Binance rate limit to 1 message per 250ms (#5584) 2021-05-20 17:47:07 -03:00
Colton Sellers
112c14e0e8 IDE Integration Updates & Doc Updates (#5550)
* Update launch options and tasks

* Update readme

* Mention building manually is optional

* Add portable pdbs to use C# coreclr debugging

* Update VS and VSCode docs

* Add reference to Lean CLI in main readme

* remove run_docker scripts

* Remove PyCharm files

* Cleanup

* Remove run_docker tasks from VS Code

* Address typos
2021-05-20 13:47:33 -03:00
Jason Harmon
87b16bc20c Implemented AlphaVantageDataDownloader (#5475)
* Implemented AlphaVantageDataDownloader

* Style and documentation changes requested

* Throw exception for unexpected response content

* Added rate limiting to AlphaVantageDataDownloader

* Minor tweaks and rebase

Co-authored-by: Martin-Molinero <martin@quantconnect.com>
2021-05-20 13:36:25 -03:00
Jasper van Merle
bb8bd27fe5 Support 2-leg currency conversions (#5552)
* Apply changes from #2146 on current master

Credit for most of these changes goes to https://github.com/viliwonka.
Rebasing three years of changes didn't go so well, so I manually
applied the changes in #2146 on the current master branch.

This commit attempts to represent the changes in #2146 as closely as
possible, no cleanup has been performed yet. Despite this, some changes
were inevitable because part of #2146 has been implemented another way
in the past three years.

* Clean up

* Process review comments

* Add tests

* symbol -> potentialConversionRateSymbol

* Ensure regression tests run/get data

* Fix broken test

* Process review comments

* Process review comments

* Simplify currency conversion logic

* Performance improvement, doc updates and test rename

* Rebase fixes

* Remove obsolete properties

Co-authored-by: Martin-Molinero <martin@quantconnect.com>
2021-05-20 13:19:39 -03:00
Martin-Molinero
978da37cda Minor tweaks (#5580)
* Minor tweaks

- Add AccountCurrency and symbol for live result packet
- Improve performance of Tick clone and reading

* Reduce unit test from 9s to 500ms
2021-05-20 12:00:42 -03:00
Colton Sellers
4bb7fc17a2 Resolve Currency ConversionRate Backup (#5575)
* Attempt to use daily resolution request to resolve currency conversion

* Add BaseSetupHandlerTests

* Minor tweaks. Adding missing dispose call.

Co-authored-by: Martin-Molinero <martin@quantconnect.com>
2021-05-19 19:54:02 -03:00
Jasper van Merle
d903ca60ef Fix AdjustedVolumeRegressionAlgorithm on Linux (#5579) 2021-05-19 19:09:08 -03:00
Colton Sellers
ec77cf3ca5 Delisted Warning Time Correction (#5568)
* Use DelistingDate for Warning event

* Update test

* Add regression

* Cleanup regression

* Add issue reproducing unit test
2021-05-19 15:19:38 -03:00
Stefano Raggi
76600a3a0e Fix IBAutomater timeout error (#5578)
* Update IBAutomater to v2.0.18

* Update IBAutomater to v2.0.19
2021-05-19 14:59:28 -03:00
IlshatGaripov
dcb578cdfb Do not restrict unrequested securities by 1.0m leverage (#5375)
* Do not restrict unrequested securities by 1.0m leverage, let security initializer do its job

* Use UniverseSettings for leverage, fillforward, and extendedmarkethours

* Update unrequested security message

* Use UniverseSettings ExtendedMarketHours for underlying on OptionContracts

* Add unit test to prove setting persistence

* Cleanup unit test

* Adjust crypto unit test assert

Co-authored-by: Colton Sellers <Colton.R.Sellers@gmail.com>
Co-authored-by: Martin-Molinero <martin@quantconnect.com>
2021-05-19 12:59:42 -03:00
Gerardo Salazar
838e94ec18 Fix large file downloads for SEC causing integer overflow in HttpClient (#5577) 2021-05-19 12:05:10 -03:00
Martin-Molinero
9887a05d77 Fix FutureOptionMarginModel Margin Requirements (#5570)
* Fix FutureOptionMarginModel Margin Requirements

- Fixes FuturesOptionsMarginModel margin requirements being zero due to
  underlying being null on model creation. Adding unit test

* Address reviews

- SecurityService will set underlying when creating a new security when
  provided
2021-05-18 14:04:30 -03:00
Gerardo Salazar
cd0c447bcc Fixes SEC rate limiting issue by adding user-agent and reducing clustering of requests (#5567)
* Fixes SEC rate limiting issue by reducing clustering of requests

  * We add a user-agent header to all outgoing requests for SEC
    as they require it to identify the client, otherwise we're rate
    limited.

  * Some adjustments to how we wait for work to be done, and RateGate
    rate of requests. We wait for all requests now/don't use tasks
    anymore

* Address review - remove class HttpClient in favor of local instance
2021-05-18 13:55:15 -03:00
Colton Sellers
d91ccac4aa Use decimal for Oanda OrderFillQuantity conversion (#5571)
* Use decimal for Oanda OrderFillQuantity conversion

* Use decimals for all order values
2021-05-18 12:46:49 -03:00
Łukasz Szymański
9d93dc1570 Fix wrong market hours for Oanda DE30EUR CFD (#5564)
* Fix wrong market hours for Oanda DE30EUR CFD

* Update unit tests expected result

Co-authored-by: Martin-Molinero <martin@quantconnect.com>
2021-05-17 18:32:58 -03:00
Colton Sellers
5bf72d2432 Adjust Volume for Splits (#5525)
* Adjust TradeBar volume for splits

* Refactor solution to centralized function `Scale`

* Expand BaseData scale/adjust/normalize tests to assert volume behavior

* Add regression algorithm

* Update regression statistics

* Address review

* NOP to trigger cloud build

* adjust QuoteBar ask and bid size

* adjust broken regression

* Update tests to include QuoteBar adjustments

* nit cleanup

* Adjust Quote Tick bid and ask sizes

* Round volume and size values to nearest int in scale()

* nit

* Adjust regressions
2021-05-17 16:47:44 -03:00
Stefano Raggi
d24edf5a6c IB Brokerage updates (#5518)
* Upgrade IBAutomater to v2.0.0

* Upgrade IBAutomater to v2.0.1

* Upgrade IBAutomater to v2.0.6

* Upgrade IBAutomater to v2.0.7

* Upgrade IBAutomater to v2.0.9

* Upgrade IBAutomater to v2.0.10

* Upgrade IBAutomater to v2.0.12

* Upgrade IBAutomater to v2.0.13

* Upgrade IBAutomater to v2.0.14

* Upgrade IBAutomater to v2.0.15

* Reset disconnected flag on IBGateway exit/restart

This bug was causing invalid algorithm termination after reconnection

* Fix unhandled exceptions in exit/restart event handlers

* Upgrade IBAutomater to v2.0.16

* Upgrade IBAutomater to v2.0.17
2021-05-17 15:08:24 -03:00
Martin-Molinero
a0c2e38eae Remove exception being thrown because of lotsize (#5566) 2021-05-17 12:06:36 -03:00
Martin-Molinero
fe2ac131af Remove exception being thrown because of lotsize (#5562) 2021-05-14 21:18:09 -03:00
Alexandre Catarino
b8e3294a5f Improves Position Constructor Exception Message (#5560) 2021-05-14 19:36:10 -03:00
Stefano Raggi
25f4cdd92f Tradier brokerage updates (#5546)
* Update testing OrderProvider to clone orders as BrokerageTransactionHandler

* Add immediate logging for brokerage unit tests

* Tradier brokerage updates

- Fixed NullReferenceException with zero-crossing orders
- Added a few missing null checks
- Fixed issues in error handling
- Added new unit tests for some common errors
2021-05-14 17:59:21 -03:00
Gerardo Salazar
82c9b6ccb7 Updates and improvements to ToolBox projects (#5537)
* Adds processed data directory to read price data from

* Make coarse universe generator look at data directory before failing to find daily data

* Set coarse generator output of missing daily file to debug log

* Add CoarseUniverseGenerator logs

* Fixes 100 nanosecond increment lookahead bias when parsing large numbers

  * Whenever we parse a number that is has precision greater than
    DateTime ticks (sub-100 nanoseconds), if we have nanoseconds
    between [0, 1000), excluding numbers divisible by 100,
    we will have leftover nanoseconds between [0, 100) nanoseconds, but
    they won't be factored in to the DateTime calculation, since casting
    to `long` only takes the integer component of the number, so we lose
    the extra nanoseconds that came with the decimal, and time is set to
    the "floored" value without those nanoseconds.

    Since .NET `DateTime` type has a limitation of only being able
    to represent time in increments of 100 nanoseconds, by not
    considering the sub-100 nanoseconds, we introduce a look-ahead
    bias of at most 100 nanoseconds/1 tick

  * Misc adjustment to make method use `decimal` instead of `double`
    for increased precision when parsing large numbers

* Changes CoinAPI data converter to support processing raw files in original directory structure and file name

  * Removes Market requirement from CoinAPI data converter

* Remove timeout on decompression of raw AlgoSeek futures data

* Updates SEC downloader to use HttpClient where requests were failing

  * For some unknown reason, valid requests to a valid URL were
    failing when using WebClient. Changing our requester to
    HttpClient fixes the issue, and enables us to leverage
    async capabilities where applicable.

  * Added fault tolerance to index file downloads, including a
    rate limit in case we've been rate limited

* Further refactoring; catches 429 errors, adds missing rategate calls

* Replace all usage of WebClient, force retry for all failures

* Adds optional config value for Benzinga News API key in downloader

* Modifies Estimize Downloader api config name and fixes directory not found bug

* Refactor Estimize to speed up processing time

  * Adds ticker limits if desired
  * Misc. bug fixes, performance improvements, code cleanup

* Remove debug log statements leftover from previous commit

* Add support for non-tick Index resolutions in LeanDataWriter

* Empty commit

* Empty commit

* Empty commit

* Empty commit

* Empty commit

* Empty commit

* Lower requests/second for SEC downloader, add missing rategate call

Co-authored-by: Martin-Molinero <martin@quantconnect.com>
2021-05-14 17:06:47 -03:00
Martin-Molinero
9c1722d0b9 Update readme.md 2021-05-14 14:34:28 -03:00
Martin-Molinero
a475178dbb Fix FOPs maintenance margin requirements (#5559)
- Fix FOPs maintenance margin requirements since they were relaying on
  the underlyings holdings cost to return 0 in some cases. Updating unit
  tests
- Fix Option exercise order being rejected because of margin not
  available, will now take into account the margin used by the option
  itself. Adding unit test
2021-05-14 14:02:56 -03:00
Martin-Molinero
e6ffb1ac62 Add missing containsKey dictionary check (#5558) 2021-05-14 12:30:28 -03:00
Jasper van Merle
70996b0507 Increase Binance rate limit timespan (#5556) 2021-05-14 12:13:05 -03:00
Alexandre Catarino
58793acae8 Removes Assets that Are Not Invested and Not Tradable From Capacity Calculations (#5515)
* Add property for capacity. Remove unused variable

* Move SymbolCapacity and CapacityEstimate to common, passed through Symbol to runtime statistics

* Add null checks

* Remove uninvested and untradable assets from capacty calculations

* Add SymbolCapacity influential period

* Updates Regression Tests

- DelistingEventsAlgorithm
  - Allows additional contributions from delisted AAA.1

- DelistingFutureOptionRegressionAlgorithm
  - Removes DC01H12 contributions one month later

- FutureOptionBuySellCallIntradayRegressionAlgorithm
  - Allows additional contributions from future after expiry replacing the contribution of the next contract option

- DelistedFutureLiquidateRegressionAlgorithm
- FutureOptionCallITMExpiryRegressionAlgorithm
- FutureOptionCallITMGreeksExpiryRegressionAlgorithm
- FutureOptionPutITMExpiryRegressionAlgorithm
- FutureOptionShortCallITMExpiryRegressionAlgorithm
- FutureOptionShortPutITMExpiryRegressionAlgorithm
- FuturesAndFuturesOptionsExpiryTimeAndLiquidationRegressionAlgorithm
  - Allows additional contributions from future after expiry

- FutureOptionCallOTMExpiryRegressionAlgorithm
- FutureOptionPutOTMExpiryRegressionAlgorithm
- FutureOptionShortPutOTMExpiryRegressionAlgorithm
- IndexOptionCallITMGreeksExpiryRegressionAlgorithm
- IndexOptionCallOTMExpiryRegressionAlgorithm
- IndexOptionShortCallOTMExpiryRegressionAlgorithm
  - Allows additional contributions from option after expiry

- MACDTrendAlgorithm
  - Removes contribution when SPY is not invested for over one month

- UniverseSelectionRegressionAlgorithm
  - Allows additional contributions from delisted GOOAV replacing GOOG (new symbols)

* Adds Lowest Capacity Asset to Regression Tests

* Normalize expected value -0, because -0 is also written to file if updated

* Write Symbol.Value for lowestCapacitySymbol or  empty string for empty Symbol

* Update Regressions

* Update 'Lowest Capacity Asset' to Symbol.ID

Co-authored-by: Jared Broad <jaredbroad@gmail.com>
Co-authored-by: Martin-Molinero <martin@quantconnect.com>
Co-authored-by: Colton Sellers <Colton.R.Sellers@gmail.com>
2021-05-13 20:25:19 -03:00
Colton Sellers
6af3f70fed Return empty targets list if no insights are given (#5548) 2021-05-13 19:29:00 -03:00
Jasper van Merle
373c41e568 Fix regression tests on case-sensitive filesystems (#5542) 2021-05-11 19:55:13 -03:00
Alexandre Catarino
96f42eb591 Updates Fundamental Data (#5502)
* Updates Fundamental Data

* Updates Regression Algorithms

- `CoarseFundamentalTop3Algorithm`
  - New coarse has higher `DollarVolume` for `FB`
- `CoarseNoLookAheadBiasAlgorithm`
  - Change from `SPY` update not included in #5493
- `SectorExposureRiskFrameworkAlgorithm`
  - `HasFundamentalData` was false for `GOOG` on 20140401 and 20140402.

* Updates Unit Tests

Minor changes in expected values

* Updates Regression Tests

Should have been included in #5493:
- `OptionsExpiredContractRegression`
- `FuturesExpiredContractRegression`

* Adjusted Quantity By Lot Size in OrderTargetsByMarginImpact

`OrderTargetsByMarginImpact` didn't calculate the order value with the quantity adjusted by order size which less to values that did not reflect the actual order value.
It has a particular affect in `SectorExposureRiskFrameworkAlgorithm` where the Python and C# versions have the same orders but placed in a different sequence because of decimal/double precision.

* Reduce dictionary access x3 on OrderTargetsByMarginImpact

Co-authored-by: Martin-Molinero <martin@quantconnect.com>
2021-05-11 17:54:45 -03:00
Jasper van Merle
62c51ab17c Add new C# and Python libraries (#5536)
* Add new C# and Python libraries

* Remove C# changes

* Update System.Reflection.Emit to 4.7.0

* Add scikit-learn-extra
2021-05-11 17:28:24 -03:00
Stefano Raggi
bbcb81804c Remove unused OpenJDK from DockerfileLeanFoundation (#5540)
- Since IBAutomater 1.0.35 (https://github.com/QuantConnect/IBAutomater/pull/28, merged in #4984) we are using the Java Runtime bundled with IBGateway
2021-05-11 17:27:52 -03:00
David Acker
6dfe492212 Fix IsReady and WarmUpPeriod for RateOfChange (#5501)
* Redefine IsReady and WarmUpPeriod

* Update warm up periods of other indicators to account for ROC warmup change

* Update regressions affected by this change (because of HistoricalReturnsAlphaModel using ROC)

* Add simple unit test for issue #5491

* Cleanup warmup period math and add comments

Co-authored-by: Colton Sellers <Colton.R.Sellers@gmail.com>
2021-05-11 17:12:48 -03:00
Colton Sellers
d76bfaade4 Consolidate SetupHandlers (#5529)
* Reconcile and consolidate SetupHandlers

* Centralize GetConfiguredDataFeeds()

* nit - extra space

* Check for null, also allow null to be passed back if no config value

* Fix breaking test

* Cleanup

* fix return var

* remove unneeded if/else

* Minor changes

Co-authored-by: Martin-Molinero <martin@quantconnect.com>
2021-05-10 22:12:16 -03:00
Colton Sellers
ed077da501 DataNormalizationMode Applies to AddSecurity (#5528)
* Use UniverseSettings.DataNormalizationMode for securities added in Algorithm

* Stop SubscriptionUtils from forcing Adjusted mode

* Return behavior to original and add comments

* nit typo

* Add regression

* Add unit test that verifies DataNormalizationMode can be altered manually by security

* Cleanup and add Py version of regression
2021-05-10 20:58:50 -03:00
Martin-Molinero
1958ac2935 Minor adjustments for WorkScheduler (#5533) 2021-05-07 19:28:14 -03:00
Martin-Molinero
2847d9e27d Update readme.md 2021-05-06 21:09:54 -03:00
Martin-Molinero
cf7a26b8b6 Increase pip install timeouts (#5527) 2021-05-06 17:45:49 -03:00
Martin-Molinero
f3c386663b Feature .net 5 (#5505)
* Update projects to use .NET 5.0, the successor to .NET Core

* Fix ambiguous errors. Add IBAutomator net5

* Remove FXCM

* Upgrade IBAutomater to v1.0.51

ignored, and an empty message aborts the commit.

* Fix rebase

- Fix ambiguous Index
- Remove StrategyCapacity.cs
- Update System.Threading.Tasks.Extensionsy

* Remove unrequired references

* Fixes

- Travis will use dotnet, not nunit nor mono
- Remove mono from foundation image
- Fix python setup in research
- Fix unit tests

* Don't call ReadKey when input is redirected

* Fix ConsoleLeanOptimizer

* Research fixes

* Update comment

* Add vsdbg to Dockerfile

* Fixes

- Revert dockerfile FROM custom changes
- Adjust and fix regression algorithms
   - Option assignment will be deterministic in the order
   - 'Rolling Averaged Population' is calculated using doubles, updating
     expected values.
- Update readme, removing references to mono
- Add missing Py.Gil lock

* Replace ICSharp with .NET Interactive

* Fixes after rebase

* CSharp research fixes

- Adding new Initialize.csx that pre loads all assemblies
- Adjusting template research file
- Moving steps in dockerfilejupyter
- Fix unit tests and regression tests after rebase

Co-authored-by: Gerardo Salazar <gsalaz9800@gmail.com>
Co-authored-by: Stefano Raggi <stefano.raggi67@gmail.com>
Co-authored-by: Jasper van Merle <jaspervmerle@gmail.com>
2021-05-06 17:23:51 -03:00
Colton Sellers
865da14540 Scheduled Universe Timed Triggers Bug (#5521)
* Add unit test

* Make test cover issue case

* Filter out times before startTimeUtc

* Refactor solution, fixes missing first date

* Fix case where none is expected

* Cleanup tests, add TriggerTimesNone

* Drop unused imports

* Add missing dipose call

Co-authored-by: Martin-Molinero <martin@quantconnect.com>
2021-05-05 11:23:38 -03:00
Colton Sellers
019ac01a4c Reset SubmissionTimeBuffer to default value for other regressions (#5522) 2021-05-05 11:17:13 -03:00
Martin-Molinero
4a8bcb82db Add reference to quantconnect/research (#5519) 2021-05-03 19:16:51 -03:00
Colton Sellers
7ddee34e86 Configurable MarketOnCloseOrder Buffer (#5516)
* Create a configurable SubmissionTimeBuffer for MarketClose orders.

* Nit error spacing

* Add Py and C# regression
2021-05-03 18:08:27 -03:00
Jasper van Merle
f00d4655cf Add support for ARM64 Docker images (#5497)
* Add support for ARM64 Docker images

* Update DockerfileLeanFoundationARM base image
2021-05-03 12:58:22 -03:00
Jasper van Merle
83431c956c Move Python stubs deployment from Travis to GH Actions (#5512) 2021-04-30 19:10:40 -03:00
Colton Sellers
772eb4650c Stop UniverseSelection from removing the Symbol from the cache (#5513) 2021-04-30 19:01:29 -03:00
Colton Sellers
a7e5acd8d3 Small test adjustment for changes in #5510 (#5514) 2021-04-30 18:47:16 -03:00
Martin-Molinero
83f9499b4a Option Margin Strategies (#5511)
* Refactor HasSufficientBuyingPowerForOrder implementations

Adds Sufficient and Insufficient helper methods to HashSufficientbuyingPowerForOrderParameters
enabling syntax like:

return paraeeters.Sufficient()
returnparameters.Insufficient(reason)

The next change will add the initial margin required which will simply require
updating both of these helper methods to accept the value.

* IBuyingPowerModel: Add margin functions Maintenance/Initial/ForOrder

These were originally hidden in an effort to only expose what's necessary
for the engine to perform its work. Additionally, we encapsulated all of
the method arguments into parameters classes to prevent having to break
anyone in the future. Not including these foundational methods turns out to
be an oversight. These methods are not required by the engine, but rather by
other models. Another possible solution here is to add an additional abstraction
and include these methods on this new abstraction. BuyingPowerModel would then
explicitly implement these methods and models that depend on them would require
two code paths, one for when the buying power model implements this interface
and another for when it doesn't.

Tests were additionally updated to remove test model implementations created for
the sole purpose of exposing these private methods.

* Add ConstantBuyingPowerModel

Provides an implementation of IBuyingPowerModel that returns the same
constant value

* Update BuyingPowerModelPythonWrapper to use reflection for method names

Having a bunch of hard-coded strings is a sure fire way for someone to
overlook when changing methods. This change ensures that noone needs to
remember that this code exists :)

Cleans up the syntax around verifying a python object implements a particular
C# interface via the ValidateImplementationOf<T> method by having it return a
value since the only use cases are in constructors when setting the models.

I was initially going to update ALL python wrappers to validate the passed
in models, but such a change could break many things that are 'working' right
now. Such an effort should be saved for its own dedicated PR.

* Add Parameters/Result types for new buying power model methods

* Support computing maintenance margin for arbitrary quantities

The existing GetMaintenanceMargin function assumes that we're only interested
in the maintenance margin for the entirety of the provided security's holdings.
This makes it impossible to perform what-if analysis or to even ask how much
maintenance margin is devoted to a particular subset of the security's holdings.
This change adds the quantity to the MaintenanceMarginParameters class. Futures
and Options models also depend on holdings cost and holdings value, so they have
also been added to the parameters type. Finally, static factory methods were
added to improve discernment of intent: ForCurrentHoldings provides the existing
behavior and then ForQuantityAtCurrentPrice to support what-if scenarios where
we're looking for the change in maintenance margin if we were to execute an order
for the securiy at the current time step. Obviously a constructor is provided to
set all of the values explicitly, using any price metric the caller desires.

* Address review

- Fix BPM xml documentation
- Fix python unit tests and PythonWrapper validate method

* Add SecurityHolding.QuantityChanged event

Adding event handlers will allow us to orchestrate complex
events from distant parts of the codebase through wiring
them up. If we continue down this path, it will move us away
from the current, very 'mechanical' data flows expressed in
LEAN and towards a more modern, event processing based system.
This is but a baby step in that direction and the initial use
case is using this QuantityChanged event to trigger resolution
of the algoritm's positions groups. This is part of an effort
to improve the fidelity of options margin modeling where we'll
model an OptionStrategy as an IPositionGroup. This will allow
us to compute the margin requirements of an OptionStrategy as
a unit instead of computing margin of each security individually
in isolation.

See #4065

* PortfolioManager: Group fields and remove unused field

This codebase generally places fields as the first members, but
this class had some fields at the top, then some properties, and
then some more fields. This change brings all the fields together
at the top of the file and also removes pointless comments placed
directly above some of the fields. Additionally, an unused field
was removed.

* Remove unused _currencyConverter from Security

Looks like at some point the only code using this member variable was removed
and the necessary clean up was overlooked.

* Add Parse.Enum functions

* Support disabling regression algorithms by language via config.json

Adds 'regression-test-languages' to config.json and filters regerssion algorithms to
run based on this value. When cycling on a particular feature, it's nice to be able
to run the entire regression set while ignoring the python algorithms. Once the C#
algorithms are all passing, one can then go back and run C# and Python in a final run,
since 99% of feature work doesn't impact python specifically.

* Implement IComparable in SecurityIdentitfier

This can be used to deterministically sort securities and symbols

* Add .editorconfig to enforce common formatting for json/sh files

* Fix typo in IBuyingPowerModel.GetBuyingPower xml docs

* Add ListEquals/GetListHashCode and OrderDirection.Closes(PositionSide)

ListEquals and GetListHashCode are designed to be used together as they
complement each other according to C#'s requirements for Equals and
GetHashCode functions.

PositionSide.ToOrderDirection() extension simply converts a PositionSide
to its logical equivalent OrderDirection. Long->Buy, Short->Sell, None->Hold

OrderDirection.Closes(PositionSide) determines if a particular OrderDirection
would have the effect of reducing a position's absolute size. This function
greatly improves the readability of buying power functions that must provide
adjustments when an order/contemplated trade reduces/closes an existing position.
OrderDirection.Buy.Closes(PositionSide.Short)
OrderDirection.Sell.Closes(PositionSide.Long)
All other combinations return false

Adds ToArray/ToImmutableArray convenience functions that combine a call
to Select followed by To(Immutable)Array all in one function call.

* Add decimal.DiscretelyRoundBy extension method

Supports rounding a decimal value by an arbitrarily chosen maximum precision,
or 'quanta'

* Update FutureMarginBuyingPowerModelTests to respect the security's lot size

* Add core position group classes and abstractions

* Add initial/maintenance margin support, buying power model consistency tests

* Add SufficientBuyingPower and GetReservedBuyingPower to position group model

Includes update to BrokerageTransactionHandler to use position group BPM for
sufficient buying power checks.

* Resolve position groups on each fill

We need to update the state of our position groups on each fill so that
we can properly handle multiple orders within the same time step. We
also limit the number of positions sent into the resolver by removing
securities without any holdings.

* fixup! Add SufficientBuyingPower and GetReservedBuyingPower to position group model

* Add GetMaximumLotsFor{Target|Delta}BuyingPower

Instead of computing order quantity, these functions compute the
maximum number of position group lots, which is the position group
quantity, and is guaranteed to be a whole number, for the provided
target/delta buying power parameters.

The SecurityPositionGroupBuyingPowerModel delegates to the security's
IBuyingPowerModel by applying a scaling factor equal to the security's
lot size.

This change also updates references to IBuyingPowerModel.GetMaximum...
to use the new position group model methods.

* Convert remaining IBuyingPowerModel call sites to position groups

* Rename PositionManasger.CreateDefaultGroup -> GetOrCreateDefaultGroup

Better describes its behavior

* Add Position Groups readme.md

* Add Option Strategy BuyingPowerModel

- Adding CompositePrositionGroupResolver and
  OptionStrategyPositionGroupResolver
- Adding OptionStrategyPositionGroupBuyingPowerModel handling option
  strategies based on IBs margin table. Adding regression algorithms
- Few changes so that option strategies executed by multiple orders are
  detected
- Adjust OptionStrategyDefinitionMatch to include equity legs in the
  matching result
- Minor tweaks fixing previous rebase
- Minor fixes for existing option strategies definitions, adding new
  missing strategies.
- Fixing minor bugs in option strategy matcher. Adding more unit tests

* Address self reviews

- Fixing bug in 'PositionGroupCollection'
- Few minor simplificaitons
- Adding BasicTemplateOptionEquityStrategyAlgorithm

* Address reviews

- Improve regression algorithms margin remaining and used assert logic to be exact. Taking into account spread and fees

Co-authored-by: Michael Handschuh <mhandschuh@gmail.com>
2021-04-30 18:45:27 -03:00
Colton Sellers
a3836a64c4 Refactor StartDateLimited Warning Logs (#5510)
* Refactor to queue up start date changes to log on dispose

* Fix typo in warning collection used

Co-authored-by: Martin-Molinero <martin@quantconnect.com>
2021-04-30 10:55:16 -03:00
Colton Sellers
db61cea3db Refactor logging for SubscriptionDataReader FactorFile processing (#5508)
* Collect and log symbols that had start date adjusted because of factor files

* Only post the message if the set has values

* Modify message to be [Symbol, Date] combo for more information on log

* Set a hard limit on the warning set to keep it from growing unnecessarily large

* Enforce a hard limit and improve message if full

* Enforce limit in log message because of possible threading adding past max

* Cleanup
2021-04-29 11:02:04 -03:00
Colton Sellers
fd4e1dc0a0 Address Security Normalization Changed to Raw Logging (#5509)
* Log security mode change once per universe addition process

* Limit max size of the warning queue to 10

* Only allow to emit once per backtest

* Set limit as var, if at limit suggest more

* Always suggest more warnings may exist because we opted to log only once
2021-04-29 10:54:46 -03:00
Gerardo Salazar
bb9cde1cee Adds StandardDeviationOfReturns configurability and improves greeks warmup for Futures/Index Options (#5495)
* Improves greeks configurability and defaults for all option asset types

  * Makes `StandardDeviationOfReturns` configurable by users, so that
    greeks can be loaded according to user expectations and the series
    of returns that they'd like to compute for `n` periods and timespan
    of `T`, as well as resolution of the data in live mode.

  * Changes resolution to max resolution available for the default
    volatility model created for the security. Usually this only applies
    to live mode, but if creating an instance of the
    `StandardDeviationOfReturns` volatility model and no `updateFrequency`
    is provided, the resolution's time span will be used as the default
    value. Backwards compatibility for equities is maintained.

  * Changes defaults for `StandardDeviationOfReturnsVolatilityModel`
    to warmup greeks faster for other derivative asset types

  * Improves comments on `StandardDeviationOfReturns` for clarity on how
    to use the volatility model for end users

* Fixes bug where TradeBar could not have proper Symbol set when getting
max resolution

  * Applies to QCAlgorithm.Universe and StandardDeviationOfReturnsVolatilityModel
  * Adds tests to check volatility model is updated at specified config intervals

* Address review: add shared method for (Relative)StandardDeviation
volatility models

  * Adjusts logic to determine bar type

* Address review: order by TickType when getting configs inside volatility models
2021-04-28 19:05:00 -03:00
Colton Sellers
c082f0dda3 Address Missing StableCoin Pairs in Crypto Exchanges (#5488)
* Allow USDC in cashbook without USDC-USD pair

* Cover more stablecoin cases unique to our crypto brokers

* Add unit test

* Cleanup and expand test cases

* Add USDCEUR and USDCGBP to GDAX Symbols

* Add missing tickers to SPDB

* Cleanup test
2021-04-28 14:20:15 -03:00
Adalyat Nazirov
845e874132 Modify partially filled (#5500)
* allow partially filled orders to be updated
need unit tests

* test is progress

* implement PartialFillModel
2021-04-27 20:36:32 -03:00
Jasper van Merle
706091b25e Update foundation base to latest stable phusion/baseimage (#5506) 2021-04-27 19:20:31 -03:00
Jared
fe040a55e9 Update readme.md 2021-04-23 14:25:14 -07:00
Martin-Molinero
ab82e75885 Fix undeterministic regression algorithms (#5504)
- Testing net5 uncovered these algorithms to be undeterministic
    - Adjusting AllShortableSymbolsCoarseSelectionRegressionAlgorithm
      internal implementation
    - Order removal of universe members will be deterministic, when the
      entire universe is removed.
2021-04-23 11:58:12 -07:00
Derek Melchin
ba4e2b115c Update Summary of DefaultDataProvider (#5503) 2021-04-23 11:19:46 -03:00
Alexandre Catarino
2b0fd2e607 Updates SPY Market Data (#5493)
* Fixes Double to Decimal Cast in GetAnnualPerformance

`GetAnnualPerformance` raises an exception if the `AnnualPerformance` calculation returns a double that cannot be cast to decimal (smaller than `decimal.MinValue` or bigger than `decimal.MaxValue`).
See `ProbabilisticSharpeRatio` where the same solution was applied.

* Updates SPY Market Data

SPY is a key asset since it is the default benchmark, and any change can lead to different `Alpha` and `Beta`

* Updates Unit Tests to Reflect Data Update

* Updates Regression Tests to Reflect Data Update I

Most of the regression tests change because of updated data (market and factors) of SPY (default benchmark) while the total trade remain the same.

* Updates Regression Tests to Reflect Data Update II

The following regression tests were changed to adapt to adjusted prices and keep the total trades:
- `BacktestingBrokerageRegressionAlgorithm`
- `LimitIfTouchedRegressionAlgorithm`
- `PortfolioRebalanceOnCustomFuncRegressionAlgorithm`
- `SetAccountCurrencySecurityMarginModelRegressionAlgorithm`
- `StopLossOnOrderEventRegressionAlgorithm`
- `TimeInForceAlgorithm`

The following regression tests have more trades since adjusted prices allowed more 1-2 shares trades that were rounded down to zero before:
- `FreePortfolioValueRegressionAlgorithm` 2 -> 3
- `PortfolioRebalanceOnDateRulesRegressionAlgorithm` 291 -> 298
- `TrailingStopRiskFrameworkAlgorithm` 5 -> 7

Especial cases:
- `AutoRegressiveIntegratedMovingAverageRegressionAlgorithm` 65 -> 52
 - ARIMA model sensibility
- `BlackLittermanPortfolioOptimizationFrameworkAlgorithm` 18 -> 19
 - BLM model sensibility
- `ExtendedMarketHoursHistoryRegressionAlgorithm` 20 -> 18
 - Less minute bars before market opens

* Addresses Peer-Review

Fix `BacktestingBrokerageRegressionAlgorithm` to use `CalculateOrderQuantity` and round down `quantity` to an even number to pass a value assertion and update the expected value from 50 to 52.
The quantity calculated by `CalculateOrderQuantity` has changed from 50 to 53 because of factor file update.
2021-04-19 13:31:01 -03:00
Colton Sellers
5b10b3b509 Refactor of Auxiliary Data Filtering (#5485)
* Add futures regression reproducing the issue

* Cleanup futures regression

* Add Options regression

* Add IRegressionAlgorithmDefinition

* Add IRegressionAlgorithmDefinition

* Adjust regressions to compare to expiration date; delisting time is not always correct

* Refactor subscription enumerator filtering of AuxData to top of the stack

* Update broken tests to reflect the split/dividends/delisting subscriptions

* Update regression statistics because of Delisting EOD instead of at time

* Let custom data configurations bypass filter

* Adjust expected count, now that we are letting aux data through to history requests

* another small adjustment

* Use ExpectedBarCount in error message

* Add filter test for both cases

* Add some clarifying comments

* Verify we did recieve data in the regressions

* Make _shouldEmitAuxiliaryData private readonly

* Filter out aux data for history requests

* Remove option to not include aux data in subscriptions

* Refactor filtering to be more explicit for each piece of data; fixes universe selection aux data

* Cleanup comments after removed var

* Refactor order of filtering for performance reasons.
2021-04-19 11:10:47 -03:00
Alexandre Catarino
a7b2d9450f Fixes Double to Decimal Cast in GetAnnualPerformance (#5492)
`GetAnnualPerformance` raises an exception if the `AnnualPerformance` calculation returns a double that cannot be cast to decimal (smaller than `decimal.MinValue` or bigger than `decimal.MaxValue`).
See `ProbabilisticSharpeRatio` where the same solution was applied.
2021-04-19 10:43:47 -03:00
Jasper van Merle
6af20c3d8a Fix using Bitfinex data feed in paper trading (#5490)
* Fix using Bitfinex data feed in paper trading

* Add BrokerageFactory to TradierBrokerage
2021-04-16 12:04:14 -03:00
Colton Sellers
cb9bc95c37 Refactor IndicatorExtensions to use SafeAsManagedObject to convert PyObjects (#5489) 2021-04-16 10:59:10 -03:00
David Acker
72b6a22230 Add Wilder Accumulative Swing Index (#5476)
* Add SI

* Add ASI

* Add Swing Index

* Add Accumulative Swing Index

* Fix XML comment

* Add SI and ASI

* Add test data

* Add SI tests

* Add ASI tests

* Convert get only properties to methods

* Fix indicator name

* Replace special characters

* Fix indicator formula

* Replace test data

* Replace test data

* Update QCAlgorithm.Indicators.cs

* Minor format tweaks

Co-authored-by: Jared <jaredbroad@gmail.com>
Co-authored-by: Martin-Molinero <martin@quantconnect.com>
2021-04-16 10:54:02 -03:00
Stefano Raggi
6fbc3786b0 GDAXBrokerage bug fixes (#5477)
- Fixed GDAXBrokerage missing fills caused by an incorrect assumption of a global counter for order fills (it is actually per-symbol)
- Filtered out rate limit messages in the fill monitor task
2021-04-12 12:56:52 -03:00
Colton Sellers
ea11fb41c9 LiveDataBasedDelistingEventProvider Fix (#5471)
* Fix race condition in DelistingEventProvider

* Remove logging and speed up test time advancement

* Reduce timeout to original
2021-04-09 20:26:09 -03:00
Colton Sellers
f5b729dc0d Accept symbol array or IEnumerable for TRIN (#5473) 2021-04-09 12:43:55 -07:00
Jasper van Merle
9ba15b23e3 Make random data generator generate symbols with entries in SPD (#5470)
* Make random data generator generate symbols with entries in SPD

* Cap symbol count in generator when needed
2021-04-09 10:37:35 -07:00
Martin-Molinero
6ab91a13e1 Add note for TimeZoneOffsetProvider StartTime (#5469) 2021-04-08 18:00:17 -03:00
Colton Sellers
beaa705646 Loader Support Full Algorithm Name (#5467)
* Apply fix

* Address possible mismatching subset of name
2021-04-08 17:59:08 -03:00
Colton Sellers
4c830c8235 Fix Breaking Unit Test (#5466)
* Adjust Timeout; Reduce time advance

* Move logging of EndTime above asserts
2021-04-07 21:09:56 -03:00
Colton Sellers
395c1123da Remove Obsolete QCAlgorithm.OnEndOfDay() (#5441)
* Remove and replace OnEndOfDay() ref

* Restore functionality of obsolete EOD, waiting for deprecation in August 2021

* Cleanup

* Adjustments to only post message when using obsolete EOD

* nit, extra space

* Address review

* Adjust test to reflect new behaviour

* Move GetPythonArgCount to an extension method

* Add unit test

* nit accidental import

* Refactor broken test

* Use Py.GIL() state for extension
2021-04-07 13:39:49 -03:00
Martin-Molinero
8e50645640 Update System.Threading.Tasks.Extensions (#5340) 2021-04-07 12:36:22 -03:00
Colton Sellers
68ca504d3a Apply fixes (#5464) 2021-04-07 11:46:31 -03:00
Jasper van Merle
12df1c9a31 Fix drawdown plotting failing on single equity point (#5461) 2021-04-06 16:30:23 -07:00
Aaron Janeiro Stone
4de25b6cd4 _lastLow and _lastHigh are given resets under DeM's Reset method (#5449) 2021-04-06 10:15:16 -03:00
dependabot[bot]
cdef9e709a Bump System.Net.Security from 4.3.0 to 4.3.1 in /Tests (#5453)
Bumps System.Net.Security from 4.3.0 to 4.3.1.

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-04-06 10:11:43 -03:00
Colton Sellers
3579fecc58 Live Consolidator Bug Fix (#5429)
* Set _lastEmit before emitting, otherwise _workingBar is always null

* Aggregate bars if the data endTime is past lastEmit

* Add unit test

* Address Review

* Clean up unit tests

* Refactor solution to set consistent _lastEmit behaviour

* Add another unit test

* Make fixture non-parallelizable

* Undo last change, and adjust breaking test directly
2021-04-05 17:05:53 -07:00
Stefano Raggi
3a390cfa9f Add IB brokerage message event filtering (#5452) 2021-04-05 17:17:14 -03:00
Stefano Raggi
58dae061e7 Add REST API exception logging in Tradier brokerage (#5454) 2021-04-05 17:14:52 -03:00
Martin-Molinero
3f2479393f Update clr-loader and remove workaround (#5451) 2021-04-05 14:25:19 -03:00
Jasper van Merle
4849588c3b Fix flipped operator in random data generator (#5446) 2021-04-05 11:07:51 -03:00
Martin-Molinero
3d84c76abb Add missing timedelta import in python custom data regression algorithms. Relate to https://github.com/QuantConnect/Lean/pull/5426/files (#5450) 2021-04-05 10:26:51 -03:00
Colton Sellers
1c3d849ad5 Fix Warnings V2 (#5436)
* Reconcile duplicated code

* Add License header

* CS0219 Fixes: Value assigned, but never used

* CA1507: Use nameof in place of string literals

* CS0108 : Hides Inherited Member; Use new keyword to overwrite formally

* CS0114: Hides inherited member; use override keyword

* CS0168: Variable is declared but never used

* Tests CS1062; using obsolete implicit Symbol -> String; fix via .ToString()

* CS0472: Non Nullable Obj getting Null Checked

* CS0067 Member not used; ignore all cases for future use

* CS00162 : Unreachable code; either removed or ignored for debugging and test cases

* CS0169 Remove non-used fields; ignore those that may be used in future

* CS0414; Field is assigned but never used.

* CS0618; Obsolete properties and members; Only fixes simple ones, rest will have to broken up

* CS0649; Field never assigned too

* CS0659 & CS0661 ; Overwrite operators and equals but not hashcode; I don't really override it but just call base

* Small comment fix

* Cleanup pragma statement
2021-04-02 11:20:01 -07:00
Jasper van Merle
271220083b Fix various map file generation issues (#5443) 2021-04-02 11:08:02 -07:00
Stefano Raggi
b29d0cbfaf Tradier Brokerage Updates (#5445)
* Tradier brokerage updates

- Add missing status check after REST API calls
- Initialize DataQueueHandler on-demand (on first subscribe call)

* Trigger build
2021-04-02 10:58:27 -07:00
Tomas Rampas
27a25cd663 The null value parameter removed from call of OandaBrokerage c'tor from OandaDownloader class (#5430)
Co-authored-by: rampasto <tomas.rampas@outlook.com>
2021-03-30 15:25:54 -07:00
Derek Melchin
5ed61db2bb Fix timestamps in custom data algorithms (#5426)
* Correct custom data timestamp and match performance across languages

* Add EndTime property

* Add comment for crypto SetHoldings
2021-03-30 14:48:59 -07:00
Colton Sellers
4a1485a291 QB Fundamental Test Fix (#5437)
* Use only 1 QB instance for fundamental tests, (want to see github workflow result)

* Fix small bug in test
2021-03-30 06:42:39 -07:00
Alexandre Catarino
d6072c88a5 Fixes LiveOptionChainProvider.FindOptionContracts (#5434)
`LiveOptionChainProvider.FindOptionContracts` handles the following data format:
`SPY  2021 03 26 190 000 C P  0 612 360000000`
where both existing `OptionRight.Call` and `OptionRight.Put` are declared in the same line.
2021-03-29 13:39:41 -07:00
Colton Sellers
20910ca2dc Broken Regressions Fixes (#5421)
* Remove regression references to non-existant Python versions

* Adjust regressions estimated capacity not adjusted by #5389

* Adjusts regression algorithms so that they pass (Index/Index Options)

  * Changes start/end date on BasicTemplateIndexAlgorithm
  * Changes option pricing model to BlackScholes in
    IndexOptionCallITMGreeksExpiryRegressionAlgorithm

    - The root cause of why there are no greeks at times for these
      options was identified. It is most likely due to the underlying's
      VolatilityModel not having had enough data to be "warmed up",
      which means it will return a standard deviation of zero to the
      option pricing model, rendering most metrics as NaN.

* Adds missing index/index options regression algorithms

  - Regression algorithms are now 1-1 between C# and Python for
    Indexes/Index options. All regression tests are now passing

* Fixes broken BasicTemplateIndex regression algorithm

  * Previously traded SPY, but because we have no SPY data in Lean
    master, I instead opted for index options, since data for those
    dates is already included

* Deal with weekend for breaking test case

* Adjust DefaultEndDate test to always pass

* Check todays date for open

Co-authored-by: Gerardo Salazar <gsalaz9800@gmail.com>
2021-03-29 13:35:03 -07:00
Jasper van Merle
c333ccdc4a Check whether storage directory exists before enumerating it (#5432) 2021-03-29 13:32:28 -07:00
Christian Korn
88c4a332bc Update PearsonCorrelationPairsTradingAlphaModel.cs (#5428)
Fix index of out bounds (#5427)
2021-03-26 10:55:19 -07:00
Colton Sellers
5d762d16b2 GetFundamental Default End Date (#5401)
* Change default end date for GetFundamental

* Add DefaultEndDate test
2021-03-23 14:18:07 -07:00
Colton Sellers
e2a0873b7c Fix Lean Warnings V1 (#5408)
Cleanup all non-breaking warnings
2021-03-22 11:08:48 -07:00
Gerardo Salazar
31ebaaeaa9 Fixes live BTC futures contract crashing in IB brokerage (#5409) 2021-03-22 08:48:58 -07:00
Jared
7625e232f4 Update readme.md 2021-03-19 14:53:46 -07:00
Alexandre Catarino
63f3af7afe Remove decimal.py (#5406)
* Removes decimal.py

* Removes References to Decimal in Examples
2021-03-19 14:17:05 -07:00
Colton Sellers
87b42f6fb5 Named Args Unit Tests (#5381)
Add regression and unit test
2021-03-16 16:53:02 -07:00
Gerardo Salazar
f9dc38efab Use trades per period instead of days for capacity calculation (#5389)
Use trades per period instead of days for capacity calculation
Updates regression algorithms
2021-03-16 16:30:49 -07:00
Colton Sellers
5587efaadd Update Python Runtime dll location (#5398) 2021-03-16 15:56:56 -07:00
Colton Sellers
a642d53bf9 Specify clr-loader version (#5400) 2021-03-16 14:50:47 -07:00
Colton Sellers
002151eab2 PythonNet 2.0.1 (#5390)
* Trigger rebuild

* Add Package QC PythonNet 2.0.1

* Update project files

* Push latest package

* Remove test package for shipping
2021-03-12 22:26:28 -03:00
Gerardo Salazar
4c085ff853 Adds Indexes and Index Options asset types (Backtesting/Live, IB only) (#5379)
* Add support for Index SecurityType  🚀 (#5364)

* Add Index SecurityType  🚀

* Extend SecurityIdentifier & Lean Data classes with Index support

* Add Index SecurityType  🚀

* Extend SecurityIdentifier & Lean Data classes with Index support

* Fixes

* Added index cross basic template demonstration

* WIP: Prototype index security type for LEAN as non tradable asset

* Re-adds Index entries to MHDB after rebase

* First steps to getting Index Options running

  * Looks at any instance where we pattern match for an option type
    and replaces it with a generic call to `.IsOption()` for easier
    extensibility in the future for additional option security types

  * Adds IndexOption security and misc. classes

  * Misc. changes, mainly related to any sort of special casing of
    equity options and made index options take the same path

* Enables index options data for backtesting

  * Adds new index options market hours to MHDB
  * Misc. bug fixes for index options
  * WIP: add live support for index options and indexes
  * Use OptionMarginModel for Index Options because they both use the
    same calculation for margin requirements

* Fixes contract not found errors on SPX index options and SPX index in IB

  * Turns out index options' last trading day is the day before expiry,
    which IB was expecting the last trading day.

* Add index option test cases (temp)

* LiveOptionChainProvider fix, use Symbol vs. ticker

  * Description updates to regression algorithms

* Fixes bug in live trading for indexes and index options

  * Adds overridable minimum price variation symbol property
  * Adds variable sized minimum price variation for index options
  * Adjusts symbol properties for index options
  * Misc. bug fixes

* Fixes option assignment simulation for European options

  * Updates index options regression algorithms (WIP)

* Fixes bug where index option exercise would trade index underlying

  * Fixes bugs where SecurityType.Index was getting flagged as tradable

* Regression algorithms updates and addresses review

  * Misc. style fixes and refactoring + a few bug fixes
  * Updates regression algorithms to run without runtime errors
  * Adds data for regression algos

* Sets DefaultOptionStyle on Canonical and support index options

* Update regression algos statistics

* Removes bad line in regression algorithm causing build to fail

* Minor tweaks

* Address review add comment about quoteBar parse scale

Co-authored-by: Balamurali Pandranki <balamurali@live.com>
Co-authored-by: Jared Broad <jaredbroad@gmail.com>
Co-authored-by: Martin-Molinero <martin@quantconnect.com>
2021-03-12 20:46:23 -03:00
Jasper van Merle
3aa76d4289 Add report creator to Docker image (#5386) 2021-03-11 14:42:26 -08:00
Martin-Molinero
5236fc202d Adding Symbol.Canonical (#5383)
- Adding Symbol.Canonical property which will be cached. Adding unit and
  regression tests
2021-03-11 18:38:20 -03:00
quantify-cflynn
1ca4389ed2 Adds SharpeRatio indicator (#5348)
* RollingSharpeRatio Submission

Creation of RollingSharpeRatio indicator, utilizing LEAN engine. Tests were created and successfully passed by the indicator, using spy_rsr.txt as outside data file which was created during a prior running of the program.

* Fixed Test Case Loading and Added Indicator Function

Added the RSR() function to auto load the indicator in Algorithm\QCAlgorithm.Indicators.cs. Also added a reference for the test file ("spy_rsr.txt") in Tests\QuantConnect.Tests.csproj.

* Fixed SharpeRatio Indicator

Updated the base formula, indicator structure/call, and the testing data for the SharpeRatio indicator.

* Minor Fixes

- Removed dividend yield from calculation
- Fixed typos in code/documentation

* Minor Style Fix and Error Confirmation

- Changed style to match style guide better.
- Checking for confirmation that QuantConnect.Tests.Engine.DataFeeds.LinveTradingDataFeedTests.DelistedEventEmmited_Equity() is server side, as it runs locally and should not have been affected by prior changes

* Simplification and fixing of SR calculation

- Updates calculation to proper SR formula
- Utilizes IndicatorExtensions for SR calculation rather than manual calculation
- Defines counter for 1 extra period offset on warmup (otherwise first datapoint is inaccurate if warmup period is SharpePeriod length)

* Minor Fixes

- Removal of SharpePeriod and RiskFreeRate variables
- Substitution of (SharpePeriod + 1) for WarmUpPeriod
- Outdated comment fixes

* Resubmission for Mono Confirmation Error

Error detected on Git for this version of the program. An error should not occur as only comments and minor variables were edited. Resubmitting to see if it is a false positive mono error.

* Notation Fixes

Fixed notation regarding spacing and outdated comments.

* Removal of Counter Logic

- Replaces counter for warmup with improved IsReady logic

* Fixed Syntax

- Removed unused imports
- Fixed variable readability
- Fixed comments
- Replaced Tabs with spacing

Co-authored-by: quantify-cflynn <quantify-cflynn>
2021-03-11 13:35:08 -08:00
Jared
b8397db0b7 Usability buffer on allocation (#5385) 2021-03-11 11:44:54 -08:00
Martin-Molinero
d4ea5f7b04 Simplify cash limit allocation (#5382) 2021-03-10 14:47:39 -08:00
Martin-Molinero
458272b2ea Fix mono running in research (#5380) 2021-03-10 17:34:59 -03:00
Colton Sellers
6c7353d09a Trigger rebuild (#5377) 2021-03-09 18:44:18 -03:00
Colton Sellers
834d4a4d58 QC PythonNet 2.0 (#5376)
* Update to new QC PythonNet

* Update readme

* Remove Python.Runtime config, replaced by env var

* Allow local packages testing in repo

* Address Review

* Add the LocalPackages readme

* Update Jupyter Image

* Update Research ReadMe
2021-03-09 18:25:31 -03:00
Gerardo Salazar
561aa3cf25 Adds backwards compatibility for MHDB and SPDB for new SecurityTypes (#5373)
* Adds backwards compatibility for MHDB and SPDB for new SecurityTypes

* Skip invalid SecurityTypes in MHDB and SPDB

* One time log invalid SecurityTypes in MHDB/SPDB

* Moves logging of SecurityType into new extension method

  * Adds TryParseSecurityType to Extensions
2021-03-09 10:52:14 -03:00
hsm207
e4af2ef856 Fix typo (#5374) 2021-03-09 10:29:21 -03:00
Martin-Molinero
3f8158a5be Add live trading Cash enforcement flag (#5372)
- Add live trading cash enforcement flag usefull for brokerages like IB
  which allow trading with currecies you don't have. Updating unit test
2021-03-08 22:09:44 -03:00
Jared
0c4a641590 Changes Protection Level of Constructor of Serialized Order Classes (#5366)
Makes `SerializedOrderEvent.Id` a virtual member.

Co-authored-by: Alexandre Catarino <AlexCatarino@users.noreply.github.com>
2021-03-08 17:03:09 -08:00
Stefano Raggi
20986059a9 Add OutsideRth property to InteractiveBrokersOrderProperties (#5360)
* Add OutsideRth property to InteractiveBrokersOrderProperties

* Address review
2021-03-08 20:15:25 -03:00
Balamurali Pandranki
c22a538bad Indian stock markets support & Zerodha brokerage implementation (#4873)
* Indian stock markets & Samco and Zerodha brokerage implementations

* Build fixes & Implement multi leg orders (BracketOrder & CoverOrder)

* Build fixes

* Clean & refactor

* Clean up & remove samco brokerage

* Clean up & remove samco brokerage

* Fix Nifty, BankNifty & Sensex Index futures expiry time functions

* Fix Nifty, BankNifty & Sensex Index futures expiry time functions

* Fix Futures Expiry Testcases

* Fix Futures Expiry Testcases

* Refactor Zerodha Symbol Mapper

* Refactor Zerodha Symbol Mapper

* Add Future symbols to symbol prop db csv

* Fix Symbol Mapper context

* Fix Market Hours Database

* Fix OrderJsonConverter

* Add Zerodha AccountBaseCurrency

* Add QuantConnect License headers to new source files

* cleanup config.json formatting & tick aggregator implementation

* cleanup config.json formatting & tick aggregator implementation

* Refactor ZerodhaBrokerageModel

* Fix

* Build Fixes

* Refactor

* Refactor Brokerage class & remove TextFieldParser

* Refactor Brokerage FeeModel

* Add ZerodhaOrderProperties

* Add Refactor HistoryProvider

* Refactor CanExecuteOrder

* Refactor SymbolMapper

* Refactor market names

* Refactor & remove Zerodha subscription manager

* Refactor & remove ZerodhaWebSocketChannels

* Refactor & remove ZerodhaWebSocketChannels

* Refactor ZerodhaBrokerage

* Refactor symbol prop db

* zerodha update downloader ticker data using symbol name

* 1 Zerodha mapper class update to get instruments based on Market. 2 Zerodha Getholdings data fetch fix.

* Update market-hours-database.json

* Implement basic testcases for ZerodhaBrokerage

* Update market-hours-database.json

* Update Market.cs

* 1 Fix for Zerodha subscriber and unsubscribe 2 User of CSVHelper to read instrument list

* Rename Zerodha DataQueueHandler class implementation

* Changes related to TradeBar and emit tick

* Fix DataQueueUniverseProvider & Handle Timezone conversion in WS EmitQuotes

* Emit Order Fixes

* DataQueueHandler refactoring and build fix

* Update config.json

* Removal of IHistoryProvider impplementation

* Reverting timezone logic as already taken care by BrokerImplementation using Unix time

* Place, modify and cancel order implementation

* fix zerodha test cases

* Updating get quotes and restricting getHoldings to MIS

* Testcase Fixes

* Testcase Fixes

* Testcase Fixes

* Updating emitFillOrder

* Add ProductType to ZerodhaOrderProperties

* Addition of ZerodhaProduct Type property and test update

* Fix for unit tests and minor changes for place and update order

* Unit test fix for Zerodha

* Addition of the product type and trading segment configs

* PR review fixes

* Addition of trading segment and product type configs

* Nuget Fixes

* Fix ZerodhaBrokerage DataQueueHandler

* Cleanup OrderTypes & rm global.json

* Update UpdateOrderRequest.cs

* Removal of custom csvreader

* Implementing additional method CanPerformSelection

* Add LiveOptionChainProvider

* Clean up and add QC license headers

* Quick cleanup

* Update ZerodhaBrokerage.cs

* Fix OrderEvent timezone conversions

* use item.Unrealised for Intraday position holdings

* Refactor Option chain get instruments calls

* Refactor Option chain get instruments calls

* Review fixes

* Remove whitespaces

* Updating options strike price

* Undo time stamp change

* Optional gethistory

* Addition of comments and minor changes

* Build Fixes

* Add comments for LogType enums

* Options fix

* Fix json name in CsvInstrument

* Update tick generation in DataQueueHandler

- Use Timestamp field for both trades and quotes
- Fix incorrect bid/ask sizes
- Avoid reading depth on each tick to find top quote
- Use new Tick constructors
- Remove unnecessary locking

* Add missing null check in Utils.StringToDate

* Order fixes

- Include TriggerPending orders in GetOpenOrders
- Remove unnecessary invalid check in PlaceOrder
- Fix GetOrderPrice and GetOrderTriggerPrice

* Zerodha account balance fetch

* Removal of Futures and Options

* Remove Futures & Options Support

* Update ZerodhaBrokerage.cs

* Update ZerodhaBrokerage.cs

* Add License headers

* Add License Headers

* Refactor

* historical TradeBar & security fee calculation fixes

* fix brokerage test case

* Update ZerodhaBrokerage.cs

* Update ZerodhaBrokerageHistoryProviderTests.cs

Co-authored-by: Aman Ray <ray.aman9876@gmail.com>
Co-authored-by: Stefano Raggi <stefano.raggi67@gmail.com>
2021-03-08 18:51:54 -03:00
Martin-Molinero
5dcda56a73 Revert "Revert "Upgrade IBAutomater to v1.0.51 (#5359)" (#5362)" (#5365)
This reverts commit c7fb6165e2.
2021-03-08 09:54:50 -03:00
Jasper van Merle
8076782ea6 Make random data generator save non-equity data (#5371) 2021-03-08 09:49:17 -03:00
hsm207
e869765759 Fix typo (#5361) 2021-03-04 15:28:21 -03:00
Martin-Molinero
c7fb6165e2 Revert "Upgrade IBAutomater to v1.0.51 (#5359)" (#5362)
This reverts commit caedddddf0.
2021-03-04 15:20:15 -03:00
IlshatGaripov
d9d02bc2d0 Applies a fix (#5358) 2021-03-04 13:13:41 -03:00
Stefano Raggi
caedddddf0 Upgrade IBAutomater to v1.0.51 (#5359) 2021-03-04 13:03:31 -03:00
Martin-Molinero
4e00324b57 Bug insight internal to procted internal (#5357)
* Update Insight.cs

* Insight protected to protected internal

Co-authored-by: Jared <jaredbroad@gmail.com>
2021-03-03 16:14:36 -08:00
Martin-Molinero
1b6301d813 Update Insight.cs (#5356) 2021-03-03 16:02:57 -08:00
Jared
d24695856d Update Insight.cs (#5355) 2021-03-03 15:17:25 -08:00
hsm207
17e13665eb Fix typo (#5353) 2021-03-03 10:23:05 -03:00
Gerardo Salazar
8c6aa6a3b3 Refactors Capacity Estimation and moves estimation to main event loop (#5351)
* Adds CapacityEstimate and SymbolCapacity

  The capacity estimation has been moved from
  the report generator and wired directly into
  Lean via the ResultHandler. In addition,
  the capacity estimation strategy has changed
  to account for errors in the previous iteration
  of the capacity estimation.

  Many many thanks to Jared for being much of the
  mastermind behind this project. It would have
  been harder to complete without him to bounce ideas
  off of.

  * Moves old tests to regression algorithms
  * Adds Estimated Capacity statistic
  * Removes old capacity estimation tests

Final report capacity estimation. Pushing to save state

* Fixes bugs, cleans up code and adds comments

  * Adds forced sampling to Capacity Estimation
  * Misc. bug fixes for daily data

* Updates capacity test cases' Estimated Strategy Capacity statistic

* Adds Capacity Estimate to all regression algorithms

* Removes Report's StrategyCapacity class and fixes bug in tests

  * Adds null check in BacktestingResultHandler to fix
    BacktestingTransactionHandler failing tests

  * Deletes old capacity estimation classes

  * Retrieve capacity estimates from backtest statistics results
    instead of calculating at runtime

* Make $0.00 capacity return as "-" and Result = 0 in report

* Adds capacity to runtime statistics

* Converts capacity to number denoted by financial figures in RuntimeStats

* Addresses review: code cleanup for Capacity and adds comments to regression tests
2021-03-02 18:46:31 -03:00
IlshatGaripov
83da0affc5 Implements Coin API HistoryProvider (#5298)
* CoinApi HistoryProvider impl.

* Small fix of ToTradeBar()

* Revert the change : CreateSliceEnumerableFromSubscriptions

* More tests and fixes.

* Removes redundant ToList()

* too much spacing

* Fixes to get data for an unlimited period of time, by means of pagination
2021-03-02 11:08:14 -03:00
Jasper van Merle
60798df64c Make optimizer usable in Docker and improve its logging (#5344)
* Make optimizer usable in Docker and improve its logging

* Wait for reset event instead of polling state
2021-02-26 15:50:16 -03:00
Martin-Molinero
bb20f9d9df IB will not load holdings internally if requested (#5342) 2021-02-25 11:43:38 -08:00
Martin-Molinero
32686db739 NotificationJsonConverter is case insensitive (#5341)
- NotificationJsonConverter will be case insensitive. Adding unit test
2021-02-25 11:42:42 -08:00
Stefano Raggi
7d97f05133 Tradier Brokerage updates (#5326)
* Add options support

- Added IDataQueueUniverseProvider implementation
- Fix subscribe ticker for options

* Tradier DataQueueHandler web sockets implementation

- Equities and Options (trades and quotes)

* Add error handling

* Add support for options

* Fix log messages

* Address review

- Updated Tick constructor usage
- Use $empty$ symbol for last unsubscribe message
- Added symbol mapper unit tests
2021-02-25 10:41:47 -03:00
Colton Sellers
8b173f2306 Add dotnet 5 to Lean Foundation Image (#5307)
* Add dotnet 5 to foundation image

* Address review. Remove net5 package after install

Co-authored-by: Martin Molinero <martin.molinero1@gmail.com>
2021-02-24 21:09:59 -03:00
Jasper van Merle
9cde4344fc Re-apply changes from #4870 to fix ThreadAbortException in ToolBox (#5339) 2021-02-24 20:50:56 -03:00
Martin-Molinero
785c706d4c Live delisting will only ask mapfile for equities (#5336)
* Live delisting will only ask mapfile for equities

* Remove unrequired log error
2021-02-24 14:14:50 -03:00
Gerardo Salazar
0dc521f787 Reduces log spam on long backtests when generating capacity (#5334) 2021-02-23 16:22:49 -08:00
Martin-Molinero
94d9996b21 Enforce USD account currency if allocation is limited (#5333)
* Enforce USD account currency if allocation is limited

- Enforce USD account currency if allocation is limited. Adding unit
  test

* Adjust currency log message
2021-02-23 11:57:48 -08:00
Martin-Molinero
67b3873205 Reduce live coarse selection interval check to 10 min (#5332)
* Reduce live coarse selection interval check to 10 min

- Reduce live coarse selection interval check to 10 min. Adding unit
  tests, reducing code duplication in tests.

* Adjust unit test after self review
2021-02-23 16:37:08 -03:00
Gerardo Salazar
acd9ef4cfd Removes SevenZipSharp library from ToolBox (#5329)
* Removes SevenZipSharp library from ToolBox

  - Library removal required for update to .NET 5.0 since it's not
    compatible with it and Linux is unsupported.

  * Adds new extract 7z functionality to Compression project
  * Refactors AlgoSeekFuturesConverter 7z extract
  * Refactors DukascopyDataDownloader 7z extract

* Addresses review: code cleanup + exception type change on timeout

  * Removes not needed stream of data in Dukascopy downloader
  * Makes output directory non-optional
2021-02-23 11:38:07 -03:00
Gerardo Salazar
7f934b2adf Remove unused dependency WebSocketSharpFork (#5331) 2021-02-23 11:33:17 -03:00
Martin-Molinero
596e940ccd Update R library (#5328)
* Update R.Net libraries

* Update R installation version
2021-02-22 19:24:05 -03:00
Gerardo Salazar
f38ff0d1f2 Reduces StrategyCapacity memory load and boosts performance (#5327)
* Adds logging for progress tracking
  * Reads data one day at a time rather than loading all data at once
2021-02-22 11:53:12 -08:00
Gerardo Salazar
37d26a35ce Fixes various bugs in estimated capacity class (#5324)
* Fixes potential mapping issue, caused by not mapping Symbols before
    reading data off disk

  * Fixes issue where some results would evaluate to zero capacity

  * Loads of refactoring, mostly resulting in cleaner code
2021-02-19 18:00:08 -08:00
Martin-Molinero
834326760d Fix regression test History Request (#5321)
- After https://github.com/QuantConnect/Lean/pull/5207 history requests
  are selecting the correct data type and cause the regression test to
  fail because there is no QuoteBars for daily equity. Updating and
  fixing this.
- Centralizing the logic around getting the SubscriptionDataConfig to
  use
2021-02-19 20:39:50 -03:00
Martin-Molinero
d4ebd93586 Limit live cash allocation (#5320)
* Add brokerage data cash limit feature

* Expand unit test to asser orders are skipped

* Add algorithm debug messages

* Ignore account changed event
2021-02-19 20:08:32 -03:00
Gerardo Salazar
0645513f5e Capacity estimation in report generator (#5318)
* Adds strategy capacity estimation in report generator

* Style and license fixes

* Adds comments, constants, and new method accessibility

* Removes unneeded imports
2021-02-18 17:51:40 -08:00
Martin-Molinero
ecf91546e6 Update Nlog Math and fasterflect (#5310)
* Update Nlog Math and fasterflect

* Remove NLog
2021-02-18 20:18:07 -03:00
Martin-Molinero
c834a1c902 Revert Lean.Launcher nuget package rename (#5317) 2021-02-18 19:39:05 -03:00
Colton Sellers
43a540cbb1 OpenInterest Bug Fixes (#5207)
* Filter values that are before subscription start time; also adjust starttime for OpenInterest

* Use data EndTime for comparison

* Allow Auxiliary data through

* Fix OpenInterest DataReader Logic

* Add regression

* Address review

* Ignore open interest for time slice

- TimeSliceFactory will directly ignore open interest for determining if
  the slice has data or not. Open interest will still be available
  through the Tick collection. Reverting some of the previous commits
  changes since they are no longer required.
- HistoryRequests and SubscriptionRequest will use AlwaysOpen exchange
  for open interest requests. Adding unit test reproducing issue
- Adding `BaseDataRequest` to avoid duplication logic.

* Make OpenInterest an internal feed and ignored by default in history

- Adding unit tests

* Revert SubscriptionFilterEnumerator Start time addition

Co-authored-by: Martin Molinero <martin.molinero1@gmail.com>
2021-02-18 19:04:29 -03:00
Alexandre Catarino
c5bb840bde Adds Static AlgorithmCreationTimeout Property to BaseSetupHandler (#5316)
* Adds Static AlgorithmCreationTimeout Property to BaseSetupHandler

This value will be used to set maximum time that the creation of an algorithm can take.

* Adds Additional Logging to AlgorithmPythonWrapper

It will informing the user how long it takes to import the module.

* Changes How AlgorithmCreationTimeout is Initialized

It will prevent callling Config.GetDouble on every call.
2021-02-18 19:00:33 -03:00
Martin-Molinero
4632840da9 Add license file for project packages (#5314) 2021-02-18 18:57:36 -03:00
Martin-Molinero
ba4c45d729 Remove version checking (#5315) 2021-02-18 18:32:07 -03:00
Martin-Molinero
9232427663 Remove all nuspec files (#5311) 2021-02-18 17:13:11 -03:00
Martin-Molinero
c30929f612 Add support for live trading delisting events (#5195)
* Add support for live trading delisting events

- Adding `LiveDelistingEventProviderEnumerator` that will emit delisting
  events. Adding unit tests
- Remove unused `LiveAuxiliaryDataEnumerator`.
- Refactor the corporate event providers being used per security type

* Self review: compare date component

* Add new LiveDataBaseDelistingEventProvider for equities

- Add support for delisting events for equities. Adding unit tests

* Fix cleanup of delisting equity subscription
2021-02-17 19:53:53 -03:00
Martin-Molinero
df6e133833 Fixes for assembly information (#5306)
- Update version to 2.5
- Normalize version and assembly information
- Remove commented and unrequired code
2021-02-17 16:42:23 -03:00
Juan José D'Ambrosio
2d99afc8c3 Refactor IPrimaryExchangeProvider.GetPrimaryExchange (#5302)
* Refactor IPrimaryExchangeProvider.GetPrimaryExchange 

now it returns a PrimaryExchange instead of a string

* Update MapFilePrimaryExchangeProvider.cs

Co-authored-by: Martin-Molinero <martin@quantconnect.com>
2021-02-17 12:43:41 -03:00
Gerardo Salazar
b3835510d0 Changes calculation of rolling/series graphs to use EOD equity (#5303)
* To maintain consistency between calculations, we will use
    the end of day equity value to calculate the returns per day.
    This fixes a bug where daily equity series would zero out and result
    in an exception being thrown since no elements were being passed to
    the Sharpe calculation.
2021-02-16 13:43:27 -08:00
Stefano Raggi
239fa29bf3 Tradier Brokerage updates (#5265)
* Tradier brokerage updates

- Removed old authentication code (refresh tokens) and settings
- Added "tradier-use-sandbox" config setting

* Fix brokerage unit tests

* Update Tradier config.json settings

* Add sandbox check in Subscribe

* Bug fixes + unit test updates

* Trigger build

* Fix Tradier fee model

* Address review
2021-02-16 13:37:46 -03:00
Juan José D'Ambrosio
df4abd3c3a Bug algoseek taq writes tick exchanges correctly (#5301)
* Implements wrapper to get the exchange as a single letter representation

Also replace lower 'l' with capital 'L' in condition flags enums. it is a new warning on the compiler and it looks cool :)

* There are cases where the exchange is null or empty, in those cases return null

* Add tests for single character exchange representation

* Update GlobalTest.cs

Co-authored-by: Martin-Molinero <martin@quantconnect.com>
2021-02-16 12:51:08 -03:00
Gerardo Salazar
7d93f43d38 Calculate more report elements using LiveResult data in report generator (#5300)
* Calculate PSR for live algorithms in report generator

* Use live series for calculating of CAGR, Max DD, and PSR

  * Removes Kelly Estimate from report and template.html

* Update template.html

* Rolling Beta bug fix when using daily data

  * Max drawdown output as percent

* Make days live report element use equity curve last day instead of today

Co-authored-by: Jared <jaredbroad@gmail.com>
2021-02-15 19:56:52 -08:00
Gerardo Salazar
c435caa7d1 Add check for new deployments to DaysLiveReportElement (#5299)
* This fixes a potential exception thrown when trying to access the
    first element of the Live equity series, when no equity series
    exists.
2021-02-15 21:30:12 -03:00
Aaron Janeiro Stone
643e8754ed Feature 5162 - LimitIfTouched Orders (#5164)
* Adds LimitIfTouched order.

TODO:
-- Add tests.
-- Add into existing regression algorithms.
-- Refactors (?)

* Fixes

- Remove unrequired space changes
- Fix EquityFillModel min/max limit price fill
- Add TriggerPrice for UpdateOrderRequest.

Quote info used w.r.t. comparing against Limit prices for LIT

FillModel.cs implementation is fixed to use quotes when comparing against set limit prices.
Also changes test implementations to assert which of quotes/trade-bars are being used

Reviewer-suggested fixes
------------
Merge remote-tracking branch 'origin/limiftouched' into limiftouched
Styling
Adds missing null check for quotebar
Styling
Adds missing null check for quotebar
Merge remote-tracking branch 'origin/limiftouched' into limiftouched
High/Low w.r.t. trigger price for determining if TriggerTouched changed to Current price
0462ad668a (r569832380)
fill fixes:
FillModel.cs: Fills exactly at the limit
EquityFillModel.cs: https://www1.interactivebrokers.com/en/index.php?f=608
Equity fill now uses quotebars
Revert - use new constructor which emulates former SubmitOrderRequest
Style changes
Reverts order model to original by means if new constructor
High/Low w.r.t. trigger price for determining if TriggerTouched changed to Current price
0462ad668a (r569832380)
fill fixes:
FillModel.cs: Fills exactly at the limit
EquityFillModel.cs: https://www1.interactivebrokers.com/en/index.php?f=608
Equity fill now uses quotebars
Revert - use new constructor which emulates former SubmitOrderRequest
Style changes
Reverts order model to original by means if new constructor
Merge commit 'bf4c96d2a055ea808fa4293662528c11a89b72c7'

* Suggested style fixes

* Review fixes
-------------------
- Suggested style fixes
- Changes LIT regression to better incorporate order modifications
- TODO: orderlisthash must be fixed
Fixed LIT regression algo
-----------------------
- Includes asserts in OnOrderEvent

* Fix OrderListHash

OrderListHash -> -292689487

* Re-adds quote nullchecks

* EquityFillModelTests fixes asserts

* Reordering FillModel.cs

* Fixes quote logic, adds methods in FillModel.cs

* Refactoring + LIT regression fixes
-- revert unneeded changes

* Fixes list hash

* Rebase -- catch up upstream

* OrderListHash fix

* Various fixes by reviewer

* Final requested changes

* tagged time -> utcinvariant

* Fixes listorderhash

* Time changed to UtcTime.ToString(DateFormat.US, CultureInfo.InvariantCulture)

* Adds Python LimitIfTouchedRegressionAlgorithm

* adds LimitIfTouchedRegressionAlgorithm.py

* adds LimitIfTouchedRegressionAlgorithm.py

* Minor changes to LIT regression algorithms

Co-authored-by: Martin Molinero <martin.molinero1@gmail.com>
2021-02-15 10:29:51 -03:00
IlshatGaripov
d17fe34c74 Fixing up Coin API streaming (#5295)
* fixing up Coin API streaming

* Fixing file name

* Adding log showing CoinApi product plan

Co-authored-by: Martin Molinero <martin.molinero1@gmail.com>
2021-02-15 09:55:00 -03:00
Stefano Raggi
512000d500 Update IBAutomater to v1.0.44 (#5290) 2021-02-12 12:10:02 -03:00
Gerardo Salazar
f5e730d776 Re-enable second page of reports generation (#5294) 2021-02-11 17:12:30 -08:00
Martin-Molinero
a0f39ec6a4 Remove Microsoft.Net.Compilers (#5282)
* Remove Microsoft.Net.Compilers

* Remove deprecated analyzer packages

- Replace deprecated analyzer packages

* Travis will use dotnet for building
2021-02-11 09:31:37 -03:00
IlshatGaripov
54bbdacd76 Just a small fix (#5287) 2021-02-10 12:17:43 -03:00
Gerardo Salazar
096e34212c Replace AppDomain.CurrentDomain with AssemblyBuilder (#5284)
* .NET Core/5.0 will not compile when calling
    AppDomain.CurrentDomain.DefineDynamicAssembly() since it was removed
    in .NET Core.

    AssemblyBuilder replaces this specific functionality since
    AppDomains were deprecated in .NET Core
2021-02-09 18:37:39 -03:00
Martin-Molinero
6d8e38a692 Update IB Api dll (#5278) 2021-02-09 17:35:55 -03:00
Gerardo Salazar
fefac8ab34 Move report statistics JSON output to in-memory string as out param (#5283) 2021-02-09 12:27:10 -08:00
Gerardo Salazar
3f53ba9b2f Report Generator Portfolio Result Statistics Output + TradesPerDayReportElement Bug Fix (#5281)
* Report generator statistics output

* Fixes issue where unsorted list could cause a negative trades/day kpi
2021-02-09 11:51:00 -08:00
Gerardo Salazar
e2964dd4b1 Make OrderListHash deterministic by using MD5 as its underlying hash function (#5276)
* Update OrderListHash to use MD5 as hash instead of hash code

* Update regression algorithm OrderListHash statistic

* Use full MD5 hash as OrderListHash, update regression statistic

* Fixes failing regression tests
2021-02-09 12:19:25 -03:00
Martin-Molinero
a1cbe13bb0 Minor logging improvements (#5277)
* Minor logging improvements

- Remove Thread.Sleep() call when logging debug
- FileLogHandler will capture lock after generating message to log
- ConsoleLogHandler will log time as UTC, cheaper than converting time
  zones

* Fix typo

Fix typo
2021-02-09 11:17:01 -03:00
Gerardo Salazar
17dbadea5b Remove cross-platform incompatible Thread.Abort() + ThreadAbortException (#5274)
* Remove cross-platform incompatible Thread.Abort() + ThreadAbortException

* Retrigger build

* Refactor thread abort logic into call to StopSafely()
2021-02-08 20:41:05 -03:00
Martin-Molinero
d077651f32 Package updates (#5273)
- Update `System.Collections.Immutable`
2021-02-08 15:49:15 -03:00
Adalyat Nazirov
c02ad0a89f Brokerage models improvements (#5267)
* fix Atreyu brokerage type full name

* improve brokerage models

-AtreyuBrokerageModel
-TradingTechnologiesBrokerageModel

* remove Limit price checks
2021-02-05 20:23:54 -03:00
Gerardo Salazar
aef2a47892 Updates CPU performance metrics gathering approach (#5261)
* Updates CPU performance metrics gathering for project modernization

  * PerformanceCounters are not supported cross-platform in
    .NET Core/5.0, which requires the use of an alternative method
    in the gathering of performance metrics. Since no exposed .NET API
    exists to gather these metrics without blocking, a new thread is
    created to block the time necessary for the CPU performance to be
    calculated.

* Address review: remove ResetEvent and make CpuPercent atomic

* Dispose of CpuPerformance instance before exiting Lean

* Minor tweak for Task and comment

Co-authored-by: Martin Molinero <martin.molinero1@gmail.com>
2021-02-05 20:23:30 -03:00
Gerardo Salazar
bc4dbf5707 Removes extra day added to CBOE Time causing data to shift one day forward (#5266)
* Added test
2021-02-05 19:42:01 -03:00
Gerardo Salazar
fe1948d0ae Removes/updates System.ComponentModel.Composition package (#5257) 2021-02-05 12:03:49 -03:00
Gerardo Salazar
254d0896f1 Replaces Microsoft.Extensions.CommandLineUtils with McMaster CLI utils (#5255)
* Replaces Microsoft.Extensions.CommandLineUtils with McMaster CLI utils

  * Updates ValueTuple to 5.0.0 for compatibility with package.

* Retrigger build

* Retrigger build
2021-02-03 19:56:14 -03:00
Gerardo Salazar
115dcab789 Removes app.config and sets automatic binding redirects (#5248)
* Some app.config files were kept to either enable features
    that are only enable-able via the config files, or binding redirects
    for DLLs that are not packaged with NuGet (i.e. VisualStudio
    package, required to run tests successfully @ 15.0.0.0)
2021-02-03 11:45:29 -03:00
Gerardo Salazar
5117609ea5 Fixes CBOE custom data consolidation (#5252)
* Adds regression algorithm testing consolidation of data.
2021-02-03 10:56:58 -03:00
Stefano Raggi
6040cc8e90 Add TradingTechnologies brokerage model + configuration (#5250)
* Add TradingTechnologies brokerage model + config

* Address review
2021-02-03 10:45:16 -03:00
Martin-Molinero
eb25dce462 Remove Alpaca brokerage implementation (#5249)
- Removing Alpaca brokerage implementation. See https://www.quantconnect.com/forum/discussion/10079/alpaca-paper-disabled
2021-02-02 20:16:34 -03:00
IlshatGaripov
0d0389ef6a BrokerageSetupHandler min resolution variable default value bug fix (#5243)
* fix

* Minor tweaks adding unit tests

* Address reviews

- BrokerageSetupHandler will use UniverseSettings.Resolution as default
  resolution

Co-authored-by: Martin Molinero <martin.molinero1@gmail.com>
2021-02-02 12:10:18 -03:00
IlshatGaripov
3e962b2e76 Fixes Bitfinex Brokerage history call bug (#5242)
* Fixes a bug #5173

* This is not timestamp but total ms.

* BitfinexBrokerageHistoryProviderTests fix
2021-02-01 21:58:57 -03:00
Adalyat Nazirov
f263fd49a7 Atreyu Brokerage initial setup (#5247)
* Atreyu Brokerage initial setup, and changes required for integration with main Atreyu project

* Address reviews

Co-authored-by: Martin Molinero <martin.molinero1@gmail.com>
2021-02-01 21:57:25 -03:00
IlshatGaripov
9b38bf3d91 More details: (#5244)
Bitfinex exchange may return us an empty result - if we request data for a small time interval during which no trades occurred - for example 1 minute interval - can happen even with most liquid pairs, like "ETHUSD" - would be good to have some time margin  for such scenario. and pump more data to warm up conversion rates
2021-02-01 21:57:10 -03:00
Aaron Janeiro Stone
7d70698c9a Feature #5098 - Time Series Indicators (#5099)
* Cleans history for ArimaIndicator/TimeSeriesIndicator.

-- removes commits from a tracked, already merged branch
-- removes artifacts from debugging sessions

* Removes AR/MA method as a user-specifiable method.
-- Prevents need to reference dll for MathNet in Tests (and potentially elsewhere).
-- Wrapper can be implemented around this functionality.

* Removes AR/MA method as a user-specifiable method.
-- Prevents need to reference dll for MathNet in Tests (and potentially elsewhere).
-- Wrapper can be implemented around this functionality.

* Better adherence to established code style

* Makes _intercept = true by default in constructor where it is not parameter

* WIP -- addressing reviews

* Passing tests following prior refactor

* Rearranged code, access modifiers adjusted

* Fixed indexing of _mafits, adds example algorithm

* Adds regression algo in python + addresses some refactors

* Addresses review

* Adds regression stats

* Fixes missing value signs

* Removes redundant code

* style changes

* style changes

* style: "err" -> "error"

* Minor tweaks

* Fixes python arima regression test

* Refactors AutoregressiveIntegratedMovingAverageTests.cs

Co-authored-by: Martin Molinero <martin.molinero1@gmail.com>
2021-02-01 20:17:49 -03:00
Martin-Molinero
1606b12475 Fix IB future chain being started at reset hours (#5246)
* Fix IB future chain being started at reset hours

- Fix IB future chain being started at reset hours. Adding unit test

* Refactor CanAdvanceTime into CanPerformSelection
2021-02-01 18:53:33 -03:00
Juan José D'Ambrosio
3a483fc4ec Migrate TradeConditionFlags and QuoteConditionFlags to Lean (#5227)
* Migrate TradeConditionFlags and QuoteConditionFlags to Lean

* Address revirew

Implement flag systems using long, this allows us to declare up to 64 flags
2021-02-01 13:11:30 -03:00
Gerardo Salazar
fe74d037c6 Updates NodaTime to latest version (3.0.5) (#5237)
* Updates NodaTime to version 3.0.5

  * Updates code to ensure compatibility with new NodaTime version
  * Updates System.Runtime.CompilerServices.Unsafe to 5.0.0
    - Required by NodaTime

* Adds comments explaining changes in NodaTime
2021-02-01 13:06:56 -03:00
Martin-Molinero
43e9cad2d6 Remove deprecated Http package (#5235) 2021-01-29 18:26:38 -03:00
Balamurali Pandranki
403ea22606 Setup GitHub Actions CI (#5192)
* Create gh-actions.yml

* Run github actions on all branches

* Setup Python and Deps

* Escape brackets

* Move to mono runtime instead of dotnet core

* lock mono version

* pin mono dep version

* Update gh-actions.yml

* Update gh-actions.yml

* Use Ubuntu 16.04

Use Ubuntu 16.04

* Update gh-actions.yml

* Try on container

* Fix indentation

* Try Self Hosted runner

* switch back to ubuntu runner

* Update gh-actions.yml
2021-01-29 12:38:05 -03:00
Gerardo Salazar
6cb103b17a DockerfileLeanFoundation package updates and new additions (#5072)
* Updates and adds new Python packages to DockerfileLeanFoundation

* Remove torch-geometric packages due to import issues

Torch geometric packages installed from pip as they are here result in an error saying to install the CUDA version of the packages. When the CUDA version is installed, we get a symbol error when attempting to link the `_version.so` shared object.
2021-01-29 10:25:14 -03:00
Martin-Molinero
8cbdfcaf28 Fix hour resolution mapping data handling (#5233)
- In some cases hour resolution data subscription would end early
  because of remapping not being correctly handled. Adding regression
  test
2021-01-28 20:41:04 -03:00
Juan José D'Ambrosio
1778462505 Fix broken regression tests (#5234) 2021-01-28 20:14:03 -03:00
Colton Sellers
472896c2d0 Update JSON Library (#5218)
* Update NewtonSoft.Json from 10.0.3 to 12.0.3

* Remove JsonSerializer.Populate(), values are already populated
2021-01-28 19:24:49 -03:00
Stefano Raggi
15cb846570 Add missing connection check in IB brokerage GetHistory (#5230) 2021-01-28 15:43:04 -03:00
Stefano Raggi
553b50a92e Ignore IB error 506 when disconnected (#5229) 2021-01-28 15:42:53 -03:00
Gerardo Salazar
5f73a05e04 Set default market hours for futures exchanges to 16:00 Central Time (#5226) 2021-01-27 20:00:19 -03:00
Colton Sellers
a5eaa43e35 Remove F# and VB Projects (#5223)
* Remove F# and VB projects

* Remove FSharp.Core package

* Readd FSharp to engine

Co-authored-by: Martin Molinero <martin.molinero1@gmail.com>
2021-01-27 11:31:49 -03:00
Martin-Molinero
e91af0814f Add notification targets and events to live packet (#5210)
* Add notification targets and events to live packet

- Add notification targets and events to live packet. Adding unit tests

* Add project name to job packet

* Add ShortToString and WebNotification Header

- Adding ShortToString implemnetation of OrderEvent and Insight
- Add Web notification headers

* Add more unit tests

* Revert json lower case fields
2021-01-27 10:26:35 -03:00
Colton Sellers
a2850fb20c Address Non-Compiled Files (#5225)
* Include MortgageRateVolatilityAlpha and fixes

* Include PlaceHolder PythonAlgorithm.cs

* Delete BinanceUtil

* Remove unused Regression Algorithms

* Minor tweaks

Co-authored-by: Martin Molinero <martin.molinero1@gmail.com>
2021-01-27 09:56:03 -03:00
Colton Sellers
c86fceac97 Fix regression typo (#5224) 2021-01-26 15:31:57 -03:00
Stefano Raggi
9997df45af IB Brokerage updates (#5222)
* Upgrade IBAutomater to v1.0.40

* Fix FinancialAdvisor account id check

- The Ixxxxxx account code is the Master Account for Fully Disclosed Brokers and this account is not tradable. Proprietary accounts for Brokers/Dealers used for proprietary trading have the Uxxxxxx account code.

* Update IBAutomater to v1.0.42

* Update IBAutomater to v1.0.43

* Log server version in ConnectAck handler
2021-01-26 09:52:05 -08:00
Jared
1ef92b3eca Update Crisis.cs 2021-01-25 10:47:15 -08:00
Adalyat Nazirov
c6d29c8be5 add FIX Protocol UTC timestamp format (#5212) 2021-01-25 11:24:54 -03:00
Derek Melchin
97deb4bbc6 Fix typo (#5216) 2021-01-25 10:24:15 -03:00
Gerardo Salazar
6ab40c102b Only report daily point-in-time portfolios instead of every trade (#5214)
* Only report daily point-in-time portfolios instead of every trade

* Allow for cash holdings to be visible in point-in-time portfolio output
2021-01-22 17:00:09 -08:00
Gerardo Salazar
41417593aa Writes point-in-time portfolios to disk (#5213)
* Writes point-in-time portfolios to disk

* Adds optional argument to Report constructor in ReportGenerator
2021-01-22 15:17:19 -08:00
Martin-Molinero
3ccf428498 Adjust delisting liquidation time (#5203)
* Adjust delisting liquidation time

- Adjust delisting liquidation time to 15 min before market closes.
  Adding unit tests. Updating existing.
- Handle `Statistics.CompoundingAnnualPerformance` invalid calculation
  to avoid exception.
- AlgorithmManager will not handle delisting events in live trading
- Fix bug where due to a split driven liquidation matching delisting
  date a position in the option would remain open. Reproduced by
  `BasicTemplateOptionsFrameworkAlgorithm`

* Address review

- Address review add documentation on delisting offset span
2021-01-22 14:41:29 -03:00
Colton Sellers
5d8a62c2e1 Symbol Alias Fix (#5205)
* Fix Symbol Alias

- Fix Symbol Alias being wrong in some cases for futures and options

* Add test cases

* Address review

Co-authored-by: Martin Molinero <martin.molinero1@gmail.com>
2021-01-22 13:00:14 -03:00
Martin-Molinero
5df29f16dd Fix thread safety of Mapfile exchange provider (#5208) 2021-01-21 19:02:50 -08:00
Martin-Molinero
56a0d52212 Allow limiting streaming security Types per job packet (#5206) 2021-01-21 21:23:32 -03:00
Juan José D'Ambrosio
765f2cab3b Add primary exchage to map files (#5194)
* Add main exchange to map file

minimum minimorum test

* Add MainExchange to MapFilRow IEquatable implementation
Also write CSV line correctly

* Normalize exchanges

Also add small test form MapFileRow

* Exchange name normalization

- Exchange name normalization.
- Tick will protobuf `ExchangeCode` which will set existing `Exchange`

* Include single character exchange code

* Encode exchange as byte, Include exchange name as Enum

* Update MapFileRow.cs to accept a byte instead a string for primary exchange

* Fix issues in encoding exchanges map

* Fix broken MapFile tests

* Rename Main Exchange property in MapFileRow

* Use BATS instead of BATSZ

* Add primary exchange from map file

* Move MapFilePrimaryExchangeProvider to its own file

* Implement Char for primary exchange in map files

* Fix broken tests after implementing char exchange into map file

* Add a new constructor for MapFileRow

it  accepts a PrimaryExxchange object as parameter

* Fix broken test 

WIP

* Address review 

WIP

* Handles unexpected encoded exchanges

* Keep addressing review

* Address review

* Fix broken tests

Make PrimaryExchange as default even if the IPrimaryExchangeProvider is not instantiated

* Revert breaking change.

* Add a check that resolved map file actually have content

The issue that leads to this change was caused by a map file resolved to APC in the CoarseFundamentalTop3Algorithm. 
The resolver returns a not-null MapFile, but it is empty.
To my best understand, the MapFile Resolver should return only existing map files in the map_files folder. But the LocalMapFileProvider returned a map file with a permtick that doesn't exist in the file system as CSV.

* Set PrimaryExchange.UNKNOWN as default

* Address review couple minor bugs

- Use SID market instead of USA
- Default ticke exchange is UNKNOWN

* Update map files with latest format and latest info

This include:
 - VXX, it was delisted, then VXXB appears and later it chnages from VXXB -> VXX
 - AAA delisting and a new listing with ticker AAA
 - FOXA ticker changue to TFCFA and later it was delisted

* Update test after updating latest map files

* Fix bug with factor files after updating map files

* Fix bug with factor files after updating map files

and revert statistics in regression tests

* Update OrderHash in regression test

Co-authored-by: Martin Molinero <martin.molinero1@gmail.com>
2021-01-21 18:46:12 -03:00
Martin-Molinero
f175ac6c6b Fix universe selection symbol cache removal (#5193)
- Only remove symbol from cache during universe selection if there is no
  other universe using it. Adding regression test reproducing issue
2021-01-21 15:48:33 -03:00
Gerardo Salazar
79c544d3a2 Reduces output log size and warnings emitted when building with mono's msbuild (#5200) 2021-01-21 11:09:16 -03:00
Aaron Janeiro Stone
5dcbed535d 5052 - Adds missing constructor routing (#5201)
* Adds missing constructor routing

* Minor tweak remove unrequired lines and format

Co-authored-by: Martin Molinero <martin.molinero1@gmail.com>
2021-01-21 10:49:27 -03:00
Gerardo Salazar
35393b66a3 Updates report generator template.crisis.html (#5202) 2021-01-20 18:01:44 -08:00
Karthik Kailash
ce42c888ce Add 2001-12-24 to US equities early closes in market-hours-database.json (#5184) 2021-01-19 13:21:00 -08:00
Colton Sellers
f2fd10d9d2 Build Configuration Hotfix (#5186)
* Reflect properties prior to migration onto projects

* Do not prefer 32bit

* Reinstate SelectedOptimization var
2021-01-19 09:38:16 -03:00
Colton Sellers
94d766ff89 Refactor Default Benchmark (#5158)
* Have BrokerageModel determine default benchmark

* Add DefaultBenchmark to Python wrapper

* Handle Null benchmark case

* Add NullBenchmarkRegressionAlgorithm

* Refactor solution to have BrokerageModel return IBenchmark; also refactor QCAlgorithm benchmark handling

* Always create a new security for benchmark

* Drop security overload, Always create a new security for benchmark

* Check our securities for a symbol matching the ticker before creating a new one

* No Python version of this regression

* Address review

* Create shared SecurityBenchmark creator function

* Add Python regression and needed FuncBenchmark constructor
2021-01-19 08:40:41 -03:00
Martin-Molinero
592d037085 Fix delisted liquidation orders being cancelled (#5169)
* Fix delisted liquidation orders being cancelled

- Place delisted liquidation orders 10 min before market closes of 10
  min before the end of the delisting warning date. Adding regression
  test and unit tests. Updating existing tests.

* Fix failing python option unit tests

* Fix bug where positions would be open delisting liquidation

* Fix universe selection and delisting

- Delisting will happen ASAP for all types. Giving priority to close
  positions on derivates first
- Fix bug in universe selection where OptionChain would remove
  underlying even if holding a position in derivate.
- Updating regression tests statistics

* Add unit test, fix unit test expected stats
2021-01-18 22:02:40 -03:00
Gerardo Salazar
17ab10531a Fixes ETB/shortable regression algorithms that were previously failing (#5174)
* Fixes ETB/shortable regression algorithms that were previously failing

* Addresses review and fixes bug

  * Fixes bug where orders would be denied regardless of direction
    whenever they exceeded the absolute value of the shortable quantity

  * Updates regression algorithm + statistics + simplifies test

  * Fixes python regression algorithm

* Addresses review: removes comments and unneeded imports
2021-01-18 21:19:42 -03:00
Juan José D'Ambrosio
9d576a4121 Update regression tests statistics (#5187)
Those statistic were affected for the new early market close entries in MHBD.
2021-01-18 21:06:26 -03:00
Aaron Janeiro Stone
7aefe07274 4553 - Refactor RenkoConsolidator (#5052)
* Separated Update calls and other non-common RenkoConsolidator.cs artifacts.

* Added type safe init for wicked

* Refactor; moved wicked-specific fields to WickedRenkoConsolidator.cs

* Addresses requested changes (and compacts constructors)

* Separated Update calls and other non-common RenkoConsolidator.cs artifacts.

* Added type safe init for wicked

* Refactor; moved wicked-specific fields to WickedRenkoConsolidator.cs

* Addresses requested changes (and compacts constructors)

* Removes base class for brevity

* Delete BaseRenkoConsolidator.cs

* Fixes naming for classic Renko consolidator

* Addresses review concerns

* Fixes missing null checks and missing typesafe constructor

* Adds warning

* WickedRenkoConsolidator -> RenkoConsolidator calls

* Separated Update calls and other non-common RenkoConsolidator.cs artifacts.

* Added type safe init for wicked

* Refactor; moved wicked-specific fields to WickedRenkoConsolidator.cs

* Addresses requested changes (and compacts constructors)

* Removes base class for brevity

* Fixes naming for classic Renko consolidator

* Separated Update calls and other non-common RenkoConsolidator.cs artifacts.

* Added type safe init for wicked

* Refactor; moved wicked-specific fields to WickedRenkoConsolidator.cs

* Addresses requested changes (and compacts constructors)

* Delete BaseRenkoConsolidator.cs

* Addresses review concerns

* Fixes missing null checks and missing typesafe constructor

* Adds warning

* WickedRenkoConsolidator -> RenkoConsolidator calls

* Addresses review

* unneeded tag removed

* Minor tweaks address reviews

Co-authored-by: Martin Molinero <martin.molinero1@gmail.com>
2021-01-18 15:54:15 -03:00
Karthik Kailash
6de9a146a9 Issue 5149: Added missing early closes for 1999-2008 (#5163)
* Added missing early closes for 1999-2008

See GitHub issue for details

* Fix expected Treynor ratio for backtest in test suite

This backtest runs from 2008-10-10 to 2010-10-10 so it is affected by the early close date now recorded on 2008-12-24.
2021-01-15 11:22:44 -03:00
Gerardo Salazar
4d4ad92fa7 Easy To Borrow Hotfix (#5167) 2021-01-14 15:07:54 -08:00
Jared
345fe7357e Update readme.md 2021-01-14 13:58:26 -08:00
Gerardo Salazar
3e7af17e02 Implements Easy To Borrow Reality Modeling (WIP) (#5159)
* Creates IShortableProvider interface + interface impls

  * This is the foundational work for the addition of the shortable stocks
    feature for backtesting and live trading. Note that the QCAlgorithm
    API and the backend transaction handling will be implemented
    separately.

* temp; work on preorder checks

* improve checks

* tmep

* Enforces ETB checks at BrokerageTransactionHandler

  * Adds ETB Shortable Provider to QCAlgorithm and IAlgorithm
  * Removes ETB check from PreOrderChecksImpl
  * Removes outdated test, new test to come soon for relevant class

* Work in progress commit, pushing for review.

  * Adds new regression algorithm (WIP)
  * Enhances ShortableProviderOrdersRejectedRegressionAlgorithm
  * Adds new methods to QCAlgorithm
  * Move IShortableProvider to have BrokerageModel own it
  * Comments updates
  * Adds new properties to Equity Security for shortable

  * Fixes bug where retrieving open order quantities would aggregate the
    submitted order quantity rather than the remaining order quantity for
    open orders.

  * Fixes bug where quantity of zero would result in a
    false positive in QCAlgorithm.Shortable(...)

  * Code refactoring and comments updates

Co-authored-by: Jared <jaredbroad@gmail.com>
2021-01-14 13:33:44 -08:00
Colton Sellers
a2a874e333 CSProj Update (#5145)
* Migrate to newer CSProj format; build succesful

Rebase onto master

* Maintain binaries directory

* Reinstate FSharp default condition

* Remove reference to packages.config

* Test project fixes

* Remove nuget.config and "Solution Items"

* Remove repetitive assembly info

* Reinstate default compiles and cleanup redundant settings

* Reinstate any specific settings that defaults are unclear for

* Reinstate Framework.nuspec

* Make test internal classes public for composer use; undo assembly change

Rebase onto master part 2

* Address review; restore some settings

* Restore RootNamespace and AssemblyName attributes

* Use NugetPackageRoot instead of NugetPackageFolders

* Reinstate "RestorePackages" setting

* Transfer compilied Python files to launcher and tests bin

* Remove conflicting settings

* Fix WebSocketSharpFork references

* Fix FSharp Core reference

* Upgrade TestPlatform.ObjectModel to 16.8.3, and redirect V11 binding

* Add Mono.Cecil package

* Address review
2021-01-14 12:55:09 -08:00
Juan José D'Ambrosio
96592b3387 Update RTY price multiplier (#5166) 2021-01-14 16:45:24 -03:00
Colton Sellers
7e3741d983 Allow Custom Security Properties and MarketHours (#5100)
* Add interface to allow custom security entries for MHDB and SPD

* Simplify adding custom Properties and MarketHours via AddData overload

* Refactor

* Remove AddData and GetDatabaseSymbolKey overloads

* Add unit tests

* Remove AddData overload, for real.

* Nit changes

* Set CustomDataBitcoinAlgorithm back to original

* Add Python and C# Regression

* nit typo

* nit typo actual

* Reset symbol property to default

* Reflect last change to py regression

* Revert "Remove AddData overload, for real."

This reverts commit dc877495c0.

* Implement AddData solution fully

* Function nit fix

* Address review

* nit - remove param comment

* Address review
2021-01-14 11:34:02 -03:00
Martin-Molinero
e6d16882f7 Remove raw Sleeps for Sleeps+Event (#5153)
- Remove raw Thread.Sleep for Event driven wait/sleeps. Improves startup
  performance significantly
2021-01-12 19:12:07 -03:00
Gerardo Salazar
d5aa9e65f3 Adds FuturesOptionsUnderlyingMapper and FuturesListing (#5142)
* Adds FuturesOptionsUnderlyingMapper

  This adds a mapper for Futures options that have a different
  contract month between the FOP and the underlying future, as is
  observed in the contracts ZB, ZC, ZS, ZT, ZW, HG, SI, GC.
  An example of this is GC (e.g. OGH21 -> GCJ21). Other contracts follow
  different rules, which have been included as part of this commit.

  * Adds unit tests for FuturesOptionsUnderlyingMapper

  * Adds unit and regresssion tests for underlying Futures mapping for FOPs

* Addresses review and adds FuturesListings

  * Removes dependency on IFuturesChainProvider in
    FuturesOptionsUnderlyingMapper

  * Fixes bugs related to FuturesOptionsUnderlyingMapper and incorrect
    results

  * Modifies misc. code to handle new results correctly from FOPs
    underlying mapper

  * Makes FOPs underlying mapper static, and makes other methods private

  * Adds new tests for FuturesListings

* Addresses review: code cleanup

* Address review: Makes arrays to List in FuturesListing private methods
2021-01-12 06:12:00 -08:00
Mathieu Paquette
ec1c4b7142 update IQFeed.CSharpApiClient (#5148)
* update IQFeed.CSharpApiClient

fixes #5147

* Update IQFeed client csproj referece

Co-authored-by: Martin Molinero <martin.molinero1@gmail.com>
2021-01-11 18:11:16 -03:00
Adalyat Nazirov
9a0d943f1d Fill forward data points until delisted date (#4973)
* fill forward data points until expiry date

* wip: test non Delisting

* handle Aux not-Delisting dp; keep order while ff'ing

* simplify test checks

* wip

* fix liquidation expected date

* change statistics

* check EndTime, because it's used for time synchronization

* clean up code; remove duplicated test
2021-01-11 16:45:09 -03:00
Ari Cooperman
771244aaa0 Add order related mappings to resolve type & status IDs in pure python (#5075)
* Add order related mappings to resolve tye & status IDs in pure python

* Update order.py

Co-authored-by: Martin-Molinero <martin@quantconnect.com>
2021-01-11 15:45:51 -03:00
Alexandre Catarino
659a57884c Improves Error Message for Api.Download (#5038)
* Improves Error Message for Api.Download

Catches the exceptios, logs it and returns null.

* Replace Logging for Re-Throwing the Exception
2021-01-11 15:40:46 -03:00
Martin-Molinero
3f2a558f91 Remove pythonNet from stacktrace (#5146)
* Avoid pythonNet  stackTrace in algorithm status

* Handle algorithm initialization exception
2021-01-11 10:28:32 -03:00
Martin-Molinero
9bb7c77fb7 Fix UniverseSelectionAddAndRemove race condition (#5144)
* Fix UniverseSelectionAddAndRemove race condition

- Fix unit test UniverseSelectionAddAndRemove thread race condition

* Avoid boolean flag thread race condition

* Exclude test from travis build
2021-01-08 19:18:58 -03:00
Derek Melchin
c8eb9e0099 Fix MACD WarmUpPeriod and Updating (#5110)
* Fix MACD WarmUpPeriod and Updating

* Add System to use Math library

* Fix WarmUpPeriod math and add tests

* Fix SchaffTrendCycle Indicator WarmUpPeriod

* Ensure fastPeriod < slowPeriod

* Minor tweaks

- Remove unrequired Math.Max operation
- Remove unrequired changes in solution file

Co-authored-by: Martin Molinero <martin.molinero1@gmail.com>
2021-01-08 16:58:53 -03:00
Jovad Uribe
b85a32a391 Bug #5030 Generation of CFD data not working (#5112)
* Update RandomDataGeneratorProgram.cs

Replaced AddMonths(6) with a Datetime value half way between settings.Start and settings.End.

* Update RandomDataGeneratorProgram.cs

* Update to bug-5030-CFDdatanotoworking

* Added midpoint unit test

* Minor test assert improvement

Co-authored-by: Martin Molinero <martin.molinero1@gmail.com>
2021-01-08 11:38:36 -03:00
Martin-Molinero
31d101253c LeanDataReader future/option data (#5117)
* LeanDataReader future option data

- The LeanDataReader will be able to read an entire zip of future and
  option data, currently it's just returning the first entry in the zip
  file. Adding unit tests

* Fix added unit test data path
2021-01-08 11:13:05 -03:00
Aaron Janeiro Stone
7531046f14 Feature 4999 -- Adds RVI (#5041)
* adds RVI

* RVI refactor and tests
TODO: fix ComparesWithExternalDataRviSignal

* Fixed to allow all tests to pass.

* Addresses requested changes

* Addresses requested changes

* Addresses reviewer recommendations
2021-01-08 11:11:00 -03:00
Martin-Molinero
6b99266669 Update IBAutomator increased init timeout (#5139)
- Updating IBAutomator to 1.0.40 which has an increased initialization
  timeout
2021-01-07 19:13:07 -03:00
Adalyat Nazirov
8d48996948 fix covesion to string: decimal are represented using comma decimal separator for non-US English cultures, but expected dot (#5138) 2021-01-07 17:35:51 -03:00
Martin-Molinero
7f381cb135 Universe dispose and removal (#5134)
* Universe dispose and removal

- Fix bug where in some cases the disposed universe would not get removed
from UniverseManager not allowing new universes to get added correctly,
using the same symbol. Adding regression test
- Fix bug where in some cases selected symbols would not get removed
  when the parent universe would get disposed of.
- Minor normalization on UniverseSelection call

* Address review

- Add status plots for the added regression test

* Adding regression algorithm reproducing issue 3914
2021-01-07 12:03:17 -03:00
Riley Shea
2b7372783a Fix column headings in Data/equity/readme.md (#5125)
* Swapped incorrect column heading postions
2021-01-07 11:01:51 -03:00
Adalyat Nazirov
54fce3f666 FillForward enumerator does not loop infinitely if fillforward resolution is different from data resolution (#5118)
* change filename template. add fillforward resolution suffix

* replicate GH issue 5116 on master

it's easy to reproduce on FXCM market by using data resolution different from fillforward resolution.
in this cases daily vs hour/minute were added

* change priorities of Time & EndTime values.

it's necessary to calculate EndTime  properly, and then we can align Time to it.
potential end time should be also calculated using ptoper TZ. Because of we store open hours without TZ movement TZ in market-hours it's necessary to reapply TZ

fix tests

* Miss 2AM bar on Sunday of DST; FF 2AM bar on Sunday ST

* use UTC TimeZone as baseline during comparison
2021-01-06 20:18:08 -03:00
Colton Sellers
12db2261dc Allow Saving of Octet Stream in API (#5130)
* Allow downloading of octet stream

* Refactor solution

* Match lowercase ContentType
2021-01-06 19:46:09 -03:00
Alexandre Catarino
c6d4888e70 Refactors Market Fill of Equity Fill Model (#5114)
* Refactors Market Fill Model

Create `GetBidPrice` and `GetAskPrice` methods to request the most suitable price to fill market orders.

Fix unit tests to show that new implementation prevents using non-market data to fill the order.

* Addresses Peer Review …

Modifies EquityTickQuoteAdjustedModeRegressionAlgorithm to reflect changes in the market fill method. The previous implementation only looks for the last tick when it should look for the last tick of quote type, so current implementation is an improvement.
2021-01-06 12:35:33 -03:00
Martin-Molinero
33b58b0dbc Fixes for IB malformed symbols (#5127)
* Fixes for IB malformed symbols

- Add handling for IB future malformed symbols. Adding unit test
- Fix IB option malformed symbols which had more whitespaces than
  expected. Adding unit test

* Address review
2021-01-06 11:59:22 -03:00
Martin-Molinero
56cb9fbec5 IB will wait for connection response (#5124)
- IB.Connect() will wait for connection response before starting reader
2021-01-05 19:44:04 -03:00
Jared
194e6f6b58 Update benchmark algorithm to include disabling (#5115)
* Update benchmark algorithm to include disabling

* Update C# benchmark example algo

Co-authored-by: Martin Molinero <martin.molinero1@gmail.com>
2021-01-04 18:11:18 -03:00
Martin-Molinero
612c4f8b66 Fix BTC future price multiplier (#5113) 2021-01-04 15:44:38 -03:00
Martin-Molinero
d3b9f8bc7a Protobuf OpenInterest (#5107)
- Add OpenInterest protobuf support. Adding unit test
- Use composer for future and option chain provider
2021-01-04 10:40:35 -03:00
Gerardo Salazar
c4a1c245a7 Adds data parsing for malformed option contracts for InteractiveBrokers (#5101)
* Adds data parsing for malformed option contracts in IBBrokerage

  * Some contracts come in malformed from IB when downloading our
    account holdings. We attempt to detect whenever this happens with
    our options Symbols and try to recover the contract.

* Addresses review and fixes bug

  * Uses contract currency for the new contract created from the
    malformed contract.

  * Bug fix: Sets ibSymbol to new Symbol of the contract once the
    malformed contract has been parsed.

  * Adds support for Futures and FOPs

  * Refactoring code and cleanup

* Addresses review: code cleanup and refactoring

* Addresses review: remove redundant logging of contract in log statement
2020-12-30 16:28:33 -08:00
Martin-Molinero
050dadc21f Increase low resolution cache size (#5105)
- Increasing low resolution cache size so it can hold QC500
2020-12-30 20:59:36 -03:00
Colton Sellers
7b0ea0982e Update ExpectedStatistics (#5094) 2020-12-29 12:04:36 -03:00
Adalyat Nazirov
f8cf923d7b upload SHY quote bars (#5097) 2020-12-29 11:58:13 -03:00
Colton Sellers
14b44bbe17 Reduce Travis Logs v2 (#5049)
* Silence DotNet in building stubs

* Reapply silence to stub publishing

* Have QuantBook store and restore initial LogHandler

* Add assembly action to maintain LogHandler

* Allow AlgorithmRunner to use ConsoleLogHandler

* Use MaintainLogHandlerAttribute to provide current test logger

* Refactor LogHandler creation
2020-12-28 21:10:21 -03:00
Colton Sellers
2ed221b623 Linux PyCharm Docker Debugger Fix (#5092)
* Map host.docker.internal to host ip

* Typo fix

* Only add host in Linux environment
2020-12-28 21:08:34 -03:00
Gerardo Salazar
3f1c33e1c5 Fixes DockerfileLeanFoundation build and adds/updates new packages (#5036)
* Fixes DockerfileLeanFoundation build

  * Updates DockerfileLeanFoundation packages and adds new packages
  * apt-get performance improvements

* Moves packages to CDN and install packages from CDN

  * Updates all CDN downloads to HTTPS

* Removes interactive `rm` command arg in DockerfileLeanFoundation cleanup
2020-12-28 18:22:15 -03:00
5632 changed files with 711107 additions and 398219 deletions

8
.devcontainer/Dockerfile Normal file
View File

@@ -0,0 +1,8 @@
# Use QuantConnect Research as the base
FROM quantconnect/research:latest
# Install dos2unix utility for converting pesky windows formatting when needed
RUN apt-get update && apt-get install -y dos2unix
# Install QuantConnect Stubs for Python Autocomplete
RUN pip install --no-cache-dir quantconnect-stubs

View File

@@ -0,0 +1,34 @@
{
"name": "Lean Development Container",
"workspaceMount": "source=${localWorkspaceFolder},target=/Lean,type=bind",
"workspaceFolder": "/Lean",
// Use devcontainer Dockerfile that is based on Lean foundation image
"build": { "dockerfile": "Dockerfile" },
// Set *default* container specific settings.json values on container create.
"settings": {
"terminal.integrated.profiles.linux": {
"bash": {
"path": "bash",
"icon": "terminal-bash"
}
}
},
// Add the IDs of extensions you want installed when the container is created.
"extensions": ["ms-dotnettools.csharp", "ms-python.python", "ms-python.vscode-pylance", "formulahendry.dotnet-test-explorer", "eamodio.gitlens", "yzhang.markdown-all-in-one"],
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],
// Uncomment the next line to run commands after the container is created - for example installing curl.
"postCreateCommand": "dotnet nuget add source /Lean/LocalPackages;chmod u+x /Lean/.vscode/launch_research.sh;dos2unix /Lean/.vscode/launch_research.sh",
// Add mounts to docker container
"mounts": [
// Example data mount from local machine, must use target directory in Config.json
// "source=C:/Users/XXXXXXXXXXXX/Lean/Data,target=/Data,type=bind,consistency=cached"
]
}

13
.editorconfig Normal file
View File

@@ -0,0 +1,13 @@
root = true
[*]
charset = utf-8
indent_size = 4
indent_style = space
insert_final_newline = true
[*.{js,yml,json,config,csproj}]
indent_size = 2
[*.sh]
end_of_line = lf

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 /usr/share/dotnet && sudo rm -rf /usr/local/lib/android && sudo rm -rf /opt/ghc && 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|ObjectStoreTests" -- TestRunParameters.Parameter\(name=\"log-handler\", value=\"ConsoleErrorLogHandler\"\)

39
.github/workflows/benchmarks.yml vendored Normal file
View File

@@ -0,0 +1,39 @@
name: Benchmarks
on:
push:
branches: ['*']
tags: ['*']
pull_request:
branches: [master]
jobs:
build:
runs-on: self-hosted
container:
image: quantconnect/lean:foundation
volumes:
- /nas:/Data
steps:
- uses: actions/checkout@v2
- name: Checkout Lean Master
uses: actions/checkout@v2
with:
repository: QuantConnect/Lean
path: LeanMaster
ref: 'master'
- name: Build Lean Master
run: dotnet build --verbosity q /p:Configuration=Release /p:WarningLevel=1 LeanMaster/QuantConnect.Lean.sln
- name: Run Benchmarks Master
run: cp run_benchmarks.py LeanMaster/run_benchmarks.py && cd LeanMaster && python run_benchmarks.py /Data && cd ../
- name: Build
run: dotnet build --verbosity q /p:Configuration=Release /p:WarningLevel=1 QuantConnect.Lean.sln
- name: Run Benchmarks
run: python run_benchmarks.py /Data
- name: Compare Benchmarks
run: python compare_benchmarks.py LeanMaster/benchmark_results.json benchmark_results.json

30
.github/workflows/gh-actions.yml vendored Normal file
View File

@@ -0,0 +1,30 @@
name: Build & Test Lean
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 /usr/share/dotnet && sudo rm -rf /usr/local/lib/android && sudo rm -rf /opt/ghc && 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 -e GITHUB_REF=${{ github.ref }} -e PYPI_API_TOKEN=${{ secrets.PYPI_API_TOKEN }} -e ADDITIONAL_STUBS_REPOS=${{ secrets.ADDITIONAL_STUBS_REPOS }} -e QC_GIT_TOKEN=${{ secrets.QC_GIT_TOKEN }}
shell: bash
run: |
# Build
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\"\) && \
# Generate & Publish python stubs
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

View File

@@ -0,0 +1,21 @@
name: Rebase Organization Branches
on:
push:
branches:
- 'master'
jobs:
build:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Rebase Organization Branches
run: |
chmod +x rebase_organization_branches.sh
./rebase_organization_branches.sh
env:
QC_GIT_TOKEN: ${{ secrets.QC_GIT_TOKEN }}

28
.github/workflows/regression-tests.yml vendored Normal file
View File

@@ -0,0 +1,28 @@
name: Regression 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 /usr/share/dotnet && sudo rm -rf /usr/local/lib/android && sudo rm -rf /opt/ghc && 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 Tests
dotnet test ./Tests/bin/Release/QuantConnect.Tests.dll --filter TestCategory=RegressionTests -- TestRunParameters.Parameter\(name=\"log-handler\", value=\"ConsoleErrorLogHandler\"\) TestRunParameters.Parameter\(name=\"reduced-disk-size\", value=\"true\"\)

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 /usr/share/dotnet && sudo rm -rf /usr/local/lib/android && sudo rm -rf /opt/ghc && 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

@@ -0,0 +1,36 @@
name: Research Regression 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 /usr/share/dotnet && sudo rm -rf /usr/local/lib/android && sudo rm -rf /opt/ghc && 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: |
# install dependencies
pip3 install papermill==2.4.0 clr-loader==0.1.6
# install kernel
dotnet tool install --global Microsoft.dotnet-interactive --version 1.0.340501
# Add dotnet tools to Path
export PATH="$HOME/.dotnet/tools:$PATH"
# activate kernel for jupyter
dotnet interactive jupyter install
# Build
dotnet build /p:Configuration=Release /v:quiet /p:WarningLevel=1 QuantConnect.Lean.sln
# Run Tests
dotnet test ./Tests/bin/Release/QuantConnect.Tests.dll --filter TestCategory=ResearchRegressionTests -- TestRunParameters.Parameter\(name=\"log-handler\", value=\"ConsoleErrorLogHandler\"\) TestRunParameters.Parameter\(name=\"reduced-disk-size\", value=\"true\"\)

View File

@@ -0,0 +1,57 @@
name: Python Virtual Environments
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 /usr/share/dotnet && sudo rm -rf /usr/local/lib/android && sudo rm -rf /opt/ghc && 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 && \
# Python Virtual Environment System Packages
python -m venv /lean-testenv --system-site-packages && . /lean-testenv/bin/activate && pip install --no-cache-dir lean==1.0.185 && deactivate && \
# Run Virtual Environment Test System Packages
dotnet test ./Tests/bin/Release/QuantConnect.Tests.dll --filter "FullyQualifiedName=QuantConnect.Tests.Python.PythonVirtualEnvironmentTests.AssertVirtualEnvironment" && \
# Python Virtual Environment
rm -rf /lean-testenv && python -m venv /lean-testenv && . /lean-testenv/bin/activate && pip install --no-cache-dir lean==1.0.185 && deactivate && \
# Run Virtual Environment Test
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 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 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
dotnet test ./Tests/bin/Release/QuantConnect.Tests.dll --filter "FullyQualifiedName=QuantConnect.Tests.Python.PythonPackagesTests.NeuralTangentsTest|IgniteTest" --blame-hang-timeout 120seconds --blame-crash && \
# Run TensorflowTest
dotnet test ./Tests/bin/Release/QuantConnect.Tests.dll --filter "FullyQualifiedName=QuantConnect.Tests.Python.PythonPackagesTests.TensorflowTest" --blame-hang-timeout 120seconds --blame-crash && \
# Run TensorflowProbability
dotnet test ./Tests/bin/Release/QuantConnect.Tests.dll --filter "FullyQualifiedName=QuantConnect.Tests.Python.PythonPackagesTests.TensorflowProbabilityTest" --blame-hang-timeout 120seconds --blame-crash && \
# Run Hvplot Python Package Test
dotnet test ./Tests/bin/Release/QuantConnect.Tests.dll --filter "FullyQualifiedName=QuantConnect.Tests.Python.PythonPackagesTests.HvplotTest" --blame-hang-timeout 120seconds --blame-crash && \
# Run Keras Python Package Test
dotnet test ./Tests/bin/Release/QuantConnect.Tests.dll --filter "FullyQualifiedName=QuantConnect.Tests.Python.PythonPackagesTests.KerasTest" --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.XTransformers" --blame-hang-timeout 120seconds --blame-crash && \
# Run Shap
dotnet test ./Tests/bin/Release/QuantConnect.Tests.dll --filter "FullyQualifiedName=QuantConnect.Tests.Python.PythonPackagesTests.ShapTest" --blame-hang-timeout 120seconds --blame-crash

5
.gitignore vendored
View File

@@ -1,3 +1,6 @@
# OS Files
.DS_Store
# Object files
*.o
*.ko
@@ -196,6 +199,7 @@ publish/
# NuGet Packages
*.nupkg
!LocalPackages/*
# The packages folder can be ignored because of Package Restore
**/packages/*
# except build/, which is used as an MSBuild target.
@@ -204,6 +208,7 @@ publish/
#!**/packages/repositories.config
# ignore sln level nuget
.nuget/
!.nuget/NuGet.config
# Windows Azure Build Output
csx/

144
.idea/readme.md generated
View File

@@ -1,144 +0,0 @@
<h1>Local Development & Docker Integration with Pycharm</h1>
This document contains information regarding ways to use Leans Docker image in conjunction with local development in Pycharm.
<br />
<h1>Getting Setup</h1>
Before anything we need to ensure a few things have been done:
1. Get [Pycharm Professional](https://www.jetbrains.com/pycharm/)**
2. Get [Docker](https://docs.docker.com/get-docker/):
* Follow the instructions for your Operating System
* New to Docker? Try docker getting-started
3. Pull Leans latest image from a terminal
* _docker pull quantconnect/lean_
4. Get Lean into Pycharm
* Download the repo or clone it using: _git clone[ https://github.com/QuantConnect/Lean](https://github.com/QuantConnect/Lean)_
* Open the folder using Pycharm
_**PyCharms remote debugger requires PyCharm Professional._
<br />
<h1>Develop Algorithms Locally, Run in Container</h1>
We have set up a relatively easy way to develop algorithms in your local IDE and push them into the container to be run and debugged.
Before we can use this method with Windows or Mac OS we need to share the Lean directory with Docker.
<br />
<h2>Activate File Sharing for Docker:</h2>
* Windows:
* [Guide to sharing](https://docs.docker.com/docker-for-windows/#file-sharing)
* Share the LEAN root directory with docker
* Mac:
* [Guide to sharing](https://docs.docker.com/docker-for-mac/#file-sharing)
* Share the LEAN root directory with docker
* Linux:
* (No setup required)
<br />
<h2>Lean Configuration</h2>
Next we need to be sure that our Lean configuration at **.\Launcher\config.json** is properly set. Just like running lean locally the config must reflect what we want Lean to run.
You configuration file should look something like this:
<h3>Python:</h3>
"algorithm-type-name": "**AlgorithmName**",
"algorithm-language": "Python",
"algorithm-location": "../../../Algorithm.Python/**AlgorithmName**.py",
<h4>Note About Python Algorithm Location</h4>
Our specific configuration binds the Algorithm.Python directory to the container by default so any algorithm you would like to run should be in that directory. Please ensure your algorithm location looks just the same as the example above. If you want to use a different location refer to the section bellow on setting that argument for the container and make sure your config.json also reflects this.
<br />
<h2>Running Lean in the Container</h2>
This section will cover how to actually launch Lean in the container with your desired configuration.
From a terminal; Pycharm has a built in terminal on the bottom taskbar labeled **Terminal**; launch the run_docker.bat/.sh script; there are a few choices on how to launch this:
1. Launch with no parameters and answer the questions regarding configuration (Press enter for defaults)
*   Enter docker image [default: quantconnect/lean:latest]:
*   Enter absolute path to Lean config file [default: _~currentDir_\Launcher\config.json]:
*   Enter absolute path to Data folder [default: ~_currentDir_\Data\]:
*   Enter absolute path to store results [default: ~_currentDir_\]:
* Would you like to debug C#? (Requires mono debugger attachment) [default: N]:
2. Using the **run_docker.cfg** to store args for repeated use; any blank entries will resort to default values! example: **_./run_docker.bat run_docker.cfg_**
IMAGE=quantconnect/lean:latest
CONFIG_FILE=
DATA_DIR=
RESULTS_DIR=
DEBUGGING=
PYTHON_DIR=
3. Inline arguments; anything you don't enter will use the default args! example: **_./run_docker.bat DEBUGGING=y_**
* Accepted args for inline include all listed in the file in #2; must follow the **key=value** format
<br />
<h1>Debugging Python</h1>
Debugging your Python algorithms requires an extra step within your configuration and inside of PyCharm. Thankfully we were able to configure the PyCharm launch configurations to take care of most of the work for you!
<br />
<h2>Modifying the Configuration</h2>
First in order to debug a Python algorithm in Pycharm we must make the following change to our configuration (Launcher\config.json) under the comment debugging configuration:
"debugging": true,
"debugging-method": "PyCharm",
In setting this we are telling Lean to reach out and create a debugger connection using PyCharms PyDevd debugger server. Once this is set Lean will **always** attempt to connect to a debugger server on launch. **If you are no longer debugging set “debugging” to false.**
<br />
<h2>Using PyCharm Launch Options</h2>
Now that Lean is configured for the debugger we can make use of the programmed launch options to connect.
**<h3>Container (Recommended)</h3>**
To debug inside of the container we must first start the debugger server in Pycharm, to do this use the drop down configuration “Debug in Container” and launch the debugger. Be sure to set some breakpoints in your algorithms!
Then we will need to launch the container, follow the steps described in the section “[Running Lean in the Container](#Running-Lean-in-the-Container)”. After launching the container the debugging configuration will take effect and it will connect to the debug server where you can begin debugging your algorithm.
**<h3>Local</h3>**
To debug locally we must run the program locally. First, just as the container setup, start the PyCharm debugger server by running the “Debug Local” configuration.
Then start the program locally by whatever means you typically use, such as Mono, directly running the program at **QuantConnect.Lean.Launcher.exe**, etc. Once the program is running it will make the connection to your PyCharm debugger server where you can begin debugging your algorithm.

37
.idea/workspace.xml generated
View File

@@ -1,37 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RunManager" selected="Python Debug Server.Debug in Container">
<configuration name="Debug Local" type="PyRemoteDebugConfigurationType" factoryName="Python Remote Debug">
<module name="LEAN" />
<option name="PORT" value="6000" />
<option name="HOST" value="localhost" />
<PathMappingSettings>
<option name="pathMappings">
<list />
</option>
</PathMappingSettings>
<option name="REDIRECT_OUTPUT" value="true" />
<option name="SUSPEND_AFTER_CONNECT" value="true" />
<method v="2" />
</configuration>
<configuration name="Debug in Container" type="PyRemoteDebugConfigurationType" factoryName="Python Remote Debug">
<module name="LEAN" />
<option name="PORT" value="6000" />
<option name="HOST" value="localhost" />
<PathMappingSettings>
<option name="pathMappings">
<list>
<mapping local-root="$PROJECT_DIR$" remote-root="/Lean" />
</list>
</option>
</PathMappingSettings>
<option name="REDIRECT_OUTPUT" value="true" />
<option name="SUSPEND_AFTER_CONNECT" value="true" />
<method v="2" />
</configuration>
<list>
<item itemvalue="Python Debug Server.Debug Local" />
<item itemvalue="Python Debug Server.Debug in Container" />
</list>
</component>
</project>

10
.nuget/NuGet.config Normal file
View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageRestore>
<add key="enabled" value="true" />
<add key="automatic" value="true" />
</packageRestore>
<packageSources>
<add key="LocalPackages" value="../LocalPackages" />
</packageSources>
</configuration>

View File

@@ -1,10 +1,11 @@
sudo: required
language: csharp
mono:
- 5.12.0
solution: QuantConnect.Lean.sln
mono: none
dotnet: 5.0
os: linux
dist: focal
before_install:
- export PATH="$HOME/miniconda3/bin:$PATH"
- export PYTHONNET_PYDLL="$HOME/miniconda3/lib/libpython3.6m.so"
- wget -q https://cdn.quantconnect.com/miniconda/Miniconda3-4.5.12-Linux-x86_64.sh
- bash Miniconda3-4.5.12-Linux-x86_64.sh -b
- rm -rf Miniconda3-4.5.12-Linux-x86_64.sh
@@ -16,11 +17,7 @@ before_install:
- conda install -y cython=0.29.15
- conda install -y scipy=1.4.1
- conda install -y wrapt=1.12.1
install:
- nuget restore QuantConnect.Lean.sln -v quiet
- nuget install NUnit.Runners -Version 3.11.1 -OutputDirectory testrunner
script:
- msbuild /p:Configuration=Release /p:VbcToolExe=vbnc.exe /v:quiet /p:WarningLevel=1 QuantConnect.Lean.sln
- mono ./testrunner/NUnit.ConsoleRunner.3.11.1/tools/nunit3-console.exe ./Tests/bin/Release/QuantConnect.Tests.dll --where "cat != TravisExclude" --labels=Off --params:log-handler=ConsoleErrorLogHandler
- chmod +x ci_build_stubs.sh
- sudo -E ./ci_build_stubs.sh -d -t -g -p
- dotnet nuget add source $TRAVIS_BUILD_DIR/LocalPackages
- dotnet build /p:Configuration=Release /v:quiet /p:WarningLevel=1 QuantConnect.Lean.sln
- dotnet test ./Tests/bin/Release/QuantConnect.Tests.dll --filter TestCategory!=TravisExclude -- TestRunParameters.Parameter\(name=\"log-handler\", value=\"ConsoleErrorLogHandler\"\)

View File

@@ -1,64 +1,49 @@
<h1>Local Development & Docker Integration with Visual Studio</h1>
<h1>Local Development with Visual Studio</h1>
This document contains information regarding ways to use Visual Studio to work with the Lean engine, this includes a couple options that make lean easy to develop on any machine:
This document contains information regarding ways to use Visual Studio to work with the Lean's Docker image.
- Using Lean CLI -> A great tool for working with your algorithms locally, while still being able to deploy to the cloud and have access to Lean data. It is also able to run algorithms locally through our official docker images **Recommended for algorithm development.
- Locally installing all dependencies to run Lean with Visual Studio on your OS.
<br />
<h1>Getting Setup</h1>
<h1>Setup</h1>
<h2>Option 1: Lean CLI</h2>
Before anything we need to ensure a few things have been done:
1. Get [Visual Studio](https://code.visualstudio.com/download)
* Get the Extension [VSMonoDebugger](https://marketplace.visualstudio.com/items?itemName=GordianDotNet.VSMonoDebugger0d62) for C# Debugging
2. Get [Docker](https://docs.docker.com/get-docker/):
* Follow the instructions for your Operating System
* New to Docker? Try docker getting-started
3. Pull Leans latest image from a terminal
* _docker pull quantconnect/lean_
4. Get Lean into Visual Studio
* Download the repo or clone it using: _git clone[ https://github.com/QuantConnect/Lean](https://github.com/QuantConnect/Lean)_
* Open the solution **QuantConnect.Lean.sln** using Visual Studio
To use Lean CLI follow the instructions for installation and tutorial for usage in our [documentation](https://www.quantconnect.com/docs/v2/lean-cli/getting-started/lean-cli).
<br />
<h1>Develop Algorithms Locally, Run in Container</h1>
<h2>Option 2: Install Locally</h2>
1. Install [.Net 6](https://dotnet.microsoft.com/download) for the project
We have set up a relatively easy way to develop algorithms in your local IDE and push them into the container to be run and debugged.
2. (Optional) Get [Python 3.8.13](https://www.python.org/downloads/release/python-3813/) for running Python algorithms
- Follow Python instructions [here](https://github.com/QuantConnect/Lean/tree/master/Algorithm.Python#installing-python-38) for your platform
Before we can use this method with Windows or Mac OS we need to share the Lean directory with Docker.
3. Get [Visual Studio](https://visualstudio.microsoft.com/vs/)
4. Get Lean into VS
- Download the repo or clone it using: _git clone [https://github.com/QuantConnect/Lean](https://github.com/QuantConnect/Lean)_
- Open the project file with VS (QuantConnect.Lean.sln)
Your environment is prepared and ready to run lean
<br />
<h2>Activate File Sharing for Docker:</h2>
<h1>How to use Lean</h1>
* Windows:
* [Guide to sharing](https://docs.docker.com/docker-for-windows/#file-sharing)
* Share the LEAN root directory with docker
* Mac:
* [Guide to sharing](https://docs.docker.com/docker-for-mac/#file-sharing)
* Share the LEAN root directory with docker
* Linux:
* (No setup required)
This section will cover configuring, launching and debugging lean. This is only applicable to option 2 from above. This does not apply to Lean CLI, please refer to [CLI documentation](https://www.quantconnect.com/docs/v2/lean-cli/getting-started/lean-cli)
<br />
<h2>Lean Configuration</h2>
<h2>Configuration</h2>
Next we need to be sure that our Lean configuration at **.\Launcher\config.json** is properly set. Just like running lean locally the config must reflect what we want Lean to run.
We need to be sure that our Lean configuration at **.\Launcher\config.json** is properly set.
You configuration file should look something like this for the following languages:
Your configuration file should look something like this for the following languages:
<h3>Python:</h3>
@@ -78,59 +63,11 @@ You configuration file should look something like this for the following languag
<br />
<h2>Important Note About C#</h2>
<h2>Launching Lean</h2>
In order to use a custom C# algorithm, the C# file must be compiled before running in the docker, as it is compiled into the file **"QuantConnect.Algorithm.CSharp.dll"**. Any new C# files will need to be added to the csproj compile list before it will compile, check **Algorithm.CSharp/QuantConnect.Algorithm.CSharp.csproj** for all algorithms that are compiled. Once there is an entry for your algorithm the project can be compiled by using **Build > Build Solution**.
If you would like to debug this file in the docker container one small change to the solutions target build is required.
1. Right click on the solution **QuantConnect.Lean** in the _Solution Explorer_
2. Select **Properties**
3. For project entry **QuantConnect.Algorithm.CSharp** change the configuration to **DebugDocker**
4. Select **Apply** and close out of the window.
5. Build the project at least once before running the docker.
Now that lean is configured we can launch. Use Visual Studio's run option, Make sure QuantConnect.Lean.Launcher is selected as the launch project. Any breakpoints in Lean C# will be triggered.
<br />
<h2>Running Lean in the Container</h2>
This section will cover how to actually launch Lean in the container with your desired configuration.
From a terminal launch the run_docker.bat/.sh script; there are a few choices on how to launch this:
1. Launch with no parameters and answer the questions regarding configuration (Press enter for defaults)
*   Enter docker image [default: quantconnect/lean:latest]:
*   Enter absolute path to Lean config file [default: _~currentDir_\Launcher\config.json]:
*   Enter absolute path to Data folder [default: ~_currentDir_\Data\]:
*   Enter absolute path to store results [default: ~_currentDir_\]:
* Would you like to debug C#? (Requires mono debugger attachment) [default: N]:
2. Using the **run_docker.cfg** to store args for repeated use; any blank entries will resort to default values! example: **_./run_docker.bat run_docker.cfg_**
IMAGE=quantconnect/lean:latest
CONFIG_FILE=
DATA_DIR=
RESULTS_DIR=
DEBUGGING=
PYTHON_DIR=
3. Inline arguments; anything you don't enter will use the default args! example: **_./run_docker.bat DEBUGGING=y_**
* Accepted args for inline include all listed in the file in #2
<br />
<h1>Connecting to Mono Debugger</h1>
If you launch the script with debugging set to **yes** (y), then you will need to connect to the debugging server with the mono extension that you installed in the setup stage.
To setup the extension do the following:
* Go to **Extensions > Mono > Settings...**
* Enter the following for the settings:
* Remote Host IP: 127.0.0.1
* Remote Host Port: 55555
* Mono Debug Port: 55555
* Click **Save** and then close the extension settings
Now that the extension is setup use it to connect to the Docker container by using:
* **Extensions > Mono > Attach to mono debugger**
The program should then launch and trigger any breakpoints you have set in your C# Algorithm.
<h1>Common Issues</h1>
Here we will cover some common issues with setting this up. Feel free to contribute to this section!

77
.vscode/launch.json vendored
View File

@@ -2,74 +2,39 @@
/*
VS Code Launch configurations for the LEAN engine
Launch w/ Mono (Local):
Builds the project with MSBuild and then launches the program using mono locally;
supports debugging. In order to use this you need msbuild and mono on your system path.
As well as the Mono Debug extension from the marketplace.
Debug in Container:
Launches our run_docker script to start the container and attaches to the debugger.
Requires that you have built the project at least once as it will transfer the compiled
csharp files.
Requires Mono Debug extension from the marketplace.
Attach to Python (Container):
Will attempt to attach to LEAN in the container using PTVSD. Requires that the container is
actively running and config is set: "debugging": true, "debugging-method": "PTVSD",
Requires Python extension from the marketplace.
Attach to Python (Local):
Will attempt to attach to LEAN running locally using PTVSD. Requires that the process is
actively running and config is set: "debugging": true, "debugging-method": "PTVSD",
Requires Python extension from the marketplace.
Launch:
Builds the project with dotnet 6 and then launches the program using coreclr; supports debugging.
In order to use this you need dotnet 6 on your system path, As well as the C# extension from the
marketplace.
Attach to Python:
Will attempt to attach to LEAN running locally using DebugPy. Requires that the process is
actively running and config is set: "debugging": true, "debugging-method": "DebugPy",
Requires Python extension from the marketplace. Currently only works with algorithms in
Algorithm.Python directory. This is because we map that directory to our build directory
that contains the py file at runtime. If using another location change "localRoot" value
to the directory in use.
*/
"version": "0.2.0",
"configurations": [
{
"name": "Launch w/ Mono (Local)",
"type": "mono",
"name": "Launch",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"cwd": "${workspaceFolder}/Launcher/bin/Debug/",
"program": "${workspaceFolder}/Launcher/bin/Debug/QuantConnect.Lean.Launcher.exe",
"program": "${workspaceFolder}/Launcher/bin/Debug/QuantConnect.Lean.Launcher.dll",
"args": [
"--data-folder",
"${workspaceFolder}/Data",
"--config",
"${workspaceFolder}/Launcher/config.json"],
"console": "externalTerminal"
"${workspaceFolder}/Launcher/bin/Debug/config.json"
],
"cwd": "${workspaceFolder}/Launcher/bin/Debug/",
"stopAtEntry": false,
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
},
{
"name": "Debug in Container",
"type": "mono",
"preLaunchTask": "run-docker",
"postDebugTask": "close-docker",
"request": "attach",
"address": "localhost",
"port": 55555
},
{
"name": "Attach to Mono",
"type": "mono",
"request": "attach",
"address": "localhost",
"postDebugTask": "close-docker",
"port": 55555
},
{
"name": "Attach to Python (Container)",
"type": "python",
"request": "attach",
"port": 5678,
"pathMappings":[{
"localRoot": "${workspaceFolder}",
"remoteRoot": "/Lean/"
}]
},
{
"name": "Attach to Python (Local)",
"name": "Attach to Python",
"type": "python",
"request": "attach",
"port": 5678,

15
.vscode/launch_research.sh vendored Normal file
View File

@@ -0,0 +1,15 @@
# Realpath polyfill, notably absent macOS and some debian distros
absolute_path() {
echo "$(cd "$(dirname "${1}")" && pwd)/$(basename "${1}")"
}
# Get build directory from args position 1, or use default
DEFAULT_BUILD_DIR=../Launcher/bin/Debug/
BUILD_DIR=${1:-$DEFAULT_BUILD_DIR}
BUILD_DIR=$(absolute_path "${BUILD_DIR}")
#Add our build directory to python path for python kernel
export PYTHONPATH="${PYTHONPATH}:${BUILD_DIR}"
# Launch jupyter-lab
jupyter-lab --allow-root --no-browser --notebook-dir=$BUILD_DIR --LabApp.token=''

188
.vscode/readme.md vendored
View File

@@ -1,73 +1,84 @@
<h1>Local Development & Docker Integration with Visual Studio Code</h1>
This document contains information regarding ways to use Visual Studio Code to work with the Lean engine, this includes a couple options that make lean easy to develop on any machine:
This document contains information regarding ways to use Visual Studio Code to work with the Lean engine, this includes using Leans Docker image in conjunction with local development as well as running Lean locally.
- Using Lean CLI -> A great tool for working with your algorithms locally, while still being able to deploy to the cloud and have access to Lean data. It is also able to run algorithms locally through our official docker images **Recommended for algorithm development.
- Using a Lean Dev container -> A docker environment with all dependencies pre-installed to allow seamless Lean development across platforms. Great for open source contributors.
- Locally installing all dependencies to run Lean with Visual Studio Code on your OS.
<br />
<h1>Getting Setup</h1>
<h1>Setup</h1>
<h2>Option 1: Lean CLI</h2>
Before anything we need to ensure a few things have been done:
To use Lean CLI follow the instructions for installation and tutorial for usage in our [documentation](https://www.quantconnect.com/docs/v2/lean-cli/key-concepts/getting-started)
<br />
<h2>Option 2: Lean Development Container</h2>
Before anything we need to ensure a few things have been done for either option:
1. Get [Visual Studio Code](https://code.visualstudio.com/download)
* Get the Extension [Mono Debug **15.8**](https://marketplace.visualstudio.com/items?itemName=ms-vscode.mono-debug) for C# Debugging
* Get the Extension [Python](https://marketplace.visualstudio.com/items?itemName=ms-python.python) for Python Debugging
- Get [Remote Containers](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) Extension
2. Get [Docker](https://docs.docker.com/get-docker/):
* Follow the instructions for your Operating System
* New to Docker? Try docker getting-started
- Follow the instructions for your Operating System
- New to Docker? Try [docker getting-started](https://docs.docker.com/get-started/)
3. Install a compiler for the project **(Only needed for C# Debugging or Running Locally)**
* On Linux or Mac:
* Install [mono-complete](https://www.mono-project.com/docs/getting-started/install/linux/)
* Test msbuild with command: _msbuild -version_
* On Windows:
* Visual Studio comes packed with msbuild or download without VS [here](https://visualstudio.microsoft.com/downloads/?q=build+tools)
* Put msbuild on your system path and test with command: _msbuild -version_
3. Pull Leans latest research image from a terminal
- `docker pull quantconnect/research:latest`
4. Pull Leans latest image from a terminal
* _docker pull quantconnect/lean_
4. Get Lean into VS Code
- Download the repo or clone it using: `git clone [https://github.com/QuantConnect/Lean](https://github.com/QuantConnect/Lean)`
- Open the folder using VS Code
5. Get Lean into VS Code
* Download the repo or clone it using: _git clone[ https://github.com/QuantConnect/Lean](https://github.com/QuantConnect/Lean)_
* Open the folder using VS Code
5. Open Development Container
- In VS Code, either:
- Select "Reopen in Container" from pop up box.
**NOTES**:
- Mono Extension Version 16 and greater fails to debug the docker container remotely, please install **Version 15.8**. To install an older version from within VS Code go to the extensions tab, search "Mono Debug", and select "Install Another Version...".
<br />
OR
<h1>Develop Algorithms Locally, Run in Container</h1>
- Ctrl+Shift+P (Command Palette) and select "Remote-Containers: Rebuild and Reopen in Container"
We have set up a relatively easy way to develop algorithms in your local IDE and push them into the container to be run and debugged.
Before we can use this method with Windows or Mac OS we need to share the Lean directory with Docker.
You should now be in the development container, give VS Code a moment to prepare and you will be ready to go!
If you would like to mount any additional local files to your container, checkout [devcontainer.json "mounts" section](https://containers.dev/implementors/json_reference/) for an example! Upon any mount changes you must rebuild the container using Command Palette as in step 5.
<br />
<h2>Activate File Sharing for Docker:</h2>
<h2>Option 3: Install Dependencies Locally</h2>
* Windows:
* [Guide to sharing](https://docs.docker.com/docker-for-windows/#file-sharing)
* Share the LEAN root directory with docker
* Mac:
* [Guide to sharing](https://docs.docker.com/docker-for-mac/#file-sharing)
* Share the LEAN root directory with docker
1. Install [.NET 6](https://dotnet.microsoft.com/en-us/download/dotnet/6.0) for the project
* Linux:
* (No setup required)
2. (Optional) Get [Python 3.8.13](https://www.python.org/downloads/release/python-3813/) for running Python algorithms
- Follow Python instructions [here](https://github.com/QuantConnect/Lean/tree/master/Algorithm.Python#installing-python-38) for your platform
3. Get [Visual Studio Code](https://code.visualstudio.com/download)
- Get the Extension [C#](https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.csharp) for C# Debugging
- Get the Extension [Python](https://marketplace.visualstudio.com/items?itemName=ms-python.python) for Python Debugging
4. Get Lean into VS Code
- Download the repo or clone it using: `git clone [https://github.com/QuantConnect/Lean](https://github.com/QuantConnect/Lean)`
- Open the folder using VS Code
Your environment is prepared and ready to run Lean.
<br />
<h2>Lean Configuration</h2>
<h1>How to use Lean</h1>
Next we need to be sure that our Lean configuration at **.\Launcher\config.json** is properly set. Just like running lean locally the config must reflect what we want Lean to run.
This section will cover configuring, building, launching and debugging lean. This is only applicable to option 2 from above. This does not apply to Lean CLI, please refer to [CLI documentation](https://www.quantconnect.com/docs/v2/lean-cli/key-concepts/getting-started)
You configuration file should look something like this for the following languages:
<br />
<h2>Configuration</h2>
We need to be sure that our Lean configuration at **.\Launcher\config.json** is properly set.
Your configuration file should look something like this for the following languages:
<h3>Python:</h3>
@@ -85,105 +96,48 @@ You configuration file should look something like this for the following languag
"algorithm-location": "QuantConnect.Algorithm.CSharp.dll",
<br />
<h3>Important Note About C#</h3>
<h2>Building</h2>
In order to use a custom C# algorithm, the C# file must be compiled before running in the docker, as it is compiled into the file "QuantConnect.Algorithm.CSharp.dll". Any new C# files will need to be added to the csproj compile list before it will compile, check Algorithm.CSharp/QuantConnect.Algorithm.CSharp.csproj for all algorithms that are compiled. Once there is an entry for your algorithm the project can be compiled by using the “build” task under _“Terminal” > “Run Build Task”._
Before running Lean, we must build the project. Currently the VS Code task will automatically build before launching. But find more information below about how to trigger building manually.
Python **does not** have this requirement as the engine will compile it on the fly.
In VS Code run build task (Ctrl+Shift+B or "Terminal" dropdown); there are a few options:
- __Build__ - basic build task, just builds Lean once
- __Rebuild__ - rebuild task, completely rebuilds the project. Use if having issues with debugging symbols being loaded for your algorithms.
- __Clean__ - deletes out all project build files
<br />
<h2>Running Lean in the Container</h2>
<h2>Launching Lean</h2>
This section will cover how to actually launch Lean in the container with your desired configuration.
Now that lean is configured and built we can launch Lean. Under "Run & Debug" use the launch option "Launch". This will start Lean with C# debugging. Any breakpoints in Lean C# will be triggered.
<br />
<h3>Option 1 (Recommended)</h3>
In VS Code click on the debug/run icon on the left toolbar, at the top you should see a drop down menu with launch options, be sure to select **Debug in Container**. This option will kick off a launch script that will start the docker. With this specific launch option the parameters are already configured in VS Codes **tasks.json** under the **run-docker** task args. These set arguments are:
"IMAGE=quantconnect/lean:latest",
"CONFIG_FILE=${workspaceFolder}/Launcher/config.json",
"DATA_DIR=${workspaceFolder}/Data",
"RESULTS_DIR=${workspaceFolder}/Results",
"DEBUGGING=Y",
"PYHTON_DIR=${workspaceFolder}/Algorithm.Python"
As defaults these are all great! Feel free to change them as needed for your setup.
**NOTE:** VSCode may try and throw errors when launching this way regarding build on `QuantConnect.csx` and `Config.json` these errors can be ignored by selecting "*Debug Anyway*". To stop this error message in the future select "*Remember my choice in user settings*".
If using C# algorithms ensure that msbuild can build them successfully.
<h2>Debugging Python</h2>
Python algorithms require a little extra work in order to be able to debug them. Follow the steps below to get Python debugging working.
<br />
<h3>Option 2</h3>
From a terminal launch the run_docker.bat/.sh script; there are a few choices on how to launch this:
1. Launch with no parameters and answer the questions regarding configuration (Press enter for defaults)
*   Enter docker image [default: quantconnect/lean:latest]:
*   Enter absolute path to Lean config file [default: .\Launcher\config.json]:
*   Enter absolute path to Data folder [default: .\Data\]:
*   Enter absolute path to store results [default: .\Results]:
* Would you like to debug C#? (Requires mono debugger attachment) [default: N]:
2. Using the **run_docker.cfg** to store args for repeated use; any blank entries will resort to default values! example: **_./run_docker.bat run_docker.cfg_**
IMAGE=quantconnect/lean:latest
CONFIG_FILE=
DATA_DIR=
RESULTS_DIR=
DEBUGGING=
PYTHON_DIR=
3. Inline arguments; anything you don't enter will use the default args! example: **_./run_docker.bat DEBUGGING=y_**
* Accepted args for inline include all listed in the file in #2
<br />
<h1>Debugging Python</h1>
Python algorithms require a little extra work in order to be able to debug them locally or in the container. Thankfully we were able to configure VS code tasks to take care of the work for you! Follow the steps below to get Python debugging working.
<br />
<h2>Modifying the Configuration</h2>
<h3>Modifying the Configuration</h3>
First in order to debug a Python algorithm in VS Code we must make the following change to our configuration (Launcher\config.json) under the comment debugging configuration:
"debugging": true,
"debugging-method": "PTVSD",
"debugging-method": "DebugPy",
In setting this we are telling Lean to expect a debugger connection using Python Tools for Visual Studio Debugger. Once this is set Lean will stop upon initialization and await a connection to the debugger via port 5678.
<br />
<h2>Using VS Code Launch Options to Connect</h2>
<h3>Using VS Code Launch Options to Connect</h3>
Now that Lean is configured for the python debugger we can make use of the programmed launch options to connect.
Now that Lean is configured for the python debugger we can make use of the programmed launch options to connect to Lean during runtime.
<br />
<h3>Container</h3>
To debug inside of the container we must first start the container, follow the steps described in the section “[Running Lean in the Container](#Running-Lean-in-the-Container)”. Once the container is started you should see the messages in Figure 2.
If the message is displayed, use the same drop down for “Debug in Container” and select “Attach to Python (Container)”. Then press run, VS Code will now enter and debug any breakpoints you have set in your Python algorithm.
<br />
<h3>Local</h3>
To debug locally we must run the program locally using the programmed task found under Terminal > Run Task > “Run Application”. Once Lean is started you should see the messages in Figure 2.
If the message is displayed, use the launch option “Attach to Python (Local)”. Then press run, VS Code will now enter and debug any breakpoints you have set in your python algorithm.
Start Lean using the "Launch" option covered above. Once Lean starts you should see the messages in figure 2 If the message is displayed, use the launch option “Attach to Python”. Then press run, VS Code will now enter and debug any breakpoints you have set in your python algorithm.
<br />
@@ -201,6 +155,6 @@ _Figure 2: Python Debugger Messages_
<h1>Common Issues</h1>
Here we will cover some common issues with setting this up. This section will expand as we get user feedback!
* Any error messages about building in VSCode that point to comments in JSON. Either select **ignore** or follow steps described [here](https://stackoverflow.com/questions/47834825/in-vs-code-disable-error-comments-are-not-permitted-in-json) to remove the errors entirely.
* `Errors exist after running preLaunchTask 'run-docker'`This VSCode error appears to warn you of CSharp errors when trying to use `Debug in Container` select "Debug Anyway" as the errors are false flags for JSON comments as well as `QuantConnect.csx` not finding references. Neither of these will impact your debugging.
* `The container name "/LeanEngine" is already in use by container "****"` This Docker error implies that another instance of lean is already running under the container name /LeanEngine. If this error appears either use Docker Desktop to delete the container or use `docker kill LeanEngine` from the command line.
- The "project file cannot be loaded" and "nuget packages not found" errors occurs when the project files are open by another process in the host. Closing all applications and/or restarting the computer solve the issue.
- Autocomplete and reference finding with omnisharp can sometimes be buggy, if this occurs use the command palette to restart omnisharp. (Ctrl+Shift+P "OmniSharp: Restart OmniSharp")
- Any error messages about building in VSCode that point to comments in JSON. Either select **ignore** or follow steps described [here](https://stackoverflow.com/questions/47834825/in-vs-code-disable-error-comments-are-not-permitted-in-json) to remove the errors entirely.

7
.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,7 @@
{
"files.eol": "\n",
"python.analysis.extraPaths": [
"/Lean/Algorithm.Python",
"/opt/miniconda3/lib/python3.8/site-packages"
]
}

100
.vscode/tasks.json vendored
View File

@@ -8,11 +8,12 @@
{
"label": "build",
"type": "shell",
"command": "msbuild",
"command": "dotnet",
"args": [
"build",
"/p:Configuration=Debug",
"/p:DebugType=portable",
"/t:build",
"/p:WarningLevel=1"
],
"group": "build",
"presentation": {
@@ -23,11 +24,13 @@
{
"label": "rebuild",
"type": "shell",
"command": "msbuild",
"command": "dotnet",
"args": [
"build",
"--no-incremental",
"/p:Configuration=Debug",
"/p:DebugType=portable",
"/t:rebuild",
"/p:WarningLevel=1"
],
"group": "build",
"presentation": {
@@ -38,9 +41,9 @@
{
"label": "clean",
"type": "shell",
"command": "msbuild",
"command": "dotnet",
"args": [
"/t:clean",
"clean",
],
"group": "build",
"presentation": {
@@ -49,91 +52,16 @@
"problemMatcher": "$msCompile"
},
{
"label": "force build linux",
"label": "start research",
"type": "shell",
"command": "msbuild",
"args": [
"/property:GenerateFullPaths=true",
"/p:Configuration=Debug",
"/p:DebugType=portable",
"/t:build",
"/p:ForceLinuxBuild=true"
],
"dependsOn": ["build"],
"group": "build",
"presentation": {
"reveal": "silent"
},
"problemMatcher": "$msCompile"
},
{
"label": "run-docker",
"type": "shell",
"isBackground": true,
"windows": {
"command": "${workspaceFolder}/run_docker.bat",
},
"linux": {
"command": "${workspaceFolder}/run_docker.sh"
},
"osx": {
"command": "${workspaceFolder}/run_docker.sh"
},
"args": [
"IMAGE=quantconnect/lean:latest",
"CONFIG_FILE=${workspaceFolder}/Launcher/config.json",
"DATA_DIR=${workspaceFolder}/Data",
"RESULTS_DIR=${workspaceFolder}/Results",
"DEBUGGING=Y",
"PYTHON_DIR=${workspaceFolder}/Algorithm.Python",
"EXIT=Y"
],
"problemMatcher": [
{
"pattern": [
{
"regexp": ".",
"file": 1,
"location": 2,
"message": 3
}
],
"background": {
"activeOnStart": true,
"beginsPattern": ".",
"endsPattern": ".",
}
}
]
},
{
"label": "close-docker",
"type": "shell",
"command": "docker stop LeanEngine",
"presentation": {
"echo": false,
"reveal": "never",
"focus": false,
"panel": "shared",
"showReuseMessage": false,
"clear": true,
},
"linux":{
"command": "sudo docker stop LeanEngine"
}
},
{
"label": "Run Application",
"type": "process",
"command": "QuantConnect.Lean.Launcher.exe",
"command" : "${workspaceFolder}/.vscode/launch_research.sh",
"args" : [
"--data-folder",
"${workspaceFolder}/Data",
"--config",
"${workspaceFolder}/Launcher/config.json"
"${workspaceFolder}/Launcher/bin/Debug"
],
"options": {
"cwd": "${workspaceFolder}/Launcher/bin/Debug/"
}
"problemMatcher": "$msCompile"
}
]
}

View File

@@ -55,7 +55,7 @@ namespace QuantConnect.Algorithm.CSharp
||
Portfolio.TotalHoldingsValue < Portfolio.TotalPortfolioValue * 0.01m)
{
throw new Exception($"Unexpected Total Holdings Value: {Portfolio.TotalHoldingsValue}");
throw new RegressionTestException($"Unexpected Total Holdings Value: {Portfolio.TotalHoldingsValue}");
}
}
@@ -67,53 +67,55 @@ 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, Language.Python };
public List<Language> Languages { get; } = new() { 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>
/// Final status of the algorithm
/// </summary>
public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed;
/// <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 Trades", "199"},
{"Total Orders", "199"},
{"Average Win", "0.00%"},
{"Average Loss", "0.00%"},
{"Compounding Annual Return", "-12.472%"},
{"Compounding Annual Return", "-12.611%"},
{"Drawdown", "0.200%"},
{"Expectancy", "-0.586"},
{"Net Profit", "-0.170%"},
{"Sharpe Ratio", "-9.693"},
{"Probabilistic Sharpe Ratio", "12.704%"},
{"Loss Rate", "79%"},
{"Win Rate", "21%"},
{"Profit-Loss Ratio", "0.95"},
{"Alpha", "-0.149"},
{"Beta", "0.037"},
{"Expectancy", "-0.585"},
{"Start Equity", "100000"},
{"End Equity", "99827.80"},
{"Net Profit", "-0.172%"},
{"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.156"},
{"Beta", "0.035"},
{"Annual Standard Deviation", "0.008"},
{"Annual Variance", "0"},
{"Information Ratio", "-9.471"},
{"Tracking Error", "0.212"},
{"Treynor Ratio", "-2.13"},
{"Information Ratio", "-9.603"},
{"Tracking Error", "0.215"},
{"Treynor Ratio", "-2.478"},
{"Total Fees", "$199.00"},
{"Fitness Score", "0.002"},
{"Kelly Criterion Estimate", "38.64"},
{"Kelly Criterion Probability Value", "0.229"},
{"Sortino Ratio", "-21.545"},
{"Return Over Maximum Drawdown", "-77.972"},
{"Portfolio Turnover", "1.135"},
{"Total Insights Generated", "100"},
{"Total Insights Closed", "99"},
{"Total Insights Analysis Completed", "99"},
{"Long Insight Count", "100"},
{"Short Insight Count", "0"},
{"Long/Short Ratio", "100%"},
{"Estimated Monthly Alpha Value", "$126657.6305"},
{"Total Accumulated Estimated Alpha Value", "$20405.9516"},
{"Mean Population Estimated Insight Value", "$206.1207"},
{"Mean Population Direction", "54.5455%"},
{"Mean Population Magnitude", "54.5455%"},
{"Rolling Averaged Population Direction", "59.8056%"},
{"Rolling Averaged Population Magnitude", "59.8056%"},
{"OrderListHash", "1256341962"}
{"Estimated Strategy Capacity", "$26000000.00"},
{"Lowest Capacity Asset", "SPY R735QTJ8XC9X"},
{"Portfolio Turnover", "119.89%"},
{"OrderListHash", "d06c26f557b83d8d42ac808fe2815a1e"}
};
}
}

View File

@@ -66,7 +66,7 @@ namespace QuantConnect.Algorithm.CSharp
|| insightsCollection.Insights.Count(insight => insight.Symbol == _spy) != 1
|| insightsCollection.Insights.Count(insight => insight.Symbol == _ibm) != 1)
{
throw new Exception("Unexpected insights were emitted");
throw new RegressionTestException("Unexpected insights were emitted");
}
}
@@ -103,53 +103,55 @@ 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, Language.Python };
public List<Language> Languages { get; } = new() { Language.CSharp, Language.Python };
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 58;
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 0;
/// <summary>
/// Final status of the algorithm
/// </summary>
public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed;
/// <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 Trades", "9"},
{"Average Win", "0.89%"},
{"Total Orders", "9"},
{"Average Win", "0.86%"},
{"Average Loss", "-0.27%"},
{"Compounding Annual Return", "196.104%"},
{"Compounding Annual Return", "206.404%"},
{"Drawdown", "1.700%"},
{"Expectancy", "1.853"},
{"Net Profit", "1.498%"},
{"Sharpe Ratio", "4.275"},
{"Probabilistic Sharpe Ratio", "60.462%"},
{"Expectancy", "1.781"},
{"Start Equity", "100000"},
{"End Equity", "101441.92"},
{"Net Profit", "1.442%"},
{"Sharpe Ratio", "4.836"},
{"Sortino Ratio", "10.481"},
{"Probabilistic Sharpe Ratio", "59.497%"},
{"Loss Rate", "33%"},
{"Win Rate", "67%"},
{"Profit-Loss Ratio", "3.28"},
{"Alpha", "1.574"},
{"Beta", "-0.289"},
{"Annual Standard Deviation", "0.276"},
{"Annual Variance", "0.076"},
{"Information Ratio", "-0.495"},
{"Tracking Error", "0.367"},
{"Treynor Ratio", "-4.079"},
{"Total Fees", "$14.33"},
{"Fitness Score", "0.408"},
{"Kelly Criterion Estimate", "16.447"},
{"Kelly Criterion Probability Value", "0.315"},
{"Sortino Ratio", "13.611"},
{"Return Over Maximum Drawdown", "117.635"},
{"Portfolio Turnover", "0.411"},
{"Total Insights Generated", "3"},
{"Total Insights Closed", "3"},
{"Total Insights Analysis Completed", "3"},
{"Long Insight Count", "0"},
{"Short Insight Count", "3"},
{"Long/Short Ratio", "0%"},
{"Estimated Monthly Alpha Value", "$19868365.6628"},
{"Total Accumulated Estimated Alpha Value", "$3421774.0864"},
{"Mean Population Estimated Insight Value", "$1140591.3621"},
{"Mean Population Direction", "100%"},
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "100%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "-887015098"}
{"Profit-Loss Ratio", "3.17"},
{"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.174"},
{"Total Fees", "$14.78"},
{"Estimated Strategy Capacity", "$120000000.00"},
{"Lowest Capacity Asset", "IBM R735QTJ8XC9X"},
{"Portfolio Turnover", "41.18%"},
{"OrderListHash", "713c956deb193bed2290e9f379c0f9f9"}
};
}
}

View File

@@ -0,0 +1,134 @@
/*
* 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.Linq;
using QuantConnect.Data;
using QuantConnect.Interfaces;
using System.Collections.Generic;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Regression algorithm reproducing GH issue #5748 where in some cases an option underlying symbol was not being
/// removed from all universes it was hold
/// </summary>
public class AddAndRemoveOptionContractRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
{
private Symbol _contract;
private bool _hasRemoved;
public override void Initialize()
{
SetStartDate(2014, 06, 06);
SetEndDate(2014, 06, 09);
UniverseSettings.DataNormalizationMode = DataNormalizationMode.Raw;
UniverseSettings.MinimumTimeInUniverse = TimeSpan.Zero;
var aapl = QuantConnect.Symbol.Create("AAPL", SecurityType.Equity, Market.USA);
_contract = OptionChain(aapl)
.OrderBy(x => x.ID.Symbol)
.FirstOrDefault(optionContract => optionContract.ID.OptionRight == OptionRight.Call
&& optionContract.ID.OptionStyle == OptionStyle.American);
AddOptionContract(_contract);
}
public override void OnData(Slice slice)
{
if (slice.HasData)
{
if (!_hasRemoved)
{
RemoveOptionContract(_contract);
RemoveSecurity(_contract.Underlying);
_hasRemoved = true;
}
else
{
throw new RegressionTestException("Expect a single call to OnData where we removed the option and underlying");
}
}
}
public override void OnEndOfAlgorithm()
{
if (!_hasRemoved)
{
throw new RegressionTestException("Expect a single call to OnData where we removed the option and underlying");
}
}
/// <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 List<Language> Languages { get; } = new() { Language.CSharp };
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 24;
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 1;
/// <summary>
/// Final status of the algorithm
/// </summary>
public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed;
/// <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"},
{"Start Equity", "100000"},
{"End Equity", "100000"},
{"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", "-9.486"},
{"Tracking Error", "0.008"},
{"Treynor Ratio", "0"},
{"Total Fees", "$0.00"},
{"Estimated Strategy Capacity", "$0"},
{"Lowest Capacity Asset", ""},
{"Portfolio Turnover", "0%"},
{"OrderListHash", "d41d8cd98f00b204e9800998ecf8427e"}
};
}
}

View File

@@ -0,0 +1,131 @@
/*
* 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.Linq;
using QuantConnect.Data;
using QuantConnect.Interfaces;
using System.Collections.Generic;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Regression algorithm reproducing GH issue #5971 where we add and remove an option in the same loop
/// </summary>
public class AddAndRemoveSecuritySameLoopRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
{
private Symbol _contract;
private bool _hasRemoved;
public override void Initialize()
{
SetStartDate(2014, 06, 06);
SetEndDate(2014, 06, 09);
UniverseSettings.DataNormalizationMode = DataNormalizationMode.Raw;
UniverseSettings.MinimumTimeInUniverse = TimeSpan.Zero;
var aapl = AddEquity("AAPL").Symbol;
_contract = OptionChain(aapl)
.OrderBy(x => x.ID.Symbol)
.FirstOrDefault(optionContract => optionContract.ID.OptionRight == OptionRight.Call
&& optionContract.ID.OptionStyle == OptionStyle.American);
}
public override void OnData(Slice slice)
{
if (_hasRemoved)
{
throw new RegressionTestException("Expect a single call to OnData where we removed the option and underlying");
}
_hasRemoved = true;
AddOptionContract(_contract);
// changed my mind!
RemoveOptionContract(_contract);
RemoveSecurity(_contract.Underlying);
RemoveSecurity(AddEquity("SPY", Resolution.Daily).Symbol);
}
public override void OnEndOfAlgorithm()
{
if (!_hasRemoved)
{
throw new RegressionTestException("We did not remove the option contract!");
}
}
/// <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 List<Language> Languages { get; } = new() { Language.CSharp };
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 24;
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 1;
/// <summary>
/// Final status of the algorithm
/// </summary>
public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed;
/// <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"},
{"Start Equity", "100000"},
{"End Equity", "100000"},
{"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", "-9.486"},
{"Tracking Error", "0.008"},
{"Treynor Ratio", "0"},
{"Total Fees", "$0.00"},
{"Estimated Strategy Capacity", "$0"},
{"Lowest Capacity Asset", ""},
{"Portfolio Turnover", "0%"},
{"OrderListHash", "d41d8cd98f00b204e9800998ecf8427e"}
};
}
}

View File

@@ -0,0 +1,151 @@
/*
* 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.Indicators;
using QuantConnect.Interfaces;
using QuantConnect.Orders;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Regression test to explain how Beta indicator works
/// </summary>
public class AddBetaIndicatorRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
{
private Beta _beta;
private SimpleMovingAverage _sma;
private decimal _lastSMAValue;
public override void Initialize()
{
SetStartDate(2013, 10, 07);
SetEndDate(2013, 10, 15);
SetCash(10000);
AddEquity("IBM");
AddEquity("SPY");
EnableAutomaticIndicatorWarmUp = true;
_beta = B("IBM", "SPY", 3, Resolution.Daily);
_sma = SMA("SPY", 3, Resolution.Daily);
_lastSMAValue = 0;
if (!_beta.IsReady)
{
throw new RegressionTestException("_beta indicator was expected to be ready");
}
}
public override void OnData(Slice slice)
{
if (!Portfolio.Invested)
{
var price = slice["IBM"].Close;
Buy("IBM", 10);
LimitOrder("IBM", 10, price * 0.1m);
StopMarketOrder("IBM", 10, price / 0.1m);
}
if (_beta.Current.Value < 0m || _beta.Current.Value > 2.80m)
{
throw new RegressionTestException($"_beta value was expected to be between 0 and 2.80 but was {_beta.Current.Value}");
}
Log($"Beta between IBM and SPY is: {_beta.Current.Value}");
}
public override void OnOrderEvent(OrderEvent orderEvent)
{
var order = Transactions.GetOrderById(orderEvent.OrderId);
var goUpwards = _lastSMAValue < _sma.Current.Value;
_lastSMAValue = _sma.Current.Value;
if (order.Status == OrderStatus.Filled)
{
if (order.Type == OrderType.Limit && Math.Abs(_beta.Current.Value - 1) < 0.2m && goUpwards)
{
Transactions.CancelOpenOrders(order.Symbol);
}
}
if (order.Status == OrderStatus.Canceled)
{
Log(orderEvent.ToString());
}
}
/// <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 virtual List<Language> Languages { get; } = new() { Language.CSharp };
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 10977;
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 11;
/// <summary>
/// Final status of the algorithm
/// </summary>
public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed;
/// <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", "12.939%"},
{"Drawdown", "0.300%"},
{"Expectancy", "0"},
{"Start Equity", "10000"},
{"End Equity", "10028.93"},
{"Net Profit", "0.289%"},
{"Sharpe Ratio", "3.924"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "68.349%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"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.78"},
{"Total Fees", "$1.00"},
{"Estimated Strategy Capacity", "$35000000.00"},
{"Lowest Capacity Asset", "IBM R735QTJ8XC9X"},
{"Portfolio Turnover", "1.51%"},
{"OrderListHash", "1db1ce949db995bba20ed96ea5e2438a"}
};
}
}

View File

@@ -0,0 +1,164 @@
/*
* 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.Linq;
using QuantConnect.Data;
using QuantConnect.Orders;
using QuantConnect.Interfaces;
using QuantConnect.Securities;
using System.Collections.Generic;
using QuantConnect.Securities.Future;
using QuantConnect.Data.UniverseSelection;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Continuous Futures Regression algorithm. Asserting and showcasing the behavior of adding a continuous future
/// and a future contract at the same time
/// </summary>
public class AddFutureContractWithContinuousRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
{
private Future _continuousContract;
private Future _futureContract;
private bool _ended;
/// <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(2013, 10, 6);
SetEndDate(2013, 10, 10);
_continuousContract = AddFuture(Futures.Indices.SP500EMini,
dataNormalizationMode: DataNormalizationMode.BackwardsRatio,
dataMappingMode: DataMappingMode.LastTradingDay,
contractDepthOffset: 0
);
_futureContract = AddFutureContract(FutureChainProvider.GetFutureContractList(_continuousContract.Symbol, Time).First());
}
/// <summary>
/// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
/// </summary>
/// <param name="slice">Slice object keyed by symbol containing the stock data</param>
public override void OnData(Slice slice)
{
if (_ended)
{
throw new RegressionTestException($"Algorithm should of ended!");
}
if (slice.Keys.Count > 2)
{
throw new RegressionTestException($"Getting data for more than 2 symbols! {string.Join(",", slice.Keys.Select(symbol => symbol))}");
}
if (UniverseManager.Count != 3)
{
throw new RegressionTestException($"Expecting 3 universes (chain, continuous and user defined) but have {UniverseManager.Count}");
}
if (!Portfolio.Invested)
{
Buy(_futureContract.Symbol, 1);
Buy(_continuousContract.Mapped, 1);
RemoveSecurity(_futureContract.Symbol);
RemoveSecurity(_continuousContract.Symbol);
_ended = true;
}
}
public override void OnOrderEvent(OrderEvent orderEvent)
{
if (orderEvent.Status == OrderStatus.Filled)
{
Log($"{orderEvent}");
}
}
public override void OnSecuritiesChanged(SecurityChanges changes)
{
Debug($"{Time}-{changes}");
if (changes.AddedSecurities.Any(security => security.Symbol != _continuousContract.Symbol && security.Symbol != _futureContract.Symbol)
|| changes.RemovedSecurities.Any(security => security.Symbol != _continuousContract.Symbol && security.Symbol != _futureContract.Symbol))
{
throw new RegressionTestException($"We got an unexpected security changes {changes}");
}
}
/// <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 List<Language> Languages { get; } = new() { Language.CSharp };
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 73;
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 0;
/// <summary>
/// Final status of the algorithm
/// </summary>
public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed;
/// <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.03%"},
{"Compounding Annual Return", "-2.594%"},
{"Drawdown", "0.000%"},
{"Expectancy", "-1"},
{"Start Equity", "100000"},
{"End Equity", "99966.4"},
{"Net Profit", "-0.034%"},
{"Sharpe Ratio", "-10.666"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "1.216%"},
{"Loss Rate", "100%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "-0.029"},
{"Beta", "0.004"},
{"Annual Standard Deviation", "0.003"},
{"Annual Variance", "0"},
{"Information Ratio", "-0.768"},
{"Tracking Error", "0.241"},
{"Treynor Ratio", "-6.368"},
{"Total Fees", "$8.60"},
{"Estimated Strategy Capacity", "$5500000.00"},
{"Lowest Capacity Asset", "ES VMKLFZIH2MTD"},
{"Portfolio Turnover", "66.80%"},
{"OrderListHash", "579e2e83dd7e5e7648c47e9eff132460"}
};
}
}

View File

@@ -40,8 +40,8 @@ namespace QuantConnect.Algorithm.CSharp
public override void Initialize()
{
SetStartDate(2020, 1, 5);
SetEndDate(2020, 1, 6);
SetStartDate(2020, 1, 4);
SetEndDate(2020, 1, 8);
_es20h20 = AddFutureContract(
QuantConnect.Symbol.CreateFuture(Futures.Indices.SP500EMini, Market.CME, new DateTime(2020, 3, 20)),
@@ -51,8 +51,9 @@ namespace QuantConnect.Algorithm.CSharp
QuantConnect.Symbol.CreateFuture(Futures.Indices.SP500EMini, Market.CME, new DateTime(2020, 6, 19)),
Resolution.Minute).Symbol;
var optionChains = OptionChainProvider.GetOptionContractList(_es20h20, Time)
.Concat(OptionChainProvider.GetOptionContractList(_es19m20, Time));
// Get option contract lists for 2020/01/05 (Time.AddDays(1)) because Lean has local data for that date
var optionChains = OptionChainProvider.GetOptionContractList(_es20h20, Time.AddDays(1))
.Concat(OptionChainProvider.GetOptionContractList(_es19m20, Time.AddDays(1)));
foreach (var optionContract in optionChains)
{
@@ -65,9 +66,9 @@ namespace QuantConnect.Algorithm.CSharp
}
}
public override void OnData(Slice data)
public override void OnData(Slice slice)
{
if (!data.HasData)
if (!slice.HasData)
{
return;
}
@@ -75,7 +76,7 @@ namespace QuantConnect.Algorithm.CSharp
_onDataReached = true;
var hasOptionQuoteBars = false;
foreach (var qb in data.QuoteBars.Values)
foreach (var qb in slice.QuoteBars.Values)
{
if (qb.Symbol.SecurityType != SecurityType.FutureOption)
{
@@ -98,7 +99,7 @@ namespace QuantConnect.Algorithm.CSharp
return;
}
if (data.ContainsKey(_es20h20) && data.ContainsKey(_es19m20))
if (slice.ContainsKey(_es20h20) && slice.ContainsKey(_es19m20))
{
SetHoldings(_es20h20, 0.2);
SetHoldings(_es19m20, 0.2);
@@ -113,7 +114,7 @@ namespace QuantConnect.Algorithm.CSharp
if (!_onDataReached)
{
throw new Exception("OnData() was never called.");
throw new RegressionTestException("OnData() was never called.");
}
if (_symbolsReceived.Count != _expectedSymbolsReceived.Count)
{
@@ -131,7 +132,7 @@ namespace QuantConnect.Algorithm.CSharp
if (missingSymbols.Count > 0)
{
throw new Exception($"Symbols: \"{string.Join(", ", missingSymbols)}\" were not found in OnData");
throw new RegressionTestException($"Symbols: \"{string.Join(", ", missingSymbols)}\" were not found in OnData");
}
foreach (var expectedSymbol in _expectedSymbolsReceived)
@@ -145,7 +146,7 @@ namespace QuantConnect.Algorithm.CSharp
if (nonDupeDataCount < 1000)
{
throw new Exception($"Received too few data points. Expected >=1000, found {nonDupeDataCount} for {expectedSymbol}");
throw new RegressionTestException($"Received too few data points. Expected >=1000, found {nonDupeDataCount} for {expectedSymbol}");
}
}
}
@@ -158,53 +159,55 @@ 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, Language.Python };
public List<Language> Languages { get; } = new() { Language.CSharp, Language.Python };
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 311879;
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 0;
/// <summary>
/// Final status of the algorithm
/// </summary>
public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed;
/// <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 Trades", "2"},
{"Total Orders", "2"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "217.585%"},
{"Drawdown", "0.600%"},
{"Compounding Annual Return", "5512.811%"},
{"Drawdown", "1.000%"},
{"Expectancy", "0"},
{"Net Profit", "0.635%"},
{"Sharpe Ratio", "0"},
{"Probabilistic Sharpe Ratio", "0%"},
{"Start Equity", "100000"},
{"End Equity", "105332.8"},
{"Net Profit", "5.333%"},
{"Sharpe Ratio", "64.084"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "95.977%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "0"},
{"Beta", "0"},
{"Annual Standard Deviation", "0"},
{"Annual Variance", "0"},
{"Information Ratio", "-14.395"},
{"Tracking Error", "0.043"},
{"Treynor Ratio", "0"},
{"Total Fees", "$7.40"},
{"Fitness Score", "1"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "79228162514264337593543950335"},
{"Return Over Maximum Drawdown", "79228162514264337593543950335"},
{"Portfolio Turnover", "3.199"},
{"Total Insights Generated", "0"},
{"Total Insights Closed", "0"},
{"Total Insights Analysis Completed", "0"},
{"Long Insight Count", "0"},
{"Short Insight Count", "0"},
{"Long/Short Ratio", "100%"},
{"Estimated Monthly Alpha Value", "$0"},
{"Total Accumulated Estimated Alpha Value", "$0"},
{"Mean Population Estimated Insight Value", "$0"},
{"Mean Population Direction", "0%"},
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "1074366800"}
{"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.308"},
{"Total Fees", "$8.60"},
{"Estimated Strategy Capacity", "$22000000.00"},
{"Lowest Capacity Asset", "ES XFH59UK0MYO1"},
{"Portfolio Turnover", "122.11%"},
{"OrderListHash", "d744fa8beaa60546c84924ed68d945d9"}
};
}
}

View File

@@ -0,0 +1,142 @@
/*
* 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.Interfaces;
using QuantConnect.Securities;
using System.Collections.Generic;
using System.Linq;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// This regression algorithm tests we can add future option contracts from contracts in the future chain
/// </summary>
public class AddFutureOptionContractFromFutureChainRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
{
private bool _addedOptions;
public override void Initialize()
{
SetStartDate(2020, 1, 4);
SetEndDate(2020, 1, 6);
var es = AddFuture(Futures.Indices.SP500EMini, Resolution.Minute, Market.CME);
es.SetFilter((futureFilter) =>
{
return futureFilter.Expiration(0, 365).ExpirationCycle(new[] { 3, 6 });
});
}
public override void OnData(Slice slice)
{
if (!_addedOptions)
{
_addedOptions = true;
foreach (var futuresContracts in slice.FutureChains.Values)
{
foreach (var contract in futuresContracts)
{
var option_contract_symbols = OptionChain(contract.Symbol).ToList();
if(option_contract_symbols.Count == 0)
{
continue;
}
foreach (var option_contract_symbol in option_contract_symbols.OrderBy(x => x.ID.Date)
.ThenBy(x => x.ID.StrikePrice)
.ThenBy(x => x.ID.OptionRight).Take(5))
{
AddOptionContract(option_contract_symbol);
}
}
}
}
if (Portfolio.Invested)
{
return;
}
foreach (var chain in slice.OptionChains.Values)
{
foreach (var option in chain.Contracts.Keys)
{
MarketOrder(option, 1);
MarketOrder(option.Underlying, 1);
}
}
}
/// <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 List<Language> Languages { get; } = new() { Language.CSharp };
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 12169;
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 0;
/// <summary>
/// Final status of the algorithm
/// </summary>
public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed;
/// <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", "20"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "386219349.202%"},
{"Drawdown", "5.200%"},
{"Expectancy", "0"},
{"Start Equity", "100000"},
{"End Equity", "111911.55"},
{"Net Profit", "11.912%"},
{"Sharpe Ratio", "1604181.904"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "0%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "2144882.02"},
{"Beta", "31.223"},
{"Annual Standard Deviation", "1.337"},
{"Annual Variance", "1.788"},
{"Information Ratio", "1657259.526"},
{"Tracking Error", "1.294"},
{"Treynor Ratio", "68696.045"},
{"Total Fees", "$35.70"},
{"Estimated Strategy Capacity", "$2600000.00"},
{"Lowest Capacity Asset", "ES 31C3JQS9D84PW|ES XCZJLC9NOB29"},
{"Portfolio Turnover", "495.15%"},
{"OrderListHash", "85257286f088992d599c1ad0799a6237"}
};
}
}

View File

@@ -21,6 +21,7 @@ using QuantConnect.Data.Market;
using QuantConnect.Interfaces;
using QuantConnect.Securities;
using QuantConnect.Securities.Future;
using QuantConnect.Securities.Option;
namespace QuantConnect.Algorithm.CSharp
{
@@ -41,8 +42,8 @@ namespace QuantConnect.Algorithm.CSharp
public override void Initialize()
{
SetStartDate(2020, 1, 5);
SetEndDate(2020, 1, 6);
SetStartDate(2020, 1, 4);
SetEndDate(2020, 1, 8);
_es = AddFuture(Futures.Indices.SP500EMini, Resolution.Minute, Market.CME);
_es.SetFilter((futureFilter) =>
@@ -54,10 +55,10 @@ namespace QuantConnect.Algorithm.CSharp
{
_optionFilterRan = true;
var expiry = new HashSet<DateTime>(optionContracts.Select(x => x.Underlying.ID.Date)).SingleOrDefault();
// Cast to IEnumerable<Symbol> because OptionFilterContract overrides some LINQ operators like `Select` and `Where`
var expiry = new HashSet<DateTime>(optionContracts.Select(x => x.Symbol.Underlying.ID.Date)).SingleOrDefault();
// Cast to List<Symbol> because OptionFilterContract overrides some LINQ operators like `Select` and `Where`
// and cause it to mutate the underlying Symbol collection when using those operators.
var symbol = new HashSet<Symbol>(((IEnumerable<Symbol>)optionContracts).Select(x => x.Underlying)).SingleOrDefault();
var symbol = new HashSet<Symbol>(((List<Symbol>)optionContracts).Select(x => x.Underlying)).SingleOrDefault();
if (expiry == null || symbol == null)
{
@@ -74,9 +75,9 @@ namespace QuantConnect.Algorithm.CSharp
});
}
public override void OnData(Slice data)
public override void OnData(Slice slice)
{
if (!data.HasData)
if (!slice.HasData)
{
return;
}
@@ -84,7 +85,7 @@ namespace QuantConnect.Algorithm.CSharp
_onDataReached = true;
var hasOptionQuoteBars = false;
foreach (var qb in data.QuoteBars.Values)
foreach (var qb in slice.QuoteBars.Values)
{
if (qb.Symbol.SecurityType != SecurityType.FutureOption)
{
@@ -107,7 +108,7 @@ namespace QuantConnect.Algorithm.CSharp
return;
}
foreach (var chain in data.OptionChains.Values)
foreach (var chain in slice.OptionChains.Values)
{
var futureInvested = false;
var optionInvested = false;
@@ -121,13 +122,37 @@ namespace QuantConnect.Algorithm.CSharp
var future = option.Underlying;
if (!optionInvested && data.ContainsKey(option))
if (!optionInvested && slice.ContainsKey(option))
{
var optionContract = Securities[option];
var marginModel = optionContract.BuyingPowerModel as FuturesOptionsMarginModel;
if (marginModel.InitialIntradayMarginRequirement == 0
|| marginModel.InitialOvernightMarginRequirement == 0
|| marginModel.MaintenanceIntradayMarginRequirement == 0
|| marginModel.MaintenanceOvernightMarginRequirement == 0)
{
throw new RegressionTestException("Unexpected margin requirements");
}
if (marginModel.GetInitialMarginRequirement(optionContract, 1) == 0)
{
throw new RegressionTestException("Unexpected Initial Margin requirement");
}
if (marginModel.GetMaintenanceMargin(optionContract) != 0)
{
throw new RegressionTestException("Unexpected Maintenance Margin requirement");
}
MarketOrder(option, 1);
_invested = true;
optionInvested = true;
if (marginModel.GetMaintenanceMargin(optionContract) == 0)
{
throw new RegressionTestException("Unexpected Maintenance Margin requirement");
}
}
if (!futureInvested && data.ContainsKey(future))
if (!futureInvested && slice.ContainsKey(future))
{
MarketOrder(future, 1);
_invested = true;
@@ -139,15 +164,13 @@ namespace QuantConnect.Algorithm.CSharp
public override void OnEndOfAlgorithm()
{
base.OnEndOfAlgorithm();
if (!_optionFilterRan)
{
throw new InvalidOperationException("Option chain filter was never ran");
}
if (!_onDataReached)
{
throw new Exception("OnData() was never called.");
throw new RegressionTestException("OnData() was never called.");
}
if (_symbolsReceived.Count != _expectedSymbolsReceived.Count)
{
@@ -165,7 +188,7 @@ namespace QuantConnect.Algorithm.CSharp
if (missingSymbols.Count > 0)
{
throw new Exception($"Symbols: \"{string.Join(", ", missingSymbols)}\" were not found in OnData");
throw new RegressionTestException($"Symbols: \"{string.Join(", ", missingSymbols)}\" were not found in OnData");
}
foreach (var expectedSymbol in _expectedSymbolsReceived)
@@ -179,7 +202,7 @@ namespace QuantConnect.Algorithm.CSharp
if (nonDupeDataCount < 1000)
{
throw new Exception($"Received too few data points. Expected >=1000, found {nonDupeDataCount} for {expectedSymbol}");
throw new RegressionTestException($"Received too few data points. Expected >=1000, found {nonDupeDataCount} for {expectedSymbol}");
}
}
}
@@ -192,53 +215,55 @@ 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, Language.Python };
public List<Language> Languages { get; } = new() { Language.CSharp, Language.Python };
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 608377;
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 0;
/// <summary>
/// Final status of the algorithm
/// </summary>
public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed;
/// <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 Trades", "2"},
{"Total Orders", "2"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "-15.625%"},
{"Drawdown", "0.200%"},
{"Compounding Annual Return", "347.065%"},
{"Drawdown", "0.900%"},
{"Expectancy", "0"},
{"Net Profit", "-0.093%"},
{"Sharpe Ratio", "-11.181"},
{"Probabilistic Sharpe Ratio", "0%"},
{"Start Equity", "100000"},
{"End Equity", "101950.53"},
{"Net Profit", "1.951%"},
{"Sharpe Ratio", "15.402"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "95.977%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "0.002"},
{"Beta", "-0.016"},
{"Annual Standard Deviation", "0.001"},
{"Annual Variance", "0"},
{"Information Ratio", "-14.343"},
{"Tracking Error", "0.044"},
{"Treynor Ratio", "0.479"},
{"Total Fees", "$3.70"},
{"Fitness Score", "0.41"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "79228162514264337593543950335"},
{"Return Over Maximum Drawdown", "-185.654"},
{"Portfolio Turnover", "0.821"},
{"Total Insights Generated", "0"},
{"Total Insights Closed", "0"},
{"Total Insights Analysis Completed", "0"},
{"Long Insight Count", "0"},
{"Short Insight Count", "0"},
{"Long/Short Ratio", "100%"},
{"Estimated Monthly Alpha Value", "$0"},
{"Total Accumulated Estimated Alpha Value", "$0"},
{"Mean Population Estimated Insight Value", "$0"},
{"Mean Population Direction", "0%"},
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "1532330301"}
{"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.237"},
{"Total Fees", "$3.57"},
{"Estimated Strategy Capacity", "$760000.00"},
{"Lowest Capacity Asset", "ES XCZJLDQX2SRO|ES XCZJLC9NOB29"},
{"Portfolio Turnover", "32.31%"},
{"OrderListHash", "7a04f66a30d793bf187c2695781ad3ee"}
};
}
}

View File

@@ -42,12 +42,12 @@ namespace QuantConnect.Algorithm.CSharp
AddUniverse("my-daily-universe-name", time => new List<string> { "AAPL" });
}
public override void OnData(Slice data)
public override void OnData(Slice slice)
{
if (_option == null)
{
var option = OptionChainProvider.GetOptionContractList(_twx, Time)
.OrderBy(symbol => symbol.ID.Symbol)
var option = OptionChain(_twx)
.OrderBy(x => x.ID.Symbol)
.FirstOrDefault(optionContract => optionContract.ID.Date == _expiration
&& optionContract.ID.OptionRight == OptionRight.Call
&& optionContract.ID.OptionStyle == OptionStyle.American);
@@ -68,11 +68,11 @@ namespace QuantConnect.Algorithm.CSharp
if (!config.Any())
{
throw new Exception($"Was expecting configurations for {symbol}");
throw new RegressionTestException($"Was expecting configurations for {symbol}");
}
if (config.Any(dataConfig => dataConfig.DataNormalizationMode != DataNormalizationMode.Raw))
{
throw new Exception($"Was expecting DataNormalizationMode.Raw configurations for {symbol}");
throw new RegressionTestException($"Was expecting DataNormalizationMode.Raw configurations for {symbol}");
}
}
}
@@ -81,14 +81,14 @@ namespace QuantConnect.Algorithm.CSharp
{
if (SubscriptionManager.SubscriptionDataConfigService.GetSubscriptionDataConfigs(_option).Any())
{
throw new Exception($"Unexpected configurations for {_option} after it has been delisted");
throw new RegressionTestException($"Unexpected configurations for {_option} after it has been delisted");
}
if (Securities[_twx].Invested)
{
if (!SubscriptionManager.SubscriptionDataConfigService.GetSubscriptionDataConfigs(_twx).Any())
{
throw new Exception($"Was expecting configurations for {_twx}");
throw new RegressionTestException($"Was expecting configurations for {_twx}");
}
// first we liquidate the option exercised position
@@ -99,7 +99,7 @@ namespace QuantConnect.Algorithm.CSharp
{
if (SubscriptionManager.SubscriptionDataConfigService.GetSubscriptionDataConfigs(_twx).Any())
{
throw new Exception($"Unexpected configurations for {_twx} after it has been liquidated");
throw new RegressionTestException($"Unexpected configurations for {_twx} after it has been liquidated");
}
}
}
@@ -112,53 +112,55 @@ 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, Language.Python };
public List<Language> Languages { get; } = new() { Language.CSharp, Language.Python };
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 37597;
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 1;
/// <summary>
/// Final status of the algorithm
/// </summary>
public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed;
/// <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 Trades", "3"},
{"Total Orders", "3"},
{"Average Win", "2.73%"},
{"Average Loss", "-2.98%"},
{"Compounding Annual Return", "-4.619%"},
{"Drawdown", "0.300%"},
{"Expectancy", "-0.042"},
{"Start Equity", "100000"},
{"End Equity", "99668"},
{"Net Profit", "-0.332%"},
{"Sharpe Ratio", "-3.7"},
{"Probabilistic Sharpe Ratio", "0.563%"},
{"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.023"},
{"Beta", "0.005"},
{"Annual Standard Deviation", "0.006"},
{"Alpha", "-0.022"},
{"Beta", "-0.012"},
{"Annual Standard Deviation", "0.005"},
{"Annual Variance", "0"},
{"Information Ratio", "-3.424"},
{"Tracking Error", "0.057"},
{"Treynor Ratio", "-4.775"},
{"Information Ratio", "-2.823"},
{"Tracking Error", "0.049"},
{"Treynor Ratio", "2.01"},
{"Total Fees", "$2.00"},
{"Fitness Score", "0"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "-43.418"},
{"Return Over Maximum Drawdown", "-14.274"},
{"Portfolio Turnover", "0.007"},
{"Total Insights Generated", "0"},
{"Total Insights Closed", "0"},
{"Total Insights Analysis Completed", "0"},
{"Long Insight Count", "0"},
{"Short Insight Count", "0"},
{"Long/Short Ratio", "100%"},
{"Estimated Monthly Alpha Value", "$0"},
{"Total Accumulated Estimated Alpha Value", "$0"},
{"Mean Population Estimated Insight Value", "$0"},
{"Mean Population Direction", "0%"},
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "-1185639451"}
{"Estimated Strategy Capacity", "$5700000.00"},
{"Lowest Capacity Asset", "AOL VRKS95ENLBYE|AOL R735QTJ8XC9X"},
{"Portfolio Turnover", "0.55%"},
{"OrderListHash", "24191a4a3bf11c07622a21266618193d"}
};
}
}

View File

@@ -13,12 +13,12 @@
* limitations under the License.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using QuantConnect.Data;
using QuantConnect.Data.UniverseSelection;
using QuantConnect.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
namespace QuantConnect.Algorithm.CSharp
{
@@ -50,7 +50,7 @@ namespace QuantConnect.Algorithm.CSharp
enumerable => new[] { Time.Date <= new DateTime(2014, 6, 5) ? _twx : _aapl });
}
public override void OnData(Slice data)
public override void OnData(Slice slice)
{
if (_option != null && Securities[_option].Price != 0 && !_traded)
{
@@ -66,7 +66,7 @@ namespace QuantConnect.Algorithm.CSharp
// assert underlying still there after the universe selection removed it, still used by the manually added option contract
if (!configs.Any())
{
throw new Exception($"Was expecting configurations for {_twx}" +
throw new RegressionTestException($"Was expecting configurations for {_twx}" +
$" even after it has been deselected from coarse universe because we still have the option contract.");
}
}
@@ -83,7 +83,7 @@ namespace QuantConnect.Algorithm.CSharp
var configs = SubscriptionManager.SubscriptionDataConfigService.GetSubscriptionDataConfigs(symbol);
if (configs.Any())
{
throw new Exception($"Unexpected configuration for {symbol} after it has been deselected from coarse universe and option contract is removed.");
throw new RegressionTestException($"Unexpected configuration for {symbol} after it has been deselected from coarse universe and option contract is removed.");
}
}
}
@@ -94,11 +94,11 @@ namespace QuantConnect.Algorithm.CSharp
{
if (_securityChanges.RemovedSecurities.Intersect(changes.RemovedSecurities).Any())
{
throw new Exception($"SecurityChanges.RemovedSecurities intersect {changes.RemovedSecurities}. We expect no duplicate!");
throw new RegressionTestException($"SecurityChanges.RemovedSecurities intersect {changes.RemovedSecurities}. We expect no duplicate!");
}
if (_securityChanges.AddedSecurities.Intersect(changes.AddedSecurities).Any())
{
throw new Exception($"SecurityChanges.AddedSecurities intersect {changes.RemovedSecurities}. We expect no duplicate!");
throw new RegressionTestException($"SecurityChanges.AddedSecurities intersect {changes.RemovedSecurities}. We expect no duplicate!");
}
// keep track of all removed and added securities
_securityChanges += changes;
@@ -110,24 +110,24 @@ namespace QuantConnect.Algorithm.CSharp
foreach (var addedSecurity in changes.AddedSecurities)
{
var option = OptionChainProvider.GetOptionContractList(addedSecurity.Symbol, Time)
.OrderBy(symbol => symbol.ID.Symbol)
var option = OptionChain(addedSecurity.Symbol)
.OrderBy(contractData => contractData.ID.Symbol)
.First(optionContract => optionContract.ID.Date == _expiration
&& optionContract.ID.OptionRight == OptionRight.Call
&& optionContract.ID.OptionStyle == OptionStyle.American);
AddOptionContract(option);
foreach (var symbol in new[] { option, option.Underlying })
foreach (var symbol in new[] { option.Symbol, option.Underlying.Symbol })
{
var config = SubscriptionManager.SubscriptionDataConfigService.GetSubscriptionDataConfigs(symbol).ToList();
if (!config.Any())
{
throw new Exception($"Was expecting configurations for {symbol}");
throw new RegressionTestException($"Was expecting configurations for {symbol}");
}
if (config.Any(dataConfig => dataConfig.DataNormalizationMode != DataNormalizationMode.Raw))
{
throw new Exception($"Was expecting DataNormalizationMode.Raw configurations for {symbol}");
throw new RegressionTestException($"Was expecting DataNormalizationMode.Raw configurations for {symbol}");
}
}
@@ -143,16 +143,16 @@ namespace QuantConnect.Algorithm.CSharp
{
if (SubscriptionManager.Subscriptions.Any(dataConfig => dataConfig.Symbol == _twx || dataConfig.Symbol.Underlying == _twx))
{
throw new Exception($"Was NOT expecting any configurations for {_twx} or it's options, since we removed the contract");
throw new RegressionTestException($"Was NOT expecting any configurations for {_twx} or it's options, since we removed the contract");
}
if (SubscriptionManager.Subscriptions.All(dataConfig => dataConfig.Symbol != _aapl))
{
throw new Exception($"Was expecting configurations for {_aapl}");
throw new RegressionTestException($"Was expecting configurations for {_aapl}");
}
if (SubscriptionManager.Subscriptions.All(dataConfig => dataConfig.Symbol.Underlying != _aapl))
{
throw new Exception($"Was expecting options configurations for {_aapl}");
throw new RegressionTestException($"Was expecting options configurations for {_aapl}");
}
}
@@ -164,53 +164,55 @@ 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, Language.Python };
public List<Language> Languages { get; } = new() { Language.CSharp, Language.Python };
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 5798;
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 2;
/// <summary>
/// Final status of the algorithm
/// </summary>
public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed;
/// <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 Trades", "2"},
{"Total Orders", "2"},
{"Average Win", "0%"},
{"Average Loss", "-0.23%"},
{"Compounding Annual Return", "-15.596%"},
{"Drawdown", "0.200%"},
{"Expectancy", "-1"},
{"Start Equity", "100000"},
{"End Equity", "99768"},
{"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.027"},
{"Beta", "-0.174"},
{"Alpha", "0.015"},
{"Beta", "-0.171"},
{"Annual Standard Deviation", "0.006"},
{"Annual Variance", "0"},
{"Information Ratio", "-11.586"},
{"Tracking Error", "0.042"},
{"Treynor Ratio", "0.286"},
{"Information Ratio", "-11.082"},
{"Tracking Error", "0.043"},
{"Treynor Ratio", "0.335"},
{"Total Fees", "$2.00"},
{"Fitness Score", "0"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "-19.883"},
{"Return Over Maximum Drawdown", "-67.224"},
{"Portfolio Turnover", "0.014"},
{"Total Insights Generated", "0"},
{"Total Insights Closed", "0"},
{"Total Insights Analysis Completed", "0"},
{"Long Insight Count", "0"},
{"Short Insight Count", "0"},
{"Long/Short Ratio", "100%"},
{"Estimated Monthly Alpha Value", "$0"},
{"Total Accumulated Estimated Alpha Value", "$0"},
{"Mean Population Estimated Insight Value", "$0"},
{"Mean Population Direction", "0%"},
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "721476625"}
{"Estimated Strategy Capacity", "$2800000.00"},
{"Lowest Capacity Asset", "AOL VRKS95ENLBYE|AOL R735QTJ8XC9X"},
{"Portfolio Turnover", "1.14%"},
{"OrderListHash", "cde7b518b7ad6d86cff6e5e092d9a413"}
};
}
}

View File

@@ -0,0 +1,165 @@
/*
* 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.Linq;
using QuantConnect.Data;
using QuantConnect.Interfaces;
using System.Collections.Generic;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Regression algorithm reproducing GH issue #6073 where we remove and re add an option and expect it to work
/// </summary>
public class AddOptionContractTwiceRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
{
private Symbol _contract;
private bool _hasRemoved;
private bool _reAdded;
public override void Initialize()
{
SetStartDate(2014, 06, 06);
SetEndDate(2014, 06, 09);
UniverseSettings.DataNormalizationMode = DataNormalizationMode.Raw;
UniverseSettings.MinimumTimeInUniverse = TimeSpan.Zero;
UniverseSettings.FillForward = false;
AddEquity("SPY", Resolution.Hour);
var aapl = QuantConnect.Symbol.Create("AAPL", SecurityType.Equity, Market.USA);
_contract = OptionChain(aapl)
.OrderBy(x => x.ID.StrikePrice)
.FirstOrDefault(optionContract => optionContract.ID.OptionRight == OptionRight.Call
&& optionContract.ID.OptionStyle == OptionStyle.American);
AddOptionContract(_contract);
}
public override void OnData(Slice slice)
{
if (_hasRemoved)
{
if (!_reAdded && slice.ContainsKey(_contract) && slice.ContainsKey(_contract.Underlying))
{
throw new RegressionTestException("Getting data for removed option and underlying!");
}
if (!Portfolio.Invested && _reAdded)
{
var option = Securities[_contract];
var optionUnderlying = Securities[_contract.Underlying];
if (option.IsTradable && optionUnderlying.IsTradable
&& slice.ContainsKey(_contract) && slice.ContainsKey(_contract.Underlying))
{
Buy(_contract, 1);
}
}
if (!Securities[_contract].IsTradable
&& !Securities[_contract.Underlying].IsTradable
&& !_reAdded)
{
// ha changed my mind!
AddOptionContract(_contract);
_reAdded = true;
}
}
if (slice.ContainsKey(_contract) && slice.ContainsKey(_contract.Underlying))
{
if (!_hasRemoved)
{
RemoveOptionContract(_contract);
RemoveSecurity(_contract.Underlying);
_hasRemoved = true;
}
}
}
public override void OnEndOfAlgorithm()
{
if (!_hasRemoved)
{
throw new RegressionTestException("We did not remove the option contract!");
}
if (!_reAdded)
{
throw new RegressionTestException("We did not re add the option contract!");
}
}
/// <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 List<Language> Languages { get; } = new() { Language.CSharp };
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 3814;
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 1;
/// <summary>
/// Final status of the algorithm
/// </summary>
public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed;
/// <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.50%"},
{"Compounding Annual Return", "-39.406%"},
{"Drawdown", "0.700%"},
{"Expectancy", "-1"},
{"Start Equity", "100000"},
{"End Equity", "99498"},
{"Net Profit", "-0.502%"},
{"Sharpe Ratio", "0"},
{"Sortino 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", "-9.486"},
{"Tracking Error", "0.008"},
{"Treynor Ratio", "0"},
{"Total Fees", "$2.00"},
{"Estimated Strategy Capacity", "$5000000.00"},
{"Lowest Capacity Asset", "AAPL VXBK4R62CXGM|AAPL R735QTJ8XC9X"},
{"Portfolio Turnover", "22.70%"},
{"OrderListHash", "29fd1b75f6db05dd823a6db7e8bd90a9"}
};
}
}

View File

@@ -0,0 +1,126 @@
/*
* 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.Collections.Generic;
using System.Linq;
using QuantConnect.Data.UniverseSelection;
using QuantConnect.Interfaces;
using QuantConnect.Securities;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Algorithm asserting that using OnlyApplyFilterAtMarketOpen along with other dynamic filters will make the filters be applied only on market
/// open, regardless of the order of configuration of the filters
/// </summary>
public class AddOptionWithOnMarketOpenOnlyFilterRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
{
public override void Initialize()
{
SetStartDate(2014, 6, 5);
SetEndDate(2014, 6, 10);
// OnlyApplyFilterAtMarketOpen as first filter
AddOption("AAPL", Resolution.Minute).SetFilter(u =>
u.OnlyApplyFilterAtMarketOpen()
.Strikes(-5, 5)
.Expiration(0, 100)
.IncludeWeeklys());
// OnlyApplyFilterAtMarketOpen as last filter
AddOption("TWX", Resolution.Minute).SetFilter(u =>
u.Strikes(-5, 5)
.Expiration(0, 100)
.IncludeWeeklys()
.OnlyApplyFilterAtMarketOpen());
}
public override void OnSecuritiesChanged(SecurityChanges changes)
{
// This will be the first call, the underlying securities are added.
if (changes.AddedSecurities.All(s => s.Type != SecurityType.Option))
{
return;
}
var changeOptions = changes.AddedSecurities.Concat(changes.RemovedSecurities)
.Where(s => s.Type == SecurityType.Option);
if (Time != Time.Date)
{
throw new RegressionTestException($"Expected options filter to be run only at midnight. Actual was {Time}");
}
}
/// <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 List<Language> Languages { get; } = new() { Language.CSharp };
/// <summary>
/// Data Points count of all time slices of algorithm
/// </summary>
public long DataPoints => 470217;
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 0;
/// <summary>
/// Final status of the algorithm
/// </summary>
public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed;
/// <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"},
{"Start Equity", "100000"},
{"End Equity", "100000"},
{"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", "-10.144"},
{"Tracking Error", "0.033"},
{"Treynor Ratio", "0"},
{"Total Fees", "$0.00"},
{"Estimated Strategy Capacity", "$0"},
{"Lowest Capacity Asset", ""},
{"Portfolio Turnover", "0%"},
{"OrderListHash", "d41d8cd98f00b204e9800998ecf8427e"}
};
}
}

View File

@@ -29,20 +29,21 @@ namespace QuantConnect.Algorithm.CSharp
public class AddRemoveOptionUniverseRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
{
private const string UnderlyingTicker = "GOOG";
public readonly Symbol Underlying = QuantConnect.Symbol.Create(UnderlyingTicker, SecurityType.Equity, Market.USA);
public readonly Symbol OptionChainSymbol = QuantConnect.Symbol.Create(UnderlyingTicker, SecurityType.Option, Market.USA);
private readonly Symbol Underlying = QuantConnect.Symbol.Create(UnderlyingTicker, SecurityType.Equity, Market.USA);
private readonly Symbol OptionChainSymbol = QuantConnect.Symbol.Create(UnderlyingTicker, SecurityType.Option, Market.USA);
private readonly HashSet<Symbol> _expectedSecurities = new HashSet<Symbol>();
private readonly HashSet<Symbol> _expectedData = new HashSet<Symbol>();
private readonly HashSet<Symbol> _expectedUniverses = new HashSet<Symbol>();
private bool _expectUniverseSubscription;
private DateTime _universeSubscriptionTime;
// order of expected contract additions as price moves
private int _expectedContractIndex;
private readonly List<Symbol> _expectedContracts = new List<Symbol>
{
SymbolRepresentation.ParseOptionTickerOSI("GOOG 151224P00750000"),
SymbolRepresentation.ParseOptionTickerOSI("GOOG 151224P00747500"),
SymbolRepresentation.ParseOptionTickerOSI("GOOG 151224P00752500")
SymbolRepresentation.ParseOptionTickerOSI("GOOG 151224P00752500"),
SymbolRepresentation.ParseOptionTickerOSI("GOOG 151224P00755000")
};
public override void Initialize()
@@ -59,16 +60,16 @@ namespace QuantConnect.Algorithm.CSharp
_expectedUniverses.Add(UserDefinedUniverse.CreateSymbol(SecurityType.Equity, Market.USA));
}
public override void OnData(Slice data)
public override void OnData(Slice slice)
{
// verify expectations
if (SubscriptionManager.Subscriptions.Count(x => x.Symbol == OptionChainSymbol)
!= (_expectUniverseSubscription ? 1 : 0))
{
Log($"SubscriptionManager.Subscriptions: {string.Join(" -- ", SubscriptionManager.Subscriptions)}");
throw new Exception($"Unexpected {OptionChainSymbol} subscription presence");
throw new RegressionTestException($"Unexpected {OptionChainSymbol} subscription presence");
}
if (!data.ContainsKey(Underlying))
if (Time != _universeSubscriptionTime && !slice.ContainsKey(Underlying))
{
// TODO : In fact, we're unable to properly detect whether or not we auto-added or it was manually added
// this is because when we auto-add the underlying we don't mark it as an internal security like we do with other auto adds
@@ -77,41 +78,46 @@ namespace QuantConnect.Algorithm.CSharp
// of the internal flag's purpose, so kicking this issue for now with a big fat note here about it :) to be considerd for any future
// refactorings of how we manage subscription/security data and track various aspects about the security (thinking a flags enum with
// 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");
throw new RegressionTestException("The underlying equity data should NEVER be removed in this algorithm because it was manually added");
}
if (_expectedSecurities.AreDifferent(LinqExtensions.ToHashSet(Securities.Keys)))
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()));
throw new Exception($"{Time}:: Detected differences in expected and actual securities{Environment.NewLine}Expected:{Environment.NewLine}{expected}{Environment.NewLine}Actual:{Environment.NewLine}{actual}");
throw new RegressionTestException($"{Time}:: Detected differences in expected and actual securities{Environment.NewLine}Expected:{Environment.NewLine}{expected}{Environment.NewLine}Actual:{Environment.NewLine}{actual}");
}
if (_expectedUniverses.AreDifferent(LinqExtensions.ToHashSet(UniverseManager.Keys)))
if (_expectedUniverses.AreDifferent(UniverseManager.Keys.ToHashSet()))
{
var expected = string.Join(Environment.NewLine, _expectedUniverses.OrderBy(s => s.ToString()));
var actual = string.Join(Environment.NewLine, UniverseManager.Keys.OrderBy(s => s.ToString()));
throw new Exception($"{Time}:: Detected differences in expected and actual universes{Environment.NewLine}Expected:{Environment.NewLine}{expected}{Environment.NewLine}Actual:{Environment.NewLine}{actual}");
throw new RegressionTestException($"{Time}:: Detected differences in expected and actual universes{Environment.NewLine}Expected:{Environment.NewLine}{expected}{Environment.NewLine}Actual:{Environment.NewLine}{actual}");
}
if (_expectedData.AreDifferent(LinqExtensions.ToHashSet(data.Keys)))
if (Time != _universeSubscriptionTime && _expectedData.AreDifferent(slice.Keys.ToHashSet()))
{
var expected = string.Join(Environment.NewLine, _expectedData.OrderBy(s => s.ToString()));
var actual = string.Join(Environment.NewLine, data.Keys.OrderBy(s => s.ToString()));
throw new Exception($"{Time}:: Detected differences in expected and actual slice data keys{Environment.NewLine}Expected:{Environment.NewLine}{expected}{Environment.NewLine}Actual:{Environment.NewLine}{actual}");
var actual = string.Join(Environment.NewLine, slice.Keys.OrderBy(s => s.ToString()));
throw new RegressionTestException($"{Time}:: Detected differences in expected and actual slice data keys{Environment.NewLine}Expected:{Environment.NewLine}{expected}{Environment.NewLine}Actual:{Environment.NewLine}{actual}");
}
// 10AM add GOOG option chain
if (Time.TimeOfDay.Hours == 10 && Time.TimeOfDay.Minutes == 0)
if (Time.TimeOfDay.Hours == 10 && Time.TimeOfDay.Minutes == 0 && !_expectUniverseSubscription)
{
if (Securities.ContainsKey(OptionChainSymbol))
{
throw new Exception("The option chain security should not have been added yet");
throw new RegressionTestException("The option chain security should not have been added yet");
}
var googOptionChain = AddOption(UnderlyingTicker);
googOptionChain.SetFilter(u =>
{
// we added the universe at 10, the universe selection data should not be from before
if (u.LocalTime.Hour < 10)
{
throw new RegressionTestException($"Unexpected selection time {u.LocalTime}");
}
// 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));
});
@@ -119,6 +125,7 @@ namespace QuantConnect.Algorithm.CSharp
_expectedSecurities.Add(OptionChainSymbol);
_expectedUniverses.Add(OptionChainSymbol);
_expectUniverseSubscription = true;
_universeSubscriptionTime = Time;
}
// 11:30AM remove GOOG option chain
@@ -136,16 +143,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)
@@ -156,7 +153,7 @@ namespace QuantConnect.Algorithm.CSharp
var expectedContract = _expectedContracts[_expectedContractIndex];
if (added.Symbol != expectedContract)
{
throw new Exception($"Expected option contract {expectedContract} to be added but received {added.Symbol}");
throw new RegressionTestException($"Expected option contract {expectedContract.Value} to be added but received {added.Symbol}");
}
_expectedContractIndex++;
@@ -177,21 +174,21 @@ namespace QuantConnect.Algorithm.CSharp
// receive removed event next timestep at 11:31AM
if (Time.TimeOfDay.Hours != 11 || Time.TimeOfDay.Minutes != 31)
{
throw new Exception($"Expected option contracts to be removed at 11:31AM, instead removed at: {Time}");
throw new RegressionTestException($"Expected option contracts to be removed at 11:31AM, instead removed at: {Time}");
}
if (changes.RemovedSecurities
.Where(x => x.Symbol.SecurityType == SecurityType.Option)
.ToHashSet(s => s.Symbol)
.AreDifferent(LinqExtensions.ToHashSet(_expectedContracts)))
.AreDifferent(_expectedContracts.ToHashSet()))
{
throw new Exception("Expected removed securities to equal expected contracts added");
throw new RegressionTestException("Expected removed securities to equal expected contracts added");
}
}
if (Securities.ContainsKey(Underlying))
{
Console.WriteLine($"{Time:o}:: PRICE:: {Securities[Underlying].Price} CHANGES:: {changes}");
Log($"{Time:o}:: PRICE:: {Securities[Underlying].Price} CHANGES:: {changes}");
}
}
@@ -203,21 +200,39 @@ 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 List<Language> Languages { get; } = new() { Language.CSharp };
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 3502;
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 0;
/// <summary>
/// Final status of the algorithm
/// </summary>
public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed;
/// <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 Trades", "6"},
{"Total Orders", "6"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "0%"},
{"Drawdown", "0%"},
{"Expectancy", "0"},
{"Start Equity", "100000"},
{"End Equity", "98784"},
{"Net Profit", "0%"},
{"Sharpe Ratio", "0"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "0%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
@@ -230,26 +245,10 @@ namespace QuantConnect.Algorithm.CSharp
{"Tracking Error", "0"},
{"Treynor Ratio", "0"},
{"Total Fees", "$6.00"},
{"Fitness Score", "0"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "0"},
{"Return Over Maximum Drawdown", "0"},
{"Portfolio Turnover", "0"},
{"Total Insights Generated", "0"},
{"Total Insights Closed", "0"},
{"Total Insights Analysis Completed", "0"},
{"Long Insight Count", "0"},
{"Short Insight Count", "0"},
{"Long/Short Ratio", "100%"},
{"Estimated Monthly Alpha Value", "$0"},
{"Total Accumulated Estimated Alpha Value", "$0"},
{"Mean Population Estimated Insight Value", "$0"},
{"Mean Population Direction", "0%"},
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "731140098"}
{"Estimated Strategy Capacity", "$4000.00"},
{"Lowest Capacity Asset", "GOOCV 305RBQ2BZBZT2|GOOCV VP83T1ZUHROL"},
{"Portfolio Turnover", "2.58%"},
{"OrderListHash", "09f766c470a8bcf4bb6862da52bf25a7"}
};
}
}

View File

@@ -0,0 +1,132 @@
/*
* 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 QuantConnect.Interfaces;
using System.Collections.Generic;
using QuantConnect.Orders;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Regression algorithm making sure the securities cache is reset correctly once it's removed from the algorithm
/// </summary>
public class AddRemoveSecurityCacheRegressionAlgorithm : 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(2013, 10, 07); //Set Start Date
SetEndDate(2013, 10, 11); //Set End Date
SetCash(100000); //Set Strategy Cash
AddEquity("SPY", Resolution.Minute, extendedMarketHours: true);
}
/// <summary>
/// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
/// </summary>
/// <param name="slice">Slice object keyed by symbol containing the stock data</param>
public override void OnData(Slice slice)
{
if (!Portfolio.Invested)
{
SetHoldings("SPY", 1);
}
if (Time.Day == 11)
{
return;
}
if (!ActiveSecurities.ContainsKey("AIG"))
{
var aig = AddEquity("AIG", Resolution.Minute);
var ticket = MarketOrder("AIG", 1);
if (ticket.Status != OrderStatus.Invalid)
{
throw new RegressionTestException("Expected order to always be invalid because there is no data yet!");
}
}
else
{
RemoveSecurity("AIG");
}
}
/// <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 List<Language> Languages { get; } = new() { Language.CSharp };
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 11202;
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 0;
/// <summary>
/// Final status of the algorithm
/// </summary>
public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed;
/// <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", "19"},
{"Average Win", "0%"},
{"Average Loss", "0.00%"},
{"Compounding Annual Return", "271.720%"},
{"Drawdown", "2.500%"},
{"Expectancy", "-1"},
{"Start Equity", "100000"},
{"End Equity", "101753.84"},
{"Net Profit", "1.754%"},
{"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.616"},
{"Beta", "0.81"},
{"Annual Standard Deviation", "0.185"},
{"Annual Variance", "0.034"},
{"Information Ratio", "3.961"},
{"Tracking Error", "0.061"},
{"Treynor Ratio", "2.737"},
{"Total Fees", "$21.45"},
{"Estimated Strategy Capacity", "$830000.00"},
{"Lowest Capacity Asset", "SPY R735QTJ8XC9X"},
{"Portfolio Turnover", "20.49%"},
{"OrderListHash", "6ebe462373e2ecc22de8eb2fe114d704"}
};
}
}

View File

@@ -18,6 +18,7 @@ using System.Collections.Generic;
using QuantConnect.Data.Market;
using QuantConnect.Orders;
using QuantConnect.Interfaces;
using QuantConnect.Data;
namespace QuantConnect.Algorithm.CSharp
{
@@ -51,7 +52,7 @@ namespace QuantConnect.Algorithm.CSharp
/// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
/// </summary>
/// <param name="data">Slice object keyed by symbol containing the stock data</param>
public void OnData(TradeBars data)
public override void OnData(Slice slice)
{
if (lastAction.Date == Time.Date) return;
@@ -104,53 +105,55 @@ 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, Language.Python };
public List<Language> Languages { get; } = new() { Language.CSharp, Language.Python };
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 7063;
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 0;
/// <summary>
/// Final status of the algorithm
/// </summary>
public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed;
/// <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 Trades", "5"},
{"Average Win", "0.47%"},
{"Total Orders", "5"},
{"Average Win", "0.46%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "293.067%"},
{"Compounding Annual Return", "296.356%"},
{"Drawdown", "1.400%"},
{"Expectancy", "0"},
{"Net Profit", "1.765%"},
{"Sharpe Ratio", "13.11"},
{"Probabilistic Sharpe Ratio", "80.231%"},
{"Start Equity", "100000"},
{"End Equity", "101776.32"},
{"Net Profit", "1.776%"},
{"Sharpe Ratio", "12.966"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "80.409%"},
{"Loss Rate", "0%"},
{"Win Rate", "100%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "0.705"},
{"Beta", "0.7"},
{"Annual Standard Deviation", "0.157"},
{"Annual Variance", "0.025"},
{"Information Ratio", "1.76"},
{"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.933"},
{"Total Fees", "$26.39"},
{"Fitness Score", "0.374"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "79228162514264337593543950335"},
{"Return Over Maximum Drawdown", "373.973"},
{"Portfolio Turnover", "0.374"},
{"Total Insights Generated", "0"},
{"Total Insights Closed", "0"},
{"Total Insights Analysis Completed", "0"},
{"Long Insight Count", "0"},
{"Short Insight Count", "0"},
{"Long/Short Ratio", "100%"},
{"Estimated Monthly Alpha Value", "$0"},
{"Total Accumulated Estimated Alpha Value", "$0"},
{"Mean Population Estimated Insight Value", "$0"},
{"Mean Population Direction", "0%"},
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "1779055144"}
{"Treynor Ratio", "2.935"},
{"Total Fees", "$28.30"},
{"Estimated Strategy Capacity", "$4700000.00"},
{"Lowest Capacity Asset", "AIG R735QTJ8XC9X"},
{"Portfolio Turnover", "29.88%"},
{"OrderListHash", "6061ecfbb89eb365dff913410d279b7c"}
};
}
}

View File

@@ -57,53 +57,55 @@ 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, Language.Python };
public List<Language> Languages { get; } = new() { 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>
/// Final status of the algorithm
/// </summary>
public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed;
/// <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 Trades", "3"},
{"Total Orders", "3"},
{"Average Win", "1.02%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "289.119%"},
{"Compounding Annual Return", "296.066%"},
{"Drawdown", "2.200%"},
{"Expectancy", "0"},
{"Net Profit", "1.752%"},
{"Sharpe Ratio", "9.235"},
{"Probabilistic Sharpe Ratio", "68.013%"},
{"Start Equity", "100000"},
{"End Equity", "101775.37"},
{"Net Profit", "1.775%"},
{"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"},
{"Beta", "1.022"},
{"Annual Standard Deviation", "0.224"},
{"Annual Variance", "0.05"},
{"Information Ratio", "24.59"},
{"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.029"},
{"Total Fees", "$9.77"},
{"Fitness Score", "0.747"},
{"Kelly Criterion Estimate", "38.64"},
{"Kelly Criterion Probability Value", "0.229"},
{"Sortino Ratio", "79228162514264337593543950335"},
{"Return Over Maximum Drawdown", "107.109"},
{"Portfolio Turnover", "0.747"},
{"Total Insights Generated", "100"},
{"Total Insights Closed", "99"},
{"Total Insights Analysis Completed", "99"},
{"Long Insight Count", "100"},
{"Short Insight Count", "0"},
{"Long/Short Ratio", "100%"},
{"Estimated Monthly Alpha Value", "$126657.6305"},
{"Total Accumulated Estimated Alpha Value", "$20405.9516"},
{"Mean Population Estimated Insight Value", "$206.1207"},
{"Mean Population Direction", "54.5455%"},
{"Mean Population Magnitude", "54.5455%"},
{"Rolling Averaged Population Direction", "59.8056%"},
{"Rolling Averaged Population Magnitude", "59.8056%"},
{"OrderListHash", "-887190565"}
{"Treynor Ratio", "2.079"},
{"Total Fees", "$10.33"},
{"Estimated Strategy Capacity", "$38000000.00"},
{"Lowest Capacity Asset", "SPY R735QTJ8XC9X"},
{"Portfolio Turnover", "59.74%"},
{"OrderListHash", "5d7657ec9954875eca633bed711085d3"}
};
}
}

View File

@@ -0,0 +1,150 @@
/*
* 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.Linq;
using QuantConnect.Data;
using QuantConnect.Interfaces;
using System.Collections.Generic;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Regression algorithm reproducing issue where underlying option contract would be removed with the first call
/// too RemoveOptionContract
/// </summary>
public class AddTwoAndRemoveOneOptionContractRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
{
private Symbol _contract1;
private Symbol _contract2;
private bool _hasRemoved;
public override void Initialize()
{
SetStartDate(2014, 06, 06);
SetEndDate(2014, 06, 06);
UniverseSettings.DataNormalizationMode = DataNormalizationMode.Raw;
UniverseSettings.MinimumTimeInUniverse = TimeSpan.Zero;
var aapl = QuantConnect.Symbol.Create("AAPL", SecurityType.Equity, Market.USA);
var contracts = OptionChain(aapl)
.OrderBy(x => x.ID.StrikePrice)
.Where(optionContract => optionContract.ID.OptionRight == OptionRight.Call
&& optionContract.ID.OptionStyle == OptionStyle.American)
.Take(2)
.ToList();
_contract1 = contracts[0];
_contract2 = contracts[1];
AddOptionContract(_contract1);
AddOptionContract(_contract2);
}
public override void OnData(Slice slice)
{
if (slice.HasData)
{
if (!_hasRemoved)
{
RemoveOptionContract(_contract1);
_hasRemoved = true;
}
else
{
var subscriptions =
SubscriptionManager.SubscriptionDataConfigService.GetSubscriptionDataConfigs("AAPL");
if (subscriptions.Count == 0)
{
throw new RegressionTestException("No configuration for underlying was found!");
}
if (!Portfolio.Invested)
{
Buy(_contract2, 1);
}
}
}
}
public override void OnEndOfAlgorithm()
{
if (!_hasRemoved)
{
throw new RegressionTestException("Expect a single call to OnData where we removed the option and underlying");
}
}
/// <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 List<Language> Languages { get; } = new() { Language.CSharp };
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 1578;
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 1;
/// <summary>
/// Final status of the algorithm
/// </summary>
public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed;
/// <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"},
{"Start Equity", "100000"},
{"End Equity", "99238"},
{"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", "$2.00"},
{"Estimated Strategy Capacity", "$6200000.00"},
{"Lowest Capacity Asset", "AAPL VXBK4QA5EM92|AAPL R735QTJ8XC9X"},
{"Portfolio Turnover", "90.27%"},
{"OrderListHash", "a111609c2c64554268539b5798e5b31f"}
};
}
}

View File

@@ -57,14 +57,14 @@ namespace QuantConnect.Algorithm.CSharp
{
if (UniverseManager.Count != 3)
{
throw new Exception("Unexpected universe count");
throw new RegressionTestException("Unexpected universe count");
}
if (UniverseManager.ActiveSecurities.Count != 3
|| UniverseManager.ActiveSecurities.Keys.All(symbol => symbol.Value != "SPY")
|| UniverseManager.ActiveSecurities.Keys.All(symbol => symbol.Value != "AAPL")
|| UniverseManager.ActiveSecurities.Keys.All(symbol => symbol.Value != "FB"))
{
throw new Exception("Unexpected active securities");
throw new RegressionTestException("Unexpected active securities");
}
}
@@ -76,53 +76,55 @@ 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, Language.Python };
public List<Language> Languages { get; } = new() { Language.CSharp, Language.Python };
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 50;
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 0;
/// <summary>
/// Final status of the algorithm
/// </summary>
public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed;
/// <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 Trades", "10"},
{"Average Win", "0%"},
{"Average Loss", "-0.01%"},
{"Compounding Annual Return", "-14.333%"},
{"Drawdown", "3.300%"},
{"Expectancy", "-1"},
{"Net Profit", "-0.169%"},
{"Sharpe Ratio", "-0.131"},
{"Probabilistic Sharpe Ratio", "45.057%"},
{"Loss Rate", "100%"},
{"Win Rate", "0%"},
{"Total Orders", "6"},
{"Average Win", "0.01%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "1296.838%"},
{"Drawdown", "0.400%"},
{"Expectancy", "0"},
{"Start Equity", "100000"},
{"End Equity", "102684.23"},
{"Net Profit", "2.684%"},
{"Sharpe Ratio", "34.319"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "0%"},
{"Loss Rate", "0%"},
{"Win Rate", "100%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "-3.068"},
{"Beta", "0.595"},
{"Annual Standard Deviation", "0.382"},
{"Annual Variance", "0.146"},
{"Information Ratio", "-13.618"},
{"Tracking Error", "0.376"},
{"Treynor Ratio", "-0.084"},
{"Total Fees", "$13.98"},
{"Fitness Score", "0.146"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "1"},
{"Sortino Ratio", "79228162514264337593543950335"},
{"Return Over Maximum Drawdown", "-4.398"},
{"Portfolio Turnover", "0.268"},
{"Total Insights Generated", "15"},
{"Total Insights Closed", "12"},
{"Total Insights Analysis Completed", "12"},
{"Long Insight Count", "15"},
{"Short Insight Count", "0"},
{"Long/Short Ratio", "100%"},
{"Estimated Monthly Alpha Value", "$0"},
{"Total Accumulated Estimated Alpha Value", "$0"},
{"Mean Population Estimated Insight Value", "$0"},
{"Mean Population Direction", "0%"},
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "1917702312"}
{"Alpha", "-5.738"},
{"Beta", "1.381"},
{"Annual Standard Deviation", "0.246"},
{"Annual Variance", "0.06"},
{"Information Ratio", "-26.937"},
{"Tracking Error", "0.068"},
{"Treynor Ratio", "6.106"},
{"Total Fees", "$18.61"},
{"Estimated Strategy Capacity", "$980000000.00"},
{"Lowest Capacity Asset", "FB V6OIPNZEM8V9"},
{"Portfolio Turnover", "25.56%"},
{"OrderListHash", "5ee20c8556d706ab0a63ae41b6579c62"}
};
}
}

View File

@@ -37,6 +37,10 @@ namespace QuantConnect.Algorithm.CSharp
// Set requested data resolution
UniverseSettings.Resolution = Resolution.Daily;
// Order margin value has to have a minimum of 0.5% of Portfolio value, allows filtering out small trades and reduce fees.
// Commented so regression algorithm is more sensitive
//Settings.MinimumOrderMarginPortfolioPercentage = 0.005m;
SetStartDate(2014, 03, 24);
SetEndDate(2014, 04, 07);
SetCash(100000);
@@ -64,14 +68,14 @@ namespace QuantConnect.Algorithm.CSharp
{
if (UniverseManager.Count != 3)
{
throw new Exception("Unexpected universe count");
throw new RegressionTestException("Unexpected universe count");
}
if (UniverseManager.ActiveSecurities.Count != 3
|| UniverseManager.ActiveSecurities.Keys.All(symbol => symbol.Value != "SPY")
|| UniverseManager.ActiveSecurities.Keys.All(symbol => symbol.Value != "AAPL")
|| UniverseManager.ActiveSecurities.Keys.All(symbol => symbol.Value != "FB"))
{
throw new Exception("Unexpected active securities");
throw new RegressionTestException("Unexpected active securities");
}
}
@@ -83,53 +87,55 @@ 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 List<Language> Languages { get; } = new() { Language.CSharp };
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 234015;
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 0;
/// <summary>
/// Final status of the algorithm
/// </summary>
public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed;
/// <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 Trades", "23"},
{"Average Win", "0.00%"},
{"Total Orders", "21"},
{"Average Win", "0.01%"},
{"Average Loss", "-0.01%"},
{"Compounding Annual Return", "-75.307%"},
{"Drawdown", "5.800%"},
{"Expectancy", "-0.859"},
{"Net Profit", "-5.586%"},
{"Sharpe Ratio", "-3.257"},
{"Probabilistic Sharpe Ratio", "5.931%"},
{"Loss Rate", "92%"},
{"Win Rate", "8%"},
{"Compounding Annual Return", "-77.566%"},
{"Drawdown", "6.000%"},
{"Expectancy", "-0.811"},
{"Start Equity", "100000"},
{"End Equity", "94042.73"},
{"Net Profit", "-5.957%"},
{"Sharpe Ratio", "-3.345"},
{"Sortino Ratio", "-3.766"},
{"Probabilistic Sharpe Ratio", "4.557%"},
{"Loss Rate", "89%"},
{"Win Rate", "11%"},
{"Profit-Loss Ratio", "0.70"},
{"Alpha", "-0.593"},
{"Beta", "0.692"},
{"Annual Standard Deviation", "0.204"},
{"Annual Variance", "0.042"},
{"Information Ratio", "-2.884"},
{"Tracking Error", "0.194"},
{"Treynor Ratio", "-0.962"},
{"Total Fees", "$25.92"},
{"Fitness Score", "0.004"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "1"},
{"Sortino Ratio", "-4.462"},
{"Return Over Maximum Drawdown", "-13.032"},
{"Portfolio Turnover", "0.083"},
{"Total Insights Generated", "33"},
{"Total Insights Closed", "30"},
{"Total Insights Analysis Completed", "30"},
{"Long Insight Count", "33"},
{"Short Insight Count", "0"},
{"Long/Short Ratio", "100%"},
{"Estimated Monthly Alpha Value", "$0"},
{"Total Accumulated Estimated Alpha Value", "$0"},
{"Mean Population Estimated Insight Value", "$0"},
{"Mean Population Direction", "0%"},
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "-1674230481"}
{"Alpha", "-0.519"},
{"Beta", "1.491"},
{"Annual Standard Deviation", "0.2"},
{"Annual Variance", "0.04"},
{"Information Ratio", "-3.878"},
{"Tracking Error", "0.147"},
{"Treynor Ratio", "-0.449"},
{"Total Fees", "$29.11"},
{"Estimated Strategy Capacity", "$680000000.00"},
{"Lowest Capacity Asset", "AAPL R735QTJ8XC9X"},
{"Portfolio Turnover", "7.48%"},
{"OrderListHash", "2c814c55e7d7c56482411c065b861b33"}
};
}
}

View File

@@ -0,0 +1,205 @@
/*
* 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.Configuration;
using QuantConnect.Data;
using QuantConnect.Data.Auxiliary;
using QuantConnect.Interfaces;
using QuantConnect.Util;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Regression algorithm to test volume adjusted behavior
/// </summary>
public class AdjustedVolumeRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
{
private Symbol _aapl;
private const string Ticker = "AAPL";
private CorporateFactorProvider _factorFile;
private readonly IEnumerator<decimal> _expectedAdjustedVolume = new List<decimal> { 6164842, 3044047, 3680347, 3468303, 2169943, 2652523,
1499707, 1518215, 1655219, 1510487 }.GetEnumerator();
private readonly IEnumerator<decimal> _expectedAdjustedAskSize = new List<decimal> { 215600, 5600, 25200, 8400, 5600, 5600, 2800,
8400, 14000, 2800 }.GetEnumerator();
private readonly IEnumerator<decimal> _expectedAdjustedBidSize = new List<decimal> { 2800, 11200, 2800, 2800, 2800, 5600, 11200,
8400, 30800, 2800 }.GetEnumerator();
public override void Initialize()
{
SetStartDate(2014, 6, 5); //Set Start Date
SetEndDate(2014, 6, 5); //Set End Date
UniverseSettings.DataNormalizationMode = DataNormalizationMode.SplitAdjusted;
_aapl = AddEquity(Ticker, Resolution.Minute).Symbol;
var dataProvider =
Composer.Instance.GetExportedValueByTypeName<IDataProvider>(Config.Get("data-provider",
"DefaultDataProvider"));
var mapFileProvider = new LocalDiskMapFileProvider();
mapFileProvider.Initialize(dataProvider);
var factorFileProvider = new LocalDiskFactorFileProvider();
factorFileProvider.Initialize(mapFileProvider, dataProvider);
_factorFile = factorFileProvider.Get(_aapl) as CorporateFactorProvider;
}
/// <summary>
/// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
/// </summary>
/// <param name="data">Slice object keyed by symbol containing the stock data</param>
public override void OnData(Slice slice)
{
if (!Portfolio.Invested)
{
SetHoldings(_aapl, 1);
}
if (slice.Splits.ContainsKey(_aapl))
{
Log(slice.Splits[_aapl].ToString());
}
if (slice.Bars.ContainsKey(_aapl))
{
var aaplData = slice.Bars[_aapl];
// Assert our volume matches what we expect
if (_expectedAdjustedVolume.MoveNext() && _expectedAdjustedVolume.Current != aaplData.Volume)
{
// Our values don't match lets try and give a reason why
var dayFactor = _factorFile.GetPriceScale(aaplData.Time, DataNormalizationMode.SplitAdjusted);
var probableAdjustedVolume = aaplData.Volume / dayFactor;
if (_expectedAdjustedVolume.Current == probableAdjustedVolume)
{
throw new ArgumentException($"Volume was incorrect; but manually adjusted value is correct." +
$" Adjustment by multiplying volume by {1 / dayFactor} is not occurring.");
}
else
{
throw new ArgumentException($"Volume was incorrect; even when adjusted manually by" +
$" multiplying volume by {1 / dayFactor}. Data may have changed.");
}
}
}
if (slice.QuoteBars.ContainsKey(_aapl))
{
var aaplQuoteData = slice.QuoteBars[_aapl];
// Assert our askSize matches what we expect
if (_expectedAdjustedAskSize.MoveNext() && _expectedAdjustedAskSize.Current != aaplQuoteData.LastAskSize)
{
// Our values don't match lets try and give a reason why
var dayFactor = _factorFile.GetPriceScale(aaplQuoteData.Time, DataNormalizationMode.SplitAdjusted);
var probableAdjustedAskSize = aaplQuoteData.LastAskSize / dayFactor;
if (_expectedAdjustedAskSize.Current == probableAdjustedAskSize)
{
throw new ArgumentException($"Ask size was incorrect; but manually adjusted value is correct." +
$" Adjustment by multiplying size by {1 / dayFactor} is not occurring.");
}
else
{
throw new ArgumentException($"Ask size was incorrect; even when adjusted manually by" +
$" multiplying size by {1 / dayFactor}. Data may have changed.");
}
}
// Assert our bidSize matches what we expect
if (_expectedAdjustedBidSize.MoveNext() && _expectedAdjustedBidSize.Current != aaplQuoteData.LastBidSize)
{
// Our values don't match lets try and give a reason why
var dayFactor = _factorFile.GetPriceScale(aaplQuoteData.Time, DataNormalizationMode.SplitAdjusted);
var probableAdjustedBidSize = aaplQuoteData.LastBidSize / dayFactor;
if (_expectedAdjustedBidSize.Current == probableAdjustedBidSize)
{
throw new ArgumentException($"Bid size was incorrect; but manually adjusted value is correct." +
$" Adjustment by multiplying size by {1 / dayFactor} is not occurring.");
}
else
{
throw new ArgumentException($"Bid size was incorrect; even when adjusted manually by" +
$" multiplying size by {1 / dayFactor}. Data may have changed.");
}
}
}
}
/// <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 List<Language> Languages { get; } = new() { Language.CSharp };
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 795;
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 0;
/// <summary>
/// Final status of the algorithm
/// </summary>
public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed;
/// <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", "1"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "0%"},
{"Drawdown", "0%"},
{"Expectancy", "0"},
{"Start Equity", "100000"},
{"End Equity", "100146.57"},
{"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", "$21.60"},
{"Estimated Strategy Capacity", "$42000000.00"},
{"Lowest Capacity Asset", "AAPL R735QTJ8XC9X"},
{"Portfolio Turnover", "99.56%"},
{"OrderListHash", "60f03c8c589a4f814dc4e8945df23207"}
};
}
}

View File

@@ -0,0 +1,119 @@
/*
* 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.Interfaces;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Algorithm asserting the correct values for the deployment target and algorithm mode.
/// </summary>
public class AlgorithmModeAndDeploymentTargetAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
{
public override void Initialize()
{
SetStartDate(2013, 10, 07);
SetEndDate(2013, 10, 07);
SetCash(100000);
Debug($"Algorithm Mode: {AlgorithmMode}. Is Live Mode: {LiveMode}. Deployment Target: {DeploymentTarget}.");
if (AlgorithmMode != AlgorithmMode.Backtesting)
{
throw new RegressionTestException($"Algorithm mode is not backtesting. Actual: {AlgorithmMode}");
}
if (LiveMode)
{
throw new RegressionTestException("Algorithm should not be live");
}
if (DeploymentTarget != DeploymentTarget.LocalPlatform)
{
throw new RegressionTestException($"Algorithm deployment target is not local. Actual{DeploymentTarget}");
}
// For a live deployment these checks should pass:
//if (AlgorithmMode != AlgorithmMode.Live) throw new RegressionTestException("Algorithm mode is not live");
//if (!LiveMode) throw new RegressionTestException("Algorithm should be live");
// For a cloud deployment these checks should pass:
//if (DeploymentTarget != DeploymentTarget.CloudPlatform) throw new RegressionTestException("Algorithm deployment target is not cloud");
Quit();
}
/// <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 List<Language> Languages { get; } = new() { Language.CSharp, Language.Python };
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 0;
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 0;
/// <summary>
/// Final status of the algorithm
/// </summary>
public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed;
/// <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"},
{"Start Equity", "100000"},
{"End Equity", "100000"},
{"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", ""},
{"Portfolio Turnover", "0%"},
{"OrderListHash", "d41d8cd98f00b204e9800998ecf8427e"}
};
}
}

View File

@@ -0,0 +1,287 @@
/*
* 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 System.Linq;
using QuantConnect.Brokerages;
using QuantConnect.Securities;
using QuantConnect.Data;
using QuantConnect.Data.Shortable;
using QuantConnect.Data.UniverseSelection;
using QuantConnect.Interfaces;
using System.IO;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Tests filtering in coarse selection by shortable quantity
/// </summary>
public class AllShortableSymbolsCoarseSelectionRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
{
private static readonly DateTime _20140325 = new DateTime(2014, 3, 25);
private static readonly DateTime _20140326 = new DateTime(2014, 3, 26);
private static readonly DateTime _20140327 = new DateTime(2014, 3, 27);
private static readonly DateTime _20140328 = new DateTime(2014, 3, 28);
private static readonly DateTime _20140329 = new DateTime(2014, 3, 29);
private static readonly Symbol _aapl = QuantConnect.Symbol.Create("AAPL", SecurityType.Equity, Market.USA);
private static readonly Symbol _bac = QuantConnect.Symbol.Create("BAC", SecurityType.Equity, Market.USA);
private static readonly Symbol _gme = QuantConnect.Symbol.Create("GME", SecurityType.Equity, Market.USA);
private static readonly Symbol _goog = QuantConnect.Symbol.Create("GOOG", SecurityType.Equity, Market.USA);
private static readonly Symbol _qqq = QuantConnect.Symbol.Create("QQQ", SecurityType.Equity, Market.USA);
private static readonly Symbol _spy = QuantConnect.Symbol.Create("SPY", SecurityType.Equity, Market.USA);
private DateTime _lastTradeDate;
private static readonly Dictionary<DateTime, bool> _coarseSelected = new Dictionary<DateTime, bool>
{
{ _20140325, false },
{ _20140326, false },
{ _20140327, false },
{ _20140328, false },
};
private static readonly Dictionary<DateTime, Symbol[]> _expectedSymbols = new Dictionary<DateTime, Symbol[]>
{
{ _20140325, new[]
{
_bac,
_qqq,
_spy
}
},
{ _20140326, new[]
{
_spy
}
},
{ _20140327, new[]
{
_aapl,
_bac,
_gme,
_qqq,
_spy,
}
},
{ _20140328, new[]
{
_goog
}
},
{ _20140329, new Symbol[0] }
};
private Security _security;
public override void Initialize()
{
SetStartDate(2014, 3, 25);
SetEndDate(2014, 3, 29);
SetCash(10000000);
_security = AddEquity(_spy);
_security.SetShortableProvider(new RegressionTestShortableProvider());
AddUniverse(CoarseSelection);
UniverseSettings.Resolution = Resolution.Daily;
SetBrokerageModel(new AllShortableSymbolsRegressionAlgorithmBrokerageModel());
}
public override void OnData(Slice slice)
{
if (Time.Date == _lastTradeDate)
{
return;
}
foreach (var (symbol, security) in ActiveSecurities.Where(kvp => !kvp.Value.Invested).OrderBy(kvp => kvp.Key))
{
var shortableQuantity = security.ShortableProvider.ShortableQuantity(symbol, Time);
if (shortableQuantity == null)
{
throw new RegressionTestException($"Expected {symbol} to be shortable on {Time:yyyy-MM-dd}");
}
// Buy at least once into all Symbols. Since daily data will always use
// MOO orders, it makes the testing of liquidating buying into Symbols difficult.
MarketOrder(symbol, -(decimal)shortableQuantity);
_lastTradeDate = Time.Date;
}
}
private IEnumerable<Symbol> CoarseSelection(IEnumerable<CoarseFundamental> coarse)
{
var shortableSymbols = (_security.ShortableProvider as dynamic).AllShortableSymbols(Time);
var selectedSymbols = coarse
.Select(x => x.Symbol)
.Where(s => shortableSymbols.ContainsKey(s) && shortableSymbols[s] >= 500)
.OrderBy(s => s)
.ToList();
var expectedMissing = 0;
if (Time.Date == _20140327)
{
var gme = QuantConnect.Symbol.Create("GME", SecurityType.Equity, Market.USA);
if (!shortableSymbols.ContainsKey(gme))
{
throw new RegressionTestException("Expected unmapped GME in shortable symbols list on 2014-03-27");
}
if (!coarse.Select(x => x.Symbol.Value).Contains("GME"))
{
throw new RegressionTestException("Expected mapped GME in coarse symbols on 2014-03-27");
}
expectedMissing = 1;
}
var missing = _expectedSymbols[Time.Date].Except(selectedSymbols).ToList();
if (missing.Count != expectedMissing)
{
throw new RegressionTestException($"Expected Symbols selected on {Time.Date:yyyy-MM-dd} to match expected Symbols, but the following Symbols were missing: {string.Join(", ", missing.Select(s => s.ToString()))}");
}
_coarseSelected[Time.Date] = true;
return selectedSymbols;
}
public override void OnEndOfAlgorithm()
{
if (!_coarseSelected.Values.All(x => x))
{
throw new AggregateException($"Expected coarse selection on all dates, but didn't run on: {string.Join(", ", _coarseSelected.Where(kvp => !kvp.Value).Select(kvp => kvp.Key.ToStringInvariant("yyyy-MM-dd")))}");
}
}
private class AllShortableSymbolsRegressionAlgorithmBrokerageModel : DefaultBrokerageModel
{
public AllShortableSymbolsRegressionAlgorithmBrokerageModel() : base()
{
}
public override IShortableProvider GetShortableProvider(Security security)
{
return new RegressionTestShortableProvider();
}
}
private class RegressionTestShortableProvider : LocalDiskShortableProvider
{
public RegressionTestShortableProvider() : base("testbrokerage")
{
}
/// <summary>
/// Gets a list of all shortable Symbols, including the quantity shortable as a Dictionary.
/// </summary>
/// <param name="localTime">The algorithm's local time</param>
/// <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.
// If not, then we return a list of all Symbols with quantity set to zero.
var i = 0;
while (i <= 7)
{
var shortableListFile = Path.Combine(shortableDataDirectory, "dates", $"{localTime.AddDays(-i):yyyyMMdd}.csv");
foreach (var line in DataProvider.ReadLines(shortableListFile))
{
var csv = line.Split(',');
var ticker = csv[0];
var symbol = new Symbol(
SecurityIdentifier.GenerateEquity(ticker, QuantConnect.Market.USA,
mappingResolveDate: localTime), ticker);
var quantity = Parse.Long(csv[1]);
allSymbols[symbol] = quantity;
}
if (allSymbols.Count > 0)
{
return allSymbols;
}
i++;
}
// Return our empty dictionary if we did not find a file to extract
return allSymbols;
}
}
/// <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 List<Language> Languages { get; } = new() { Language.CSharp, Language.Python };
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 36573;
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 0;
/// <summary>
/// Final status of the algorithm
/// </summary>
public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed;
/// <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", "8"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "11.027%"},
{"Drawdown", "0.000%"},
{"Expectancy", "0"},
{"Start Equity", "10000000"},
{"End Equity", "10011469.88"},
{"Net Profit", "0.115%"},
{"Sharpe Ratio", "11.963"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "0%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "0.07"},
{"Beta", "-0.077"},
{"Annual Standard Deviation", "0.008"},
{"Annual Variance", "0"},
{"Information Ratio", "3.876"},
{"Tracking Error", "0.105"},
{"Treynor Ratio", "-1.215"},
{"Total Fees", "$282.50"},
{"Estimated Strategy Capacity", "$61000000000.00"},
{"Lowest Capacity Asset", "NB R735QTJ8XC9X"},
{"Portfolio Turnover", "3.62%"},
{"OrderListHash", "0ea806c53bfa2bdca2504ba7155ef130"}
};
}
}

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

@@ -1,165 +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 System.Linq;
using QuantConnect.Data;
using QuantConnect.Indicators;
using QuantConnect.Orders.Fees;
using QuantConnect.Data.Custom;
using System.Collections.Generic;
using QuantConnect.Algorithm.Framework;
using QuantConnect.Algorithm.Framework.Alphas;
using QuantConnect.Algorithm.Framework.Execution;
using QuantConnect.Algorithm.Framework.Portfolio;
using QuantConnect.Algorithm.Framework.Risk;
using QuantConnect.Algorithm.Framework.Selection;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// This Alpha Model uses Wells Fargo 30-year Fixed Rate Mortgage data from Quandl to
/// generate Insights about the movement of Real Estate ETFs. Mortgage rates can provide information
/// regarding the general price trend of real estate, and ETFs provide good continuous-time instruments
/// to measure the impact against. Volatility in mortgage rates tends to put downward pressure on real
/// estate prices, whereas stable mortgage rates, regardless of true rate, lead to stable or higher real
/// estate prices. This Alpha model seeks to take advantage of this correlation by emitting insights
/// based on volatility and rate deviation from its historic mean.
/// This alpha is part of the Benchmark Alpha Series created by QuantConnect which are open
/// sourced so the community and client funds can see an example of an alpha.
/// <summary>
public class MortgageRateVolatilityAlgorithm : QCAlgorithmFramework
{
public override void Initialize()
{
SetStartDate(2017, 1, 1); //Set Start Date
SetCash(100000); //Set Strategy Cash
UniverseSettings.Resolution = Resolution.Daily;
SetSecurityInitializer(security => security.FeeModel = new ConstantFeeModel(0));
// Basket of 6 liquid real estate ETFs
Func<string, Symbol> ToSymbol = x => QuantConnect.Symbol.Create(x, SecurityType.Equity, Market.USA);
var realEstateETFs = new[] { "VNQ", "REET", "TAO", "FREL", "SRET", "HIPS" }.Select(ToSymbol).ToArray();
SetUniverseSelection(new ManualUniverseSelectionModel(realEstateETFs));
SetAlpha(new MortgageRateVolatilityAlphaModel(this));
SetPortfolioConstruction(new EqualWeightingPortfolioConstructionModel());
SetExecution(new ImmediateExecutionModel());
SetRiskManagement(new NullRiskManagementModel());
}
public void OnData(QuandlMortgagePriceColumns data) { }
private class MortgageRateVolatilityAlphaModel : AlphaModel
{
private readonly int _indicatorPeriod;
private readonly Resolution _resolution;
private readonly TimeSpan _insightDuration;
private readonly int _deviations;
private readonly double _insightMagnitude;
private readonly Symbol _mortgageRate;
private readonly SimpleMovingAverage _mortgageRateSma;
private readonly StandardDeviation _mortgageRateStd;
public MortgageRateVolatilityAlphaModel(
QCAlgorithmFramework algorithm,
int indicatorPeriod = 15,
double insightMagnitude = 0.0005,
int deviations = 2,
Resolution resolution = Resolution.Daily
)
{
// Add Quandl data for a Well's Fargo 30-year Fixed Rate mortgage
_mortgageRate = algorithm.AddData<QuandlMortgagePriceColumns>("WFC/PR_GOV_30YFIXEDVA_APR").Symbol;
_indicatorPeriod = indicatorPeriod;
_resolution = resolution;
_insightDuration = resolution.ToTimeSpan().Multiply(indicatorPeriod);
_insightMagnitude = insightMagnitude;
_deviations = deviations;
// Add indicators for the mortgage rate -- Standard Deviation and Simple Moving Average
_mortgageRateStd = algorithm.STD(_mortgageRate, _indicatorPeriod, resolution);
_mortgageRateSma = algorithm.SMA(_mortgageRate, _indicatorPeriod, resolution);
// Use a history call to warm-up the indicators
WarmUpIndicators(algorithm);
}
public override IEnumerable<Insight> Update(QCAlgorithmFramework algorithm, Slice data)
{
var insights = new List<Insight>();
// Return empty list if data slice doesn't contain monrtgage rate data
if (!data.Keys.Contains(_mortgageRate))
{
return insights;
}
// Extract current mortgage rate, the current STD indicator value, and current SMA value
var rate = data[_mortgageRate].Value;
var deviation = _deviations * _mortgageRateStd;
var sma = _mortgageRateSma;
// Loop through all Active Securities to emit insights
foreach (var security in algorithm.ActiveSecurities.Keys)
{
// Mortgage rate Symbol will be in the collection, so skip it
if (security == _mortgageRate)
{
return insights;
}
// If volatility in mortgage rates is high, then we emit an Insight to sell
if ((rate < sma - deviation) || (rate > sma + deviation))
{
insights.Add(Insight.Price(security, _insightDuration, InsightDirection.Down, _insightMagnitude));
}
// If volatility in mortgage rates is low, then we emit an Insight to buy
if ((rate < sma - (decimal)deviation/2) || (rate > sma + (decimal)deviation/2))
{
insights.Add(Insight.Price(security, _insightDuration, InsightDirection.Up, _insightMagnitude));
}
}
return insights;
}
private void WarmUpIndicators(QCAlgorithmFramework algorithm)
{
// Make a history call and update the indicators
algorithm.History(new[] { _mortgageRate }, _indicatorPeriod, _resolution).PushThrough(bar =>
{
_mortgageRateSma.Update(bar.EndTime, bar.Value);
_mortgageRateStd.Update(bar.EndTime, bar.Value);
});
}
}
public class QuandlMortgagePriceColumns : Quandl
{
public QuandlMortgagePriceColumns()
// Rename the Quandl object column to the data we want, which is the 'Value' column
// of the CSV that our API call returns
: base(valueColumnName: "Value")
{
}
}
}
}

View File

@@ -80,14 +80,29 @@ namespace QuantConnect.Algorithm.CSharp.Alphas
/// <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 };
public List<Language> Languages { get; } = new() { Language.CSharp, Language.Python };
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 0;
/// </summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 0;
/// <summary>
/// Final status of the algorithm
/// </summary>
public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed;
/// <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 Trades", "2465"},
{"Total Orders", "2465"},
{"Average Win", "0.26%"},
{"Average Loss", "-0.24%"},
{"Compounding Annual Return", "7.848%"},
@@ -195,4 +210,4 @@ namespace QuantConnect.Algorithm.CSharp.Alphas
UltraShort = ultraShort;
}
}
}
}

View File

@@ -31,7 +31,7 @@ namespace QuantConnect.Algorithm.CSharp.Alphas
/// A number of companies publicly trade two different classes of shares
/// in US equity markets. If both assets trade with reasonable volume, then
/// the underlying driving forces of each should be similar or the same. Given
/// this, we can create a relatively dollar-netural long/short portfolio using
/// this, we can create a relatively dollar-neutral long/short portfolio using
/// the dual share classes. Theoretically, any deviation of this portfolio from
/// its mean-value should be corrected, and so the motivating idea is based on
/// mean-reversion. Using a Simple Moving Average indicator, we can

View File

@@ -109,7 +109,7 @@ namespace QuantConnect.Algorithm.CSharp.Alphas
int barsToConsolidate = 1
)
{
// coefficient that used to determinte upper and lower borders of a breakout channel
// coefficient that used to determine upper and lower borders of a breakout channel
_k1 = k1;
_k2 = k2;
@@ -202,7 +202,7 @@ namespace QuantConnect.Algorithm.CSharp.Alphas
SymbolData symbolData;
if (_symbolDataBySymbol.TryGetValue(removed.Symbol, out symbolData))
{
// unsibscribe consolidator from data updates
// unsubscribe consolidator from data updates
algorithm.SubscriptionManager.RemoveConsolidator(removed.Symbol, symbolData.GetConsolidator());
// remove item from dictionary collection

View File

@@ -1,117 +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 System.Collections.Generic;
using System.Linq;
using QuantConnect.Data;
using QuantConnect.Data.Custom.Benzinga;
using QuantConnect.Data.UniverseSelection;
namespace QuantConnect.Algorithm.CSharp.AltData
{
/// <summary>
/// Benzinga is a provider of news data. Their news is made in-house
/// and covers stock related news such as corporate events.
/// </summary>
public class BenzingaNewsAlgorithm : QCAlgorithm
{
// Predefine a dictionary of words with scores to scan for in the description
// of the Benzinga news article
private readonly Dictionary<string, double> _words = new Dictionary<string, double>()
{
{"bad", -0.5}, {"good", 0.5},
{"negative", -0.5}, {"great", 0.5},
{"growth", 0.5}, {"fail", -0.5},
{"failed", -0.5}, {"success", 0.5},
{"nailed", 0.5}, {"beat", 0.5},
{"missed", -0.5}
};
// Trade only every 5 days
private DateTime _lastTrade = DateTime.MinValue;
/// <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, 6, 5);
SetEndDate(2018, 8, 4);
SetCash(100000);
var aapl = AddEquity("AAPL", Resolution.Hour).Symbol;
var ibm = AddEquity("IBM", Resolution.Hour).Symbol;
AddData<BenzingaNews>(aapl);
AddData<BenzingaNews>(ibm);
}
public override void OnData(Slice data)
{
if ((Time - _lastTrade) < TimeSpan.FromDays(5))
{
return;
}
// Get rid of our holdings after 5 days, and start fresh
Liquidate();
// Get all Benzinga data and loop over it
foreach (var article in data.Get<BenzingaNews>().Values)
{
// Select the same Symbol we're getting a data point for
// from the articles list so that we can get the sentiment of the article.
// We use the underlying Symbol because the Symbols included in the `Symbols` property
// are equity Symbols.
var selectedSymbol = article.Symbols.SingleOrDefault(s => s == article.Symbol.Underlying);
if (selectedSymbol == null)
{
throw new Exception($"Could not find current Symbol {article.Symbol.Underlying} even though it should exist");
}
// The intersection of the article contents and the pre-defined words are the words that are included in both collections
var intersection = article.Contents.ToLowerInvariant().Split(' ').Intersect(_words.Keys);
// Get the words, then get the aggregate sentiment
var sentimentSum = intersection.Select(x => _words[x]).Sum();
if (sentimentSum >= 0.5)
{
Log($"Longing {article.Symbol.Underlying} with sentiment score of {sentimentSum}");
SetHoldings(article.Symbol.Underlying, sentimentSum / 5);
_lastTrade = Time;
}
if (sentimentSum <= -0.5)
{
Log($"Shorting {article.Symbol.Underlying} with sentiment score of {sentimentSum}");
SetHoldings(article.Symbol.Underlying, sentimentSum / 5);
_lastTrade = Time;
}
}
}
public override void OnSecuritiesChanged(SecurityChanges changes)
{
foreach (var r in changes.RemovedSecurities)
{
// If removed from the universe, liquidate and remove the custom data from the algorithm
Liquidate(r.Symbol);
RemoveSecurity(QuantConnect.Symbol.CreateBase(typeof(BenzingaNews), r.Symbol, Market.USA));
}
}
}
}

View File

@@ -1,66 +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 QuantConnect.Data;
using QuantConnect.Data.Custom.CBOE;
using QuantConnect.Data.Custom.Fred;
using QuantConnect.Data.Custom.USEnergy;
namespace QuantConnect.Algorithm.CSharp.AltData
{
public class CachedAlternativeDataAlgorithm : QCAlgorithm
{
private Symbol _cboeVix;
private Symbol _usEnergy;
private Symbol _fredPeakToTrough;
public override void Initialize()
{
SetStartDate(2003, 1, 1);
SetEndDate(2019, 10, 11);
SetCash(100000);
// QuantConnect caches a small subset of alternative data for easy consumption for the community.
// You can use this in your algorithm as demonstrated below:
_cboeVix = AddData<CBOE>("VIX", Resolution.Daily).Symbol;
// United States EIA data: https://eia.gov/
_usEnergy = AddData<USEnergy>(USEnergy.Petroleum.UnitedStates.WeeklyGrossInputsIntoRefineries, Resolution.Daily).Symbol;
// FRED data
_fredPeakToTrough = AddData<Fred>(Fred.OECDRecessionIndicators.UnitedStatesFromPeakThroughTheTrough, Resolution.Daily).Symbol;
}
public override void OnData(Slice data)
{
if (data.ContainsKey(_cboeVix))
{
var vix = data.Get<CBOE>(_cboeVix);
Log($"VIX: {vix}");
}
if (data.ContainsKey(_usEnergy))
{
var inputIntoRefineries = data.Get<USEnergy>(_usEnergy);
Log($"U.S. Input Into Refineries: {Time}, {inputIntoRefineries.Value}");
}
if (data.ContainsKey(_fredPeakToTrough))
{
var peakToTrough = data.Get<Fred>(_fredPeakToTrough);
Log($"OECD based Recession Indicator for the United States from the Peak through the Trough: {peakToTrough}");
}
}
}
}

View File

@@ -1,62 +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.Linq;
using QuantConnect.Data;
using QuantConnect.Data.Custom.Quiver;
namespace QuantConnect.Algorithm.CSharp.AltData
{
/// <summary>
/// Quiver Quantitative is a provider of alternative data.
/// This algorithm shows how to consume the <see cref="QuiverWallStreetBets"/>
/// </summary>
public class QuiverWallStreetBetsDataAlgorithm : QCAlgorithm
{
/// <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(2019, 1, 1);
SetEndDate(2020, 6, 1);
SetCash(100000);
var aapl = AddEquity("AAPL", Resolution.Daily).Symbol;
var quiverWSBSymbol = AddData<QuiverWallStreetBets>(aapl).Symbol;
var history = History<QuiverWallStreetBets>(quiverWSBSymbol, 60, Resolution.Daily);
Debug($"We got {history.Count()} items from our history request");
}
public override void OnData(Slice data)
{
var points = data.Get<QuiverWallStreetBets>();
foreach (var point in points.Values)
{
// Go long in the stock if it was mentioned more than 5 times in the WallStreetBets daily discussion
if (point.Mentions > 5)
{
SetHoldings(point.Symbol.Underlying, 1);
}
// Go short in the stock if it was mentioned less than 5 times in the WallStreetBets daily discussion
if (point.Mentions < 5)
{
SetHoldings(point.Symbol.Underlying, -1);
}
}
}
}
}

View File

@@ -1,99 +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.Collections.Generic;
using System.Linq;
using QuantConnect.Algorithm.Framework.Selection;
using QuantConnect.Data;
using QuantConnect.Data.Custom.SEC;
using QuantConnect.Data.UniverseSelection;
namespace QuantConnect.Algorithm.CSharp
{
public class SECReport8KAlgorithm : QCAlgorithm
{
/// <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(2019, 1, 1);
SetEndDate(2019, 8, 21);
SetCash(100000);
UniverseSettings.Resolution = Resolution.Minute;
AddUniverseSelection(new CoarseFundamentalUniverseSelectionModel(CoarseSelector));
// Request underlying equity data.
var ibm = AddEquity("IBM", Resolution.Minute).Symbol;
// Add SEC report 10-Q data for the underlying IBM asset
var earningsFiling = AddData<SECReport10Q>(ibm, Resolution.Daily).Symbol;
// Request 120 days of history with the SECReport10Q IBM custom data Symbol.
var history = History<SECReport10Q>(earningsFiling, 120, Resolution.Daily);
// Count the number of items we get from our history request
Debug($"We got {history.Count()} items from our history request");
}
public IEnumerable<Symbol> CoarseSelector(IEnumerable<CoarseFundamental> coarse)
{
// Add SEC data from the filtered coarse selection
var symbols = coarse.Where(x => x.HasFundamentalData && x.DollarVolume > 50000000)
.Select(x => x.Symbol)
.Take(10);
foreach (var symbol in symbols)
{
AddData<SECReport8K>(symbol);
}
return symbols;
}
public override void OnData(Slice data)
{
// Store the symbols we want to long in a list
// so that we can have an equal-weighted portfolio
var longEquitySymbols = new List<Symbol>();
// Get all SEC data and loop over it
foreach (var report in data.Get<SECReport8K>().Values)
{
// Get the length of all contents contained within the report
var reportTextLength = report.Report.Documents.Select(x => x.Text.Length).Sum();
if (reportTextLength > 20000)
{
longEquitySymbols.Add(report.Symbol.Underlying);
}
}
foreach (var equitySymbol in longEquitySymbols)
{
SetHoldings(equitySymbol, 1m / longEquitySymbols.Count);
}
}
public override void OnSecuritiesChanged(SecurityChanges changes)
{
foreach (var r in changes.RemovedSecurities)
{
// If removed from the universe, liquidate and remove the custom data from the algorithm
Liquidate(r.Symbol);
RemoveSecurity(QuantConnect.Symbol.CreateBase(typeof(SECReport8K), r.Symbol, Market.USA));
}
}
}
}

View File

@@ -1,90 +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.Collections.Generic;
using System.Linq;
using QuantConnect.Algorithm.Framework.Selection;
using QuantConnect.Data;
using QuantConnect.Data.Custom.SmartInsider;
using QuantConnect.Data.UniverseSelection;
namespace QuantConnect.Algorithm.CSharp
{
public class SmartInsiderTransactionAlgorithm : QCAlgorithm
{
public override void Initialize()
{
SetStartDate(2019, 3, 1);
SetEndDate(2019, 7, 4);
SetCash(1000000);
AddUniverseSelection(new CoarseFundamentalUniverseSelectionModel(CoarseUniverse));
// Request underlying equity data.
var ibm = AddEquity("IBM", Resolution.Minute).Symbol;
// Add Smart Insider stock buyback transaction data for the underlying IBM asset
var si = AddData<SmartInsiderTransaction>(ibm).Symbol;
// Request 60 days of history with the SmartInsiderTransaction IBM Custom Data Symbol.
var history = History<SmartInsiderTransaction>(si, 60, Resolution.Daily);
// Count the number of items we get from our history request
Debug($"We got {history.Count()} items from our history request");
}
public IEnumerable<Symbol> CoarseUniverse(IEnumerable<CoarseFundamental> coarse)
{
var symbols = coarse.Where(x => x.HasFundamentalData && x.DollarVolume > 50000000)
.Select(x => x.Symbol)
.Take(10);
foreach (var symbol in symbols)
{
AddData<SmartInsiderTransaction>(symbol);
}
return symbols;
}
public override void OnData(Slice data)
{
// Get all SmartInsider data available
var transactions = data.Get<SmartInsiderTransaction>();
foreach (var transaction in transactions.Values)
{
if (transaction.VolumePercentage == null || transaction.EventType == null)
{
continue;
}
// Using the Smart Insider transaction information, buy when company does a stock buyback
if (transaction.EventType == SmartInsiderEventType.Transaction && transaction.VolumePercentage > 5)
{
SetHoldings(transaction.Symbol.Underlying, (decimal)transaction.VolumePercentage / 100);
}
}
}
public override void OnSecuritiesChanged(SecurityChanges changes)
{
foreach (var r in changes.RemovedSecurities)
{
// If removed from the universe, liquidate and remove the custom data from the algorithm
Liquidate(r.Symbol);
RemoveSecurity(QuantConnect.Symbol.CreateBase(typeof(SmartInsiderTransaction), r.Symbol, Market.USA));
}
}
}
}

View File

@@ -1,85 +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.Collections.Generic;
using System.Linq;
using QuantConnect.Data;
using QuantConnect.Data.Custom.Tiingo;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Look for positive and negative words in the news article description
/// and trade based on the sum of the sentiment
/// </summary>
public class TiingoNewsAlgorithm : QCAlgorithm
{
private Symbol _tiingoSymbol;
// Predefine a dictionary of words with scores to scan for in the description
// of the Tiingo news article
private readonly Dictionary<string, double> _words = new Dictionary<string, double>()
{
{"bad", -0.5}, {"good", 0.5},
{ "negative", -0.5}, {"great", 0.5},
{"growth", 0.5}, {"fail", -0.5},
{"failed", -0.5}, {"success", 0.5},
{"nailed", 0.5}, {"beat", 0.5},
{"missed", -0.5}
};
public override void Initialize()
{
SetStartDate(2019, 6, 10);
SetEndDate(2019, 10, 3);
SetCash(100000);
var aapl = AddEquity("AAPL", Resolution.Hour).Symbol;
_tiingoSymbol = AddData<TiingoNews>(aapl).Symbol;
// Request underlying equity data
var ibm = AddEquity("IBM", Resolution.Minute).Symbol;
// Add news data for the underlying IBM asset
var news = AddData<TiingoNews>(ibm).Symbol;
// Request 60 days of history with the TiingoNews IBM Custom Data Symbol.
var history = History<TiingoNews>(news, 60, Resolution.Daily);
// Count the number of items we get from our history request
Debug($"We got {history.Count()} items from our history request");
}
public override void OnData(Slice data)
{
//Confirm that the data is in the collection
if (!data.ContainsKey(_tiingoSymbol)) return;
// Gets the first piece of data from the Slice
var article = data.Get<TiingoNews>(_tiingoSymbol);
// Article descriptions come in all caps. Lower and split by word
var descriptionWords = article.Description.ToLowerInvariant().Split(' ');
// Take the intersection of predefined words and the words in the
// description to get a list of matching words
var intersection = _words.Keys.Intersect(descriptionWords);
// Get the sum of the article's sentiment, and go long or short
// depending if it's a positive or negative description
var sentiment = intersection.Select(x => _words[x]).Sum();
SetHoldings(article.Symbol.Underlying, sentiment);
}
}
}

View File

@@ -1,80 +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.Linq;
using QuantConnect.Data;
using QuantConnect.Data.Custom.TradingEconomics;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Trades on interest rate announcements from data provided by Trading Economics
/// </summary>
public class TradingEconomicsAlgorithm : QCAlgorithm
{
private Symbol _interestRate;
public override void Initialize()
{
SetStartDate(2013, 11, 1);
SetEndDate(2019, 10, 3);
SetCash(100000);
AddEquity("AGG", Resolution.Hour);
AddEquity("SPY", Resolution.Hour);
_interestRate = AddData<TradingEconomicsCalendar>(TradingEconomics.Calendar.UnitedStates.InterestRate).Symbol;
// Request 365 days of interest rate history with the TradingEconomicsCalendar custom data Symbol.
// We should expect no historical data because 2013-11-01 is before the absolute first point of data
var history = History<TradingEconomicsCalendar>(_interestRate, 365, Resolution.Daily);
// Count the number of items we get from our history request (should be zero)
Debug($"We got {history.Count()} items from our history request");
}
public override void OnData(Slice data)
{
// Make sure we have an interest rate calendar event
if (!data.ContainsKey(_interestRate))
{
return;
}
var announcement = data.Get<TradingEconomicsCalendar>(_interestRate);
// Confirm it's a FED Rate Decision
if (announcement.Event != TradingEconomics.Event.UnitedStates.FedInterestRateDecision)
{
return;
}
// In the event of a rate increase, rebalance 50% to Bonds.
var interestRateDecreased = announcement.Actual <= announcement.Previous;
if (interestRateDecreased)
{
SetHoldings("SPY", 1);
SetHoldings("AGG", 0);
}
else
{
SetHoldings("SPY", 0.5);
SetHoldings("AGG", 0.5);
}
}
}
}

View File

@@ -1,87 +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 System.Linq;
using QuantConnect.Data;
using QuantConnect.Data.Custom.USTreasury;
namespace QuantConnect.Algorithm.CSharp
{
public class USTreasuryYieldCurveRateAlgorithm : QCAlgorithm
{
private Symbol _yieldCurve;
private Symbol _spy;
private DateTime _lastInversion = DateTime.MinValue;
public override void Initialize()
{
SetStartDate(2000, 3, 1);
SetEndDate(2019, 9, 15);
SetCash(100000);
_spy = AddEquity("SPY", Resolution.Hour).Symbol;
_yieldCurve = AddData<USTreasuryYieldCurveRate>("USTYCR", Resolution.Daily).Symbol;
// Request 60 days of history with the USTreasuryYieldCurveRate custom data Symbol.
var history = History<USTreasuryYieldCurveRate>(_yieldCurve, 60, Resolution.Daily);
// Count the number of items we get from our history request
Debug($"We got {history.Count()} items from our history request");
}
public override void OnData(Slice data)
{
if (!data.ContainsKey(_yieldCurve))
{
return;
}
// Preserve null values by getting the data with `slice.Get<T>`
// Accessing the data using `data[_yieldCurve]` results in null
// values becoming `default(decimal)` which is equal to 0
var rates = data.Get<USTreasuryYieldCurveRate>().Values.First();
// Check for null before using the values
if (!rates.TenYear.HasValue || !rates.TwoYear.HasValue)
{
return;
}
// Only advance if a year has gone by
if (Time - _lastInversion < TimeSpan.FromDays(365))
{
return;
}
// if there is a yield curve inversion after not having one for a year, short SPY for two years
if (!Portfolio.Invested && rates.TwoYear > rates.TenYear)
{
Debug($"{Time} - Yield curve inversion! Shorting the market for two years");
SetHoldings(_spy, -0.5);
_lastInversion = Time;
return;
}
// If two years have passed, liquidate our position in SPY
if (Time - _lastInversion >= TimeSpan.FromDays(365 * 2))
{
Liquidate(_spy);
}
}
}
}

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

@@ -0,0 +1,125 @@
/*
* 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.Indicators;
using QuantConnect.Interfaces;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Regression algorithm to test the behaviour of ARMA versus AR models at the same order of differencing.
/// In particular, an ARIMA(1,1,1) and ARIMA(1,1,0) are instantiated while orders are placed if their difference
/// is sufficiently large (which would be due to the inclusion of the MA(1) term).
/// </summary>
public class AutoRegressiveIntegratedMovingAverageRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
{
private AutoRegressiveIntegratedMovingAverage _arima;
private AutoRegressiveIntegratedMovingAverage _ar;
private decimal _last;
public override void Initialize()
{
SetStartDate(2013, 1, 07);
SetEndDate(2013, 12, 11);
Settings.AutomaticIndicatorWarmUp = true;
AddEquity("SPY", Resolution.Daily);
_arima = ARIMA("SPY", 1, 1, 1, 50);
_ar = ARIMA("SPY", 1, 1, 0, 50);
}
public override void OnData(Slice slice)
{
if (_arima.IsReady)
{
if (Math.Abs(_ar.Current.Value - _arima.Current.Value) > 1) // Difference due to MA(1) being included.
{
if (_arima.Current.Value > _last)
{
MarketOrder("SPY", 1);
}
else
{
MarketOrder("SPY", -1);
}
}
_last = _arima.Current.Value;
}
}
/// <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 List<Language> Languages { get; } = new() { Language.CSharp, Language.Python };
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 1893;
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 100;
/// <summary>
/// Final status of the algorithm
/// </summary>
public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed;
/// <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", "53"},
{"Average Win", "0.00%"},
{"Average Loss", "0.00%"},
{"Compounding Annual Return", "0.076%"},
{"Drawdown", "0.100%"},
{"Expectancy", "2.933"},
{"Start Equity", "100000"},
{"End Equity", "100070.90"},
{"Net Profit", "0.071%"},
{"Sharpe Ratio", "-9.164"},
{"Sortino Ratio", "-9.852"},
{"Probabilistic Sharpe Ratio", "36.417%"},
{"Loss Rate", "27%"},
{"Win Rate", "73%"},
{"Profit-Loss Ratio", "4.41"},
{"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.911"},
{"Total Fees", "$53.00"},
{"Estimated Strategy Capacity", "$16000000000.00"},
{"Lowest Capacity Asset", "SPY R735QTJ8XC9X"},
{"Portfolio Turnover", "0.02%"},
{"OrderListHash", "685c37df6e4c49b75792c133be189094"}
};
}
}

View File

@@ -33,9 +33,9 @@ namespace QuantConnect.Algorithm.CSharp
public override void Initialize()
{
UniverseSettings.DataNormalizationMode = DataNormalizationMode.Raw;
EnableAutomaticIndicatorWarmUp = true;
Settings.AutomaticIndicatorWarmUp = true;
SetStartDate(2013, 10, 08);
SetEndDate(2013, 10, 09);
SetEndDate(2013, 10, 10);
var SP500 = QuantConnect.Symbol.Create(Futures.Indices.SP500EMini, SecurityType.Future, Market.CME);
_symbol = FutureChainProvider.GetFutureContractList(SP500, StartDate).First();
@@ -67,7 +67,7 @@ namespace QuantConnect.Algorithm.CSharp
// Test case: custom IndicatorBase<QuoteBar> indicator using Future subscribed symbol
var indicator = new CustomIndicator();
var consolidator = CreateConsolidator(TimeSpan.FromMinutes(1), typeof(QuoteBar));
var consolidator = CreateConsolidator(TimeSpan.FromMinutes(2), typeof(QuoteBar));
RegisterIndicator(_symbol, indicator, consolidator);
AssertIndicatorState(indicator, isReady: false);
@@ -82,7 +82,7 @@ namespace QuantConnect.Algorithm.CSharp
if (!sma11.Current.Equals(sma1.Current))
{
throw new Exception("Expected SMAs warmed up before and after adding the Future to the algorithm to have the same current value. " +
throw new RegressionTestException("Expected SMAs warmed up before and after adding the Future to the algorithm to have the same current value. " +
"The result of 'WarmUpIndicator' shouldn't change if the symbol is or isn't subscribed");
}
@@ -94,7 +94,7 @@ namespace QuantConnect.Algorithm.CSharp
if (!smaSpy.Current.Equals(sma.Current))
{
throw new Exception("Expected SMAs warmed up before and after adding the Equity to the algorithm to have the same current value. " +
throw new RegressionTestException("Expected SMAs warmed up before and after adding the Equity to the algorithm to have the same current value. " +
"The result of 'WarmUpIndicator' shouldn't change if the symbol is or isn't subscribed");
}
}
@@ -103,7 +103,7 @@ namespace QuantConnect.Algorithm.CSharp
{
if (indicator.IsReady != isReady)
{
throw new Exception($"Expected indicator state, expected {isReady} but was {indicator.IsReady}");
throw new RegressionTestException($"Expected indicator state, expected {isReady} but was {indicator.IsReady}");
}
}
@@ -111,7 +111,7 @@ namespace QuantConnect.Algorithm.CSharp
/// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
/// </summary>
/// <param name="data">Slice object keyed by symbol containing the stock data</param>
public override void OnData(Slice data)
public override void OnData(Slice slice)
{
if (!Portfolio.Invested)
{
@@ -141,53 +141,55 @@ 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 List<Language> Languages { get; } = new() { Language.CSharp };
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 6426;
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 84;
/// <summary>
/// Final status of the algorithm
/// </summary>
public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed;
/// <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 Trades", "1"},
{"Total Orders", "1"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "-99.999%"},
{"Drawdown", "16.100%"},
{"Compounding Annual Return", "733913.744%"},
{"Drawdown", "15.900%"},
{"Expectancy", "0"},
{"Net Profit", "-6.366%"},
{"Sharpe Ratio", "1.194"},
{"Start Equity", "100000"},
{"End Equity", "106827.7"},
{"Net Profit", "6.828%"},
{"Sharpe Ratio", "203744786353.299"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "0%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "5.579"},
{"Beta", "-63.972"},
{"Annual Standard Deviation", "0.434"},
{"Annual Variance", "0.188"},
{"Information Ratio", "0.996"},
{"Tracking Error", "0.441"},
{"Treynor Ratio", "-0.008"},
{"Total Fees", "$20.35"},
{"Fitness Score", "0.138"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "-1.727"},
{"Return Over Maximum Drawdown", "-12.061"},
{"Portfolio Turnover", "4.916"},
{"Total Insights Generated", "0"},
{"Total Insights Closed", "0"},
{"Total Insights Analysis Completed", "0"},
{"Long Insight Count", "0"},
{"Short Insight Count", "0"},
{"Long/Short Ratio", "100%"},
{"Estimated Monthly Alpha Value", "$0"},
{"Total Accumulated Estimated Alpha Value", "$0"},
{"Mean Population Estimated Insight Value", "$0"},
{"Mean Population Direction", "0%"},
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "-1453269600"}
{"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.717"},
{"Total Fees", "$23.65"},
{"Estimated Strategy Capacity", "$200000000.00"},
{"Lowest Capacity Asset", "ES VMKLFZIH2MTD"},
{"Portfolio Turnover", "351.80%"},
{"OrderListHash", "dfd9a280d3c6470b305c03e0b72c234e"}
};
}
}

View File

@@ -0,0 +1,126 @@
/*
* 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.Indicators;
using QuantConnect.Interfaces;
using System.Collections.Generic;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Regression algorithm asserting the behavior of the AutomaticIndicatorWarmUp on option greeks
/// </summary>
public class AutomaticIndicatorWarmupOptionIndicatorsMirrorContractsRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
{
public override void Initialize()
{
SetStartDate(2015, 12, 24);
SetEndDate(2015, 12, 24);
Settings.AutomaticIndicatorWarmUp = true;
var underlying = "GOOG";
var resolution = Resolution.Minute;
var expiration = new DateTime(2015, 12, 24);
var strike = 650m;
var equity = AddEquity(underlying, resolution).Symbol;
var option = QuantConnect.Symbol.CreateOption(underlying, Market.USA, OptionStyle.American, OptionRight.Put, strike, expiration);
AddOptionContract(option, resolution);
// add the call counter side of the mirrored pair
var mirrorOption = QuantConnect.Symbol.CreateOption(underlying, Market.USA, OptionStyle.American, OptionRight.Call, strike, expiration);
AddOptionContract(mirrorOption, resolution);
var impliedVolatility = IV(option, mirrorOption);
var delta = D(option, mirrorOption, optionModel: OptionPricingModelType.BinomialCoxRossRubinstein, ivModel: OptionPricingModelType.BlackScholes);
var gamma = G(option, mirrorOption, optionModel: OptionPricingModelType.ForwardTree, ivModel: OptionPricingModelType.BlackScholes);
var vega = V(option, mirrorOption, optionModel: OptionPricingModelType.ForwardTree, ivModel: OptionPricingModelType.BlackScholes);
var theta = T(option, mirrorOption, optionModel: OptionPricingModelType.ForwardTree, ivModel: OptionPricingModelType.BlackScholes);
var rho = R(option, mirrorOption, optionModel: OptionPricingModelType.ForwardTree, ivModel: OptionPricingModelType.BlackScholes);
if (impliedVolatility == 0m || delta == 0m || gamma == 0m || vega == 0m || theta == 0m || rho == 0m)
{
throw new RegressionTestException("Expected IV/greeks calculated");
}
if (!impliedVolatility.IsReady || !delta.IsReady || !gamma.IsReady || !vega.IsReady || !theta.IsReady || !rho.IsReady)
{
throw new RegressionTestException("Expected IV/greeks to be ready");
}
Quit($"Implied Volatility: {impliedVolatility}, Delta: {delta}, Gamma: {gamma}, Vega: {vega}, Theta: {theta}, Rho: {rho}");
}
/// <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 => true;
/// <summary>
/// This is used by the regression test system to indicate which languages this algorithm is written in.
/// </summary>
public List<Language> Languages { get; } = new() { Language.CSharp };
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 0;
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 21;
/// <summary>
/// Final status of the algorithm
/// </summary>
public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed;
/// <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"},
{"Start Equity", "100000"},
{"End Equity", "100000"},
{"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", ""},
{"Portfolio Turnover", "0%"},
{"OrderListHash", "d41d8cd98f00b204e9800998ecf8427e"}
};
}
}

View File

@@ -34,14 +34,14 @@ namespace QuantConnect.Algorithm.CSharp
SetStartDate(2013, 10, 07);
SetEndDate(2013, 10, 11);
EnableAutomaticIndicatorWarmUp = true;
Settings.AutomaticIndicatorWarmUp = true;
// Test case 1
_spy = AddEquity("SPY").Symbol;
var sma = SMA(_spy, 10);
if (!sma.IsReady)
{
throw new Exception("Expected SMA to be warmed up");
throw new RegressionTestException("Expected SMA to be warmed up");
}
// Test case 2
@@ -50,20 +50,20 @@ namespace QuantConnect.Algorithm.CSharp
if (indicator.IsReady)
{
throw new Exception("Expected CustomIndicator Not to be warmed up");
throw new RegressionTestException("Expected CustomIndicator Not to be warmed up");
}
WarmUpIndicator(_spy, indicator);
if (!indicator.IsReady)
{
throw new Exception("Expected CustomIndicator to be warmed up");
throw new RegressionTestException("Expected CustomIndicator to be warmed up");
}
}
/// <summary>
/// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
/// </summary>
/// <param name="data">Slice object keyed by symbol containing the stock data</param>
public override void OnData(Slice data)
/// <param name="slice">Slice object keyed by symbol containing the stock data</param>
public override void OnData(Slice slice)
{
if (!Portfolio.Invested)
{
@@ -72,7 +72,7 @@ namespace QuantConnect.Algorithm.CSharp
// we expect 1 consolidator per indicator
if (subscription.Consolidators.Count != 2)
{
throw new Exception($"Unexpected consolidator count for subscription: {subscription.Consolidators.Count}");
throw new RegressionTestException($"Unexpected consolidator count for subscription: {subscription.Consolidators.Count}");
}
SetHoldings(_spy, 1);
}
@@ -88,7 +88,7 @@ namespace QuantConnect.Algorithm.CSharp
{
if (_previous != null && input.EndTime == _previous.EndTime)
{
throw new Exception($"Unexpected indicator double data point call: {_previous}");
throw new RegressionTestException($"Unexpected indicator double data point call: {_previous}");
}
_previous = input;
return base.ComputeNextValue(window, input);
@@ -103,53 +103,55 @@ 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 List<Language> Languages { get; } = new() { Language.CSharp };
/// <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 => 40;
/// <summary>
/// Final status of the algorithm
/// </summary>
public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed;
/// <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 Trades", "1"},
{"Total Orders", "1"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "264.819%"},
{"Compounding Annual Return", "271.453%"},
{"Drawdown", "2.200%"},
{"Expectancy", "0"},
{"Net Profit", "1.668%"},
{"Sharpe Ratio", "8.749"},
{"Probabilistic Sharpe Ratio", "67.311%"},
{"Start Equity", "100000"},
{"End Equity", "101691.92"},
{"Net Profit", "1.692%"},
{"Sharpe Ratio", "8.854"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "67.609%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "-0.005"},
{"Beta", "0.996"},
{"Annual Standard Deviation", "0.219"},
{"Annual Variance", "0.048"},
{"Information Ratio", "-14.189"},
{"Annual Standard Deviation", "0.222"},
{"Annual Variance", "0.049"},
{"Information Ratio", "-14.565"},
{"Tracking Error", "0.001"},
{"Treynor Ratio", "1.922"},
{"Total Fees", "$3.26"},
{"Fitness Score", "0.248"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "79228162514264337593543950335"},
{"Return Over Maximum Drawdown", "93.761"},
{"Portfolio Turnover", "0.248"},
{"Total Insights Generated", "0"},
{"Total Insights Closed", "0"},
{"Total Insights Analysis Completed", "0"},
{"Long Insight Count", "0"},
{"Short Insight Count", "0"},
{"Long/Short Ratio", "100%"},
{"Estimated Monthly Alpha Value", "$0"},
{"Total Accumulated Estimated Alpha Value", "$0"},
{"Mean Population Estimated Insight Value", "$0"},
{"Mean Population Direction", "0%"},
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "491919591"}
{"Treynor Ratio", "1.97"},
{"Total Fees", "$3.44"},
{"Estimated Strategy Capacity", "$56000000.00"},
{"Lowest Capacity Asset", "SPY R735QTJ8XC9X"},
{"Portfolio Turnover", "19.93%"},
{"OrderListHash", "3da9fa60bf95b9ed148b95e02e0cfc9e"}
};
}
}

View File

@@ -0,0 +1,168 @@
/*
* 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 QuantConnect.Data.Market;
using System.Collections.Generic;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Example algorithm using and asserting the behavior of auxiliary Data handlers
/// </summary>
public class AuxiliaryDataHandlersRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
{
private bool _onSplits;
private bool _onDividends;
private bool _onDelistingsCalled;
private bool _onSymbolChangedEvents;
/// <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(2007, 05, 16);
SetEndDate(2015, 1, 1);
UniverseSettings.Resolution = Resolution.Daily;
// will get delisted
AddEquity("AAA.1");
// get's remapped
AddEquity("SPWR");
// has a split & dividends
AddEquity("AAPL");
}
public override void OnDelistings(Delistings delistings)
{
if (!delistings.ContainsKey("AAA.1"))
{
throw new RegressionTestException("Unexpected OnDelistings call");
}
_onDelistingsCalled = true;
}
public override void OnSymbolChangedEvents(SymbolChangedEvents symbolsChanged)
{
if (!symbolsChanged.ContainsKey("SPWR"))
{
throw new RegressionTestException("Unexpected OnSymbolChangedEvents call");
}
_onSymbolChangedEvents = true;
}
public override void OnSplits(Splits splits)
{
if (!splits.ContainsKey("AAPL"))
{
throw new RegressionTestException("Unexpected OnSplits call");
}
_onSplits = true;
}
public override void OnDividends(Dividends dividends)
{
if (!dividends.ContainsKey("AAPL"))
{
throw new RegressionTestException("Unexpected OnDividends call");
}
_onDividends = true;
}
public override void OnEndOfAlgorithm()
{
if (!_onDelistingsCalled)
{
throw new RegressionTestException("OnDelistings was not called!");
}
if (!_onSymbolChangedEvents)
{
throw new RegressionTestException("OnSymbolChangedEvents was not called!");
}
if (!_onSplits)
{
throw new RegressionTestException("OnSplits was not called!");
}
if (!_onDividends)
{
throw new RegressionTestException("OnDividends was not called!");
}
}
/// <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 List<Language> Languages { get; } = new() { Language.CSharp, Language.Python };
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 126221;
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 0;
/// <summary>
/// Final status of the algorithm
/// </summary>
public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed;
/// <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"},
{"Start Equity", "100000"},
{"End Equity", "100000"},
{"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.332"},
{"Tracking Error", "0.183"},
{"Treynor Ratio", "0"},
{"Total Fees", "$0.00"},
{"Estimated Strategy Capacity", "$0"},
{"Lowest Capacity Asset", ""},
{"Portfolio Turnover", "0%"},
{"OrderListHash", "d41d8cd98f00b204e9800998ecf8427e"}
};
}
}

View File

@@ -1,4 +1,4 @@
/*
/*
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
*
@@ -76,9 +76,11 @@ namespace QuantConnect.Algorithm.CSharp
/// <param name="data">Slice object keyed by symbol containing the stock data</param>
public override void OnData(Slice data)
{
if (!_equityBought && data.ContainsKey(_spy)) {
//Buy our Equity
var quantity = CalculateOrderQuantity(_spy, .1m);
if (!_equityBought && data.ContainsKey(_spy))
{
//Buy our Equity.
//Quantity is rounded down to an even number since it will be split in two equal halves
var quantity = Math.Floor(CalculateOrderQuantity(_spy, .1m) / 2) * 2;
_equityBuy = MarketOrder(_spy, quantity, asynchronous: true);
_equityBought = true;
}
@@ -119,7 +121,7 @@ namespace QuantConnect.Algorithm.CSharp
var order = Transactions.GetOrderById(orderEvent.OrderId);
// Based on the type verify the order
switch(order.Type)
switch (order.Type)
{
case OrderType.Market:
VerifyMarketOrder(order, orderEvent);
@@ -140,7 +142,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <param name="order">Order object to analyze</param>
public void VerifyMarketOrder(Order order, OrderEvent orderEvent)
{
switch(order.Status)
switch (order.Status)
{
case OrderStatus.Submitted:
break;
@@ -149,12 +151,12 @@ namespace QuantConnect.Algorithm.CSharp
case OrderStatus.PartiallyFilled:
if (order.LastFillTime == null)
{
throw new Exception("LastFillTime should not be null");
throw new RegressionTestException("LastFillTime should not be null");
}
if (order.Quantity/2 != orderEvent.FillQuantity)
if (order.Quantity / 2 != orderEvent.FillQuantity)
{
throw new Exception("Order size should be half");
throw new RegressionTestException("Order size should be half");
}
break;
@@ -162,7 +164,7 @@ namespace QuantConnect.Algorithm.CSharp
case OrderStatus.Filled:
if (order.SecurityType == SecurityType.Equity && order.CreatedTime == order.LastFillTime)
{
throw new Exception("Order should not finish during the CreatedTime bar");
throw new RegressionTestException("Order should not finish during the CreatedTime bar");
}
break;
@@ -180,12 +182,12 @@ namespace QuantConnect.Algorithm.CSharp
// If the option price isn't the same as the strike price, its incorrect
if (order.Price != _optionStrikePrice)
{
throw new Exception("OptionExercise order price should be strike price!!");
throw new RegressionTestException("OptionExercise order price should be strike price!!");
}
if (orderEvent.Quantity != -1)
{
throw new Exception("OrderEvent Quantity should be -1");
throw new RegressionTestException("OrderEvent Quantity should be -1");
}
}
@@ -196,14 +198,14 @@ namespace QuantConnect.Algorithm.CSharp
{
if (!Portfolio.ContainsKey(_optionBuy.Symbol) || !Portfolio.ContainsKey(_optionBuy.Symbol.Underlying) || !Portfolio.ContainsKey(_equityBuy.Symbol))
{
throw new Exception("Portfolio does not contain the Symbols we purchased");
throw new RegressionTestException("Portfolio does not contain the Symbols we purchased");
}
//Check option holding, should not be invested since it expired, profit should be -400
var optionHolding = Portfolio[_optionBuy.Symbol];
if (optionHolding.Invested || optionHolding.Profit != -400)
{
throw new Exception("Options holding does not match expected outcome");
throw new RegressionTestException("Options holding does not match expected outcome");
}
//Check the option underlying symbol since we should have bought it at exercise
@@ -211,15 +213,15 @@ namespace QuantConnect.Algorithm.CSharp
var optionExerciseHolding = Portfolio[_optionBuy.Symbol.Underlying];
if (!optionExerciseHolding.Invested || optionExerciseHolding.Quantity != 100 || optionExerciseHolding.AveragePrice != _optionBuy.Symbol.ID.StrikePrice)
{
throw new Exception("Equity holding for exercised option does not match expected outcome");
throw new RegressionTestException("Equity holding for exercised option does not match expected outcome");
}
//Check equity holding, should be invested, profit should be
//Quantity should be 50, AveragePrice should be ticket AverageFillPrice
//Quantity should be 52, AveragePrice should be ticket AverageFillPrice
var equityHolding = Portfolio[_equityBuy.Symbol];
if (!equityHolding.Invested || equityHolding.Quantity != 50 || equityHolding.AveragePrice != _equityBuy.AverageFillPrice)
if (!equityHolding.Invested || equityHolding.Quantity != 52 || equityHolding.AveragePrice != _equityBuy.AverageFillPrice)
{
throw new Exception("Equity holding does not match expected outcome");
throw new RegressionTestException("Equity holding does not match expected outcome");
}
}
@@ -289,35 +291,55 @@ 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 List<Language> Languages { get; } = new() { Language.CSharp };
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 27071;
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 0;
/// <summary>
/// Final status of the algorithm
/// </summary>
public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed;
/// <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 Trades", "3"},
{"Total Orders", "3"},
{"Average Win", "0%"},
{"Average Loss", "-0.40%"},
{"Compounding Annual Return", "-22.335%"},
{"Compounding Annual Return", "-21.378%"},
{"Drawdown", "0.400%"},
{"Expectancy", "-1"},
{"Net Profit", "-0.323%"},
{"Sharpe Ratio", "-0.888"},
{"Probabilistic Sharpe Ratio", "0%"},
{"Start Equity", "100000"},
{"End Equity", "99671.06"},
{"Net Profit", "-0.329%"},
{"Sharpe Ratio", "-14.095"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "1.216%"},
{"Loss Rate", "100%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "0.035"},
{"Beta", "0.183"},
{"Annual Standard Deviation", "0.004"},
{"Alpha", "-0.01"},
{"Beta", "0.097"},
{"Annual Standard Deviation", "0.002"},
{"Annual Variance", "0"},
{"Information Ratio", "12.058"},
{"Tracking Error", "0.017"},
{"Treynor Ratio", "-0.018"},
{"Information Ratio", "7.39"},
{"Tracking Error", "0.015"},
{"Treynor Ratio", "-0.234"},
{"Total Fees", "$2.00"},
{"Fitness Score", "0.213"},
{"OrderListHash", "904167951"}
{"Estimated Strategy Capacity", "$0"},
{"Lowest Capacity Asset", "GOOCV VP83T1ZUHROL"},
{"Portfolio Turnover", "17.02%"},
{"OrderListHash", "b1e5e72fb766ab894204bc4b1300912b"}
};
}
}

View File

@@ -0,0 +1,100 @@
/*
* 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 System.Linq;
using QuantConnect.Algorithm.Framework.Alphas;
using QuantConnect.Algorithm.Framework.Execution;
using QuantConnect.Algorithm.Framework.Portfolio;
using QuantConnect.Algorithm.Framework.Risk;
using QuantConnect.Algorithm.Framework.Selection;
using QuantConnect.Interfaces;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Abstract regression framework algorithm for multiple framework regression tests
/// </summary>
public abstract class BaseFrameworkRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
{
public override void Initialize()
{
SetStartDate(2014, 6, 1);
SetEndDate(2014, 6, 30);
UniverseSettings.Resolution = Resolution.Hour;
UniverseSettings.DataNormalizationMode = DataNormalizationMode.Raw;
var symbols = new[] { "AAPL", "AIG", "BAC", "SPY" }
.Select(ticker => QuantConnect.Symbol.Create(ticker, SecurityType.Equity, Market.USA))
.ToList();
// Manually add AAPL and AIG when the algorithm starts
SetUniverseSelection(new ManualUniverseSelectionModel(symbols.Take(2)));
// At midnight, add all securities every day except on the last data
// With this procedure, the Alpha Model will experience multiple universe changes
AddUniverseSelection(new ScheduledUniverseSelectionModel(
DateRules.EveryDay(), TimeRules.Midnight,
dt => dt < EndDate.AddDays(-1) ? symbols : Enumerable.Empty<Symbol>()));
SetAlpha(new ConstantAlphaModel(InsightType.Price, InsightDirection.Up, TimeSpan.FromDays(31), 0.025, null));
SetPortfolioConstruction(new EqualWeightingPortfolioConstructionModel());
SetExecution(new ImmediateExecutionModel());
SetRiskManagement(new NullRiskManagementModel());
}
public override void OnEndOfAlgorithm()
{
// The base implementation checks for active insights
var insightsCount = Insights.GetInsights(insight => insight.IsActive(UtcTime)).Count;
if (insightsCount != 0)
{
throw new RegressionTestException($"The number of active insights should be 0. Actual: {insightsCount}");
}
}
/// <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 virtual List<Language> Languages { get; } = new() { Language.CSharp, Language.Python };
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public virtual long DataPoints => 765;
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public virtual int AlgorithmHistoryDataPoints => 0;
/// <summary>
/// Final status of the algorithm
/// </summary>
public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed;
/// <summary>
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
/// </summary>
public abstract Dictionary<string, string> ExpectedStatistics { get; }
}
}

View File

@@ -49,7 +49,7 @@ namespace QuantConnect.Algorithm.CSharp
/// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
/// Slice object keyed by symbol containing the stock data
public override void OnData(Slice data)
public override void OnData(Slice slice)
{
if (!Portfolio.Invested)
{
@@ -63,4 +63,4 @@ namespace QuantConnect.Algorithm.CSharp
}
}
}
}
}

View File

@@ -14,6 +14,7 @@
*/
using System.Collections.Generic;
using QuantConnect.Brokerages;
using QuantConnect.Data;
using QuantConnect.Interfaces;
@@ -33,18 +34,23 @@ namespace QuantConnect.Algorithm.CSharp
{
SetStartDate(2018, 04, 04); //Set Start Date
SetEndDate(2018, 04, 04); //Set End Date
SetBrokerageModel(BrokerageName.GDAX, AccountType.Cash);
SetAccountCurrency();
_btcEur = AddCrypto("BTCEUR").Symbol;
}
public virtual void SetAccountCurrency()
{
//Before setting any cash or adding a Security call SetAccountCurrency
SetAccountCurrency("EUR");
SetCash(100000); //Set Strategy Cash
_btcEur = AddCrypto("BTCEUR").Symbol;
}
/// <summary>
/// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
/// </summary>
/// <param name="data">Slice object keyed by symbol containing the stock data</param>
public override void OnData(Slice data)
public override void OnData(Slice slice)
{
if (!Portfolio.Invested)
{
@@ -61,21 +67,39 @@ 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, Language.Python };
public List<Language> Languages { get; } = new() { Language.CSharp, Language.Python };
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 4319;
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 120;
/// <summary>
/// Final status of the algorithm
/// </summary>
public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed;
/// <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 Trades", "1"},
{"Total Orders", "1"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "0%"},
{"Drawdown", "0%"},
{"Expectancy", "0"},
{"Start Equity", "100000.00"},
{"End Equity", "92395.59"},
{"Net Profit", "0%"},
{"Sharpe Ratio", "0"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "0%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
@@ -87,27 +111,11 @@ namespace QuantConnect.Algorithm.CSharp
{"Information Ratio", "0"},
{"Tracking Error", "0"},
{"Treynor Ratio", "0"},
{"Total Fees", "$0.00"},
{"Fitness Score", "0.506"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "79228162514264337593543950335"},
{"Return Over Maximum Drawdown", "-14.148"},
{"Portfolio Turnover", "1.073"},
{"Total Insights Generated", "0"},
{"Total Insights Closed", "0"},
{"Total Insights Analysis Completed", "0"},
{"Long Insight Count", "0"},
{"Short Insight Count", "0"},
{"Long/Short Ratio", "100%"},
{"Estimated Monthly Alpha Value", "€0"},
{"Total Accumulated Estimated Alpha Value", "€0"},
{"Mean Population Estimated Insight Value", "€0"},
{"Mean Population Direction", "0%"},
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "-1575550889"}
{"Total Fees", "€298.35"},
{"Estimated Strategy Capacity", "€85000.00"},
{"Lowest Capacity Asset", "BTCEUR 2XR"},
{"Portfolio Turnover", "107.64%"},
{"OrderListHash", "6819dc936b86af6e4b89b6017b7d5284"}
};
}
}

View File

@@ -0,0 +1,91 @@
/*
* 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.Collections.Generic;
using QuantConnect.Interfaces;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Basic algorithm using SetAccountCurrency with an amount
/// </summary>
public class BasicSetAccountCurrencyWithAmountAlgorithm : BasicSetAccountCurrencyAlgorithm, IRegressionAlgorithmDefinition
{
public override void SetAccountCurrency()
{
//Before setting any cash or adding a Security call SetAccountCurrency
SetAccountCurrency("EUR", 200000);
}
/// <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 List<Language> Languages { get; } = new() { Language.CSharp, Language.Python };
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 4319;
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 120;
/// <summary>
/// Final status of the algorithm
/// </summary>
public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed;
/// <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", "1"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "0%"},
{"Drawdown", "0%"},
{"Expectancy", "0"},
{"Start Equity", "200000.00"},
{"End Equity", "184791.19"},
{"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", "€596.71"},
{"Estimated Strategy Capacity", "€85000.00"},
{"Lowest Capacity Asset", "BTCEUR 2XR"},
{"Portfolio Turnover", "107.64%"},
{"OrderListHash", "3d450fd418a0e845b3eaaac17fcd13fc"}
};
}
}

View File

@@ -53,7 +53,7 @@ namespace QuantConnect.Algorithm.CSharp
/// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
/// </summary>
/// <param name="data">Slice object keyed by symbol containing the stock data</param>
public override void OnData(Slice data)
public override void OnData(Slice slice)
{
if (!Portfolio.Invested)
{
@@ -70,53 +70,55 @@ 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, Language.Python };
public List<Language> Languages { get; } = new() { 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>
/// Final status of the algorithm
/// </summary>
public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed;
/// <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 Trades", "1"},
{"Total Orders", "1"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "264.819%"},
{"Compounding Annual Return", "271.453%"},
{"Drawdown", "2.200%"},
{"Expectancy", "0"},
{"Net Profit", "1.668%"},
{"Sharpe Ratio", "8.749"},
{"Probabilistic Sharpe Ratio", "67.311%"},
{"Start Equity", "100000"},
{"End Equity", "101691.92"},
{"Net Profit", "1.692%"},
{"Sharpe Ratio", "8.854"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "67.609%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "-0.005"},
{"Beta", "0.996"},
{"Annual Standard Deviation", "0.219"},
{"Annual Variance", "0.048"},
{"Information Ratio", "-14.189"},
{"Annual Standard Deviation", "0.222"},
{"Annual Variance", "0.049"},
{"Information Ratio", "-14.565"},
{"Tracking Error", "0.001"},
{"Treynor Ratio", "1.922"},
{"Total Fees", "$3.26"},
{"Fitness Score", "0.248"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "79228162514264337593543950335"},
{"Return Over Maximum Drawdown", "93.761"},
{"Portfolio Turnover", "0.248"},
{"Total Insights Generated", "0"},
{"Total Insights Closed", "0"},
{"Total Insights Analysis Completed", "0"},
{"Long Insight Count", "0"},
{"Short Insight Count", "0"},
{"Long/Short Ratio", "100%"},
{"Estimated Monthly Alpha Value", "$0"},
{"Total Accumulated Estimated Alpha Value", "$0"},
{"Mean Population Estimated Insight Value", "$0"},
{"Mean Population Direction", "0%"},
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "491919591"}
{"Treynor Ratio", "1.97"},
{"Total Fees", "$3.44"},
{"Estimated Strategy Capacity", "$56000000.00"},
{"Lowest Capacity Asset", "SPY R735QTJ8XC9X"},
{"Portfolio Turnover", "19.93%"},
{"OrderListHash", "3da9fa60bf95b9ed148b95e02e0cfc9e"}
};
}
}
}

View File

@@ -0,0 +1,118 @@
/*
* 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.Interfaces;
using QuantConnect.Brokerages;
using System.Collections.Generic;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// 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 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.
/// </summary>
public override void Initialize()
{
SetStartDate(2013, 10, 07);
SetEndDate(2013, 10, 11);
SetCash(100000);
SetBrokerageModel(BrokerageName.Axos);
AddEquity("SPY", Resolution.Minute);
}
/// <summary>
/// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
/// </summary>
/// <param name="slice">Slice object keyed by symbol containing the stock data</param>
public override void OnData(Slice slice)
{
if (!Portfolio.Invested)
{
// will set 25% of our buying power with a market order
SetHoldings("SPY", 0.25m);
Debug("Purchased SPY!");
}
}
/// <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 List<Language> Languages { get; } = new() { Language.CSharp, Language.Python };
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 3901;
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 0;
/// <summary>
/// Final status of the algorithm
/// </summary>
public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed;
/// <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", "1"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "39.143%"},
{"Drawdown", "0.500%"},
{"Expectancy", "0"},
{"Start Equity", "100000"},
{"End Equity", "100423.24"},
{"Net Profit", "0.423%"},
{"Sharpe Ratio", "5.498"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "67.498%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "0"},
{"Beta", "0"},
{"Annual Standard Deviation", "0.055"},
{"Annual Variance", "0.003"},
{"Information Ratio", "5.634"},
{"Tracking Error", "0.055"},
{"Treynor Ratio", "0"},
{"Total Fees", "$0.60"},
{"Estimated Strategy Capacity", "$150000000.00"},
{"Lowest Capacity Asset", "SPY R735QTJ8XC9X"},
{"Portfolio Turnover", "4.98%"},
{"OrderListHash", "8774049eb5141a2b6956d9432426f837"}
};
}
}

View File

@@ -0,0 +1,72 @@
/*
* 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.Linq;
using QuantConnect.Data;
using QuantConnect.Orders;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Algorithm demonstrating CFD asset types and requesting history.
/// </summary>
/// <meta name="tag" content="using data" />
/// <meta name="tag" content="history" />
/// <meta name="tag" content="cfd" />
public class BasicTemplateCfdAlgorithm : QCAlgorithm
{
private Symbol _symbol;
/// <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()
{
SetAccountCurrency("EUR");
SetStartDate(2019, 2, 20);
SetEndDate(2019, 2, 21);
SetCash("EUR", 100000);
_symbol = AddCfd("DE30EUR").Symbol;
// Historical Data
var history = History(_symbol, 60, Resolution.Daily);
Log($"Received {history.Count()} bars from CFD historical data call.");
}
/// <summary>
/// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
/// </summary>
/// <param name="data">Slice object keyed by symbol containing the stock data</param>
public override void OnData(Slice slice)
{
// Access Data
if (slice.QuoteBars.ContainsKey(_symbol))
{
var quoteBar = slice.QuoteBars[_symbol];
Log($"{quoteBar.EndTime} :: {quoteBar.Close}");
}
if (!Portfolio.Invested)
SetHoldings(_symbol, 1);
}
public override void OnOrderEvent(OrderEvent orderEvent)
{
Debug($"{Time} {orderEvent.ToString()}");
}
}
}

View File

@@ -1,53 +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.Algorithm.Framework.Alphas;
using QuantConnect.Algorithm.Framework.Execution;
using QuantConnect.Algorithm.Framework.Portfolio;
using QuantConnect.Data.UniverseSelection;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Basic template algorithm which showcases <see cref="ConstituentsUniverse"/> simple use case
/// </summary>
public class BasicTemplateConstituentUniverseAlgorithm : QCAlgorithm
{
/// <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(2013, 10, 07);
SetEndDate(2013, 10, 11);
// by default will use algorithms UniverseSettings
AddUniverse(Universe.Constituent.Steel());
// we specify the UniverseSettings it should use
AddUniverse(Universe.Constituent.AggressiveGrowth(
new UniverseSettings(Resolution.Hour,
2,
false,
false,
UniverseSettings.MinimumTimeInUniverse)));
SetAlpha(new ConstantAlphaModel(InsightType.Price, InsightDirection.Up, TimeSpan.FromDays(1)));
SetExecution(new ImmediateExecutionModel());
SetPortfolioConstruction(new EqualWeightingPortfolioConstructionModel());
}
}
}

View File

@@ -0,0 +1,167 @@
/*
* 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 QuantConnect.Orders;
using QuantConnect.Interfaces;
using System.Collections.Generic;
using System.Linq;
using QuantConnect.Data.UniverseSelection;
using QuantConnect.Indicators;
using QuantConnect.Securities;
using QuantConnect.Securities.Future;
using Futures = QuantConnect.Securities.Futures;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Basic Continuous Futures Template Algorithm
/// </summary>
public class BasicTemplateContinuousFutureAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
{
private Future _continuousContract;
private Security _currentContract;
private SimpleMovingAverage _fast;
private SimpleMovingAverage _slow;
/// <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(2013, 7, 1);
SetEndDate(2014, 1, 1);
_continuousContract = AddFuture(Futures.Indices.SP500EMini,
dataNormalizationMode: DataNormalizationMode.BackwardsRatio,
dataMappingMode: DataMappingMode.LastTradingDay,
contractDepthOffset: 0
);
_fast = SMA(_continuousContract.Symbol, 4, Resolution.Daily);
_slow = SMA(_continuousContract.Symbol, 10, Resolution.Daily);
}
/// <summary>
/// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
/// </summary>
/// <param name="data">Slice object keyed by symbol containing the stock data</param>
public override void OnData(Slice slice)
{
foreach (var changedEvent in slice.SymbolChangedEvents.Values)
{
Debug($"{Time} - SymbolChanged event: {changedEvent}");
if (Time.TimeOfDay != TimeSpan.Zero)
{
throw new RegressionTestException($"{Time} unexpected symbol changed event {changedEvent}!");
}
}
if (!Portfolio.Invested)
{
if(_fast > _slow)
{
_currentContract = Securities[_continuousContract.Mapped];
Buy(_currentContract.Symbol, 1);
}
}
else if(_fast < _slow)
{
Liquidate();
}
// We check exchange hours because the contract mapping can call OnData outside of regular hours.
if (_currentContract != null && _currentContract.Symbol != _continuousContract.Mapped && _continuousContract.Exchange.ExchangeOpen)
{
Log($"{Time} - rolling position from {_currentContract.Symbol} to {_continuousContract.Mapped}");
var currentPositionSize = _currentContract.Holdings.Quantity;
Liquidate(_currentContract.Symbol);
Buy(_continuousContract.Mapped, currentPositionSize);
_currentContract = Securities[_continuousContract.Mapped];
}
}
public override void OnOrderEvent(OrderEvent orderEvent)
{
Debug($"{orderEvent}");
}
public override void OnSecuritiesChanged(SecurityChanges changes)
{
Debug($"{Time}-{changes}");
}
/// <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 List<Language> Languages { get; } = new() { Language.CSharp, Language.Python };
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 713369;
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 0;
/// <summary>
/// Final status of the algorithm
/// </summary>
public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed;
/// <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", "2.48%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "11.325%"},
{"Drawdown", "1.500%"},
{"Expectancy", "0"},
{"Start Equity", "100000"},
{"End Equity", "105549.6"},
{"Net Profit", "5.550%"},
{"Sharpe Ratio", "1.332"},
{"Sortino Ratio", "879.904"},
{"Probabilistic Sharpe Ratio", "79.894%"},
{"Loss Rate", "0%"},
{"Win Rate", "100%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "0.075"},
{"Beta", "-0.017"},
{"Annual Standard Deviation", "0.053"},
{"Annual Variance", "0.003"},
{"Information Ratio", "-1.48"},
{"Tracking Error", "0.099"},
{"Treynor Ratio", "-4.187"},
{"Total Fees", "$10.75"},
{"Estimated Strategy Capacity", "$7100000.00"},
{"Lowest Capacity Asset", "ES VMKLFZIH2MTD"},
{"Portfolio Turnover", "2.33%"},
{"OrderListHash", "9c524830ffc7354327638142ae62acd2"}
};
}
}

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 QuantConnect.Data;
using QuantConnect.Orders;
using QuantConnect.Interfaces;
using System.Collections.Generic;
using System.Linq;
using QuantConnect.Data.UniverseSelection;
using QuantConnect.Indicators;
using QuantConnect.Securities;
using QuantConnect.Securities.Future;
using Futures = QuantConnect.Securities.Futures;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Basic Continuous Futures Template Algorithm with extended market hours
/// </summary>
public class BasicTemplateContinuousFutureWithExtendedMarketAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
{
private Future _continuousContract;
private Security _currentContract;
private SimpleMovingAverage _fast;
private SimpleMovingAverage _slow;
/// <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(2013, 7, 1);
SetEndDate(2014, 1, 1);
_continuousContract = AddFuture(Futures.Indices.SP500EMini,
dataNormalizationMode: DataNormalizationMode.BackwardsRatio,
dataMappingMode: DataMappingMode.LastTradingDay,
contractDepthOffset: 0,
extendedMarketHours: true
);
_fast = SMA(_continuousContract.Symbol, 4, Resolution.Daily);
_slow = SMA(_continuousContract.Symbol, 10, Resolution.Daily);
}
/// <summary>
/// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
/// </summary>
/// <param name="slice">Slice object keyed by symbol containing the stock data</param>
public override void OnData(Slice slice)
{
foreach (var changedEvent in slice.SymbolChangedEvents.Values)
{
Debug($"{Time} - SymbolChanged event: {changedEvent}");
if (Time.TimeOfDay != TimeSpan.Zero)
{
throw new RegressionTestException($"{Time} unexpected symbol changed event {changedEvent}!");
}
}
if (!IsMarketOpen(_continuousContract.Symbol))
{
return;
}
if (!Portfolio.Invested)
{
if(_fast > _slow)
{
_currentContract = Securities[_continuousContract.Mapped];
Buy(_currentContract.Symbol, 1);
}
}
else if(_fast < _slow)
{
Liquidate();
}
if (_currentContract != null && _currentContract.Symbol != _continuousContract.Mapped)
{
Log($"{Time} - rolling position from {_currentContract.Symbol} to {_continuousContract.Mapped}");
var currentPositionSize = _currentContract.Holdings.Quantity;
Liquidate(_currentContract.Symbol);
Buy(_continuousContract.Mapped, currentPositionSize);
_currentContract = Securities[_continuousContract.Mapped];
}
}
public override void OnOrderEvent(OrderEvent orderEvent)
{
Debug($"{orderEvent}");
}
public override void OnSecuritiesChanged(SecurityChanges changes)
{
Debug($"{Time}-{changes}");
}
/// <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 List<Language> Languages { get; } = new() { Language.CSharp, Language.Python };
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 2217299;
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 0;
/// <summary>
/// Final status of the algorithm
/// </summary>
public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed;
/// <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", "2.86%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "12.959%"},
{"Drawdown", "1.100%"},
{"Expectancy", "0"},
{"Start Equity", "100000"},
{"End Equity", "106337.1"},
{"Net Profit", "6.337%"},
{"Sharpe Ratio", "1.41"},
{"Sortino Ratio", "1.242"},
{"Probabilistic Sharpe Ratio", "77.992%"},
{"Loss Rate", "0%"},
{"Win Rate", "100%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "0.071"},
{"Beta", "0.054"},
{"Annual Standard Deviation", "0.059"},
{"Annual Variance", "0.003"},
{"Information Ratio", "-1.392"},
{"Tracking Error", "0.097"},
{"Treynor Ratio", "1.518"},
{"Total Fees", "$10.75"},
{"Estimated Strategy Capacity", "$890000000.00"},
{"Lowest Capacity Asset", "ES VMKLFZIH2MTD"},
{"Portfolio Turnover", "2.32%"},
{"OrderListHash", "f60fc7dcba2c1ff077afeb191aee5008"}
};
}
}

View File

@@ -79,8 +79,8 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
/// </summary>
/// <param name="data">Slice object keyed by symbol containing the stock data</param>
public override void OnData(Slice data)
/// <param name="slice">Slice object keyed by symbol containing the stock data</param>
public override void OnData(Slice slice)
{
if (Portfolio.CashBook["EUR"].ConversionRate == 0
|| Portfolio.CashBook["BTC"].ConversionRate == 0
@@ -92,7 +92,7 @@ namespace QuantConnect.Algorithm.CSharp
Log($"LTC conversion rate: {Portfolio.CashBook["LTC"].ConversionRate}");
Log($"ETH conversion rate: {Portfolio.CashBook["ETH"].ConversionRate}");
throw new Exception("Conversion rate is 0");
throw new RegressionTestException("Conversion rate is 0");
}
if (Time.Hour == 1 && Time.Minute == 0)
{
@@ -196,21 +196,39 @@ 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, Language.Python };
public List<Language> Languages { get; } = new() { Language.CSharp, Language.Python };
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 12965;
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 240;
/// <summary>
/// Final status of the algorithm
/// </summary>
public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed;
/// <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 Trades", "10"},
{"Total Orders", "12"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "0%"},
{"Drawdown", "0%"},
{"Expectancy", "0"},
{"Start Equity", "31588.24"},
{"End Equity", "30866.71"},
{"Net Profit", "0%"},
{"Sharpe Ratio", "0"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "0%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
@@ -223,26 +241,10 @@ namespace QuantConnect.Algorithm.CSharp
{"Tracking Error", "0"},
{"Treynor Ratio", "0"},
{"Total Fees", "$85.34"},
{"Fitness Score", "0.5"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "79228162514264337593543950335"},
{"Return Over Maximum Drawdown", "-43.943"},
{"Portfolio Turnover", "1.028"},
{"Total Insights Generated", "0"},
{"Total Insights Closed", "0"},
{"Total Insights Analysis Completed", "0"},
{"Long Insight Count", "0"},
{"Short Insight Count", "0"},
{"Long/Short Ratio", "100%"},
{"Estimated Monthly Alpha Value", "$0"},
{"Total Accumulated Estimated Alpha Value", "$0"},
{"Mean Population Estimated Insight Value", "$0"},
{"Mean Population Direction", "0%"},
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "956597072"}
{"Estimated Strategy Capacity", "$0"},
{"Lowest Capacity Asset", "BTCEUR 2XR"},
{"Portfolio Turnover", "118.08%"},
{"OrderListHash", "26b9a07ace86b6a0e0eb2ff8c168cee0"}
};
}
}

View File

@@ -0,0 +1,282 @@
/*
* 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 QuantConnect.Orders;
using QuantConnect.Brokerages;
using QuantConnect.Indicators;
using QuantConnect.Interfaces;
using QuantConnect.Securities;
using QuantConnect.Data.Market;
using System.Collections.Generic;
using QuantConnect.Securities.CryptoFuture;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Minute resolution regression algorithm trading Coin and USDT binance futures long and short asserting the behavior
/// </summary>
public class BasicTemplateCryptoFutureAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
{
private Dictionary<Symbol, int> _interestPerSymbol = new();
private CryptoFuture _btcUsd;
private CryptoFuture _adaUsdt;
private ExponentialMovingAverage _fast;
private ExponentialMovingAverage _slow;
/// <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(2022, 12, 13); // Set Start Date
SetEndDate(2022, 12, 13); // Set End Date
SetTimeZone(TimeZones.Utc);
try
{
SetBrokerageModel(BrokerageName.BinanceFutures, AccountType.Cash);
}
catch (InvalidOperationException)
{
// expected, we don't allow cash account type
}
SetBrokerageModel(BrokerageName.BinanceFutures, AccountType.Margin);
_btcUsd = AddCryptoFuture("BTCUSD");
_adaUsdt = AddCryptoFuture("ADAUSDT");
_fast = EMA(_btcUsd.Symbol, 30, Resolution.Minute);
_slow = EMA(_btcUsd.Symbol, 60, Resolution.Minute);
_interestPerSymbol[_btcUsd.Symbol] = 0;
_interestPerSymbol[_adaUsdt.Symbol] = 0;
// Default USD cash, set 1M but it wont be used
SetCash(1000000);
// the amount of BTC we need to hold to trade 'BTCUSD'
_btcUsd.BaseCurrency.SetAmount(0.005m);
// the amount of USDT we need to hold to trade 'ADAUSDT'
_adaUsdt.QuoteCurrency.SetAmount(200);
}
/// <summary>
/// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
/// </summary>
/// <param name="data">Slice object keyed by symbol containing the stock data</param>
public override void OnData(Slice slice)
{
var interestRates = slice.Get<MarginInterestRate>();
foreach (var interestRate in interestRates)
{
_interestPerSymbol[interestRate.Key]++;
var cachedInterestRate = Securities[interestRate.Key].Cache.GetData<MarginInterestRate>();
if (cachedInterestRate != interestRate.Value)
{
throw new RegressionTestException($"Unexpected cached margin interest rate for {interestRate.Key}!");
}
}
if (_fast > _slow)
{
if (!Portfolio.Invested && Transactions.OrdersCount == 0)
{
var ticket = Buy(_btcUsd.Symbol, 50);
if (ticket.Status != OrderStatus.Invalid)
{
throw new RegressionTestException($"Unexpected valid order {ticket}, should fail due to margin not sufficient");
}
Buy(_btcUsd.Symbol, 1);
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 RegressionTestException($"Unexpected TotalSaleVolume {btcUsdHoldings.TotalSaleVolume}");
}
if (Math.Abs(btcUsdHoldings.AbsoluteHoldingsCost - holdingsValueBtcUsd) > 1)
{
throw new RegressionTestException($"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 RegressionTestException($"Unexpected margin used {marginUsed}");
}
Buy(_adaUsdt.Symbol, 1000);
marginUsed = Portfolio.TotalMarginUsed - marginUsed;
var adaUsdtHoldings = _adaUsdt.Holdings;
// USDT/BUSD futures value is based on it's price
var holdingsValueUsdt = _adaUsdt.Price * _adaUsdt.SymbolProperties.ContractMultiplier * 1000;
if (Math.Abs(adaUsdtHoldings.TotalSaleVolume - holdingsValueUsdt) > 1)
{
throw new RegressionTestException($"Unexpected TotalSaleVolume {adaUsdtHoldings.TotalSaleVolume}");
}
if (Math.Abs(adaUsdtHoldings.AbsoluteHoldingsCost - holdingsValueUsdt) > 1)
{
throw new RegressionTestException($"Unexpected holdings cost {adaUsdtHoldings.HoldingsCost}");
}
if (Math.Abs(adaUsdtHoldings.AbsoluteHoldingsCost * 0.05m - marginUsed) > 1
|| _adaUsdt.BuyingPowerModel.GetMaintenanceMargin(_adaUsdt) != marginUsed)
{
throw new RegressionTestException($"Unexpected margin used {marginUsed}");
}
// position just opened should be just spread here
var profit = Portfolio.TotalUnrealizedProfit;
if ((5 - Math.Abs(profit)) < 0)
{
throw new RegressionTestException($"Unexpected TotalUnrealizedProfit {Portfolio.TotalUnrealizedProfit}");
}
if (Portfolio.TotalProfit != 0)
{
throw new RegressionTestException($"Unexpected TotalProfit {Portfolio.TotalProfit}");
}
}
}
else
{
// let's revert our position and double
if (Time.Hour > 10 && Transactions.OrdersCount == 3)
{
Sell(_btcUsd.Symbol, 3);
var btcUsdHoldings = _btcUsd.Holdings;
if (Math.Abs(btcUsdHoldings.AbsoluteHoldingsCost - 100 * 2) > 1)
{
throw new RegressionTestException($"Unexpected holdings cost {btcUsdHoldings.HoldingsCost}");
}
Sell(_adaUsdt.Symbol, 3000);
var adaUsdtHoldings = _adaUsdt.Holdings;
// USDT/BUSD futures value is based on it's price
var holdingsValueUsdt = _adaUsdt.Price * _adaUsdt.SymbolProperties.ContractMultiplier * 2000;
if (Math.Abs(adaUsdtHoldings.AbsoluteHoldingsCost - holdingsValueUsdt) > 1)
{
throw new RegressionTestException($"Unexpected holdings cost {adaUsdtHoldings.HoldingsCost}");
}
// position just opened should be just spread here
var profit = Portfolio.TotalUnrealizedProfit;
if ((5 - Math.Abs(profit)) < 0)
{
throw new RegressionTestException($"Unexpected TotalUnrealizedProfit {Portfolio.TotalUnrealizedProfit}");
}
// we barely did any difference on the previous trade
if ((5 - Math.Abs(Portfolio.TotalProfit)) < 0)
{
throw new RegressionTestException($"Unexpected TotalProfit {Portfolio.TotalProfit}");
}
}
}
}
public override void OnEndOfAlgorithm()
{
if (_interestPerSymbol[_adaUsdt.Symbol] != 1)
{
throw new RegressionTestException($"Unexpected interest rate count {_interestPerSymbol[_adaUsdt.Symbol]}");
}
if (_interestPerSymbol[_btcUsd.Symbol] != 3)
{
throw new RegressionTestException($"Unexpected interest rate count {_interestPerSymbol[_btcUsd.Symbol]}");
}
}
public override void OnOrderEvent(OrderEvent orderEvent)
{
Debug(Time + " " + orderEvent);
}
/// <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 List<Language> Languages { get; } = new() { Language.CSharp, Language.Python };
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 7205;
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 0;
/// <summary>
/// Final status of the algorithm
/// </summary>
public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed;
/// <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"},
{"Start Equity", "1000200.00"},
{"End Equity", "1000278.02"},
{"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.65"},
{"Estimated Strategy Capacity", "$500000000.00"},
{"Lowest Capacity Asset", "ADAUSDT 18R"},
{"Portfolio Turnover", "0.16%"},
{"OrderListHash", "dcc4f964b5549c753123848c32eaee41"}
};
}
}

View File

@@ -0,0 +1,245 @@
/*
* 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 QuantConnect.Orders;
using QuantConnect.Indicators;
using QuantConnect.Interfaces;
using QuantConnect.Securities;
using QuantConnect.Brokerages;
using QuantConnect.Data.Market;
using System.Collections.Generic;
using QuantConnect.Securities.CryptoFuture;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Hourly regression algorithm trading ADAUSDT binance futures long and short asserting the behavior
/// </summary>
public class BasicTemplateCryptoFutureHourlyAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
{
private Dictionary<Symbol, int> _interestPerSymbol = new();
private CryptoFuture _adaUsdt;
private ExponentialMovingAverage _fast;
private ExponentialMovingAverage _slow;
/// <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(2022, 12, 13);
SetEndDate(2022, 12, 13);
SetTimeZone(TimeZones.Utc);
try
{
SetBrokerageModel(BrokerageName.BinanceCoinFutures, AccountType.Cash);
}
catch (InvalidOperationException)
{
// expected, we don't allow cash account type
}
SetBrokerageModel(BrokerageName.BinanceCoinFutures, AccountType.Margin);
_adaUsdt = AddCryptoFuture("ADAUSDT", Resolution.Hour);
_fast = EMA(_adaUsdt.Symbol, 3, Resolution.Hour);
_slow = EMA(_adaUsdt.Symbol, 6, Resolution.Hour);
_interestPerSymbol[_adaUsdt.Symbol] = 0;
// Default USD cash, set 1M but it wont be used
SetCash(1000000);
// the amount of USDT we need to hold to trade 'ADAUSDT'
_adaUsdt.QuoteCurrency.SetAmount(200);
}
/// <summary>
/// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
/// </summary>
/// <param name="data">Slice object keyed by symbol containing the stock data</param>
public override void OnData(Slice slice)
{
var interestRates = slice.Get<MarginInterestRate>();
foreach (var interestRate in interestRates)
{
_interestPerSymbol[interestRate.Key]++;
var cachedInterestRate = Securities[interestRate.Key].Cache.GetData<MarginInterestRate>();
if (cachedInterestRate != interestRate.Value)
{
throw new RegressionTestException($"Unexpected cached margin interest rate for {interestRate.Key}!");
}
}
if (_fast > _slow)
{
if (!Portfolio.Invested && Transactions.OrdersCount == 0)
{
var ticket = Buy(_adaUsdt.Symbol, 100000);
if(ticket.Status != OrderStatus.Invalid)
{
throw new RegressionTestException($"Unexpected valid order {ticket}, should fail due to margin not sufficient");
}
Buy(_adaUsdt.Symbol, 1000);
var marginUsed = Portfolio.TotalMarginUsed;
var adaUsdtHoldings = _adaUsdt.Holdings;
// USDT/BUSD futures value is based on it's price
var holdingsValueUsdt = _adaUsdt.Price * _adaUsdt.SymbolProperties.ContractMultiplier * 1000;
if (Math.Abs(adaUsdtHoldings.TotalSaleVolume - holdingsValueUsdt) > 1)
{
throw new RegressionTestException($"Unexpected TotalSaleVolume {adaUsdtHoldings.TotalSaleVolume}");
}
if (Math.Abs(adaUsdtHoldings.AbsoluteHoldingsCost - holdingsValueUsdt) > 1)
{
throw new RegressionTestException($"Unexpected holdings cost {adaUsdtHoldings.HoldingsCost}");
}
if (Math.Abs(adaUsdtHoldings.AbsoluteHoldingsCost * 0.05m - marginUsed) > 1
|| _adaUsdt.BuyingPowerModel.GetMaintenanceMargin(_adaUsdt) != marginUsed)
{
throw new RegressionTestException($"Unexpected margin used {marginUsed}");
}
// position just opened should be just spread here
var profit = Portfolio.TotalUnrealizedProfit;
if ((5 - Math.Abs(profit)) < 0)
{
throw new RegressionTestException($"Unexpected TotalUnrealizedProfit {Portfolio.TotalUnrealizedProfit}");
}
if (Portfolio.TotalProfit != 0)
{
throw new RegressionTestException($"Unexpected TotalProfit {Portfolio.TotalProfit}");
}
}
}
else
{
// let's revert our position and double
if (Time.Hour > 10 && Transactions.OrdersCount == 2)
{
Sell(_adaUsdt.Symbol, 3000);
var adaUsdtHoldings = _adaUsdt.Holdings;
// USDT/BUSD futures value is based on it's price
var holdingsValueUsdt = _adaUsdt.Price * _adaUsdt.SymbolProperties.ContractMultiplier * 2000;
if (Math.Abs(adaUsdtHoldings.AbsoluteHoldingsCost - holdingsValueUsdt) > 1)
{
throw new RegressionTestException($"Unexpected holdings cost {adaUsdtHoldings.HoldingsCost}");
}
// position just opened should be just spread here
var profit = Portfolio.TotalUnrealizedProfit;
if ((5 - Math.Abs(profit)) < 0)
{
throw new RegressionTestException($"Unexpected TotalUnrealizedProfit {Portfolio.TotalUnrealizedProfit}");
}
// we barely did any difference on the previous trade
if ((5 - Math.Abs(Portfolio.TotalProfit)) < 0)
{
throw new RegressionTestException($"Unexpected TotalProfit {Portfolio.TotalProfit}");
}
}
if (Time.Hour >= 22 && Transactions.OrdersCount == 3)
{
Liquidate();
}
}
}
public override void OnEndOfAlgorithm()
{
if (_interestPerSymbol[_adaUsdt.Symbol] != 1)
{
throw new RegressionTestException($"Unexpected interest rate count {_interestPerSymbol[_adaUsdt.Symbol]}");
}
}
public override void OnOrderEvent(OrderEvent orderEvent)
{
Debug(Time + " " + orderEvent);
}
/// <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 List<Language> Languages { get; } = new() { Language.CSharp, Language.Python };
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 50;
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 0;
/// <summary>
/// Final status of the algorithm
/// </summary>
public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed;
/// <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"},
{"Start Equity", "1000200"},
{"End Equity", "1000189.47"},
{"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.61"},
{"Estimated Strategy Capacity", "$370000000.00"},
{"Lowest Capacity Asset", "ADAUSDT 18R"},
{"Portfolio Turnover", "0.12%"},
{"OrderListHash", "50a51d06d03a5355248a6bccef1ca521"}
};
}
}

View File

@@ -43,8 +43,8 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
/// </summary>
/// <param name="data">Slice object keyed by symbol containing the stock data</param>
public override void OnData(Slice data)
/// <param name="slice">Slice object keyed by symbol containing the stock data</param>
public override void OnData(Slice slice)
{
if (!Portfolio.Invested)
{
@@ -61,53 +61,55 @@ 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, Language.Python };
public List<Language> Languages { get; } = new() { Language.CSharp, Language.Python };
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 72;
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 0;
/// <summary>
/// Final status of the algorithm
/// </summary>
public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed;
/// <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 Trades", "1"},
{"Total Orders", "1"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "246.000%"},
{"Drawdown", "1.100%"},
{"Compounding Annual Return", "424.375%"},
{"Drawdown", "0.800%"},
{"Expectancy", "0"},
{"Net Profit", "3.459%"},
{"Sharpe Ratio", "10.11"},
{"Probabilistic Sharpe Ratio", "83.150%"},
{"Start Equity", "100000"},
{"End Equity", "104486.22"},
{"Net Profit", "4.486%"},
{"Sharpe Ratio", "17.304"},
{"Sortino Ratio", "35.217"},
{"Probabilistic Sharpe Ratio", "96.835%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "1.935"},
{"Beta", "-0.119"},
{"Annual Standard Deviation", "0.16"},
{"Annual Variance", "0.026"},
{"Information Ratio", "-4.556"},
{"Tracking Error", "0.221"},
{"Treynor Ratio", "-13.568"},
{"Total Fees", "$3.26"},
{"Fitness Score", "0.111"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "52.533"},
{"Return Over Maximum Drawdown", "214.75"},
{"Portfolio Turnover", "0.111"},
{"Total Insights Generated", "0"},
{"Total Insights Closed", "0"},
{"Total Insights Analysis Completed", "0"},
{"Long Insight Count", "0"},
{"Short Insight Count", "0"},
{"Long/Short Ratio", "100%"},
{"Estimated Monthly Alpha Value", "$0"},
{"Total Accumulated Estimated Alpha Value", "$0"},
{"Mean Population Estimated Insight Value", "$0"},
{"Mean Population Direction", "0%"},
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "1268340653"}
{"Alpha", "-0.249"},
{"Beta", "1.015"},
{"Annual Standard Deviation", "0.141"},
{"Annual Variance", "0.02"},
{"Information Ratio", "-19"},
{"Tracking Error", "0.011"},
{"Treynor Ratio", "2.403"},
{"Total Fees", "$3.49"},
{"Estimated Strategy Capacity", "$1200000000.00"},
{"Lowest Capacity Asset", "SPY R735QTJ8XC9X"},
{"Portfolio Turnover", "10.01%"},
{"OrderListHash", "70f21e930175a2ec9d465b21edc1b6d9"}
};
}
}

View File

@@ -0,0 +1,239 @@
/*
* 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.Data.UniverseSelection;
using QuantConnect.Interfaces;
using QuantConnect.Orders;
using QuantConnect.Securities;
using QuantConnect.Securities.Future;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// This algorithm tests and demonstrates EUREX futures subscription and trading:
/// - It tests contracts rollover by adding a continuous future and asserting that mapping happens at some point.
/// - It tests basic trading by buying a contract and holding it until expiration.
/// - It tests delisting and asserts the holdings are liquidated after that.
/// </summary>
public class BasicTemplateEurexFuturesAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
{
private Future _continuousContract;
private Symbol _mappedSymbol;
private Symbol _contractToTrade;
private int _mappingsCount;
private decimal _boughtQuantity;
private decimal _liquidatedQuantity;
private bool _delisted;
public override void Initialize()
{
SetStartDate(2024, 5, 30);
SetEndDate(2024, 6, 23);
SetAccountCurrency(Currencies.EUR);
SetCash(1000000);
_continuousContract = AddFuture(Futures.Indices.EuroStoxx50, Resolution.Minute,
dataNormalizationMode: DataNormalizationMode.BackwardsRatio,
dataMappingMode: DataMappingMode.FirstDayMonth,
contractDepthOffset: 0);
_continuousContract.SetFilter(TimeSpan.Zero, TimeSpan.FromDays(180));
_mappedSymbol = _continuousContract.Mapped;
var benchmark = AddIndex("SX5E", market: Market.EUREX);
SetBenchmark(benchmark.Symbol);
var seeder = new FuncSecuritySeeder(GetLastKnownPrices);
SetSecurityInitializer(security => seeder.SeedSecurity(security));
}
public override void OnData(Slice slice)
{
foreach (var changedEvent in slice.SymbolChangedEvents.Values)
{
if (++_mappingsCount > 1)
{
throw new RegressionTestException($"{Time} - Unexpected number of symbol changed events (mappings): {_mappingsCount}. " +
$"Expected only 1.");
}
Debug($"{Time} - SymbolChanged event: {changedEvent}");
if (changedEvent.OldSymbol != _mappedSymbol.ID.ToString())
{
throw new RegressionTestException($"{Time} - Unexpected symbol changed event old symbol: {changedEvent}");
}
if (changedEvent.NewSymbol != _continuousContract.Mapped.ID.ToString())
{
throw new RegressionTestException($"{Time} - Unexpected symbol changed event new symbol: {changedEvent}");
}
// Let's trade the previous mapped contract, so we can hold it until expiration for testing
// (will be sooner than the new mapped contract)
_contractToTrade = _mappedSymbol;
_mappedSymbol = _continuousContract.Mapped;
}
// Let's trade after the mapping is done
if (_contractToTrade != null && _boughtQuantity == 0 && Securities[_contractToTrade].Exchange.ExchangeOpen)
{
Buy(_contractToTrade, 1);
}
if (_contractToTrade != null && slice.Delistings.TryGetValue(_contractToTrade, out var delisting))
{
if (delisting.Type == DelistingType.Delisted)
{
_delisted = true;
if (Portfolio.Invested)
{
throw new RegressionTestException($"{Time} - Portfolio should not be invested after the traded contract is delisted.");
}
}
}
}
public override void OnOrderEvent(OrderEvent orderEvent)
{
if (orderEvent.Symbol != _contractToTrade)
{
throw new RegressionTestException($"{Time} - Unexpected order event symbol: {orderEvent.Symbol}. Expected {_contractToTrade}");
}
if (orderEvent.Direction == OrderDirection.Buy)
{
if (orderEvent.Status == OrderStatus.Filled)
{
if (_boughtQuantity != 0 && _liquidatedQuantity != 0)
{
throw new RegressionTestException($"{Time} - Unexpected buy order event status: {orderEvent.Status}");
}
_boughtQuantity = orderEvent.Quantity;
}
}
else if (orderEvent.Direction == OrderDirection.Sell)
{
if (orderEvent.Status == OrderStatus.Filled)
{
if (_boughtQuantity <= 0 && _liquidatedQuantity != 0)
{
throw new RegressionTestException($"{Time} - Unexpected sell order event status: {orderEvent.Status}");
}
_liquidatedQuantity = orderEvent.Quantity;
if (_liquidatedQuantity != -_boughtQuantity)
{
throw new RegressionTestException($"{Time} - Unexpected liquidated quantity: {_liquidatedQuantity}. Expected: {-_boughtQuantity}");
}
}
}
}
public override void OnSecuritiesChanged(SecurityChanges changes)
{
foreach (var addedSecurity in changes.AddedSecurities)
{
if (addedSecurity.Symbol.SecurityType == SecurityType.Future && addedSecurity.Symbol.IsCanonical())
{
_mappedSymbol = _continuousContract.Mapped;
}
}
}
public override void OnEndOfAlgorithm()
{
if (_mappingsCount == 0)
{
throw new RegressionTestException($"Unexpected number of symbol changed events (mappings): {_mappingsCount}. Expected 1.");
}
if (!_delisted)
{
throw new RegressionTestException("Contract was not delisted");
}
// Make sure we traded and that the position was liquidated on delisting
if (_boughtQuantity <= 0 || _liquidatedQuantity >= 0)
{
throw new RegressionTestException($"Unexpected sold quantity: {_boughtQuantity} and liquidated quantity: {_liquidatedQuantity}");
}
}
/// <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 List<Language> Languages { get; } = new() { Language.CSharp, Language.Python };
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 133945;
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 26;
/// <summary>
/// Final status of the algorithm
/// </summary>
public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed;
/// <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.11%"},
{"Compounding Annual Return", "-1.667%"},
{"Drawdown", "0.100%"},
{"Expectancy", "-1"},
{"Start Equity", "1000000"},
{"End Equity", "998849.48"},
{"Net Profit", "-0.115%"},
{"Sharpe Ratio", "-34.455"},
{"Sortino Ratio", "-57.336"},
{"Probabilistic Sharpe Ratio", "0.002%"},
{"Loss Rate", "100%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "0"},
{"Beta", "0"},
{"Annual Standard Deviation", "0.002"},
{"Annual Variance", "0"},
{"Information Ratio", "-6.176"},
{"Tracking Error", "0.002"},
{"Treynor Ratio", "0"},
{"Total Fees", "€1.02"},
{"Estimated Strategy Capacity", "€2300000000.00"},
{"Lowest Capacity Asset", "FESX YJHOAMPYKRS5"},
{"Portfolio Turnover", "0.40%"},
{"OrderListHash", "54040d29a467becaedcf59d79323321b"}
};
}
}

View File

@@ -13,6 +13,7 @@
* limitations under the License.
*/
using QuantConnect.Data;
using QuantConnect.Data.Market;
namespace QuantConnect.Algorithm.CSharp
@@ -41,8 +42,8 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
/// </summary>
/// <param name="data">TradeBars IDictionary object with your stock data</param>
public void OnData(TradeBars data)
/// <param name="slice">Slice object keyed by symbol containing the stock data</param>
public override void OnData(Slice slice)
{
if (!Portfolio.Invested)
{

View File

@@ -1,4 +1,4 @@
/*
/*
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
*
@@ -59,14 +59,14 @@ namespace QuantConnect.Algorithm.CSharp
/// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
/// </summary>
/// <param name="data">Slice object keyed by symbol containing the stock data</param>
public override void OnData(Slice data)
public override void OnData(Slice slice)
{
if (!Portfolio.Invested)
{
SetHoldings("EURUSD", .5);
SetHoldings("NZDUSD", .5);
Log(string.Join(", ", data.Values));
Log(string.Join(", ", slice.Values));
}
}
}
}
}

View File

@@ -82,53 +82,55 @@ 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, Language.Python };
public virtual List<Language> Languages { get; } = new() { 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>
/// Final status of the algorithm
/// </summary>
public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed;
/// <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 Trades", "3"},
{"Total Orders", "3"},
{"Average Win", "0%"},
{"Average Loss", "-1.01%"},
{"Compounding Annual Return", "254.782%"},
{"Compounding Annual Return", "261.134%"},
{"Drawdown", "2.200%"},
{"Expectancy", "-1"},
{"Net Profit", "1.632%"},
{"Sharpe Ratio", "8.371"},
{"Probabilistic Sharpe Ratio", "66.555%"},
{"Start Equity", "100000"},
{"End Equity", "101655.30"},
{"Net Profit", "1.655%"},
{"Sharpe Ratio", "8.472"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "66.840%"},
{"Loss Rate", "100%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "-0.088"},
{"Alpha", "-0.091"},
{"Beta", "1.006"},
{"Annual Standard Deviation", "0.221"},
{"Annual Variance", "0.049"},
{"Information Ratio", "-32.586"},
{"Annual Standard Deviation", "0.224"},
{"Annual Variance", "0.05"},
{"Information Ratio", "-33.445"},
{"Tracking Error", "0.002"},
{"Treynor Ratio", "1.839"},
{"Total Fees", "$9.77"},
{"Fitness Score", "0.747"},
{"Kelly Criterion Estimate", "38.64"},
{"Kelly Criterion Probability Value", "0.229"},
{"Sortino Ratio", "79228162514264337593543950335"},
{"Return Over Maximum Drawdown", "85.209"},
{"Portfolio Turnover", "0.747"},
{"Total Insights Generated", "100"},
{"Total Insights Closed", "99"},
{"Total Insights Analysis Completed", "99"},
{"Long Insight Count", "100"},
{"Short Insight Count", "0"},
{"Long/Short Ratio", "100%"},
{"Estimated Monthly Alpha Value", "$126657.6305"},
{"Total Accumulated Estimated Alpha Value", "$20405.9516"},
{"Mean Population Estimated Insight Value", "$206.1207"},
{"Mean Population Direction", "54.5455%"},
{"Mean Population Magnitude", "54.5455%"},
{"Rolling Averaged Population Direction", "59.8056%"},
{"Rolling Averaged Population Magnitude", "59.8056%"},
{"OrderListHash", "951346025"}
{"Treynor Ratio", "1.885"},
{"Total Fees", "$10.32"},
{"Estimated Strategy Capacity", "$27000000.00"},
{"Lowest Capacity Asset", "SPY R735QTJ8XC9X"},
{"Portfolio Turnover", "59.86%"},
{"OrderListHash", "f209ed42701b0419858e0100595b40c0"}
};
}
}

View File

@@ -0,0 +1,95 @@
/*
* 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.Linq;
using QuantConnect.Data;
using QuantConnect.Orders;
using QuantConnect.Securities;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Algorithm demonstrating FutureOption asset types and requesting history.
/// </summary>
/// <meta name="tag" content="using data" />
/// <meta name="tag" content="history" />
/// <meta name="tag" content="future option" />
public class BasicTemplateFutureOptionAlgorithm : QCAlgorithm
{
private Symbol _symbol;
/// <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(2022, 1, 1);
SetEndDate(2022, 2, 1);
SetCash(100000);
var gold_futures = AddFuture(Futures.Metals.Gold, Resolution.Minute);
gold_futures.SetFilter(0, 180);
_symbol = gold_futures.Symbol;
AddFutureOption(_symbol, universe => universe.Strikes(-5, +5)
.CallsOnly()
.BackMonth()
.OnlyApplyFilterAtMarketOpen());
// Historical Data
var history = History(_symbol, 60, Resolution.Daily);
Log($"Received {history.Count()} bars from {_symbol} FutureOption historical data call.");
}
/// <summary>
/// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
/// </summary>
/// <param name="data">Slice object keyed by symbol containing the stock data</param>
public override void OnData(Slice slice)
{
// Access Data
foreach(var kvp in slice.OptionChains)
{
var underlyingFutureContract = kvp.Key.Underlying;
var chain = kvp.Value;
if (chain.Count() == 0) continue;
foreach(var contract in chain)
{
Log($@"Canonical Symbol: {kvp.Key};
Contract: {contract};
Right: {contract.Right};
Expiry: {contract.Expiry};
Bid price: {contract.BidPrice};
Ask price: {contract.AskPrice};
Implied Volatility: {contract.ImpliedVolatility}");
}
if (!Portfolio.Invested)
{
var atmStrike = chain.OrderBy(x => Math.Abs(chain.Underlying.Price - x.Strike)).First().Strike;
var selectedContract = chain.Where(x => x.Strike == atmStrike).OrderByDescending(x => x.Expiry).First();
MarketOrder(selectedContract.Symbol, 1);
}
}
}
public override void OnOrderEvent(OrderEvent orderEvent)
{
Debug($"{Time} {orderEvent.ToString()}");
}
}
}

View File

@@ -0,0 +1,225 @@
/*
* 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.Collections.Generic;
using QuantConnect.Data;
using QuantConnect.Interfaces;
using QuantConnect.Indicators;
using QuantConnect.Securities;
using QuantConnect.Securities.Future;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Example algorithm for trading continuous future
/// </summary>
public class BasicTemplateFutureRolloverAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
{
private Dictionary<Symbol, SymbolData> _symbolDataBySymbol = new();
/// <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(2013, 10, 8);
SetEndDate(2013, 12, 10);
SetCash(1000000);
var futures = new List<string> {
Futures.Indices.SP500EMini
};
foreach (var future in futures)
{
// Requesting data
var continuousContract = AddFuture(future,
resolution: Resolution.Daily,
extendedMarketHours: true,
dataNormalizationMode: DataNormalizationMode.BackwardsRatio,
dataMappingMode: DataMappingMode.OpenInterest,
contractDepthOffset: 0
);
var symbolData = new SymbolData(this, continuousContract);
_symbolDataBySymbol.Add(continuousContract.Symbol, symbolData);
}
}
/// <summary>
/// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
/// </summary>
/// <param name="slice">Slice object keyed by symbol containing the stock data</param>
public override void OnData(Slice slice)
{
foreach (var kvp in _symbolDataBySymbol)
{
var symbol = kvp.Key;
var symbolData = kvp.Value;
// Call SymbolData.Update() method to handle new data slice received
symbolData.Update(slice);
// Check if information in SymbolData class and new slice data are ready for trading
if (!symbolData.IsReady || !slice.Bars.ContainsKey(symbol))
{
return;
}
var emaCurrentValue = symbolData.EMA.Current.Value;
if (emaCurrentValue < symbolData.Price && !symbolData.IsLong)
{
MarketOrder(symbolData.Mapped, 1);
}
else if (emaCurrentValue > symbolData.Price && !symbolData.IsShort)
{
MarketOrder(symbolData.Mapped, -1);
}
}
}
/// <summary>
/// Abstracted class object to hold information (state, indicators, methods, etc.) from a Symbol/Security in a multi-security algorithm
/// </summary>
public class SymbolData
{
private QCAlgorithm _algorithm;
private Future _future;
public ExponentialMovingAverage EMA { get; set; }
public decimal Price { get; set; }
public bool IsLong { get; set; }
public bool IsShort { get; set; }
public Symbol Symbol => _future.Symbol;
public Symbol Mapped => _future.Mapped;
/// <summary>
/// Check if symbolData class object are ready for trading
/// </summary>
public bool IsReady => Mapped != null && EMA.IsReady;
/// <summary>
/// Constructor to instantiate the information needed to be hold
/// </summary>
public SymbolData(QCAlgorithm algorithm, Future future)
{
_algorithm = algorithm;
_future = future;
EMA = algorithm.EMA(future.Symbol, 20, Resolution.Daily);
Reset();
}
/// <summary>
/// Handler of new slice of data received
/// </summary>
public void Update(Slice slice)
{
if (slice.SymbolChangedEvents.TryGetValue(Symbol, out var changedEvent))
{
var oldSymbol = changedEvent.OldSymbol;
var newSymbol = changedEvent.NewSymbol;
var tag = $"Rollover - Symbol changed at {_algorithm.Time}: {oldSymbol} -> {newSymbol}";
var quantity = _algorithm.Portfolio[oldSymbol].Quantity;
// Rolling over: to liquidate any position of the old mapped contract and switch to the newly mapped contract
_algorithm.Liquidate(oldSymbol, tag: tag);
_algorithm.MarketOrder(newSymbol, quantity, tag: tag);
Reset();
}
Price = slice.Bars.ContainsKey(Symbol) ? slice.Bars[Symbol].Price : Price;
IsLong = _algorithm.Portfolio[Mapped].IsLong;
IsShort = _algorithm.Portfolio[Mapped].IsShort;
}
/// <summary>
/// Reset RollingWindow/indicator to adapt to newly mapped contract, then warm up the RollingWindow/indicator
/// </summary>
private void Reset()
{
EMA.Reset();
_algorithm.WarmUpIndicator(Symbol, EMA, Resolution.Daily);
}
/// <summary>
/// Disposal method to remove consolidator/update method handler, and reset RollingWindow/indicator to free up memory and speed
/// </summary>
public void Dispose()
{
EMA.Reset();
}
}
/// <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 List<Language> Languages { get; } = new() { Language.CSharp, Language.Python };
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 1190;
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 2;
/// <summary>
/// Final status of the algorithm
/// </summary>
public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed;
/// <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", "1"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "-0.010%"},
{"Drawdown", "0.000%"},
{"Expectancy", "0"},
{"Start Equity", "1000000"},
{"End Equity", "999983.2"},
{"Net Profit", "-0.002%"},
{"Sharpe Ratio", "-225.214"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "0.135%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "-0.008"},
{"Beta", "0"},
{"Annual Standard Deviation", "0"},
{"Annual Variance", "0"},
{"Information Ratio", "-5.146"},
{"Tracking Error", "0.083"},
{"Treynor Ratio", "-542.359"},
{"Total Fees", "$2.15"},
{"Estimated Strategy Capacity", "$0"},
{"Lowest Capacity Asset", "ES VMKLFZIH2MTD"},
{"Portfolio Turnover", "0.13%"},
{"OrderListHash", "273dd05b937c075b75baf8af46d3c7de"}
};
}
}

View File

@@ -18,6 +18,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using QuantConnect.Data;
using QuantConnect.Data.UniverseSelection;
using QuantConnect.Interfaces;
using QuantConnect.Securities;
using QuantConnect.Securities.Future;
@@ -38,11 +39,9 @@ namespace QuantConnect.Algorithm.CSharp
// S&P 500 EMini futures
private const string RootSP500 = Futures.Indices.SP500EMini;
public Symbol SP500 = QuantConnect.Symbol.Create(RootSP500, SecurityType.Future, Market.CME);
// Gold futures
private const string RootGold = Futures.Metals.Gold;
public Symbol Gold = QuantConnect.Symbol.Create(RootGold, SecurityType.Future, Market.COMEX);
/// <summary>
/// Initialize your algorithm and add desired assets.
@@ -58,12 +57,15 @@ namespace QuantConnect.Algorithm.CSharp
// set our expiry filter for this futures chain
// SetFilter method accepts TimeSpan objects or integer for days.
// The following statements yield the same filtering criteria
// The following statements yield the same filtering criteria
futureSP500.SetFilter(TimeSpan.Zero, TimeSpan.FromDays(182));
futureGold.SetFilter(0, 182);
var benchmark = AddEquity("SPY");
SetBenchmark(benchmark.Symbol);
var seeder = new FuncSecuritySeeder(GetLastKnownPrices);
SetSecurityInitializer(security => seeder.SeedSecurity(security));
}
/// <summary>
@@ -72,6 +74,15 @@ namespace QuantConnect.Algorithm.CSharp
/// <param name="slice">The current slice of data keyed by symbol string</param>
public override void OnData(Slice slice)
{
foreach (var changedEvent in slice.SymbolChangedEvents.Values)
{
Debug($"{Time} - SymbolChanged event: {changedEvent}");
if (Time.TimeOfDay != TimeSpan.Zero)
{
throw new RegressionTestException($"{Time} unexpected symbol changed event {changedEvent}!");
}
}
if (!Portfolio.Invested)
{
foreach(var chain in slice.FutureChains)
@@ -104,7 +115,7 @@ namespace QuantConnect.Algorithm.CSharp
var futureMarginModel = buyingPowerModel as FutureMarginModel;
if (buyingPowerModel == null)
{
throw new Exception($"Invalid buying power model. Found: {buyingPowerModel.GetType().Name}. Expected: {nameof(FutureMarginModel)}");
throw new RegressionTestException($"Invalid buying power model. Found: {buyingPowerModel.GetType().Name}. Expected: {nameof(FutureMarginModel)}");
}
var initialOvernight = futureMarginModel.InitialOvernightMarginRequirement;
var maintenanceOvernight = futureMarginModel.MaintenanceOvernightMarginRequirement;
@@ -112,6 +123,19 @@ namespace QuantConnect.Algorithm.CSharp
var maintenanceIntraday = futureMarginModel.MaintenanceIntradayMarginRequirement;
}
public override void OnSecuritiesChanged(SecurityChanges changes)
{
foreach (var addedSecurity in changes.AddedSecurities)
{
if (addedSecurity.Symbol.SecurityType == SecurityType.Future
&& !addedSecurity.Symbol.IsCanonical()
&& !addedSecurity.HasData)
{
throw new RegressionTestException($"Future contracts did not work up as expected: {addedSecurity.Symbol}");
}
}
}
/// <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>
@@ -120,53 +144,55 @@ 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, Language.Python };
public List<Language> Languages { get; } = new() { Language.CSharp, Language.Python };
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 75403;
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 340;
/// <summary>
/// Final status of the algorithm
/// </summary>
public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed;
/// <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 Trades", "8220"},
{"Total Orders", "2700"},
{"Average Win", "0.00%"},
{"Average Loss", "0.00%"},
{"Compounding Annual Return", "-100.000%"},
{"Drawdown", "13.500%"},
{"Expectancy", "-0.818"},
{"Net Profit", "-13.517%"},
{"Sharpe Ratio", "-2.678"},
{"Compounding Annual Return", "-99.777%"},
{"Drawdown", "4.400%"},
{"Expectancy", "-0.724"},
{"Start Equity", "1000000"},
{"End Equity", "955700.5"},
{"Net Profit", "-4.430%"},
{"Sharpe Ratio", "-31.63"},
{"Sortino Ratio", "-31.63"},
{"Probabilistic Sharpe Ratio", "0%"},
{"Loss Rate", "89%"},
{"Win Rate", "11%"},
{"Profit-Loss Ratio", "0.69"},
{"Alpha", "4.398"},
{"Beta", "-0.989"},
{"Annual Standard Deviation", "0.373"},
{"Annual Variance", "0.139"},
{"Information Ratio", "-12.816"},
{"Tracking Error", "0.504"},
{"Treynor Ratio", "1.011"},
{"Total Fees", "$15207.00"},
{"Fitness Score", "0.033"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "-8.62"},
{"Return Over Maximum Drawdown", "-7.81"},
{"Portfolio Turnover", "302.321"},
{"Total Insights Generated", "0"},
{"Total Insights Closed", "0"},
{"Total Insights Analysis Completed", "0"},
{"Long Insight Count", "0"},
{"Short Insight Count", "0"},
{"Long/Short Ratio", "100%"},
{"Estimated Monthly Alpha Value", "$0"},
{"Total Accumulated Estimated Alpha Value", "$0"},
{"Mean Population Estimated Insight Value", "$0"},
{"Mean Population Direction", "0%"},
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "-1197265007"}
{"Loss Rate", "83%"},
{"Win Rate", "17%"},
{"Profit-Loss Ratio", "0.65"},
{"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.677"},
{"Total Fees", "$6237.00"},
{"Estimated Strategy Capacity", "$14000.00"},
{"Lowest Capacity Asset", "GC VOFJUCDY9XNH"},
{"Portfolio Turnover", "9912.69%"},
{"OrderListHash", "6e0f767a46a54365287801295cf7bb75"}
};
}
}

View File

@@ -1,4 +1,4 @@
/*
/*
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
*
@@ -33,7 +33,6 @@ namespace QuantConnect.Algorithm.CSharp
public class BasicTemplateFuturesConsolidationAlgorithm : QCAlgorithm
{
private const string RootSP500 = Futures.Indices.SP500EMini;
public Symbol SP500 = QuantConnect.Symbol.Create(RootSP500, SecurityType.Future, Market.CME);
private HashSet<Symbol> _futureContracts = new HashSet<Symbol>();
public override void Initialize()
@@ -78,4 +77,4 @@ namespace QuantConnect.Algorithm.CSharp
Log(quoteBar.ToString());
}
}
}
}

View File

@@ -0,0 +1,166 @@
/*
* 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 System.Linq;
using QuantConnect.Data;
using QuantConnect.Interfaces;
using QuantConnect.Orders;
using QuantConnect.Securities;
using QuantConnect.Securities.Future;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// This example demonstrates how to add futures with daily resolution.
/// </summary>
/// <meta name="tag" content="using data" />
/// <meta name="tag" content="benchmarks" />
/// <meta name="tag" content="futures" />
public class BasicTemplateFuturesDailyAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
{
protected virtual Resolution Resolution => Resolution.Daily;
protected virtual bool ExtendedMarketHours => false;
// S&P 500 EMini futures
private const string RootSP500 = Futures.Indices.SP500EMini;
// Gold futures
private const string RootGold = Futures.Metals.Gold;
private Future _futureSP500;
private Future _futureGold;
/// <summary>
/// Initialize your algorithm and add desired assets.
/// </summary>
public override void Initialize()
{
SetStartDate(2013, 10, 08);
SetEndDate(2014, 10, 10);
SetCash(1000000);
_futureSP500 = AddFuture(RootSP500, Resolution, extendedMarketHours: ExtendedMarketHours);
_futureGold = AddFuture(RootGold, Resolution, extendedMarketHours: ExtendedMarketHours);
// set our expiry filter for this futures chain
// SetFilter method accepts TimeSpan objects or integer for days.
// The following statements yield the same filtering criteria
_futureSP500.SetFilter(TimeSpan.Zero, TimeSpan.FromDays(182));
_futureGold.SetFilter(0, 182);
}
/// <summary>
/// Event - v3.0 DATA EVENT HANDLER: (Pattern) Basic template for user to override for receiving all subscription data in a single event
/// </summary>
/// <param name="slice">The current slice of data keyed by symbol string</param>
public override void OnData(Slice slice)
{
if (!Portfolio.Invested)
{
foreach(var chain in slice.FutureChains)
{
// find the front contract expiring no earlier than in 90 days
var contract = (
from futuresContract in chain.Value.OrderBy(x => x.Expiry)
where futuresContract.Expiry > Time.Date.AddDays(90)
select futuresContract
).FirstOrDefault();
// if found, trade it.
// Also check if exchange is open for regular or extended hours. Since daily data comes at 8PM, this allows us prevent the
// algorithm from trading on friday when there is not after-market.
if (contract != null)
{
MarketOrder(contract.Symbol, 1);
}
}
}
// Same as above, check for cases like trading on a friday night.
else if (Securities.Values.Where(x => x.Invested).All(x => x.Exchange.Hours.IsOpen(Time, true)))
{
Liquidate();
}
foreach (var changedEvent in slice.SymbolChangedEvents.Values)
{
if (Time.TimeOfDay != TimeSpan.Zero)
{
throw new RegressionTestException($"{Time} unexpected symbol changed event {changedEvent}!");
}
}
}
/// <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 virtual bool CanRunLocally { get; } = true;
/// <summary>
/// This is used by the regression test system to indicate which languages this algorithm is written in.
/// </summary>
public virtual List<Language> Languages { get; } = new() { Language.CSharp, Language.Python };
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public virtual long DataPoints => 12452;
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public virtual int AlgorithmHistoryDataPoints => 0;
/// <summary>
/// Final status of the algorithm
/// </summary>
public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed;
/// <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 Orders", "32"},
{"Average Win", "0.33%"},
{"Average Loss", "-0.04%"},
{"Compounding Annual Return", "0.110%"},
{"Drawdown", "0.300%"},
{"Expectancy", "0.184"},
{"Start Equity", "1000000"},
{"End Equity", "1001108"},
{"Net Profit", "0.111%"},
{"Sharpe Ratio", "-1.688"},
{"Sortino Ratio", "-0.772"},
{"Probabilistic Sharpe Ratio", "14.944%"},
{"Loss Rate", "88%"},
{"Win Rate", "12%"},
{"Profit-Loss Ratio", "8.47"},
{"Alpha", "-0.007"},
{"Beta", "0.002"},
{"Annual Standard Deviation", "0.004"},
{"Annual Variance", "0"},
{"Information Ratio", "-1.353"},
{"Tracking Error", "0.089"},
{"Treynor Ratio", "-4.099"},
{"Total Fees", "$72.00"},
{"Estimated Strategy Capacity", "$0"},
{"Lowest Capacity Asset", "ES VRJST036ZY0X"},
{"Portfolio Turnover", "0.87%"},
{"OrderListHash", "168731c8f3a19f230cc1410818b3b573"}
};
}
}

View File

@@ -31,9 +31,12 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public class BasicTemplateFuturesFrameworkAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
{
protected virtual bool ExtendedMarketHours => false;
public override void Initialize()
{
UniverseSettings.Resolution = Resolution.Minute;
UniverseSettings.ExtendedMarketHours = ExtendedMarketHours;
SetStartDate(2013, 10, 07);
SetEndDate(2013, 10, 11);
@@ -123,58 +126,60 @@ namespace QuantConnect.Algorithm.CSharp
/// <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;
public virtual 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 };
public virtual List<Language> Languages { get; } = new() { Language.CSharp, Language.Python };
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public virtual long DataPoints => 57759;
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public virtual int AlgorithmHistoryDataPoints => 0;
/// <summary>
/// Final status of the algorithm
/// </summary>
public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed;
/// <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>
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", "-92.656%"},
{"Drawdown", "5.000%"},
{"Compounding Annual Return", "-81.734%"},
{"Drawdown", "4.100%"},
{"Expectancy", "0"},
{"Net Profit", "-3.312%"},
{"Sharpe Ratio", "-7.795"},
{"Probabilistic Sharpe Ratio", "0.164%"},
{"Start Equity", "100000"},
{"End Equity", "97830.76"},
{"Net Profit", "-2.169%"},
{"Sharpe Ratio", "-10.299"},
{"Sortino Ratio", "-10.299"},
{"Probabilistic Sharpe Ratio", "0%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "-1.347"},
{"Beta", "0.257"},
{"Annual Standard Deviation", "0.109"},
{"Annual Variance", "0.012"},
{"Information Ratio", "-14.763"},
{"Tracking Error", "0.188"},
{"Treynor Ratio", "-3.318"},
{"Total Fees", "$3.70"},
{"Fitness Score", "0.009"},
{"Kelly Criterion Estimate", "-112.972"},
{"Kelly Criterion Probability Value", "0.671"},
{"Sortino Ratio", "-8.425"},
{"Return Over Maximum Drawdown", "-35.219"},
{"Portfolio Turnover", "0.548"},
{"Total Insights Generated", "6"},
{"Total Insights Closed", "5"},
{"Total Insights Analysis Completed", "5"},
{"Long Insight Count", "6"},
{"Short Insight Count", "0"},
{"Long/Short Ratio", "100%"},
{"Estimated Monthly Alpha Value", "$-96.12923"},
{"Total Accumulated Estimated Alpha Value", "$-15.621"},
{"Mean Population Estimated Insight Value", "$-3.1242"},
{"Mean Population Direction", "0%"},
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "-1624258832"}
{"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.109"},
{"Total Fees", "$4.62"},
{"Estimated Strategy Capacity", "$17000000.00"},
{"Lowest Capacity Asset", "GC VL5E74HP3EE5"},
{"Portfolio Turnover", "43.23%"},
{"OrderListHash", "c0fc1bcdc3008a8d263521bbc9d7cdbd"}
};
}
}

View File

@@ -0,0 +1,80 @@
/*
* 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.Algorithm.Framework.Alphas;
using QuantConnect.Algorithm.Framework.Execution;
using QuantConnect.Algorithm.Framework.Portfolio;
using QuantConnect.Algorithm.Framework.Risk;
using QuantConnect.Algorithm.Framework.Selection;
using QuantConnect.Interfaces;
using QuantConnect.Securities;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Basic template futures framework algorithm uses framework components to define an algorithm
/// that trades futures.
/// </summary>
public class BasicTemplateFuturesFrameworkWithExtendedMarketAlgorithm : BasicTemplateFuturesFrameworkAlgorithm
{
protected override bool ExtendedMarketHours => true;
/// <summary>
/// This is used by the regression test system to indicate which languages this algorithm is written in.
/// </summary>
public override List<Language> Languages { get; } = new() { Language.CSharp, Language.Python };
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public override long DataPoints => 163415;
/// <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 Orders", "2"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "-92.667%"},
{"Drawdown", "5.000%"},
{"Expectancy", "0"},
{"Start Equity", "100000"},
{"End Equity", "96685.76"},
{"Net Profit", "-3.314%"},
{"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.47"},
{"Beta", "0.312"},
{"Annual Standard Deviation", "0.134"},
{"Annual Variance", "0.018"},
{"Information Ratio", "-14.77"},
{"Tracking Error", "0.192"},
{"Treynor Ratio", "-2.742"},
{"Total Fees", "$4.62"},
{"Estimated Strategy Capacity", "$52000000.00"},
{"Lowest Capacity Asset", "GC VL5E74HP3EE5"},
{"Portfolio Turnover", "43.77%"},
{"OrderListHash", "dcdaafcefa47465962ace2759ed99c91"}
};
}
}

View File

@@ -1,4 +1,4 @@
/*
/*
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
*
@@ -36,6 +36,9 @@ namespace QuantConnect.Algorithm.CSharp
/// <meta name="tag" content="futures" />
public class BasicTemplateFuturesHistoryAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
{
protected virtual bool ExtendedMarketHours => false;
protected virtual int ExpectedHistoryCallCount => 42;
// S&P 500 EMini futures
private string [] roots = new []
{
@@ -44,7 +47,6 @@ namespace QuantConnect.Algorithm.CSharp
};
private int _successCount = 0;
public override void Initialize()
{
SetStartDate(2013, 10, 8);
@@ -54,7 +56,7 @@ namespace QuantConnect.Algorithm.CSharp
foreach (var root in roots)
{
// set our expiry filter for this futures chain
AddFuture(root, Resolution.Minute).SetFilter(TimeSpan.Zero, TimeSpan.FromDays(182));
AddFuture(root, Resolution.Minute, extendedMarketHours: ExtendedMarketHours).SetFilter(TimeSpan.Zero, TimeSpan.FromDays(182));
}
SetBenchmark(d => 1000000);
@@ -67,16 +69,16 @@ namespace QuantConnect.Algorithm.CSharp
var history = History(10, Resolution.Minute);
if (history.Count() < 10)
{
throw new Exception($"Empty history at {Time}");
throw new RegressionTestException($"Empty history at {Time}");
}
_successCount++;
}
public override void OnEndOfAlgorithm()
{
if (_successCount < 49)
if (_successCount < ExpectedHistoryCallCount)
{
throw new Exception($"Scheduled Event did not assert history call as many times as expected: {_successCount}/49");
throw new RegressionTestException($"Scheduled Event did not assert history call as many times as expected: {_successCount}/49");
}
}
@@ -118,7 +120,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <summary>
/// Order fill event handler. On an order fill update the resulting information is passed to this method.
/// </summary>
/// <param name="orderEvent">Order event details containing details of the evemts</param>
/// <param name="orderEvent">Order event details containing details of the events</param>
/// <remarks>This method can be called asynchronously and so should only be used by seasoned C# experts. Ensure you use proper locks on thread-unsafe objects</remarks>
public override void OnOrderEvent(OrderEvent orderEvent)
{
@@ -128,26 +130,44 @@ namespace QuantConnect.Algorithm.CSharp
/// <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;
public virtual 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 };
public virtual List<Language> Languages { get; } = new() { Language.CSharp, Language.Python };
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public virtual long DataPoints => 48690;
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public virtual int AlgorithmHistoryDataPoints => 5305;
/// <summary>
/// Final status of the algorithm
/// </summary>
public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed;
/// <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>
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%"},
{"Drawdown", "0%"},
{"Expectancy", "0"},
{"Start Equity", "1000000"},
{"End Equity", "1000000"},
{"Net Profit", "0%"},
{"Sharpe Ratio", "0"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "0%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
@@ -160,26 +180,10 @@ namespace QuantConnect.Algorithm.CSharp
{"Tracking Error", "0"},
{"Treynor Ratio", "0"},
{"Total Fees", "$0.00"},
{"Fitness Score", "0"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "79228162514264337593543950335"},
{"Return Over Maximum Drawdown", "79228162514264337593543950335"},
{"Portfolio Turnover", "0"},
{"Total Insights Generated", "0"},
{"Total Insights Closed", "0"},
{"Total Insights Analysis Completed", "0"},
{"Long Insight Count", "0"},
{"Short Insight Count", "0"},
{"Long/Short Ratio", "100%"},
{"Estimated Monthly Alpha Value", "$0"},
{"Total Accumulated Estimated Alpha Value", "$0"},
{"Mean Population Estimated Insight Value", "$0"},
{"Mean Population Direction", "0%"},
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "371857150"}
{"Estimated Strategy Capacity", "$0"},
{"Lowest Capacity Asset", ""},
{"Portfolio Turnover", "0%"},
{"OrderListHash", "d41d8cd98f00b204e9800998ecf8427e"}
};
}
}
}

View File

@@ -0,0 +1,96 @@
/*
* 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.Linq;
using QuantConnect.Data;
using QuantConnect.Orders;
using QuantConnect.Securities;
using QuantConnect.Data.UniverseSelection;
using QuantConnect.Interfaces;
using System.Collections.Generic;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// This example demonstrates how to get access to futures history for a given root symbol with extended market hours.
/// It also shows how you can prefilter contracts easily based on expirations, and inspect the futures
/// chain to pick a specific contract to trade.
/// </summary>
/// <meta name="tag" content="using data" />
/// <meta name="tag" content="history and warm up" />
/// <meta name="tag" content="history" />
/// <meta name="tag" content="futures" />
public class BasicTemplateFuturesHistoryWithExtendedMarketHoursAlgorithm : BasicTemplateFuturesHistoryAlgorithm
{
protected override bool ExtendedMarketHours => true;
protected override int ExpectedHistoryCallCount => 49;
/// <summary>
/// This is used by the regression test system to indicate which languages this algorithm is written in.
/// </summary>
public override List<Language> Languages { get; } = new() { Language.CSharp, Language.Python };
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public override long DataPoints => 147771;
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public override int AlgorithmHistoryDataPoints => 6112;
/// <summary>
/// Final status of the algorithm
/// </summary>
public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed;
/// <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 Orders", "0"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "0%"},
{"Drawdown", "0%"},
{"Expectancy", "0"},
{"Start Equity", "1000000"},
{"End Equity", "1000000"},
{"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", ""},
{"Portfolio Turnover", "0%"},
{"OrderListHash", "d41d8cd98f00b204e9800998ecf8427e"}
};
}
}

View File

@@ -0,0 +1,80 @@
/*
* 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 System.Linq;
using QuantConnect.Data;
using QuantConnect.Interfaces;
using QuantConnect.Securities;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// This regressions tests the BasicTemplateFuturesDailyAlgorithm with hour data
/// </summary>
/// <meta name="tag" content="using data" />
/// <meta name="tag" content="benchmarks" />
/// <meta name="tag" content="futures" />
public class BasicTemplateFuturesHourlyAlgorithm : BasicTemplateFuturesDailyAlgorithm
{
protected override Resolution Resolution => Resolution.Hour;
/// <summary>
/// This is used by the regression test system to indicate which languages this algorithm is written in.
/// </summary>
public override List<Language> Languages { get; } = new() { Language.CSharp, Language.Python };
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public override long DataPoints => 87289;
/// <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 Orders", "716"},
{"Average Win", "0.03%"},
{"Average Loss", "-0.01%"},
{"Compounding Annual Return", "-1.716%"},
{"Drawdown", "1.700%"},
{"Expectancy", "-0.770"},
{"Start Equity", "1000000"},
{"End Equity", "982718.38"},
{"Net Profit", "-1.728%"},
{"Sharpe Ratio", "-8.845"},
{"Sortino Ratio", "-5.449"},
{"Probabilistic Sharpe Ratio", "0.000%"},
{"Loss Rate", "96%"},
{"Win Rate", "4%"},
{"Profit-Loss Ratio", "4.89"},
{"Alpha", "-0.018"},
{"Beta", "-0.002"},
{"Annual Standard Deviation", "0.002"},
{"Annual Variance", "0"},
{"Information Ratio", "-1.483"},
{"Tracking Error", "0.089"},
{"Treynor Ratio", "9.102"},
{"Total Fees", "$1634.12"},
{"Estimated Strategy Capacity", "$8000.00"},
{"Lowest Capacity Asset", "ES VP274HSU1AF5"},
{"Portfolio Turnover", "20.10%"},
{"OrderListHash", "aa7e574f86b70428ca0afae381be80ba"}
};
}
}

View File

@@ -0,0 +1,198 @@
/*
* 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 System.Linq;
using QuantConnect.Data;
using QuantConnect.Data.UniverseSelection;
using QuantConnect.Interfaces;
using QuantConnect.Securities;
using QuantConnect.Securities.Future;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// This example demonstrates how to add futures for a given underlying asset.
/// It also shows how you can prefilter contracts easily based on expirations, and how you
/// can inspect the futures chain to pick a specific contract to trade.
/// </summary>
/// <meta name="tag" content="using data" />
/// <meta name="tag" content="benchmarks" />
/// <meta name="tag" content="futures" />
public class BasicTemplateFuturesWithExtendedMarketAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
{
private Symbol _contractSymbol;
// S&P 500 EMini futures
private const string RootSP500 = Futures.Indices.SP500EMini;
// Gold futures
private const string RootGold = Futures.Metals.Gold;
/// <summary>
/// Initialize your algorithm and add desired assets.
/// </summary>
public override void Initialize()
{
SetStartDate(2013, 10, 08);
SetEndDate(2013, 10, 10);
SetCash(1000000);
var futureSP500 = AddFuture(RootSP500, extendedMarketHours: true);
var futureGold = AddFuture(RootGold, extendedMarketHours: true);
// set our expiry filter for this futures chain
// SetFilter method accepts TimeSpan objects or integer for days.
// The following statements yield the same filtering criteria
futureSP500.SetFilter(TimeSpan.Zero, TimeSpan.FromDays(182));
futureGold.SetFilter(0, 182);
var benchmark = AddEquity("SPY");
SetBenchmark(benchmark.Symbol);
var seeder = new FuncSecuritySeeder(GetLastKnownPrices);
SetSecurityInitializer(security => seeder.SeedSecurity(security));
}
/// <summary>
/// Event - v3.0 DATA EVENT HANDLER: (Pattern) Basic template for user to override for receiving all subscription data in a single event
/// </summary>
/// <param name="slice">The current slice of data keyed by symbol string</param>
public override void OnData(Slice slice)
{
foreach (var changedEvent in slice.SymbolChangedEvents.Values)
{
Debug($"{Time} - SymbolChanged event: {changedEvent}");
if (Time.TimeOfDay != TimeSpan.Zero)
{
throw new RegressionTestException($"{Time} unexpected symbol changed event {changedEvent}!");
}
}
if (!Portfolio.Invested)
{
foreach(var chain in slice.FutureChains)
{
// find the front contract expiring no earlier than in 90 days
var contract = (
from futuresContract in chain.Value.OrderBy(x => x.Expiry)
where futuresContract.Expiry > Time.Date.AddDays(90)
select futuresContract
).FirstOrDefault();
// if found, trade it
if (contract != null)
{
_contractSymbol = contract.Symbol;
MarketOrder(_contractSymbol, 1);
}
}
}
else
{
Liquidate();
}
}
public override void OnEndOfAlgorithm()
{
// Get the margin requirements
var buyingPowerModel = Securities[_contractSymbol].BuyingPowerModel;
var futureMarginModel = buyingPowerModel as FutureMarginModel;
if (buyingPowerModel == null)
{
throw new RegressionTestException($"Invalid buying power model. Found: {buyingPowerModel.GetType().Name}. Expected: {nameof(FutureMarginModel)}");
}
var initialOvernight = futureMarginModel.InitialOvernightMarginRequirement;
var maintenanceOvernight = futureMarginModel.MaintenanceOvernightMarginRequirement;
var initialIntraday = futureMarginModel.InitialIntradayMarginRequirement;
var maintenanceIntraday = futureMarginModel.MaintenanceIntradayMarginRequirement;
}
public override void OnSecuritiesChanged(SecurityChanges changes)
{
foreach (var addedSecurity in changes.AddedSecurities)
{
if (addedSecurity.Symbol.SecurityType == SecurityType.Future
&& !addedSecurity.Symbol.IsCanonical()
&& !addedSecurity.HasData)
{
throw new RegressionTestException($"Future contracts did not work up as expected: {addedSecurity.Symbol}");
}
}
}
/// <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 List<Language> Languages { get; } = new() { Language.CSharp, Language.Python };
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 224662;
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 340;
/// <summary>
/// Final status of the algorithm
/// </summary>
public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed;
/// <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", "8282"},
{"Average Win", "0.00%"},
{"Average Loss", "0.00%"},
{"Compounding Annual Return", "-100.000%"},
{"Drawdown", "13.900%"},
{"Expectancy", "-0.824"},
{"Start Equity", "1000000"},
{"End Equity", "861260.7"},
{"Net Profit", "-13.874%"},
{"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.468"},
{"Beta", "-0.215"},
{"Annual Standard Deviation", "0.052"},
{"Annual Variance", "0.003"},
{"Information Ratio", "-58.37"},
{"Tracking Error", "0.295"},
{"Treynor Ratio", "4.695"},
{"Total Fees", "$19131.42"},
{"Estimated Strategy Capacity", "$130000.00"},
{"Lowest Capacity Asset", "GC VOFJUCDY9XNH"},
{"Portfolio Turnover", "32523.20%"},
{"OrderListHash", "0664a72652a19956ea3c4915269cc4b9"}
};
}
}

View File

@@ -0,0 +1,82 @@
/*
* 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 System.Linq;
using QuantConnect.Data;
using QuantConnect.Interfaces;
using QuantConnect.Orders;
using QuantConnect.Securities;
using QuantConnect.Securities.Future;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// This example demonstrates how to add futures with daily resolution and extended market hours.
/// </summary>
/// <meta name="tag" content="using data" />
/// <meta name="tag" content="benchmarks" />
/// <meta name="tag" content="futures" />
public class BasicTemplateFuturesWithExtendedMarketDailyAlgorithm : BasicTemplateFuturesDailyAlgorithm
{
protected override bool ExtendedMarketHours => true;
/// <summary>
/// This is used by the regression test system to indicate which languages this algorithm is written in.
/// </summary>
public override List<Language> Languages { get; } = new() { Language.CSharp, Language.Python };
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public override long DataPoints => 14790;
/// <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 Orders", "36"},
{"Average Win", "0.33%"},
{"Average Loss", "-0.03%"},
{"Compounding Annual Return", "0.102%"},
{"Drawdown", "0.300%"},
{"Expectancy", "0.171"},
{"Start Equity", "1000000"},
{"End Equity", "1001024.4"},
{"Net Profit", "0.102%"},
{"Sharpe Ratio", "-1.702"},
{"Sortino Ratio", "-0.836"},
{"Probabilistic Sharpe Ratio", "14.653%"},
{"Loss Rate", "89%"},
{"Win Rate", "11%"},
{"Profit-Loss Ratio", "9.54"},
{"Alpha", "-0.007"},
{"Beta", "0.002"},
{"Annual Standard Deviation", "0.004"},
{"Annual Variance", "0"},
{"Information Ratio", "-1.353"},
{"Tracking Error", "0.089"},
{"Treynor Ratio", "-4.126"},
{"Total Fees", "$80.60"},
{"Estimated Strategy Capacity", "$0"},
{"Lowest Capacity Asset", "ES VRJST036ZY0X"},
{"Portfolio Turnover", "0.97%"},
{"OrderListHash", "52c852d720692fab1e12212b2aba03d4"}
};
}
}

View File

@@ -0,0 +1,80 @@
/*
* 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 System.Linq;
using QuantConnect.Data;
using QuantConnect.Interfaces;
using QuantConnect.Securities;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// This regressions tests the BasicTemplateFuturesDailyAlgorithm with hour data and extended market hours
/// </summary>
/// <meta name="tag" content="using data" />
/// <meta name="tag" content="benchmarks" />
/// <meta name="tag" content="futures" />
public class BasicTemplateFuturesWithExtendedMarketHourlyAlgorithm : BasicTemplateFuturesHourlyAlgorithm
{
protected override bool ExtendedMarketHours => true;
/// <summary>
/// This is used by the regression test system to indicate which languages this algorithm is written in.
/// </summary>
public override List<Language> Languages { get; } = new() { Language.CSharp, Language.Python };
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public override long DataPoints => 228834;
/// <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 Orders", "1992"},
{"Average Win", "0.01%"},
{"Average Loss", "-0.01%"},
{"Compounding Annual Return", "-4.687%"},
{"Drawdown", "4.700%"},
{"Expectancy", "-0.911"},
{"Start Equity", "1000000"},
{"End Equity", "952789.22"},
{"Net Profit", "-4.721%"},
{"Sharpe Ratio", "-7.183"},
{"Sortino Ratio", "-5.14"},
{"Probabilistic Sharpe Ratio", "0%"},
{"Loss Rate", "97%"},
{"Win Rate", "3%"},
{"Profit-Loss Ratio", "2.04"},
{"Alpha", "-0.038"},
{"Beta", "-0.008"},
{"Annual Standard Deviation", "0.005"},
{"Annual Variance", "0"},
{"Information Ratio", "-1.702"},
{"Tracking Error", "0.09"},
{"Treynor Ratio", "5.054"},
{"Total Fees", "$4543.28"},
{"Estimated Strategy Capacity", "$3000.00"},
{"Lowest Capacity Asset", "ES VP274HSU1AF5"},
{"Portfolio Turnover", "56.73%"},
{"OrderListHash", "424536177e9be5895bab50638ef43a9d"}
};
}
}

View File

@@ -0,0 +1,124 @@
/*
* 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.Collections.Generic;
using QuantConnect.Data;
using QuantConnect.Interfaces;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Basic template algorithm simply initializes the date range and cash. This is a skeleton
/// framework you can use for designing an algorithm.
/// </summary>
/// <meta name="tag" content="using data" />
/// <meta name="tag" content="using quantconnect" />
/// <meta name="tag" content="trading and orders" />
public class BasicTemplateHourlyAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
{
private Symbol _spy = QuantConnect.Symbol.Create("SPY", SecurityType.Equity, Market.USA);
/// <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(2013, 10, 07); //Set Start Date
SetEndDate(2013, 10, 11); //Set End Date
SetCash(100000); //Set Strategy Cash
// Find more symbols here: http://quantconnect.com/data
// Forex, CFD, Equities Resolutions: Tick, Second, Minute, Hour, Daily.
// Futures Resolution: Tick, Second, Minute
// Options Resolution: Minute Only.
AddEquity("SPY", Resolution.Hour);
// There are other assets with similar methods. See "Selecting Options" etc for more details.
// AddFuture, AddForex, AddCfd, AddOption
}
/// <summary>
/// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
/// </summary>
/// <param name="slice">Slice object keyed by symbol containing the stock data</param>
public override void OnData(Slice slice)
{
if (!Portfolio.Invested)
{
SetHoldings(_spy, 1);
Debug("Purchased Stock");
}
}
/// <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 List<Language> Languages { get; } = new() { Language.CSharp };
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 78;
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public int AlgorithmHistoryDataPoints => 0;
/// <summary>
/// Final status of the algorithm
/// </summary>
public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed;
/// <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", "1"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "227.693%"},
{"Drawdown", "2.000%"},
{"Expectancy", "0"},
{"Start Equity", "100000"},
{"End Equity", "101529.08"},
{"Net Profit", "1.529%"},
{"Sharpe Ratio", "8.855"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "67.609%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "-0.005"},
{"Beta", "0.996"},
{"Annual Standard Deviation", "0.222"},
{"Annual Variance", "0.049"},
{"Information Ratio", "-14.564"},
{"Tracking Error", "0.001"},
{"Treynor Ratio", "1.971"},
{"Total Fees", "$3.44"},
{"Estimated Strategy Capacity", "$110000000.00"},
{"Lowest Capacity Asset", "SPY R735QTJ8XC9X"},
{"Portfolio Turnover", "19.96%"},
{"OrderListHash", "966f8355817adbc8c724d1062691a60b"}
};
}
}

View File

@@ -0,0 +1,176 @@
/*
* 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.Indicators;
using QuantConnect.Interfaces;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// This example demonstrates how to add index asset types.
/// </summary>
/// <meta name="tag" content="using data" />
/// <meta name="tag" content="benchmarks" />
/// <meta name="tag" content="indexes" />
public class BasicTemplateIndexAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
{
protected Symbol Spx { get; set; }
protected Symbol SpxOption { get; set; }
private ExponentialMovingAverage _emaSlow;
private ExponentialMovingAverage _emaFast;
protected virtual Resolution Resolution => Resolution.Minute;
protected virtual int StartDay => 4;
/// <summary>
/// Initialize your algorithm and add desired assets.
/// </summary>
public override void Initialize()
{
SetStartDate(2021, 1, StartDay);
SetEndDate(2021, 1, 18);
SetCash(1000000);
// Use indicator for signal; but it cannot be traded
Spx = AddIndex("SPX", Resolution).Symbol;
// Trade on SPX ITM calls
SpxOption = QuantConnect.Symbol.CreateOption(
Spx,
Market.USA,
OptionStyle.European,
OptionRight.Call,
3200m,
new DateTime(2021, 1, 15));
AddIndexOptionContract(SpxOption, Resolution);
_emaSlow = EMA(Spx, Resolution > Resolution.Minute ? 6 : 80);
_emaFast = EMA(Spx, Resolution > Resolution.Minute ? 2 : 200);
Settings.DailyPreciseEndTime = true;
}
/// <summary>
/// Index EMA Cross trading underlying.
/// </summary>
public override void OnData(Slice slice)
{
if (!slice.Bars.ContainsKey(Spx) || !slice.Bars.ContainsKey(SpxOption))
{
return;
}
// Warm up indicators
if (!_emaSlow.IsReady)
{
return;
}
if (_emaFast > _emaSlow)
{
SetHoldings(SpxOption, 1);
}
else
{
Liquidate();
}
}
/// <summary>
/// Asserts indicators are ready
/// </summary>
/// <exception cref="RegressionTestException"></exception>
protected void AssertIndicators()
{
if (!_emaSlow.IsReady || !_emaFast.IsReady)
{
throw new RegressionTestException("Indicators are not ready!");
}
}
public override void OnEndOfAlgorithm()
{
if (Portfolio[Spx].TotalSaleVolume > 0)
{
throw new RegressionTestException("Index is not tradable.");
}
AssertIndicators();
}
/// <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 virtual bool CanRunLocally { get; } = true;
/// <summary>
/// This is used by the regression test system to indicate which languages this algorithm is written in.
/// </summary>
public virtual List<Language> Languages { get; } = new() { Language.CSharp, Language.Python };
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public virtual long DataPoints => 16199;
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public virtual int AlgorithmHistoryDataPoints => 0;
/// <summary>
/// Final status of the algorithm
/// </summary>
public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed;
/// <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 Orders", "3"},
{"Average Win", "7.08%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "603.355%"},
{"Drawdown", "3.400%"},
{"Expectancy", "0"},
{"Start Equity", "1000000"},
{"End Equity", "1064395"},
{"Net Profit", "6.440%"},
{"Sharpe Ratio", "-4.563"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "0.781%"},
{"Loss Rate", "0%"},
{"Win Rate", "100%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "-0.169"},
{"Beta", "0.073"},
{"Annual Standard Deviation", "0.028"},
{"Annual Variance", "0.001"},
{"Information Ratio", "-6.684"},
{"Tracking Error", "0.099"},
{"Treynor Ratio", "-1.771"},
{"Total Fees", "$0.00"},
{"Estimated Strategy Capacity", "$3000.00"},
{"Lowest Capacity Asset", "SPX XL80P3GHDZXQ|SPX 31"},
{"Portfolio Turnover", "23.97%"},
{"OrderListHash", "51f1bc2ea080df79748dc66c2520b782"}
};
}
}

View File

@@ -0,0 +1,155 @@
/*
* 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.Linq;
using QuantConnect.Data;
using System.Collections.Generic;
using QuantConnect.Data.Market;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Regression for running an Index algorithm with Daily data
/// </summary>
public class BasicTemplateIndexDailyAlgorithm : BasicTemplateIndexAlgorithm
{
protected override Resolution Resolution => Resolution.Daily;
protected override int StartDay => 1;
// two complete weeks starting from the 5th. The 18th bar is not included since it is a holiday
protected virtual int ExpectedBarCount => 2 * 5;
protected int BarCounter { get; set; }
/// <summary>
/// Purchase a contract when we are not invested, liquidate otherwise
/// </summary>
public override void OnData(Slice slice)
{
if (!Portfolio.Invested)
{
// SPX Index is not tradable, but we can trade an option
MarketOrder(SpxOption, 1);
}
else
{
Liquidate();
}
// Count how many slices we receive with SPX data in it to assert later
if (slice.ContainsKey(Spx))
{
BarCounter++;
}
}
public override void OnEndOfAlgorithm()
{
if (BarCounter != ExpectedBarCount)
{
throw new ArgumentException($"Bar Count {BarCounter} is not expected count of {ExpectedBarCount}");
}
AssertIndicators();
if (Resolution != Resolution.Daily)
{
return;
}
var openInterest = Securities[SpxOption].Cache.GetAll<OpenInterest>();
if (openInterest.Single().EndTime != new DateTime(2021, 1, 15, 23, 0, 0))
{
throw new ArgumentException($"Unexpected open interest time: {openInterest.Single().EndTime}");
}
foreach (var symbol in new[] { SpxOption, Spx })
{
var history = History(symbol, 10).ToList();
if (history.Count != 10)
{
throw new RegressionTestException($"Unexpected history count: {history.Count}");
}
if (history.Any(x => x.Time.TimeOfDay != new TimeSpan(8, 30, 0)))
{
throw new RegressionTestException($"Unexpected history data start time");
}
if (history.Any(x => x.EndTime.TimeOfDay != new TimeSpan(15, 15, 0)))
{
throw new RegressionTestException($"Unexpected history data end time");
}
}
}
/// <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 override bool CanRunLocally { get; } = true;
/// <summary>
/// This is used by the regression test system to indicate which languages this algorithm is written in.
/// </summary>
public override List<Language> Languages { get; } = new() { Language.CSharp, Language.Python };
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public override long DataPoints => 121;
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public override int AlgorithmHistoryDataPoints => 30;
/// <summary>
/// Final status of the algorithm
/// </summary>
public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed;
/// <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 Orders", "11"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "621.484%"},
{"Drawdown", "0%"},
{"Expectancy", "0"},
{"Start Equity", "1000000"},
{"End Equity", "1084600"},
{"Net Profit", "8.460%"},
{"Sharpe Ratio", "9.923"},
{"Sortino Ratio", "0"},
{"Probabilistic Sharpe Ratio", "93.682%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "3.61"},
{"Beta", "-0.513"},
{"Annual Standard Deviation", "0.359"},
{"Annual Variance", "0.129"},
{"Information Ratio", "8.836"},
{"Tracking Error", "0.392"},
{"Treynor Ratio", "-6.937"},
{"Total Fees", "$0.00"},
{"Estimated Strategy Capacity", "$0"},
{"Lowest Capacity Asset", "SPX XL80P3GHDZXQ|SPX 31"},
{"Portfolio Turnover", "2.42%"},
{"OrderListHash", "61e8517ac3da6bed414ef23d26736fef"}
};
}
}

View File

@@ -0,0 +1,72 @@
using System.Collections.Generic;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Regression for running an Index algorithm with Hourly data
/// </summary>
public class BasicTemplateIndexHourlyAlgorithm : BasicTemplateIndexDailyAlgorithm
{
protected override Resolution Resolution => Resolution.Hour;
protected override int ExpectedBarCount => base.ExpectedBarCount * 8;
/// <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 override bool CanRunLocally { get; } = true;
/// <summary>
/// This is used by the regression test system to indicate which languages this algorithm is written in.
/// </summary>
public override List<Language> Languages { get; } = new() { Language.CSharp };
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public override long DataPoints => 401;
/// <summary>
/// Data Points count of the algorithm history
/// </summary>
public override int AlgorithmHistoryDataPoints => 0;
/// <summary>
/// Final status of the algorithm
/// </summary>
public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed;
/// <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 Orders", "81"},
{"Average Win", "1.28%"},
{"Average Loss", "-0.06%"},
{"Compounding Annual Return", "-20.546%"},
{"Drawdown", "1.800%"},
{"Expectancy", "-0.402"},
{"Start Equity", "1000000"},
{"End Equity", "990775"},
{"Net Profit", "-0.922%"},
{"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.157"},
{"Beta", "0.025"},
{"Annual Standard Deviation", "0.053"},
{"Annual Variance", "0.003"},
{"Information Ratio", "-2.07"},
{"Tracking Error", "0.121"},
{"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", "44325fc1fdebb8e54f64a3f6e8a4bcd7"}
};
}
}

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