Compare commits

...

580 Commits
8552 ... 11050

Author SHA1 Message Date
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
Adalyat Nazirov
017b464e21 Map legacy symbols using map file (#5017)
* map IB brokerage symbol

* map Alpaca symbols

* improve empty symbol checking
2020-12-28 17:54:00 -03:00
Gerardo Salazar
4dec21ccc0 Fixes failing option chain provider test for futures options (#5088)
* The test didn't take into account that the contract expiring on
    December would mean that there would temporarily be no Dec. FOP
    contract. We fix this by looking for the Mar. contract instead
    if the december contract has expired.
2020-12-28 16:28:41 -03:00
Martin-Molinero
529d0a3634 Fix low resolution cache (#5080)
* Replace cache size for MB

* Remove setting capacity

* Custom cache implementation

* Reduce locks in custom cache

* Add cache performance unit test
2020-12-28 16:27:11 -03:00
Martin-Molinero
9c89e8d403 Fix backtest result packet deserializing (#5084)
* added test covering minValue / maxValue issue with JsonRoundingConverter

* change namespaces

* JsonRoundingConverter fix decimal.Min and MaxValues (cannot deserialize)

* remove dependency on 3rd party library

* c# 6 compatible code (remove pattern matching)

* Fixes BacktestResultPacket deserializing

- Serializing decimals as strings to avoid precision loss, since json
  convert will use floating point precision. Updating unit tests.
- Fix logging unit test failing to delete file being used.

Co-authored-by: Mark Virchenko <mark.virchenko@calienteam.com>
2020-12-28 16:26:40 -03:00
Adalyat Nazirov
1988ad1ae5 Bug 4925 daylight out of order bar (#4941)
* test

* wip

* Revert "Fix duplicated history entries when contains daylight saving time change (#4700)"

Use proper rounding down

* regression test

* remove unused parameters

* more tests

* fix name and comment

* improve regression test

* more tests: oanda market hours

* re-apply Exchange TZ to bar EndTime

* fix expected results

* we can't substract minute because it can harm algorithm on minute resolution; so we could use tick?

* rename prop: conflict with QCAlgorithm.StartDate

* do not log messages to pass travis ci log limit

* assign loghandler in AlgorithmSetupHandler

* reference to PR for more description

* due to https://github.com/QuantConnect/Lean/pull/5039 we don't need to override it manually
2020-12-28 16:24:33 -03:00
Martin-Molinero
3658fb1405 Update config.json (#5086) 2020-12-28 13:06:07 -03:00
Colton Sellers
0ac79487d7 IB Brokerage Restore Subscriptions Fix (#5078)
* Return true after all symbols have been processed

* Continue on Canonical Future Symbols
2020-12-23 20:56:07 -03:00
Gerardo Salazar
38120a3217 Converts QuantConnect.Common.csproj file to .NET Sdk format (#5071) 2020-12-23 13:15:29 -03:00
Martin-Molinero
01a13a095a Remove cloud-api-url config setting (#5073) 2020-12-22 22:51:00 -03:00
Colton Sellers
704a5cb00e Pycharm Docker Debugging Fix (#5069)
* Move PyCharm Debugger to port 6000 and expose it

* Change PyCharm default configurations to port 6000
2020-12-22 15:22:46 -03:00
Martin-Molinero
490ad08c89 Optimization handling of failed backtest init (#5068)
- Optimizer will increment failed count and notify the strategy of
  failed backtest initialization
2020-12-21 19:27:27 -03:00
Martin-Molinero
a60cd95611 Optimizer will clean lean before last update (#5063)
- LeanOptimizer will clean up any lean instance before calling the last
  udpate, so that runtime stats are correct.
2020-12-21 15:17:44 -03:00
Colton Sellers
eed8e9c763 Improve IBBrokerage Symbol Mapping Error Message (#5051)
* Improve IBBrokerage Error Message

* Add exception message to catch statement

* Address review

* Address review edits
2020-12-21 13:04:05 -03:00
Marco Grassi
365f53dfc7 Fix the missed rename of OptimizationStatus.Ended to Completed (#5060) 2020-12-19 19:06:09 -03:00
Martin-Molinero
48a86c2626 Rename OptimizationStatus from Ended to Completed (#5059) 2020-12-18 16:53:29 -08:00
Martin-Molinero
2de9c21b6d Optimization tweaks (#5056)
* Add progress for runtimeStats

- Add optimization progress runtimestats
- Add ServerStatistics for the last backtesting package

* Add StaticOptimizationParameter

- Add StaticOptimizationParameter. Updating unit tests
2020-12-18 16:01:44 -08:00
Martin-Molinero
649aafc952 Adding Api.ReadBacktest optional getCharts (#5054)
* Adding Api.ReadBacktest optional getCharts

- Optionally allow users not to fetch backtest charts when reading a
  backtest, it can be slow

* Fix null reference for deleted/cancelled backtests

* Get Leaky bucket config settings once
2020-12-18 14:17:40 -03:00
Gerardo Salazar
25fa4c6fb6 Adds holidays to ES futures (#5045)
* Adds holidays to ES futures

* Adds CME equity product market hours and holidays (ES, NQ, YM)
2020-12-17 21:12:20 -03:00
Martin-Molinero
d1b35f7974 Optimization status update (#5050) 2020-12-17 17:09:01 -03:00
Colton Sellers
4006ba01e4 Reduce Travis Log (#5039)
* Reduce Travis setup verbosity

* Introduce ConsoleErrorLogHandler

* Change Console.WriteLine to Log statements

* Quiet wget

* Route build stubs stdout to null

* Fix Quantbook history test

* Silence stub packages directly

* Use parameterized log-handler for testing

* Rename AssemblyInitialize Setup

* Fix AlgorithmRunner file logging

* Drop all overriden LogHandlers in tests

* Change to OneTimeSetup to maintain LogHandlers

* Permit any ILogHandler to be defined in params

* Fix for AlgorithmRunner Handlers V2
2020-12-17 12:59:13 -03:00
Martin-Molinero
6d824b40a6 Add handling for custom host name (#5043)
* Add handling for custom host name

* Credit cost as decimal
2020-12-16 21:54:00 -03:00
Colton Sellers
8e410fcaf1 Update old Hourly/Daily data for ApiDataProvider (#5034)
* Update old Hourly/Daily data for ApiDataProvider

* Add unit test for IsOutOfDate

* Address review

* Fix reference to static function in test
2020-12-16 19:04:06 -03:00
Adalyat Nazirov
d136428556 ignore *.DotSettings files (#5035)
This layer is designated for common settings that enforce your team preferences for the current solution.
Since we don't have specific resharper settings we want to share within the team we ignore this file
2020-12-16 12:38:01 -03:00
Gerardo Salazar
40d81965be Adds debug logging for MapSymbol(...) method in IB Brokerage (#5040) 2020-12-15 17:44:00 -08:00
Aaron Janeiro Stone
c650eb6c1c Adds DeM indicator (#5002)
* Adds DeM indicator

* Added reference to param movingaverage type

* Fixed variable declarations

* Added nameless initialize

* Missing DeM "type" args added

* Missing DeM "type" args added

* refactor

* Undid _previousInput → protected

* Demarker symbol: DeM →DEM

* Symbol change: DeM → DEM

* Updated symbols

TestDivByZero originally had dem as cmf.

* Symbol: DeM →DEM

Co-authored-by: Alexandre Catarino <AlexCatarino@users.noreply.github.com>
2020-12-15 08:29:55 -03:00
Charles Naccio
aa2f9f927a Fixed QuantBook import path for CSharp example (#5028)
Now requires a relative path for loading QuantBook.csx
2020-12-14 21:22:22 -03:00
Charles Naccio
c698a65a84 Replaced obsolete Gitter badge with Slack (#5031) 2020-12-14 12:55:35 -03:00
Charles Naccio
181283a4cd Noted Polygon downloaded in Readme (#5025) 2020-12-11 16:55:58 -08:00
Martin-Molinero
b247724a34 Improve Optimizer runtime statistics (#5024)
- Adding optimization Id to backtests packets
- SeriesSampler will allow truncating the samples
- Removing OptimizationEstimate, simplifying getting estimate and
  runtime stats separatly
2020-12-11 16:39:13 -08:00
Gerardo Salazar
dde3576161 Fixes intraday delistings not occurring before contract expiry for Futures and FOPs (#5007)
* Fixes intraday delistings not occurring for Futures and FOPs

  * Previously, we would wait until the next market open to
    liquidate futures and futures options contracts. Since these
    contracts can not be traded at the next market open and require
    intraday delisting, changes were made to liquidate at the first
    available place where we know the market is open. This means
    we now liquidate futures and FOPs intraday as a market order.

  * Maintains backwards compatability with equities and equity options
    delisting behavior

* Addresses review: adds additional protections for ProcessDelistedSymbols

  * We choose to adjust the delisting date to the next market open only
    if the market is not open at the current time, otherwise the time
    would have been adjusted to the market open of the next trading day

* Addresses review: reverts changes and fixes error message in regression algo
2020-12-11 20:46:56 -03:00
Gerardo Salazar
e8734a0797 Adds/Fixes Futures Options History Research Support (#5013)
* Adds Futures Options History Research Support

* Address review: make canonical future throw when calling GetOptionHistory

* Improve error message, recommending users to user FutureChainProvider
2020-12-11 20:46:41 -03:00
Aaron Janeiro Stone
7f5d69bbec Adds the Awesome Oscillator (#5005)
* Adds the awesome oscillator.

* added missing type hint for AO

* cleaned initializations

* refactor in call for AO(fast,slow,type)

* added missing type parameter for AO

* Changes AO sub-indicators to public.

Co-authored-by: Alexandre Catarino <AlexCatarino@users.noreply.github.com>
2020-12-11 20:46:07 -03:00
Colton Sellers
f6be7a41a5 Bug python runtime issue with local report generation (#5014)
* Fixed Python runtime issue that was occurring when trying to generate reports locally on OSX/mono, but assume the issue impacts all configurations.

* Move Python.Runtime config to common

* Remove duplicate files

* Update readme

* Typo

* Change destination in build directory

Co-authored-by: Charles Naccio <cnaccio@gmail.com>
2020-12-11 20:45:26 -03:00
Stefano Raggi
7f30c0cd00 Downgrade IB error codes from Warning to Information (#5015) 2020-12-11 18:53:25 -03:00
Colton Sellers
6694fe01f8 Api Chart Hotfix (#5023)
* Api Chart Hotfix

* Use IsNullOrEmpty
2020-12-11 18:43:18 -03:00
Aaron Janeiro Stone
32ab4fdea1 Adds ChaikinMoneyFlow indicator (#4986)
* Added CMF indicator

CMF is a volume-weighted average of accumulation and distribution over a period.

* Added initializer for CMF

Registration for ChaikinMoneyFlow implemented.

* Added CMF tests.

* Added CMF tests.

* spy_cmf.txt changed to external indicator data.

* Implement suggestions of @AlexCatarino

* added sum terms as subindicators.

* added sum terms as subindicators.

* Removal of vestigial rolling window

* Minor nit changes

Co-authored-by: Martin Molinero <martin.molinero1@gmail.com>
2020-12-11 18:04:17 -03:00
Colton Sellers
fc81f606e4 Reserve Names for Pandas Mapper (#4978)
* Fix for #4886 and unit test

* Fix test function

* Address review

* Clarify comments
2020-12-11 16:39:13 -03:00
Stefano Raggi
ec74abd4d0 Fix Bitfinex brokerage currency mapping (#5011) 2020-12-11 16:12:57 -03:00
Colton Sellers
bd3ead3480 ApiDataProvider Zip Download Fixes (#5020)
* Stop non zip responses from being saved as a zip

* Capture and log message

* Log as Error
2020-12-11 16:01:57 -03:00
Colton Sellers
45849962a3 Readme expansion and additional VS build tasks (#5018) 2020-12-11 14:49:29 -03:00
Gerardo Salazar
8279cf7eac Improve exception message for indicators using Update(DateTime, decimal) (#5019) 2020-12-11 14:36:42 -03:00
Colton Sellers
4c4a699cb0 Stop Emitting Insights on Delisted Securities (#4997)
* Verify insights are valid before emitting

* nit

* Address review

* Address review and unit tests

* nit - remove extra lines

* Address review

* Initialize insight fields
2020-12-10 11:44:37 -03:00
Colton Sellers
31a2c31c0a Api Update November 2020 (#4981)
* WIP Backtest adjustments

* Workaround awaiting changes

* Adjustments to API Changes

* Nit fix

* Custom Newtonsoft Deserializer for AlphaRuntimeStatistics

* Workaround Travis build error

* Drop AlphaRuntimeStatistics converter; use Decimal converter

* Use StringDecimalJsonConverter

* Undo set properties

* Add more members to de-serializer class
2020-12-09 16:51:58 -03:00
Jared
877a123276 Update readme.md 2020-12-08 12:26:21 -08:00
Gerardo Salazar
4134b05bfd Fixes options order crash in ReportGenerator/PortfolioLooper (#4992) 2020-12-07 12:39:53 -03:00
Gerardo Salazar
43c6d5cc5a Adds extra simplified history request method in PortfoliioLooper (#5003) 2020-12-06 15:13:32 -08:00
Martin-Molinero
f39acceadc Load fine fundamental from data cache folder (#4995)
* Load fine fundamental from data cache folder

* Add daily backwards lookup for live fine
2020-12-04 18:28:24 -08:00
Jasper van Merle
921ddced04 Fix invalid xml on SafeMultiply100 documentation (#5000) 2020-12-04 18:22:12 -08:00
Gerardo Salazar
ff8563244f Fixes Random Length Lumber contract multiplier/min price variation (#4993) 2020-12-04 12:33:19 -03:00
Colton Sellers
041f1d9db5 Limit Futures Resolutions in BaseData (#4979)
* Limit futures support resolutions

* Fix broken tests

* Address review
2020-12-03 21:50:17 -03:00
Gerardo Salazar
eb1181f5f7 Adds Futures Options Asset Class w/ IB Support (#4928)
* Adds preliminary universe selection for Future Options

* Fixes scaling issues with Future Options

* Fixes scaling multiplying by 10000x instead of using _scaleFactor

* Fixes scaling for Tick

* Revert changes to Tick since it divides the scaling factor

* Changes stale method name to new method name after rebase

* Fixes selection bugs, adds new methods, and adds unit tests

  * Fixes bug where Equity Symbol was created for an underlying
    non-equity Symbol, resulting in equity data trying to be loaded

  * Adds unit tests covering changes to Tick, QuoteBar, TradeBar and
    LeanData

  * Adds regression test for AddUniverseOption filter contract selection
    for Future Options

* Addresses review - modifies the AddFutureOption signature

  * Adds new AddUniverseOptions method overload
  * Removes and adds a new unit test
  * Misc. modifications to account for new changes

* Fixes bug where futures were loaded using default SID Date

  * Refactors and removes unnecessary work
  * Fixes regression algorithm, which previously made no trades

* Adds future option data

  * Adds the corresponding underlying data, in this case, futures data
    to enable usage of future options data

* Replaces data with new data (ES18Z20)

  * Improves Future chain filtering and updates regression stats

* Add AddFutureOptionContract API

* Expands regression and unit tests to test in finer detail

* Adds Python regression algorithms for AddFutureOption[Contract] methods

* Adds new unit test for BacktestingOptionChainProvider

  * Fixes bug with BacktesingOptionChainProvider where we
    attempted to load the Trades option chain first, resulting
    in breakage of backwards compatibility and limitation of the
    option chain.

  * Adds new regression algorithms (Py) to Algorithm.Python project

* Adds FutureOptionMarginBuyingPowerModel

  * Modifies code paths used to select margin model
  * Adds related unit tests for margin model

* Fixes issue with unit test and MHDB/SPDB lookup for Future Options

* Preliminary regression algorithm testing ITM call/put option buying

  * Fixes bug where fee model used did not find non-US market
    options fee model. We now use the futures fee model for future
    options because IB charges the same commissions per contract
    between futures and futures options

* Adds proper regression algorithm for ITM future options expiration

* Pushing broken algorithm for review

  * Currently, algorithm does not fill forward, causing
    a single future option to not get exercised when it is delisted.

* Adds FutureOptionPutITMExpiryRegressionAlgorithm

  * Improves existing regression algorithm for call side
  * Fixes bug in existing regression algorithm
  * Adds AAPL daily data to advance enumerator for ^^^ fix

* Adds additional future option regression algorithms

  * Adds Buy OTM expiration regression algorithms
  * Adds Sell ITM/OTM expiration regression algorithms
  * Adds missing Python regression algorithms

* Adds remaining Python regression algorithms and fixes issues

  * Fixes naming issues and statistics
  * Adds short option OTM regression algorithms (Py)

* Add license header and class comments to python algorithms

  * Cleans up comments and docstrings
  * Create Buy/Sell call intraday regression algo

* Redirects future options symbol properties to futures symbol properties

  * Asserts exercise/assignment price and updates stats in regression algos
  * Adds new unit test covering changes to SecurityService

* Adds comments and fixes failing test

* Partially fixes future option mis-calculated profit/loss

* Adjusts portfolio model to calculate FOP as a no upfront pay asset class

  * Updates regression algorithm statistics

* Begin IB FOP support

* Initial support for FOP IB data streaming, live í¾‰

  * Adds additional functionality to LiveOptionChainProvider
    - Allows querying CME API to retrieve option chains for CME products
    - Ultimately, it's also the groundwork for the CME
      LiveFutureChainProvider

  * Edits IDataQueueUniverseProvider interface to provide greater
    control to implementors of it

  * Misc. bug fixes required to get FOP data streaming through IB

* Adds comments, adds missing rategate call, and cleans up code

* Force exchange for FOP and Futures when no exchange is provided

* Fixes bug with Portfolio modeling across all asset classes

* Adds LiveOptionChainProvider tests for Future Options

* IB brokerage option symbol bug fixes and improvements

* Fixes contract multiplier lookup bug

  * Fixes issue where we attempted to subscribe to IB data feed with canonical security
  * Adds ES MHDB entry

* Reverts portfolio modeling changes for Futures Options

  * Since IB eats into our account's cash balance when
    a new FOP contract is purchased, we must model by applying funds
    to our cash whenever a new purchase/sell occurs.
    If we choose to model FOPs exactly as we do with futures, we
    will end up with an invalid TotalPortfolioValue on algorithm
    restart. By all means and purposes, FOPs are modeled exactly
    the same as equity options with respect to the portfolio.

  * Adds comments clarifying portfolio modeling and clarifies
    existing portfolio modeling comments with additional context.

* Fixes IB symbol lookup for future options

  * Fixes LiveOptionChainProvider looping 5 times per option chain
    request, even on success

  * Sets OptionChainedUniverseSelectionModel to produce a canonical
    future/future option/option Symbol to avoid creating two Symbols

  * Adds GLOBEX future option symbol mapping from future -> fop

* Fixes LiveOptionChainProvider loading wrong contract option chains

  * Fixes loading of futures options ZIP files when backtesting
  * Adds a string -> decimal JSON converter
  * Additional fixes/refactoring to the LiveOptionChainProvider

* Adds tests for changes to Symbol and LeanData

  * Reverts changes to IB-symbol-map

* Fixes Value for mapped future options tickers

  * Fixes Symbol test

* Changes path of future options to future's expiry date

  * Extra changes made to remove scaling from writing CSV
  * Added method to map from FOP Globex -> FUT Globex

* Fixes MOO and MOC orders for future options

  * Note: this order type might not be supported by IB or CME.

* Bug fixes and updates unit tests

* Update regression tests and data format

* Rebase changes

* 1. Multiple bug fixes for LiveOptionChainProvider, reverts IQFeed changes
2. Address review (partial): Code reuse and cleanup

1.
  * Modifies check in
    `AddFutureOptionShort(Call|Put)ITMExpiryRegressionAlgorithm`
    to ensure no buys have negative quantity

  * Code reuse changes in IB brokerage

  * Bug fix in IB brokerage where we assigned the FOP expiry
    as the futures expiry (requires verification)

  * Doc changes and adds missing summaries/license banners
  * Disposes of HTTP client resources in LiveOptionChainProvider
  * Renames classes and adds FutureOption folder in Common/Securities

2.
  * We revert back to the quotes API for the option chain,
    since the settlement API sometimes had missing strikes.

  * Fixes future option expiry being set as future's expiry
    in LiveOptionChainProvider

  * Fixes bug where wrong option chain was selected because of bad
    expiry lookup in the futures expiries returned from CME

  * Fixes multiple looping bug in LiveOptionChainProvider
  * Adds strike price scaling for LiveOptionChainProvider

  * Reverts IQFeed changes and simplifies interface upgrade changes

  Some additional challenges we'll have to solve as part of FOPs:

    - The `OptionSymbol.IsStandard` method makes the assumption that
      weeklies contracts follow the pattern equities follows, which
      does not apply to Futures Options

    - The Subscription created in:
        `OptionChainUniverseSubscriptionEnumeratorFactory`

      ...adds a Trade config. For illiquid contracts, this
      will delay universe selection for the option symbol
      until we get a trade. However, if we add a quote config,
      the data would instead be loaded based on the first quote
      we received from the brokerage.

      But since we're currently using a trade config, illiquid
      contracts won't start streaming data until it receives a trade.

NOTE: this commit is a WIP to addressing the reviews received in the PR,
but has been committed early for efficiency in the review process

* Fixes regression algorithms and misc. bugs

  * Fixes map file lookup for non-equity options
  * Adds extra assertion at end of algorithm to ensure no holdings are
    left when the algorithm ends.

  * Adds FutureOptionSymbol, allowing all contracts through as standard
  * Changes SPDB to allow defaulting to underlying future symbol
    properties if no entry is found for the given FOP

  * Fixes calls to SPDB in SecurityService, IBBrokerage
  * Reverts AAPL daily ZIP file to fix majority of regression algorithms
  * Adds FOPs symbol properties
  * Fixes existing symbol properties for a few futures
  * Adds tests for changes to Symbol Properties Database

* Removes string SPDB lookup method

  * Updates tests and misc callees of previous method

* Updates all regression tests to use data of already expired contracts

  * Adds Futures Options Expiry Functions tests
  * Adds required futures data for 2020-01-05

* Address review (partial): Expands test coverage and fixes tests

* Set option chain tests parallelism to fixture only

* Fixes broken test for contract month delta for FuturesOptionsExpiryFunctions

* Changes delisting date logic for Futures Options

* Address review: removes duplicate code, misc code fixes

  * Bug fix in MarketHoursDatabase.GetDatabaseSymbolKey() where
    we would use the underlying's Symbol for lookup in the MHDB

  * Adds missing license banner
  * Removes Futures Options entries from MHDB
  * Adds new tests

* Adds SecurityType.FutureOption

  * Converts any underlying comparisons and uses SecurityType directly
    instead for FOP specific behavior

  * Extra code modifications to acommodate new SecurityType

* Addresses review: fixes order fee bug on exercise

  * Additional bug fixes and adding of SecurityType.FutureOption
  * Updates regression algorithms OrderListHash

* Fixes various bugs in IB live implementation

  * Fixes bug setting the right contract expiration date for FOP
    generated by LiveOptionChainProvider

  * Adds new function to FuturesOptionsExpiryFunctions

  * Clarifies parameter names better in some functions/methods

  * Fixes bugs in IB brokerage for FOPs

* Address review - code cleanup and refactor

  * Remove MappingEventProvider, SplitEventProvider, and
    DividendEventProvider for Futures Options in
    CorporateEventEnumeratorFactory

* Address review: Use MHDB key resolver in SPDB

* Makes regression tests pass and adds comment for expiry issue

* Fixes MHDB lookup on string symbol method

* Adds Futures Options greeks regression algorithm (C# only)

* Adds explanitory comment on MHDB FOP lookup

* Remove python from FutureOptionCallITMGreeksExpiryRegressionAlgorithm
2020-12-02 21:49:59 -03:00
Colton Sellers
9d4014b7db Bug 4757 Synchronize Security Additions (#4879)
* Bump time by one tick in adding subscription

* Adjust regressions

* Change removal to immediate

* Use series.AddPoint instead of directly adding it

* Adjust regression

* Add checks for fixed behavior in regressions

* Address review
2020-12-02 21:20:30 -03:00
Adalyat Nazirov
a4f66628fd Lean Optimization interface in QCAlgorithm (#4923)
* initial commit

* run parametrized algorithm with command line parameters

* skeleton: top level structure

* OptimizationNodePacket scheme

* pass parameters as HashSet

* run Lean and read results

* call method on optimization completion

* refactor public interfaces

- close ParameterSet collection; allow only get operations
- explicit method to start LeanOptimizer

* synchronize RunLean method; the result could come in before the backtest id is set in the collections

* another portion of refactoring and interface changes

* comments

* comments & tests for Extremum, Minimization and Maximization classes

* unify optimization paramater values (min, max, step) & mode GridSearch tests

- swap min&max if necessary
- iterate left => right (negate step value if necessary) & provide default step value if step == 0
- no StackOverflow Exception
- parameterSet Id should be global for current generator and retain between steps
- test signle point boundary (min == max)

* BruteForceStrategy tests

* more comments

* Update Optimizer assembly information

- Update Optimizer projects assembly information to match behavior of
  the other projects

* Tweaks

- Adding comments
- Replace OnComplete for Ended event
- Replace Abort for Dispose
- ConsoleLeanOptimizer will keep track of running processes
- Each backtest will store results in a separated directory, so they
  don't fight for the log.txt file.
- Adding cmdline option for lean to close automatically
- Adding concurrent execution backtest limit
- Console optimizer will start Lean minimized
- Escape spaces in Json path

* remove parameter set generator abstraction layer

we don't need this flexibility now.

* refactor public methods; Step shouldn't be public

* constraints: wip

* define contract

* comparison operators and tests

* specify JsonProperty values

* Move SafeMultiply100 to extensions

* Throw exception on failed Optimizer.Start

* constraints: wip

* change finish & dispose process

* minor fixes

- handle force lean abort
- notify consumer if target has been reached

* target & constraints; adapt unit tests

* Minor Tweaks and fixes

- Some logging improvements
- Remove Public since not required

* Ignore empty ParameterValue

* simplify condition

* avoid reinitialization

* reduce type; force immutable

* unit tests for constraints  and target value

* parse & normalize percent values, i.e. 20% => 0.2

* fixup

* Target & Constraint & OptimizationNodePacket unit tests

* Add more json unit tests

- Adding more json conversion unit tests. Fix bug for Extremum which
  wasn't using the converter.

* LeanOptimizer tests

* Estimation results

* User thread safe counters

* LeanOptimizer unit tests; push OptimizationResult on Ended event

* more unit tests

* Minor tweaks

-Estimate ToString in a single line.
-Typos and missing header file

* Add base SendUpdate method

- Add base SendUpdate method for LeanOptimizer

* fix LeanOptimizer test; rely on internal Update rather than timer

* Add OptimizationStatus

- Add missing commments and OptimizationStatus

* EulerSearch implementation: wip

* OptimizationParameter custom converter

* change the type

* make step optional

* change folder structure

* enumerate optimization parameter using IEnumerable & IEnumerator

* unit tests: parameters & objectives

* unit tests: strategies

* remove redundant TODO

* change Euler search boundaries

* more Euler tests

* prevent race condition

* Add account/read endpoint

- Adding account/read endpoint. Adding unit test

* Add status check before running lean

* Minor self review

- Adding missing comments, minor changes

* remove array parameters

* minor changes

- tidy up config file, rename variable
- accept min less or equal than max

* move OptimizationParameter methods to strategies

* Minor improvements for BaseResultHandler derivates

* minor changes

- strict requirements for Step and MinStep values
- strategy specific settigs

* Add TotalRuntime to estimate

Co-authored-by: Martin Molinero <martin.molinero1@gmail.com>
2020-12-02 20:10:40 -03:00
Michael Handschuh
b9974e6f54 Add OptionStrategyMatcher (#4924)
* Reformat/cleanup OptionStrategies

This file was breaking pretty much every style convention in LEAN.
There are other things that should be addressed in here that weren't,
such as passing non-argument names as argument names for ArgumentException,
as well as preferring constructors over property initializer syntax, but
such changes aren't being made to keep this commit strictly reformatting
instead of refactoring.

Added braces and reformatted long lines to make code more legible.

* Add abstract base class for OptionStrategy Option/UnderlyingLegData

This allows us to create either or and later use the Invoke method to push it
into the appropriate list on OptionStrategy.

* Replace O(n) option contract search with 2 O(1) TryGetValue calls

A better improvement would be resolving the correct symbol in the strategy, but
this immediate change is instead just focused on removing the O(n) search inside
a loop.

* Add BinaryComparison and supporting methods in ExpressionBuilder

We're going to use these binary comparisons to make it possible to create
ad-hoc queries against a collection of symbols. Using these expressions,
along with type supporting composition of these expression, we'll be able
to define predicates that can declaratively define how to match an option
strategy with an algorithms current holdings.

* Make GetValueOrDefault defaultValue optional

Was receiving ambiguous invocations leading to neading to invoke this
method explicitly (LinqExtensions.GetValueOrDefault) instead of being
able to use it as an extension method. Making the default value optional
seems to have resolved this ambiguity, leading to cleaner code in the
OptionPositionCollection (forthcoming)

* Add OptionPosition and OptionPositionCollection

OptionPositionCollection aims to provide a single coherent interface
for querying an algorithm's option contract positions and the underlying
equity's position in a performant, immutable way. The immutability of
the type is necessary for how the options matcher will operate. We need
to recursively evaluate potential matches, each step down the stack removing
positions from the collection consumed by each leg matched. This will enable
parallelism of the solution as well as simplifying the mental model for
understanding due to not needing to track mutations to the collection
instance.

* Add Option test class for easily creating option symbol objects

* Add OptionStrategyLegPredicate and OptionStrategyLegDefinition

The definition is a composition of predicates, and each predicate supports
matching against a set of pre-existing legs and a current position being
checked for the next leg (this leg). In addition to the matching functionality,
it also supports filtering the OptionPositionCollection, which is where much
of the work for resolving potential option strategies is done. By successively
filtering the OptionPositionCollection through successive application of predicates,
we wil end up with a small set of remaining positions that can be individually
evaluated for best margin impacts.

All of this effectively unrolls into a giant evaluation tree. Because of this
inherent structure, common in combinatorial optimization, the OptionPositionCollection
is an immutable type to support concurrent evaluations of different branches of
the tree. For large position collections this will dramatically improve strategy
resolution times. Finally, the interface between the predicate and the positions
collection is purposefully thin and provides a target for future optimizations.

* Add OptionStrategyDefinition and OptionStrategyDefinitions pre-defined definitions

The OptionStrategyDefinition is a definitional object provided a template and functions
used to match algorithm holdings (via OptionPositionCollection) to this definition. The
definition defines a particular way in which option positions can be combined in order to
achieve a more favorable margin requirement, thereby allowing the algorithm to hold more
positions than otherwise possible. This ties into the existing OptionStrategy classes and
the end result of the matching process will be OptionStrategy instances definiing all
strategies matched according to the provided definitions.

* Add OptionStrategyMatcher and Options class, w/ supporting types

OptionStrategyMatcherOptions aims to provide some knobs and dials to control how
the matcher behaves, and more importantly, which positions get prioritized when
matching. Prioritization is controlled via two different enumerators, one controller
which definitions are matched first and the other controller which positions are
matched first. Still unimplemented, is computing multiple solutions and running the
provided objective function to determine the best match. When this gets implemented,
we'll also want to implement the timer. For anyone looking to implement these features,
please talk with Michael Handschuh as there's a particular way of representing these
types of combinatorial solutions (a 3D tree) that can be used as a variation of the
linear simplex method for optimizing combinatorial problems.

* OptionStrategyMatcher: Address PR review comments

* Ensure created OptionStrategy legs all have the same multiplier

Each leg definition match gets it's own multiplier which indicates the
maximum number of times we matched that particular leg. When we finish
matching all legs, we pick the smallest multiplier from all the legs in
the definition and use that as the definition's multiplier. When we go
to create the OptionStrategy object we MUST make sure we're using the
multiplier from the definition and not from the individual legs.

This change fixes this issue and also provides a guard clause to ensure
that we're not trying to use a multiplier larger than what was matched.

* Add XML docs for OptionStrategyDefinitions from OptionStrategies
2020-12-02 18:42:24 -03:00
Stefano Raggi
474c5cd890 Update IBAutomater to v1.0.35 (#4984) 2020-12-02 09:56:36 -08:00
Martin-Molinero
0dfb368cb4 Lean shutdown improvements (#4982)
- Use DisposeSafely instead of dipose.
- Adding some logs to know when handlers are getting disposed.
- Normalize exit procedure
2020-12-02 09:55:50 -08:00
Colton Sellers
fbf5300bb6 Block SetWarmUp after Algorithm has compeleted initialization (#4975)
* Fix for #4939

* Address review

* Logic fix
2020-12-02 13:44:04 -03:00
Gerardo Salazar
c67845bd45 Fixes issue parsing SI data w/ unknown enum value (#4961)
* Extends tests to cover new additions
2020-12-01 20:17:25 -03:00
Colton Sellers
54ddbfbe24 Bug 4947 OnOrderEvent exceptions (#4974)
* Force algorithm to fail on runtime error

* add comment

* Remove unneeded change

* Update algorithm summary

* Address review
2020-11-30 15:55:39 -03:00
Gerardo Salazar
bd7be31ede Fixes inability to parse negative strike prices in SecurityIdentifier (#4953)
* Fixes inability to parse negative strike prices in SecurityIdentifier

  * Adds new tests ensuring backwards compat and no throwing w/ negative
    strike prices

* Changes strategy used to support negative strike prices

  * We add support for negative strike prices at the cost of
    reducing the maximum allowed precision for the strike price.
    We encode a negative sign into the 20th bit of the strike price
    and set our bounds for precision to a max (exclusive) of 475712.
    This in turn is then used to form a negative strike when rebuilding
    the SID.

  * Adds tests covering changes

* Address review: adds additional tests and refactors code

* Address self-review: remove unused import in SymbolTests

* Address review: adds additional test cases for OptionStyle and OptionRight

  * These tests are to ensure that backwards compatibility is maintained

* Addresses review: Adds option chain <-> master SID hash test

  * Refactors previous tests to reduce on code duplication

* Reduce test duplication

Co-authored-by: Martin Molinero <martin.molinero1@gmail.com>
2020-11-30 15:45:36 -03:00
Colton Sellers
041a111b92 Implement safe exiting for Lean (#4972) 2020-11-27 18:14:18 -03:00
Stefano Raggi
fa94bcc46a IB Brokerage updates (#4957)
* Update IBAutomater to version 1.0.32

* Update IBAutomater to v1.0.33

* Update IBAutomater to v1.0.34
2020-11-27 14:30:25 -03:00
Athon Millane
2988f7ec3c Bug 4809 Additional Docker Run Script Fixes (#4971)
* Fix typo in data dir volume mount permission.

* Change default notebook launch behaviour for Mac systems.

Co-authored-by: Athon Millane <athon@maxkelsen.com>
2020-11-27 10:06:08 -03:00
Martin-Molinero
b785877d33 Reenable extended market hours sampling (#4967)
* Reenable extended market hours sampling

- Will re enable extended market hours sampling using the last benchmark
  and portfolio value when user exchange were open.

* Add unit test minor tweak

- Improve shutdown latency.
- Setting portfolio initial value
- Adding unit test asserting sample behavior.
2020-11-25 20:39:19 -03:00
Juan José D'Ambrosio
5dbb0db2f9 Update regression algorithms (#4969) 2020-11-25 20:36:17 -03:00
Juan José D'Ambrosio
a489436743 Remove LUNG from blacklisted tickers (#4966) 2020-11-25 19:26:53 -03:00
Colton Sellers
ff2013b0d0 Bug 4864 Missing Brokerage Live Settings (#4958)
* Support Bitfinex live settings

* Add Alpaca and GDAX and their respective tests

* Address review
2020-11-25 10:52:26 -03:00
Colton Sellers
567e7b7679 Change Alpaca default to PolygonDataQueueHandler (#4960) 2020-11-25 10:45:21 -03:00
Martin-Molinero
646f22a63f Remove python stubs directory (#4955)
* Remove python stubs directory

- Removing python stubs directory since after https://github.com/QuantConnect/Lean/pull/4899
it was been replaced by a python package `quantconnect-stubs`.
- Reverting IDE settings using the stubs folder PR https://github.com/QuantConnect/Lean/pull/4657

* Revert "Adds Python stubs location definition for PyCharm and Visual Studio Code (#4657)"

This reverts commit aded66ec5b.

* Address self-review: Provide list of imports and refactor python readme

Co-authored-by: Gerardo Salazar <gsalaz9800@gmail.com>
2020-11-24 12:45:28 -08:00
nazbrok
fd138ec397 GDAXDownloader : save data int the right ticker name (#4799)
* Update crypto entries in SPBD

- Update values for GDAX and Bitfinex, with latest values from exchanges
- Update symbols with >3 letters
- [Fix] Remove  same base-quote entries

* Update unit tests

Increment in precision given smaller lot sizes in SPDB crypto entries.

* Add GDAX symbol properties downloader (unit test)

* Update GDAX symbol properties database

* Add BrokerageSymbol to symbol properties database

* Update GDAX symbol properties

* Address review

- Rename BrokerageSymbol to MarketTicker

* Add GDAX symbol mapper

* Update GDAXBrokerage to use symbol mapper

* Fix GDAX brokerage unit tests

* Replace GDAXSymbolMapper with SymbolPropertiesDatabaseSymbolMapper

* Address review

- use Symbol key in dictionaries

* Rename BrokerageSymbol to MarketTicker

* Save GDAX history in the real ticker folder

* rename tickerMapper to symbolMapper

* fix gdaxdownloader help message

* Save GDAX history in the real ticker folder

* rename tickerMapper to symbolMapper

* fix gdaxdownloader help message

* use SymbolPropertiesDatabaseSymbolMapper

* address review

Co-authored-by: JJD <jjdambrosio@gmail.com>
Co-authored-by: Stefano Raggi <stefano.raggi67@gmail.com>
Co-authored-by: Martin-Molinero <martin@quantconnect.com>
2020-11-23 21:35:39 -03:00
Stefano Raggi
e98b31fc4c Update CoinApi symbol mapping + symbol properties database (#4888)
* Update crypto entries in SPBD

- Update values for GDAX and Bitfinex, with latest values from exchanges
- Update symbols with >3 letters
- [Fix] Remove  same base-quote entries

* Update unit tests

Increment in precision given smaller lot sizes in SPDB crypto entries.

* Add GDAX symbol properties downloader (unit test)

* Update GDAX symbol properties database

* Add BrokerageSymbol to symbol properties database

* Update GDAX symbol properties

* Address review

- Rename BrokerageSymbol to MarketTicker

* Add GDAX symbol mapper

* Update GDAXBrokerage to use symbol mapper

* Fix GDAX brokerage unit tests

* Replace GDAXSymbolMapper with SymbolPropertiesDatabaseSymbolMapper

* Address review

- use Symbol key in dictionaries

* Rename BrokerageSymbol to MarketTicker

* Update unit test

* Add Bitfinex symbol properties downloader (unit test)

* Add Bitfinex symbol market ticker to downloader

* Update Bitfinex symbol properties database

* Update BitfinexBrokerage to use SymbolPropertiesDatabaseSymbolMapper

* Remove Bitfinex test symbols from db

* Update Binance symbol properties database

* Update BinanceBrokerage to use SymbolPropertiesDatabaseSymbolMapper

* Add missing Binance test case

* Update symbol properties database

- gdax, bitfinex, binance

* Update CoinApi symbol mapper for new SPDB

* Exclude Bitfinex BCH pre-2018-fork in CoinApiSymbolMapper

* Remove unused properties

* Add CoinApi mappings

Co-authored-by: JJD <jjdambrosio@gmail.com>
2020-11-23 19:15:31 -03:00
Stefano Raggi
d2eae2f652 IB Brokerage Updates (#4945)
* Update C# API DLL up to  Oct 30, 2020

- a8e66989e5

* Add extra account information logging after connect
2020-11-23 11:53:28 -03:00
Gerardo Salazar
0f0a2bc9a8 Fixes weeklies parsing, causing certain futures to be inaccessible in QCAlgorithm (#4936)
* Fixes weeklies parsing, causing certain futures to be inaccessible in Algorithm

  The FuturesExpiryFunction expects the contract month of the Future,
  not the expiration. As a result, the contract gets filtered as a
  weekly contract, rather than as a standard due to the discrepancy
  between the expiry dates when the contract month differs from the
  expiry date's month.

  A very important fact to note is that futures can and do expire prior
  to the contract month. BZ,(brent crude financial futures) expire two
  months prior to the contract month, CL one month prior, etc.

  There has been an addition that contains a "reverse" futures expiry function
  lookup table. We use this to lookup the contract month to re-calculate
  the Future expiry.

  This PR also fixes dairy and adds extra expiry dates. Dairy can have
  an expiry *after* the contract month, so a new path was added to the
  SymbolRepresentation to ensure that these contracts are loaded
  correctly.

* Address review: Adds tests and fixes bug in SymbolRepresentation

  * Updates SID comment on `Date` property to reflect fact that we use
    future expiry for its value

  * Fixes bug in SymbolRepresentation where expiration day would always
    be 01 when parsing a contract with an expiration after the contract
    month

  * Fixes bug in SybmolRepresentation where expiration year would be
    four digits long when parsing a contract with an expiration after
    the contract month

  * Fixes some bad dairy expiry dates

  * Adds tests for SymbolRepresentation and the futures filtering for
    standard contracts

  * Renames method used to extract delta between contract month and
    expiry date

* Removes GH comment and restores Futures contract month expiry param
2020-11-20 11:58:49 -03:00
Martin-Molinero
8ad81dca71 Update readme.md (#4949) 2020-11-20 09:12:23 -03:00
James Kardatzke
f965f34a3f Added Quiver API token variable to Config (#4946)
* Add files via upload

* Add files via upload

* Add files via upload

* Add files via upload

* Add files via upload

* Delete QuiverWikipedia.cs

* Delete QuiverWallStreetBets.cs

* Delete QuiverDataDownloader.cs

* Delete QuiverWallStreetBetsDataDownloader.cs

* Delete QuiverWikipediaDataDownloader.cs

* Delete QuiverDataAlgorithm.cs

* Delete QuiverHouse.cs

* Delete QuiverPoliticalBeta.cs

* Delete QuiverSenate.cs

* Delete QuiverHouseDataDownloader.cs

* Delete QuiverPoliticalBetaDataDownloader.cs

* Delete QuiverSenateDataDownloader.cs
2020-11-18 20:32:03 -03:00
Colton Sellers
06a7d54c38 run_docker_notebook bat hotfix (#4943) 2020-11-17 21:40:29 -03:00
Colton Sellers
7174fcb9d7 RoundDown fix for PeriodCountConsolidatorBase (#4940)
* Limit rounding interval to 1 day, add SubtractRoundDown and AddRoundUp functions

* fix error message

* Only subtract round down if period is greater than a day

* Tests

* Comment clarification

* Pivot solution to simple fix

* fix error message

* Remove RoundDown/Up limitations; add remarks

* address review
2020-11-17 21:40:10 -03:00
IlshatGaripov
29e9d678f2 Bug 4815 iex web socket library (#4914)
* Fixes 4815 by loading the requested assembly from different folder.

# Conflicts:
#	ToolBox/Program.cs

* Upgrades System.Collections.Immutable to Version=1.2.5.0

* Creates a prototype for SSE streaming in IEXDataQueueHandler.

* Revert the changes in Tick.cs

* Implements a logic in IEXDataQueueHandler that updates the data-feed subscription after Subscribe/Unsubscribe

* Implements IEXCouldSubscribeMoreThan100Symbols - which fails and other small fixes.

* Implements DoForEach LinqExtensions

* Implements IEXEventSourceCollection that wraps all logic that is SSE-subscriptions and symbol-limits-per-connection concerned.

* Changes:

1) Fixes to address review.
2) Makes IexMarketPercent in QuoteSSE nullable as null values are assigned to in this field in data object received before the traing session start.
3) Deprecates helper Subscribe/Unsubscribe in IEXDataQueueHandler and IEXCouldSubscribe test.

* Fixes:

1) _refreshEvent.Reset() order was not correct - should be called before UpdateSubscription
2) ProcessJsonObject- leaves only the functionality to emit ticks.
3) IEXEventSourceCollection - replaces int counter with CountdownEvent to improve the logic - in particular, need a mechanism that would not allow the repeated call to continue until the first one is completed

* Refines the logic with parsing a data snapshot.

* Fixes few more bugs:

1) Logic in ProcessJsonObject
2) Logic in UpdateSubscription - need to introduce additional ManualResetEvent to implement the intended logic - otherwise the logic is not suitable for general case

* Introduce rate-gate limit in IEXEventSourceCollection:

because when subscribing to a bunch of shares (more than 200 for example)
the violation of rate gate policy may occur, which described in API docs asRequest Limits

IEX Cloud only applies request limits per IP address to ensure system stability.
We limit requests to 100 per second per IP measured in milliseconds, so no more than 1 request per 10 milliseconds.
SSE endpoints are limited to 50 symbols per connection. You can make multiple connections if you need to consume more than 50 symbols.:

* Few additional fixes done after real time testing

* Adds xml-docs in stream response object + renaming a file.

* Fixes:

1) Additional StreamResponseStocksUS parsing issues, that can happen outside of regular exchange hours.
2) Cancel clientUpdateThread by means of CancellationTokenSource
3) Replace BuildSymbolsQuery by string.Join

* Fixes:

1) Changing Log Trace -> Debug
2) Adds ConfigureAwait(false) to async method call
3) Removes direct reference to System.Net.Http

* Removes a task and manual reset event in IEXEventSourceCollection

* Additions:

1) IEXEventSourceCollectionSubscribes test
2) GetSnpStocksArray() helper method
3) Installs packages in QC.tests : HtmlAgilityPack & LaunchDarkly.EventSource

* IEX history provider fixes :

1) Tiny bug in ProcessJsonObject - use continue instead of return as execution is inside the for-each block)
2) Adds period variable for the historical data retrieved
3) Fixing from  if (date.Date < start.Date || date.Date > end.Date)  conditional check -->  if (date < start || date > end)  for more precise sorting.

* Changes:

1) Removes HtmlAgilityPack and SNP scraper
2) Uses hard coded symbols instead

* Bug fix:

 - at certain hours (example: before pre-market open or on holidays) IEX may send no data on subscription - when trying to connect during those hours Message handler may not be fired - need to place the counter signal to client.Opened to be informed of successful connect.

* Implements:

1) IEXEventSourceCollectionSubscriptionThoroughTest and MockedIEXEventSourceCollection
2) Makes changes to IEXEventSourceCollection accordingly to allow the thorough testing.

* Fixes formatting issue in StreamResponseStocksUS

* Small fix for a new tests:

- Change RemovedClientSymbols to keep not clients itself, but symbols array, because clients are being disposed right further

* Enables extended logging in Toolbox.

* Fixing IEX historical data fetcher bugs:

1) Bug in IEXDataDownloader.cs - HistoryRequest not precisely correct.
2) Enables day-by-day daily bar downloading in IEXDataQueueHandler.
Motivation: Suppose we need data for some interval in the past - from-date=20170915-00:00:00 --to-date=20171103-00:00:00.
With current behavior IEX would have to download all the historical data from =20170915-00:00:00  up to this day.
3) Extends SynchronizingHistoryProvider

* Enables async fashion historical data download

* More fixes to IEXCouldGetHistory test.

* Reverts day-by-day daily bar downloading and other fixes.

* Removes needless packages & references

* Fix package reference

* To address review

* Sort out zero price ticks:

after testing on real-time algo 30 min before the market open now - IEX may send updates for many securities with zero lastPrice, lastSize - fix to sort such entries out

* Workaround for missing QuoteTicks timestamps:

Since we don't have a stamp for quote tick updates (only for trades) we calculate the average delay between trade tick's time stamp and local time, and
assuming that delay in average is the same for quote updates - just assign the local machine time adjusted for this average

* Simplifies the things.

* Changes:

1) Deprecates quote updates for IEX stocks.
2) Reduce the stream updates to reduce costs to ->
# Stock Quotes every 1 second (per symbol? )
# Can be up to 54,000 messages per symbol per day
https://iexcloud.io/docs/api/#how-messages-work

* Fixes:

1) IEXDataQueueHandler: give an error message on extended market hours or tick resolution subscription request. As they are not really well supported by IEX.
2) Few small fixes in IEXEventSourceCollection, including additional condition for when the subscription remains irrevocable.
2020-11-16 21:10:14 -03:00
Colton Sellers
098ac7d0a9 Wider range of offsets on Month tests (#4935) 2020-11-16 15:15:32 -08:00
Stefano Raggi
6cb4411f6e Update IBAutomater to v1.0.31 (#4932)
- add window handler for unsupported IBGateway versions
2020-11-16 11:36:34 -03:00
James Kardatzke
46ef9a9dbb Quiver Quantitative Integration (#4869)
* Add files via upload

* Add files via upload

* Add files via upload

* Add files via upload

* Add files via upload

* Add files via upload

* Add files via upload

* Add files via upload

* Add files via upload

* Add files via upload

* Add files via upload

* Add files via upload

* Add files via upload

* Add files via upload

* Add files via upload

* Add files via upload

* Add files via upload

* Add files via upload

* Add files via upload

* Add files via upload

* Add files via upload

* Add files via upload

* Add files via upload

* Add files via upload

* Add files via upload

* Add files via upload

* Add files via upload

* Add files via upload

* Delete QuiverHouseDataDownloader.cs

* Delete QuiverSenateDataDownloader.cs

* Delete QuiverPoliticalBetaDataDownloader.cs

* Add files via upload

* Delete QuiverHouse.cs

* Delete QuiverSenate.cs

* Delete QuiverPoliticalBeta.cs

* Add files via upload

* Add files via upload

* Add files via upload

* Add files via upload

* Add files via upload

* Add files via upload

* Add files via upload

* Delete QuiverDataAlgorithm.cs

* Add files via upload

* Add files via upload

* Add files via upload

* Addresses self review: Cleans up code and adds new unit tests

  * Adds Quiver* C# files to project
  * Adds new unit test for QuiverCongress
  * Adds Python algorithm example

* Address self reviews

- Adding some missing xml docs
- Removing unrequired imports.
- Minor rename from Date to ReportDate
- Live trading will throw InvalidOperationException

* Fixes for example algorithms

Co-authored-by: Gerardo Salazar <gsalaz9800@gmail.com>
Co-authored-by: Martin Molinero <martin.molinero1@gmail.com>
2020-11-13 20:07:17 -03:00
Colton Sellers
d8d8134437 Support Offset in DateRules MonthStart/End WeekStart/End (#4916)
* Add offset capabilities and related tests

* Add tests for Weekend Offsets on Symbol DateRules

* Unify Iterator Behavior

* Refactor and consolidate functions to reduce duplicate code

* Positive offset values only

* Address review

* Expand Month tests to include Forex and Crypto cases

* Ensure order of days in schedule

* Refactor and unify behavior

* More edge cases and tuning

* Address review + more tests
2020-11-13 15:38:34 -03:00
Jasper van Merle
9a30c9bd5f Enable logging when building and uploading stubs (#4933)
* Enable Twine logging

* Enable setup.py logging
2020-11-12 17:42:09 -08:00
Jasper van Merle
f76a0efb0e Use new generator to generate stubs and publish to PyPI (#4899)
* Use new generator to generate stubs and publish to PyPI

* Hide twine stdout and stderr to prevent token from leaking
2020-11-12 13:27:00 -08:00
Colton Sellers
7238fcd0f3 Bug 4809 Docker Run Script Fixes and Improvements (#4922)
* Refactor and hotfix run script

Removed dependency on `realpath`, notably absent from macOS and some debian distros. Replaced with an equivalent bash function.

Cleaned up prompt response handling, replaced var tests with param expressions.

Removed potentially uneeded calls to sudo (again absent on some systems and most users are part of the docker group anyway). Instead, test if it's needed and get preauth with sudo -v.

Poll for running and stopped Lean containers, and prompt before replacing them. Would fail prior.

Uppercased variabled. Sorry.

* Revert docker output redirection to stderr

* Adjustments to maintain all functionality

* Mimic behavior across run scripts

* Update readme to reflect Docker script changes

* Ignore results storage

* Correct print statement

* Mirror changes on research docker scripts

* Make executable

* Handle already running container and sudo privs

* Fix for issues found in testing

* Address Review

* Small adjustments found in linux testing

* Doc improvement

* Add auto update option for Docker images

* Fix image var reference

Co-authored-by: Peter Kazazes <peter@peterk.co>
2020-11-11 15:48:02 -03:00
Martin-Molinero
91e8393aac DividedEventProvider distribution computation (#4828)
* DividedEventProvider distribution computation

- Update regression algorithm which was using a different reference
  price when calculating the dividend
- Adjust divided event provider to compute distribution using factor
  file reference price, if not 0. Adding unit tests
- For equities, only emit auxiliary data points for
  TradeBar configurations, not for QuoteBars, nor internal.

* Address reviews

- Split and Dividend event provider will throw an exception when there
  is no reference price available. Updating `wm` factor file which was
  missing references price and regression algorithms using WM.
- Updating unit tests asserting new exception
2020-11-11 15:47:51 -03:00
Stefano Raggi
5771635265 Fix Base Account Currency message for PaperBrokerage (#4929)
- the displayed message was not showing the default currency (USD)
2020-11-10 17:46:35 -03:00
Stefano Raggi
914486fdb6 Fix OutOfRangeException in Bitfinex subscriptions (#4926) 2020-11-09 16:42:22 -03:00
Martin-Molinero
61fda8b62c Protobuf will use recyclable memory stream (#4921)
* Protobuf will use recyclable memory stream

- Serialization will reuse recyclable memory streams
- Remove serialization of exchange and sale condition for ticks.
  Updating unit tests.
- There is no need to serialize BaseData.EndTime, covered by unit tests.

* Tick will keep a parsed sale condition property

* Readd tick exchange. Json ignore ParsedSaleCondition
2020-11-06 20:59:25 -03:00
Stefano Raggi
124ac3b98e Fix FxcmBrokerage GetOpenOrders returning empty (#4917) 2020-11-06 10:35:11 -03:00
Colton Sellers
9dca43bccb Expand Filtering of Contracts by type to Futures (#4891)
* Implement future type filter

* Filter weeklys test

* Fix for test, contracts were being filtered out by new type filter

* Share core contract filtering logic in new base class

* Catch Future symbols we don't have Expiry functions for

* Expand tests for new filtering

* Address review

* Small doc change

* Compare Date component for expiry

* Clarifying comment
2020-11-04 20:55:33 -03:00
Alexandre Catarino
6efeee07dc Implements Equity Fill Model (#4913)
* Implements Equity Fill Model

This commit sets the base to create a new equity fill model and the `EquityFillModel` is just a copy of `FillModel`.

* Adds Summary to FillModelPythonWrapper.GetPricesInternal

Adds summary to FillModelPythonWrapper.GetPricesInternal with remarks that it's a temporarily method to help the refactoring of fill models.
2020-11-04 15:51:41 -03:00
Andreas Sundebo
c452dd3726 Feature 4893 performance improvements (#4895)
* Change GetSubscriptionDataConfigs to return IEnumerable<SubscriptionDataConfig>

* Move localTime outside loop

* Remove legacy code

* Remove unnecessary OrderBy

* Reorder conditions to reduce number of times Contains() is called

* Revert "Remove unnecessary OrderBy"

This reverts commit 85383b062e.

* Revert "Change GetSubscriptionDataConfigs to return IEnumerable<SubscriptionDataConfig>"

This reverts commit cbd97c9f36.
2020-11-03 19:35:36 -03:00
Stefano Raggi
c602fd0a3f Fix ambiguous future symbol error in IB brokerage (#4912)
* Fix ambiguous future symbol error in IB brokerage

* Address review

- Fix symbol mapping
2020-11-03 14:44:17 -03:00
Stefano Raggi
104071cda5 Do not terminate algorithm for exceptions in GDAX Fill Monitor (#4910)
* Do not terminate algorithm for exceptions in GDAX Fill Monitor

* Address review

- Only emit warning for REST API errors, other errors are fatal
2020-11-02 21:01:21 -03:00
Aaron Janeiro Stone
a5d9526d65 Add defaults (as comments) to Python.Runtime (#4904)
* Redone defaults for python runtime dll config and readme

* Update Python.Runtime.dll.config

Co-authored-by: Jared <jaredbroad@gmail.com>
2020-11-02 15:02:59 -08:00
Juan José D'Ambrosio
8e525c63fc Fix issue in TiingoNews converter if tickers contains space (#4908)
Also, if ticker contains pipe ( "|" )  it'll be ignored.
2020-11-02 13:58:39 -03:00
Stefano Raggi
d0e9134cc9 IB Brokerage Updates (#4900)
* Add RequestId to request information logging

* Use unique request id across all request types (orders, subscriptions, data queries)

- Previously we had three separate counters for request types and this was causing request information messages to be overwritten (different request types with same ids)

* Update GetContractDetails to log all contracts found
2020-11-02 10:58:12 -03:00
Gerardo Salazar
883d354a98 Adds DC future contract symbol mapping for IB (#4905)
* Fixes SPDB entry for Class III/IV Milk
2020-11-02 10:57:57 -03:00
Colton Sellers
76a53eb096 Local Object Store Refactor and Fixes (#4880)
* Store temp files in subdirectory

* Fix Dispose case for new temp dir

* Adjust tests for new temp dir

* Dispose unit tests

* Unit test for issue 4811

* Refactor for not using temp files

* Fix storage checks for saving data, plus tests

* Use Base64 for storing keys and decoding them; handles odd key strings

* Don't allow "?" in a key

* Address review

* Deleted test cases

* PersistData handle deletion of files

* Refactor GetFilePath to use Persist()

* Make PathForKey protected
2020-10-30 21:36:23 -03:00
Colton Sellers
c02ee1b0d8 QB Set Start Date Relative to Data Release (#4894)
* Set start date relative to timezone

* Address Review
2020-10-30 21:20:32 -03:00
Colton Sellers
9167882ab2 Feature Notebook Api Support (#4898)
* Modify Notebook scripts to load API instance

* Modify docker to move script to IPython profile

* Fix dockerfile copying of start.py

* Fix break for C# cloud and docker load

* Unnecessary path finding

* Update example notebooks

* Update documentation

* Address review

* Adjust readme

* Poor choice of words
2020-10-30 21:05:09 -03:00
Mathieu Paquette
854b987cd0 feat(ToolBox\IQFeed): prevent unordered ticks to be processed (#4884)
closes #4649
2020-10-27 20:30:46 -03:00
Juan José D'Ambrosio
a26414d273 Add decimal places as parameters to get dividends with arbitrary precision (#4883)
* Add decimal places as parameters to get dividends with arbitrary precision

 
Also, increase precision when generating strings from factor files rows.

* Add xml documentation entries for new optional arguments.
2020-10-27 20:30:17 -03:00
Alexandre Catarino
84264ca7ef Adds CustomBuyingPowerModelAlgorithm (#4824)
* Adds CustomBuyingPowerModelAlgorithm

This algorithms is an example on how to implement a custom buying power model.

In this particular case, it shows how to override `HasSufficientBuyingPowerForOrder` in order to place orders without sufficient buying power according to the default model.

* Upgrades CustomModelsAlgorithm to Include CustomBuyingPowerModel

The custom buying power model overrides `HasSufficientBuyingPowerForOrderResult` but it doesn't change the trades and, consequently, the regression statistics.
2020-10-21 17:27:30 -07:00
Stefano Raggi
b2ed398687 Allow account currency to be overridden by the algorithm (#4856)
* Allow account currency to be overridden by the algorithm

* Fix failing unit test

* Address review

- Revert removal of call check in SecurityPortfolioManager.SetAccountCurrency
- Revert changes to unit tests
- IBrokerage.AccountBaseCurrency now defaults to null
- BrokerageSetupHandler will not change the algorithm's account currency if the brokerage returns null, allowing the algorithm to call SetAccountCurrency in Initialize
2020-10-20 14:17:16 -03:00
Martin-Molinero
e8c316cbcf Fix Toolbox tickers parsing (#4876)
- Fix ToolBox tickers parsing, adding unit test.
2020-10-20 11:27:41 -03:00
Colton Sellers
724e52c0b3 Make StartDate relative to Algorithm TimeZone in Live mode (#4871) 2020-10-19 15:44:08 -03:00
Jared
4252c79e45 Create QuantConnect-Platform-2.0.0.yaml
Initial commit of QuantConnect Platform Yaml.
2020-10-18 17:46:13 -07:00
Martin-Molinero
cbb40dfa43 Ignore composer ThreadAbort Exception (#4870)
- Composer inner task will not log exception if it's of type Thread
  abort, which means we are shutting down.
2020-10-16 10:37:14 -03:00
Colton Sellers
8792fa2600 Standardize API.cs to use JSON Objects (#4868)
* Standardize API to use JSON Objects

* Address review
2020-10-15 20:24:55 -03:00
Louis Szeto
20e9fd7899 bug-#4846-Fail on restart investing after liquidation on MaximumDrawdownPercentPortfolio.py (#4847)
* Fail on restart investing after liquidation

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

* Update MaximumDrawdownPercentPortfolio.py

* Fix for MaximumDrawdownPercentPortfolio

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

Co-authored-by: Martin Molinero <martin.molinero1@gmail.com>
2020-10-15 13:34:08 -03:00
Colton Sellers
e05a6bffd0 Bug 4835 api tests failing (#4838)
* Remove F# Project, Splits, and Dividends Tests

* Separate tests that require external accounts; read from config

* Removal of non supported "prices" endpoint test

* Removal of unsupported API functions

* Address review

* NOP GetLastPrice for removal of Prices endpoint

* Post rebase fix

* Rebase fix 2

* remove /r/n from eof for api tests

* Reflect similar refactors to NodeTests

* Fix for live algorithm API testing

* Address Review
2020-10-15 13:31:53 -03:00
Colton Sellers
c2f0fdc47a Bug #4839 Docker Bash Script Hotfix (#4861)
* fix IFS issue in bash docker scripts

* Add default image to research config
2020-10-14 13:20:01 -03:00
Michael Handschuh
b1b8da1e17 Fixes Market Simulated Automatic Option Assignment (#4853)
* Add underlying holdings to regression result handler details log

When debugging option exercise/assignment issues it's useful to see the
underlying holdings at the time the option contract fill event is processed.

Also adds the full symbol string to the top of the order event section.
The Symbol.Value was being logged via OrderEvent.ToString(), but it wasn't
the full SecurityIdentifier - by including the full SID string it makes it
easier to correlate fills over symbol rename boundaries.

* Fix automatic option assignment from market simulation

During the recent OptionExerciseOrder.Quantity refactor, this case was missed.
Additionally, it was realized that there were no regression tests covering the
automatic assignment via the market conditions simulation. This change introduces
a regression algorithm that covers the automatic assignment of put/call options.

* Update BasicOptionAssignmentSimulation._rand to be non-static

If this value is static then we reuse the same Random instance for ALL regression
tests, thereby defeating the purpose of using a well known seed number. This means
we get different results based on the order execution of preceding algorithms.
By making this an instance variable each algorithm will start with the same seed
value, ensuring consistent runs between regression tests, either run as a suite or
running a single algorithm in isolation.
2020-10-13 19:39:25 -03:00
Stefano Raggi
01a0454c57 Fix Bitfinex Liquidate error with AccountType.Cash (#4852)
* Move updating of cashbook for fees out of SecurityPortfolioModel

* Update BitfinexBrokerage to handle fees in base currency
2020-10-13 15:34:44 -03:00
Stefano Raggi
90e2c48404 Remove Oanda API v1 (deprecated) (#4833) 2020-10-12 16:48:42 -03:00
Aaron Janeiro Stone
888c443264 Moves cash brokerage/IExecutionModel test to post-init (#4826) 2020-10-12 11:14:20 -03:00
adam-may
03efc1b735 Remove internal usages of implicit operator in Indicator code (#4844)
* Convert usages of implicit operator in IndicatorBase and IndicatorDataPoint

* Reverting changes to example code
2020-10-12 10:31:05 -03:00
Martin-Molinero
6ef2ead929 Do not update price scale for fillforward data & IsFillForward flag fix (#4836)
* Do not update price scale for fillforward data

- Do no update price scale for fill forward data. FillForward data
  should keep using the prev scale for which it was created. Adding unit tests
- When cloning do not lose IsFillForward flag state, affects
QuoteBars/Ticks, does not affect TradeBars since they perform a memberwise clone.
Adding unit tests

* Auxiliaries shouldn't really affect on applied price factor scale.

Despite we can receeive FillForward'ed data points, corresponding
Auxiliaries for them are not FillForward so we do meet the condition
and then refresh price factor. As a result all futher FF data points are scaled too.

* Regression algorithm to check that FillForward'ed data points arrived with last real price factor

* Add trade for regression algorithm

- Minot tweaks and adding trade for new regression algorithm.
- Updating AddOptionContractExpiresRegressionAlgorithm because it is
  using the symbol for which new data was added.

Co-authored-by: Adalyat Nazirov <aenazirov@gmail.com>
2020-10-09 18:09:30 -03:00
Martin-Molinero
bfd319c91e OptionChain and OptionContract improvements (#4804)
* OptionChain and OptionContract improvements

- QCAlgorithm.AddUniverse will return the added Universe instance.
- Adding new OptionChainedUniverseSelectionModel will monitor a Universe changes
  and will spwan new OptionChainUniverse from it's selections. Adding
  regression test Py/C#.
- Adding new OptionContractUniverse that will own option contracts and
  their underlying symbol. Adding regression test
- Fix double notification for security changes, bug seen in updated
  UniverseSelectionRegressionAlgorithm
- Remove UniverseSelection special handling for Option and Future chains
- Fix DataManager not removing SubscriptionDataConfigs for Subscriptions
  which finished before being removed from the universe
- Refactor detection of user added Universe so that they do not get
  removed after calling the UniverseSelectionModel

* Add check for option underlying price is set

* Address reviews

- Adding python regression algorithm for
  `AddOptionContractFromUniverseRegressionAlgorithm`
  and `AddOptionContractExpiresRegressionAlgorithm`
- Rename QCAlgorithm new api method to `AddChainedOptionUniverse`

* Fix universe refresh bug

- Fix bug where a universe selection refresh would cause option or
  future chain universes from being removed. Adding regression algorithm
  reproducing the issue.

* Rename new option universe Algorithm API method

- Rename new option universe Algorith API method from
  AddChainedOptionUniverse to AddUniverseOptions
- Rebase and update regression test order hash because of
  option expiration message changed
2020-10-09 10:52:50 -03:00
Stefano Raggi
5f61456df8 Set Account Base Currency from Brokerage in Live Mode (#4806)
* Add property IBrokerage.AccountBaseCurrency

* Set AccountCurrency to brokerage AccountBaseCurrency

* Remove USD AccountCurrency check

* Fix Oanda account base currency

* Fix currency symbol in CashBook.ToString()

* Fix unit tests

* Address review

* Add DebugMessage when changing account currency

* Add debug message for brokerage account base currency

* Fix currency symbol in equity chart and runtime statistics

* Update unit tests
2020-10-09 09:58:01 -03:00
Michael Handschuh
a46a551c03 Include Order.Tag/OrderEvent.Message in their ToString, Fix default tag values (#4797)
* Improve information tracked in regression's {algorithm}.{lang}.details.log

The details.log file aims at providing a diff-able document that quickly and
easily provides actionable information. Since many regression algorithms use
the algorithm's debug/error messaging facilities to log various pieces of algo
state. This document also support a configuration option: regression-high-fidelity-logging'
that logs EVERY piece of data, again, with the aim of providing an easily diff-able
documenbt to quickly highlight actionable information. I may have missed omse key
pieces of information here, but now that the entire QC knows about this regression
tool, if additional information is required then hopefully it's easy enough at this
point to extend the RegressionResultHandler to suit our needs.

The RegressionResultHandler was initially implemented to provide a concise log of
all orders. This was achieved by simply using the Order.ToString method. While
testing/investigating OptionExerciseOrder behavior, it became evident that more
information was required to properly identify the source of potential failures or
differences between previous regression test runs. This change adds logging for
almost every IResultHandler method and additionally attempts to capture the
actual portfolio impact of every OrderEvent. This is accomplished by logging
the portfolio's TotalPortfolioValue, Cash properties and the security's
SecurityHolding.Quantity property.

This change also standardizes the timestamps used to folloow the ISO-8601 format.

When using the RegressionResultHandler, it is highly recommeded to also disable
'forward-console-message' configuration option to ensure algorithm Debug/Error
message logging is done synchronously to ensure correct ordering with respect to
log messages via Log.Debug/Trace/Error.

* Fix typo in options OrderTests test case name

* Update SymbolRepresentation.GenerationOptionTickerOSI to extension method

Far more convenient as an extension method

* Improve R# default code formatting rules

Many of these rule changes focus on improving the readability of code,
with a particular emphasis on multi-line constructs, chained method calls
and multi-line method invocations/declarations.

* Add braces, use string interpolation and limit long lines

* Refactor OptionExerciseOrder.Quantity to indicate change in #contracts

For all other order types, the Order.Quantity indicates the change in the algorithm's
holdings upon order execution for the order's symbol. For OptionExerciseOrder, this
convention was broken. It appears as though only exercise was initially implemented,
in which case only long positions were supported and a code comment indicated that
only positive values of quantity were acceptable, indicating the number of contracts
to exercise. At a later date, assignment simulation was added and utilized a negative
order quantity. This caused some major inconsistencies in how models view exercise
orders compared to all other order types. This change brings OptionExerciseOrder.Quantity
into alignment with the other order types by making it represent the change in holdings
quantity upon order execution.

This change was originally going to be much larger, but in order to minimize risks and to
make for an easier review experience, the additional changes will be committed separately
and pushed in their own PR. Some of the issues identified include:
* Manual Exercise (especially for OTM) is not covered
* Margin Calculations (in particular taking into account opposing contracts held)
* IBrokerage.OptionPositionAssigned is raised for exercise (later filtered by tx handler)

Fixes OptionPortfolioModelTests to use exercise model to properly model exercise of
non-account quote currency option contract.

* Include Order.Tag/OrderEvent.Message in their ToString, Fix default tag values

There was inconsistencies in what we were checking for. The order constructors
default the tag parameter to an empty string but Order.CreateOrder checks for
a null string. Additionally, the order constructors (limit,stopmarket,stoplimit)
would check for an empty string and if so, apply a default order tag.

This change cleans these checks up using string.IsNullOrEmpty and also removes the
check from Order.CreateOrder since we're passing the tag into the various order
constructors.
2020-10-08 21:54:54 -03:00
Michael Handschuh
cf9b547e2e Refactor OptionExerciseOrder.Quantity to be consistent with other Order types (#4796)
* Improve information tracked in regression's {algorithm}.{lang}.details.log

The details.log file aims at providing a diff-able document that quickly and
easily provides actionable information. Since many regression algorithms use
the algorithm's debug/error messaging facilities to log various pieces of algo
state. This document also support a configuration option: regression-high-fidelity-logging'
that logs EVERY piece of data, again, with the aim of providing an easily diff-able
documenbt to quickly highlight actionable information. I may have missed omse key
pieces of information here, but now that the entire QC knows about this regression
tool, if additional information is required then hopefully it's easy enough at this
point to extend the RegressionResultHandler to suit our needs.

The RegressionResultHandler was initially implemented to provide a concise log of
all orders. This was achieved by simply using the Order.ToString method. While
testing/investigating OptionExerciseOrder behavior, it became evident that more
information was required to properly identify the source of potential failures or
differences between previous regression test runs. This change adds logging for
almost every IResultHandler method and additionally attempts to capture the
actual portfolio impact of every OrderEvent. This is accomplished by logging
the portfolio's TotalPortfolioValue, Cash properties and the security's
SecurityHolding.Quantity property.

This change also standardizes the timestamps used to folloow the ISO-8601 format.

When using the RegressionResultHandler, it is highly recommeded to also disable
'forward-console-message' configuration option to ensure algorithm Debug/Error
message logging is done synchronously to ensure correct ordering with respect to
log messages via Log.Debug/Trace/Error.

* Fix typo in options OrderTests test case name

* Update SymbolRepresentation.GenerationOptionTickerOSI to extension method

Far more convenient as an extension method

* Improve R# default code formatting rules

Many of these rule changes focus on improving the readability of code,
with a particular emphasis on multi-line constructs, chained method calls
and multi-line method invocations/declarations.

* Add braces, use string interpolation and limit long lines

* Refactor OptionExerciseOrder.Quantity to indicate change in #contracts

For all other order types, the Order.Quantity indicates the change in the algorithm's
holdings upon order execution for the order's symbol. For OptionExerciseOrder, this
convention was broken. It appears as though only exercise was initially implemented,
in which case only long positions were supported and a code comment indicated that
only positive values of quantity were acceptable, indicating the number of contracts
to exercise. At a later date, assignment simulation was added and utilized a negative
order quantity. This caused some major inconsistencies in how models view exercise
orders compared to all other order types. This change brings OptionExerciseOrder.Quantity
into alignment with the other order types by making it represent the change in holdings
quantity upon order execution.

This change was originally going to be much larger, but in order to minimize risks and to
make for an easier review experience, the additional changes will be committed separately
and pushed in their own PR. Some of the issues identified include:
* Manual Exercise (especially for OTM) is not covered
* Margin Calculations (in particular taking into account opposing contracts held)
* IBrokerage.OptionPositionAssigned is raised for exercise (later filtered by tx handler)

Fixes OptionPortfolioModelTests to use exercise model to properly model exercise of
non-account quote currency option contract.
2020-10-08 20:05:20 -03:00
Colton Sellers
faa4e91e04 Test 4249 fix regression algorithms executed together (#4832)
* Fix for running regressions algorithms together

* Remove unneeded changes
2020-10-08 19:59:06 -03:00
Michael Handschuh
cc83f19528 Rename QuantConnect.API to QuantConnect.Api (#4830)
Also renames API folders to Api
2020-10-08 19:35:57 -03:00
Reginald Louis
54af12b06a Fix DirectoryNotFoundException on linux/mac (#4829) 2020-10-07 20:19:01 -03:00
Michael Handschuh
1d1c8f5f82 Don't raise IBrokerage.OptionPositionAssigned on exercise (#4801) 2020-10-07 14:40:34 -03:00
Colton Sellers
3966c0e91f Market Hours Database Adjustment (#4818)
* Fix Entries

* Fix options dates
2020-10-06 20:45:03 -03:00
Gerardo Salazar
28160e1301 Fixes generation of explicit "null" value in Smart Insider Transactions/Intentions (#4817)
* Adds new unit tests covering changes and testing for old case

  * JsonConvert.SerializeObject would convert a `null` value into a
    literal string of "null" when writing to a file via the ToLine
    abstract method. We opt for an empty string whenever the underlying
    value is null so that the parsing works correctly later in the
    data loading cycle.
2020-10-06 10:20:59 -03:00
Adalyat Nazirov
f4679785a5 Pass command line parameters values as string (#4819)
* avoid preliminary typing command lines arguments

* unit tests: Config.Get can parse and cast values

* unit tests: parse command line args and return string values

* unit test: parameter attribute converter

* merge&parse unit test
2020-10-06 10:19:56 -03:00
Martin-Molinero
79b9009452 ObjectStore delete will delete file (#4816)
- LocalObjectStore.Delete() will also delete file from the local object
  store path if present, this will avoid the issue where restarting the
  object store will re load the same deleted file. Adding unit test.
  Issue https://github.com/QuantConnect/Lean/issues/4811
2020-10-05 20:19:27 -03:00
Gerardo Salazar
e5b5f80d9d Fixes "0" group code value for FixturesAndAppliances (#4820)
* Fixes "0" group code value for FixturesAndAppliances

* Address review: fixes wrong variable name
2020-10-05 20:12:27 -03:00
Stefano Raggi
027fde8f09 Fix IBAutomater restarting after Dispose (#4814)
* Fix IBAutomater restarting after Dispose

* Address review
2020-10-05 12:34:02 -03:00
Martin-Molinero
c7ccd60bf2 Fix unit test stack overflow (#4803)
- PortfolioLooper: implement IDisposable and handle the clean up of
  resources. Remove unused methods.
- BaseResultHandler will reset Console on exit
2020-10-01 14:49:43 -03:00
adam-may
b30bb3fcf5 Bug #4790 - AddBusinessDays ignores holidays when DateTime being compared has time specified (#4791)
Co-authored-by: Adam May <adam.may@lifetrading.com.au>
2020-10-01 09:56:08 -03:00
Gerardo Salazar
40a87eb056 Fixes issue where BidPrice/AskPrice were not adjusted for Quote Ticks (#4789)
* Fixes issue where BidPrice/AskPrice were not adjusted for Quote Ticks

  * Previously, ticks would have their prices (Tick.Value) adjusted whenever
    TickType == TickType.Quote, but would not have their
    BidPrice/AskPrice fields adjusted, thus potentially being orders
    of magnitude such as 4x from the actual Bid/Ask prices.

    This commit applies the pricing scaling factor in a critical
    path where Ticks are adjusted to their scaled price. This issue
    only applied to Resolution.Tick && SecurityType.Equity data.

* Refactors Extensions Tick Scale extension method

  * Adjusts unit test to dispose of resources and assert history count

* Replaces use of FileSystemDataFeed for NullDataFeed in Adjustment test

* Adds regression algorithm testing BidPrice & AskPrice adjustment

* Address review: remove SecurityType check on TickType.Trade adjustments
2020-09-30 19:43:20 -03:00
Jatin Kumar
035b29fdf5 Update readme.md (#4793)
* Update readme.md

American English sadly.
2020-09-30 13:17:59 -07:00
michael-sena
f2fc1aae9e Append the full stacktrace to the algorithm loading exception message. (#4775)
* Append the full stacktrace to the algorithm loading exception message.

* Remove exception message loader duplication

Co-authored-by: Martin Molinero <martin.molinero1@gmail.com>
2020-09-30 12:42:21 -03:00
Martin-Molinero
ff5fc5db5d HistoryRequestFactory Hour ExtendedMarketHours (#4786)
- `HistoryRequestFactory` will not sure extended market hours for hour
  resolution when determining the start time using quantity of bars.
  Adding regression test
2020-09-29 18:16:27 -03:00
Gerardo Salazar
40c3062348 Improves Report Generator stability and fixes various bugs (#4759)
* Improves stability and fixes various bugs

  * Adds unit tests covering changes
  * Adds COVID-19 crisis plots
  * Adjusts styling of crisis plots for more pleasant viewing
  * Fixes bug where null BacktestResult caused application to crash
  * Order JSON bug fixes and stability improvements
  * MaxDrawdownReportElement now produces results for Live
  * Replaced Estimated Capacity w/ Days Live
  * Added Live marker to sharpe ratio
  * Added support for MOO and MOC orders in PortfolioLooper

* Address review: adds new unit tests and cleans up code

  * Bug fix: use LastFillTime instead of Order.Time for MOO and MOC

* Address review: Fixes tests and cleans up code
2020-09-29 10:03:26 -03:00
michael-sena
371f2cd469 Upgrade NLog from 4.4.11 to 4.4.13 (#4772) 2020-09-28 21:52:22 -03:00
Aaron Janeiro Stone
090ceb131e Install instructions: Non-Windows (#4777)
* Added warning for paths in non-Windows

As per https://github.com/dotnet/msbuild/issues/4216

* reserved character instructions - clarity
2020-09-28 21:51:21 -03:00
nazbrok
6885fd130b fix decimal conversion for exponential number (#4750) 2020-09-28 21:50:58 -03:00
Adalyat Nazirov
a450cea8d0 keep actual exchange hours even it different from hours database (#4781) 2020-09-28 20:22:08 -03:00
Stefano Raggi
934128cfa0 Binance Brokerage implementation (#4688)
* Binance Brokerage skeleton

* Market hours

* Implement Symbol Mapper

- known symbols available on /api/v1/exchangeInfo
- fiat currencies are pegged

* Implement GetCashBalance

* Implement GetAccountHoldings

- there are no pre-existing currency swaps
- cash balances are pulled and stored in the cashbook

* Implement GetOpenOrders

* Manage orders: PlaceOrder

* Manage orders: UpdateOrder

Update operation is not supported

* Manage orders: CancelOrder

* Messaging: order book

* Messaging: trades

* Messaging: combine streams

- connect to fake /ws/open channel on init
- case by channel name, but not event type

* Messaging: order depth updates

- ticker symbol is not enough as it pushes updates only once a second, this would be a very incomplete data stream
- fetch ticker snapshot if lastUpdateId == 0
- follow Binance instructions for keeping local orderbook fresh

* Messaging: user data streaming

- Request userDataStream endpoint to get listenKey
- keep listenkey alive
- handle order close event
- handle order fill event

* DataDownloader: get history

- we can aggregate minute candles for higher resolutions

* fix data stream

* Tests: FeeModel tests

* Tests: base brokerage tests

* Tests: download history

* Tests: symbol mapper

* Support StopLimit andd StopMarket orders

* StopMarket orders disabled

Take profit and Stop loss orders are not supported for any symbols (tested with BTCUSDT, ETHUSDT)

* Tests: StopLimit order

* Tests: crypto parsing

* Reissue user data listen key

* comment custom currency limitation

* rework websocket connections

* implement delayed subscription

* adapt ignore message

* add license banner

* use better suited exception type

* avoid message double parsing

* support custom fee values

* extract BinanceApiClient to manage the request/response between lean and binance

* use api events to invoke brokerage events

* do not allow to terminate session if it wasn't allocated.

* update binance exchange info

* tool to add or update binance exchange info

* ExchangeInfo basic test

* Rebase + Resharp

* Binance brokerage updates

- Fix sign bug in sell order fills
- Fix bug in GetHistory
- Remove duplicate symbol from symbol properties db

* Remove unused code

* Revert removal of account currency check

* Update symbols properties database

* Address review

* Address review

- Upgrade API endpoints from v1 to v3
- Updated sub/unsub for new subscription manager
- Subscribe best bid/ask quotes instead of full order book
- Added handling of websocket error messages
- Cleanup + refactor

* Update symbol properties database

* Remove list from symbol mapper

* Fix symbol mapper tests

* Address review

- Fix resubscribe after reconnect
- Fix quote tick edge case

* Fix EnsureCurrencyDataFeed for non-tradeable currencies

* Fix check in EnsureCurrencyDataFeed

* Reuse base class subscribe on reconnect

Co-authored-by: Adalyat Nazirov <aenazirov@gmail.com>
Co-authored-by: Martin-Molinero <martin@quantconnect.com>
2020-09-28 15:57:10 -03:00
Michael Handschuh
c7a74306fb Bug 4731 Fix Option Expiration Order Tags and Order Event IsAssignment Flag (#4743)
* Add OrderRight.GetExerciseDirection(isShort) extension

Returns the OrderDirection resulting from exercise/assignment of a particular
option right

See: BUG #4731

* Fix option exercise/assignment order tags and order event messages

The algorithm manager was doing work to determine whether or not the option ended
in exercise or assignment at expiration. This decision should be left for the exercise
model to decide -- from the algorithm manager's perspective, all that matters is that
the option was expired. The DefaultExerciseModel was updated to properly track whether
the option expired with automatic assignment or exercise, dependending on whether or
not we wrote or bought the option (held liability or right, respectively). Updated unit
tests to check for order event counts and order event messages for option exercise cases.

Fixes: #4731

* Fix typo in algorithm documentation

* Update regression tests order hash

Co-authored-by: Martin Molinero <martin.molinero1@gmail.com>
2020-09-28 15:29:09 -03:00
Aaron Janeiro Stone
cfacc755fa Removal of depreciated module called in test, addition of __init__ (#4769)
* Removal of depreciated module called in test, addition of __init__ to module.

* Delete __init__.py

Currently unnecessary
2020-09-28 11:36:02 -03:00
Michael Handschuh
194ed59cbe Check collection for null (#4763)
In OptionChainUniverseDataCollectionEnumerator.IsValid we check the underlying
foir null and ensure that there are data points but we forget to check the actual
collection object for null, which it is initialized to. The collection remains
null in the case where no data is found.
2020-09-28 10:39:59 -03:00
Martin-Molinero
776caea1d3 Convert a CoarseFundamental data point into a row (#4761)
* Convert a CoarseFundamental data point into a row

- Convert a CoarseFundamental data point into a row. Adding unit tests

* Remove fixed PriceFactor format
2020-09-25 20:31:46 -03:00
Martin-Molinero
460fd626a6 Simplify BaseWebSocketsBrokerage reconnection (#4758)
* Simplify BaseWebSocketsBrokerage reconnection

- Gdax does not emit time pulse so when no subscription was present the
  DefaultConnectionHandler would trigger a reconnect. Replacing for
  directly resubscribing on reconnect.
- TPV == 0 will send warning message instead of being an exception

* Fix unit test
2020-09-25 13:13:33 -03:00
Adalyat Nazirov
1e3a1e3c43 Historical data requests start & time fix (#4733)
* regression tests

* fix: apply the same time convertion to history request time as for data time

* ver2

* fixup

* unit tests

* do not need this conversion because RoundDownInTimeZone returns in proper TZ

* comment

* requested changes

* refactoring

* more refactoring

* fix existing test: should return Sunday if open

* more symbols

* fix existing tests: submit new btcusd data

* fix

* add Cfd symbol
2020-09-24 14:51:35 -03:00
michael-sena
e20725b969 Check both late open and early closes when looking up the next market open/close time (#4755) 2020-09-24 14:51:23 -03:00
Michael Handschuh
151901bbd1 Fix regression *.{lang}.details.logs (#4753)
* Fix regression *.{lang}.details.logs

Regression tests produce syslogs and a details.logs file. The details log file
provides a mechanism for logging data that passes through the result handler,
such as order event data. A change in the initialization ordeer of components in
the engine cause the algorithm id to not be set yet. The base result handler's
AlgorithmId property is populated via the job and is available, so we use that
instance.

* Update RegressionResultHandler.cs

Co-authored-by: Martin-Molinero <martin@quantconnect.com>
2020-09-23 16:35:12 -03:00
Michael Handschuh
fb2f846159 Bug 4722: Prevent Repetitive Factor File Numerical Precision Warnings (#4742)
* Add DataProviderEventArgs base class for IDataProviderEvents event args

This base class includes a Symbol property. This will empower event listeners
to make decisions based on which security (symbol) raised the event. The immediate
use case is preventing multiple numerical precision messages for the same security.
This pattern can equally be applied to other error messages that are raised each
time a security is added to a universe.

See: #BUG-4722

* Update ConcurrentSet.Add to use ISet<T>.Add returning bool

It's a very common pattern to use if (set.Add(item)) which is enabled
via bool ISet<T>.Add(item) but not enabled via void ICollectiont<T>.Add(item).
This change simples changes the default Add implementation to use the ISet<T>
overload and relegates the ICollection<T>.Add implementation to be explicit.

See: #BUG-4722

* Prevent multiple numerical precision messages for same symbol

If a security is continually added/removed from a universe, then the user will
see this message each time the security is added. This results in some spam.
This change simply remembers for which symbols we've notified the user about the
numerical precision issue.

Fixes: #BUG-4722
2020-09-22 21:06:59 -03:00
Martin-Molinero
d03ac0fd90 Gdax reconnection & Bitfinex minor fixes (#4748)
* Fix for BaseWebSocketsBrokerage reconnection

- `BaseWebsocketsBrokerage` will handle reconnection using the
existing `DefaultConnectionHandler` to avoid code duplication.

* Fix for Bitfinex failed Subscription calls

* Fix for bitfinex orderbook

* Fix unit test
2020-09-22 20:47:41 -03:00
Martin-Molinero
56db26d16d Allow specifying email Headers (#4735)
* Allow specifying email Headers

* Address review

- Fix for Python Notification.Email use case
2020-09-18 21:16:43 -03:00
Alexandre Catarino
dd8dc473b3 Improve Error Message For Arithmetic Overflow In Decimal Cast of Double (#4728)
* SafeDecimalCast Throws Exception For Non-Finite Numbers

* Fixes Arithmetic Overflow Exception in QCAlgorithm.Trading Methods

Replace decimal cast for `SafeDecimalCast()`.

If the algorithm uses a non-finite number in QCAlgorithm trading methods, it will throw with an user-frieldly exception message.

* Fixes KellyCriterionProbabilityValue Calculation
2020-09-18 09:17:09 -03:00
Colton Sellers
b8033c496c Bug 4487 Get Fundamental for CSharp (#4703)
* Add unit tests

* Refactor Py and create C# function

* Update readme to include local

* Refactor solution; fix python cases

* Update tests

* Don't accept null selector for python; Create SelectedData class

* Fix Testing

* Pre review

* Fix tests for Travis

* Test fix V2

* Test fix V3

* Refactor quantbook and fix tests

* Sort list by date

* Move ConvertToSymbols to Python Util

* Address review

* Order dataframe columns by Security ID

* Address review V2

* header for PythonUtilTests
2020-09-16 18:06:01 -03:00
Martin-Molinero
166fee311a Fix for LiveTradingResultHandler Holdings (#4719)
- LiveTradingResultHandler will not send non tradable securities in the
  holdings update
2020-09-16 10:08:34 -03:00
Gerardo Salazar
be8e381fba Fixes historical option data not loaded when provided underlying Symbol (#4720)
* Adds unit test to cover changes
2020-09-14 20:39:48 -03:00
Adalyat Nazirov
75eac27795 Bug 4600 brokerage unsubscribe symbol granular (#4640)
* bitfinex unsubscribe impl

* IB implementation

* Alpaca Brokerage

* Fxcm Brokerage

* Bitfinex remake

* GDAX Brokerage

* move & rename DataQueueHandler subscription manager to better place for using in ToolBox

* performance tuning

use unified Channel class everywhere
BaseWebsocketBrokerage.GetSubscribed method relies on DQHSubscriptionManager

* TradierBrokerage implementation

* OandaBrokerage implementation

* FakeDataQueue subcription manager

* Fake SubscriptionManager for testing

* CoinApi implementation

* IEXDataQueueHandler implementation

* IQFeed Implementation

* unit tests

* fix SubscribeSymbols params

* thread safe subscribed symbols

* don't need to lock Keys prop, because it's thread safe

* accurate PolygonDataQueueHandler subscribe/unsubscribe methods

* Alpaca isnt DataQueueHAndler anymore

* remove unused variable

* remove redundant hashset

* fix coin api subscribe method

* disclaimer

* prettify code

* race condition?

* fix symbol conversion

* log if unsubscribed; change Channel Id type

* requested changes

* pass GetChannelName func as required parameter

* centralized logs

* use single name for all idqh with no difference in tick type

* change Oanda resubscribe method

* CanSubscribe doesn't change instance state - can be marked as static.

* change Oanda Subscription tracking

* style changes

* bitfinex fix

* fix spelling
2020-09-14 20:11:44 -03:00
Colton Sellers
12b481f1ce Adjust regression algorithm (#4714)
* Adjust test to show how to legitimately change an order

* Address review

* fix comparator; check Order Time
2020-09-14 17:07:14 -03:00
Martin-Molinero
9cb2452025 Oanda default Forex Market (#4706)
* Oanda default forex Market

- Use Oanda as default forex Market since it has more pairs.
- Remove FXCM data add Oanda equivalente data.
- Update unit and regression tests

* Address reviews

- Revert FXCM data removal
- Remove unrequired commented code

* Fix rebase
2020-09-14 16:43:23 -03:00
Stefano Raggi
d8dc03fadc Reuse symbol properties database for currency conversions (#4710)
* Remove invalid symbols from symbol properties db

* Add SymbolPropertiesDatabase.GetSymbolPropertiesList

* Remove symbol list in BitfinexSymbolMapper

* In EnsureCurrencyDataFeed fetch symbols from symbol properties database

* Remove symbol list in OandaSymbolMapper

* Remove unused code

* Address review

- Remove StringComparer.OrdinalIgnoreCase usage
- Rename KnownSymbolStrings to KnownTickers
2020-09-14 15:12:17 -03:00
Gerardo Salazar
124e76cfe8 Adds deployment of packaged stubs for distribution in CI process (#4713) 2020-09-11 17:18:08 -07:00
Martin-Molinero
4a0fb30df5 Fixes for OpenInterest storing (#4712)
- Fix Slice.Get OpenInterest type. Adding unit test
- Fix for SecurityCache that wasn't storing OpenInterest types
- Updateing regression tests to covere these usages
2020-09-11 15:28:27 -07:00
Stefano Raggi
60b8cf76ba Bitfinex Brokerage updates (#4584)
* Upgrade Bitfinex brokerage to API v2

* Fix rebase

* Address review

- use te instead of tu messages for trades
- add missing orderMap removals
- ClientOrderId is now time-based instead of a counter
- minor cleanup

* Trigger build
2020-09-10 17:14:10 -03:00
aarjaneiro
9916a9069c Update PythonPackagesTests.cs (#4673)
* Update PythonPackagesTests.cs

Detecting issues related to https://stackoverflow.com/questions/56957512/pythonnet-missing-addreference-method, which has shown up for me when using lean (https://www.quantconnect.com/forum/discussion/9054/lean-vagrant-box/p1).

* Update PythonPackagesTests.cs

Named test

* Name change of MonoTest to SanityClrInstallation 

Name suggestion by @Martin-Molinero

* Fix minor typo

Co-authored-by: Martin-Molinero <martin@quantconnect.com>
2020-09-10 16:34:37 -03:00
Colton Sellers
f135fb8060 Bug Backtesting Brokerage Clones (#4644)
* fix order updates

* Fix option exercise issue

* Regression changes

* Update regressions to reflect fixes

* Refactor handling of order to fully fix #2846

* Regression Algorithm for unit test

* Pre review

* Fix breaking tests

* OrderImmutability Regression Algo

* OrderImmutability Regression Algo Compile

* Address review

* Update regressions with new orderhash
2020-09-09 19:44:56 -03:00
Adalyat Nazirov
7bb143b215 Bug 4031 Change data depending on configuration (#4650)
* Calculate both raw and adjuasted prices for backtesting

* disable second price factoring

* move and reuse method

* test coverage for new methods

* reuse scaling method

* reuse subscriptionData.Create method

* removed unused code

* regression test

* switch to aapl

* fix regression test output

* more asserts

* fix comments - reduce shortcuts and abbrevation

* more comments

* merge parameters

* reduce number of getting price factors

* fix tests

* fix tests

* fix regression tests

* calculate TotalReturn on demand

* include TotalReturn calculations

* perf tuning

* more unit tests for SubscriptionData.Create

* simplify things - store and return only raw and precalculated data

* fix regression tests; change it back

* factor equals 1 for Raw data

* small changes

* follow code style

* implement backward compatibility
2020-09-09 18:40:19 -03:00
Stefano Raggi
d7e543736f GDAX Brokerage updates (#4635)
* GDAX Brokerage updates

- Replaced fill detection from trade stream with monitor task
- Order fees for fills are now the real fees paid (previously they were calculated by the brokerage model)
- All unit and integration tests are green

* Address review

- Remove unnecessary signals
- Add "gdax-fill-monitor-timeout" config setting

* Remove user channel
2020-09-09 16:18:10 -03:00
Stefano Raggi
8785af7ad6 Alpaca Brokerage updates (part 2) (#4601)
* Remove IDataQueueHandler from AlpacaBrokerage

- a new IDataQueueHandler implementation for Polygon.io will be added to the ToolBox

* Fix Alpaca Websocket connect not waiting for completion

* Add security type check in Alpaca history

* Fix merge

* Remove aggregator from AlpacaBrokerage
2020-09-09 15:17:10 -03:00
Adalyat Nazirov
808fa327e2 Fix duplicated history entries when contains daylight saving time change (#4700)
* regression test

* fix

* add comments

* more humanic implementation

* unit tests

* more comments
2020-09-09 13:57:40 -03:00
Martin-Molinero
778e3015c8 Revert live trading config IDQH over job packet (#4705) 2020-09-09 12:03:02 -03:00
Martin-Molinero
616b2b8d52 Prioritize job packet history provider (#4701)
- Will prioritize job packet history provider value.
- Improve LTRH logging
2020-09-08 18:45:36 -03:00
Martin-Molinero
98d3a98656 Inline some methods for performance (#4696)
- Add AggressiveInlining for some methods
2020-09-04 18:13:46 -03:00
Derek Melchin
20791d6a9e Add schedule queuing algorithm (#4695)
* Add schedule queuing algorithm

* Add algorithm file to csproj file

* Add c# version of queuing algorithm
2020-09-04 12:34:07 -07:00
Martin-Molinero
3609340281 Add internal subscriptions always (#4690)
* Add set market price during extended market hours

- Set market prices during extended market hours for live trading.
  Adding unit test

* Add assert on internal data count
2020-09-03 18:15:21 -07:00
Colton Sellers
8edc89a4ff Feature Python Option Filtering Support (#4667)
* Support List and OptionFilterUniverse for Py filter

* Regression algorithm for testing

* Unit Tests

* Fix for process

* Tighten filters to reduce load on automated testing

* Address review v2
2020-09-02 21:38:16 -03:00
Martin-Molinero
718dc02173 Add finish log for volatility warmup (#4684) 2020-09-02 16:54:39 -07:00
Martin-Molinero
ec5ff53566 Fix key not found exception at InternalSubsManager (#4679)
* Fix key not found exception at InternalSubsManager

- Fix key not found exception
- Fix backtesting chart sampling

* Add comment about PreviousUtcSampleTime
2020-09-01 22:32:21 -03:00
Martin-Molinero
400a0d42d9 Add internal subscription manager (#4678)
* Add internal subscription manager

- Add InternalSubscriptionManager that will handle internal
  Subscription. Replaces the realtime updates
- Fix thread race condition in the TimeTriggeredUniverseSubscription, we
  have one thread injecting data points, the main algorithm thread, and
  the base exchange is pulling from it
- Fixes for FakeDataQueue
- Adding unit tests

* Address reviews and fixes

- Internal subscription will use extended market hours
- Only sample charts accordingly
- Get api-url once
2020-09-01 21:22:22 -03:00
Adalyat Nazirov
ae11e9ce43 allow Composer to create IDataQueueHandler instances (#4677) 2020-09-01 11:23:08 -03:00
Colton Sellers
d3ccc14fcd Unit test for RegisterIndicator in Python (#4676) 2020-08-31 19:11:24 -03:00
QuantConnect Server Applications
90e911f22c Adds autogenerated Python stubs via Travis for QCAlgorithm (Build 14139) (#4671)
Co-authored-by: Python Stubs Deployer <stubs-deploy@quantconnect.com>
2020-08-29 13:10:37 -03:00
Colton Sellers
34676f0c46 Bug 4668 python register indicator (#4670)
* Convert to timespan if possible

* Fix to support both timespans and custom consolidators

* Adjust tests for new wrapper requirements

* Cleanup
2020-08-29 02:53:32 -03:00
QuantConnect Server Applications
d4ca27f93f Adds autogenerated Python stubs via Travis for QCAlgorithm (Build 14115) (#4662)
Co-authored-by: Python Stubs Deployer <stubs-deploy@quantconnect.com>
2020-08-28 16:43:17 -03:00
Martin-Molinero
f4ed48fce2 Always use AlgorithmHandler.DataProvider (#4658)
- `UniverseSelection` and `Research` will always use
  `AlgorithmHandler.DataProvider` instance instead of
  `DefaultDataProvider`
- Remove Compression at test/app.config since the dll isn't required
- Add missing license header
2020-08-27 16:07:56 -03:00
Gerardo Salazar
ce29a68f85 Deletes residual python files left over by stubs generation (#4666) 2020-08-27 11:47:48 -07:00
Stefano Raggi
375f192f07 Add PolygonDataQueueHandler (#4604)
* Add PolygonDataQueueHandler

* Add history provider and downloader for Polygon

* Add aggregator to PolygonDataQueueHandler

* Address review

- Removed duplication in message classes
- Added public Subscribe/Unsubscribe methods in PolygonWebSocketClientWrapper
- Added history requests for Forex and Crypto

* Address review

- Add security type and market arguments to downloader
- Fix time zone bug in downloader

* Remove unnecessary locks

* Add Polygon history for all resolutions

- Equity: trades and quotes
- Forex: quotes only
- Crypto: trades only
2020-08-27 12:09:20 -03:00
Gerardo Salazar
ef9ca98bd9 Fixes bug where build was attempted on PR submission (#4661)
* Fixes potential stale commits by changing --force-with-lease to -f
2020-08-26 16:05:33 -07:00
Gerardo Salazar
aded66ec5b Adds Python stubs location definition for PyCharm and Visual Studio Code (#4657) 2020-08-26 14:17:33 -07:00
Colton Sellers
59ce008725 typo fix (#4659) 2020-08-26 14:16:42 -07:00
Mathieu Paquette
46e10c0a27 feat(ToolBox/IQFeed): remove memory pressure from GroupBy when fetching Tick (#4646)
#4645
2020-08-26 17:46:34 -03:00
Gerardo Salazar
2431cfabe7 Updates .travis.yml to include build/deploy scripts for Python stubs (autocomplete) (#4656)
* Updates .travis.yml to include build/deploy scripts for py stubs

  * Adds stubs generator script for CI

* Silences curl output
2020-08-26 13:19:54 -07:00
Colton Sellers
b8674731a5 Feature 2456 custom Python consolidator support (#4637)
* DataConsolidator Wrapper for Python Consolidators

* Regression Unit Test

* Refactor Regression test

* Bad test fix

* pre review

* self review

* Add RegisterIndicator for Python Consolidator

* Python base class for consolidators

* Modify regression algo to register indicator

* unit test - attach event

* Test fix

* Fix test python imports

* Add license header file and null check

Co-authored-by: Martin Molinero <martin.molinero1@gmail.com>
2020-08-25 17:26:55 -03:00
Alexandre Catarino
a14f8f1f47 Refactors SecurityCache to Support Access to Tick of Different Type (#4621)
* Refactors SecurityCache to Support Access to Tick of Different Type

Adds two read-only lists of BaseData to save the last list of Tick of TickType.Trade and TickType.Quote. Changes methods accordingly to get and set these lists.

* Addresses Peer Review

The assignment of `_lastData` is moved to keep the current behavior of not beeing set with fill forward data.
`Reset` and `ShareTypeCacheInstance` implements the new class objects.

Adds unit tests for `Reset` and `ShareTypeCacheInstance`.

* Only Cache Non Fill-Forward Data

Undo changes that made AddData cache non fill-forward data.
2020-08-24 10:37:50 -03:00
Jovad Uribe
fc6ccdbc11 Feature emv indicator addition (#4591)
* Create EaseOfMovementValue.cs

Added ease of movement file

* Update EaseOfMovementValue.cs

Added calculation for EMV and return its value

* Update EaseOfMovementValue.cs

* Update EaseOfMovementValue.cs

* Update EaseOfMovementValue.cs

* Update EaseOfMovementValue.cs

Rearranged code and removed all IndicatorBases

* Update EaseOfMovementValue.cs

* Update EaseOfMovementValue.cs

Added Min and Max Indicator

* Added Tests and Compile

* Fixed Bugs and Removed Reset

* Added Current Value and revereted to Bar data

* Fixed test file and refined indicator file

* TradeBar to IBaseDataBar

* Bug fixes

* bug fix

* Switching to TradeBar and attempting to fix Volume bug

There are two bugs that I have been having trouble fixing. 1. Cannot implicitly convert decimal to int (simple fix but cannot find where bug is taking place)
2. IBaseDataBar does not contain a definition for Volume

* Update EaseOfMovementValueTests.cs

* bug fix

* added data

* updated assertion

* added reset

* Update EaseOfMovementValueTests.cs

* Update EaseOfMovementValue.cs

* Update spy_emv.txt

I had the wrong test data in. Was throwing failed test for many pull requests.

* Update EaseOfMovementValue.cs

* Update EaseOfMovementValue.cs

* Update EaseOfMovementValue.cs

* Update EaseOfMovementValue.cs

* Cleaned Data

* Bug fixes

Fixed zero division error. Used better Test Data.

* removed readonly from _previous...price

* Update EaseOfMovementValue.cs

* Update EaseOfMovementValue.cs

* Update EaseOfMovementValue.cs

* bug fix

* Test Bug Fix

* EMV data from online

* Cosmetics

* Out of bounds fix

* Update EaseOfMovementValueTests.cs

* Update spy_emv.txt

* Update spy_emv.txt

* Added changes requested

Placed constructor first, fixed nullable type if statement, set 10,000 to default argument, added SMA.

* Update EaseOfMovementValue.cs

added variables

* Update EaseOfMovementValue.cs

* Update EaseOfMovementValue.cs

* Update EaseOfMovementValue.cs

* Fixed bugs

* Changed Delta, Added Assert

Create Indicator -> Update EMV -> Assert Status. Also changed delta from 1 to 0.000001 to improve test accuracy.

* Added unit test testing the SMA
2020-08-24 09:54:58 -03:00
Martin-Molinero
ccd31bdfab Minor improvements (#4643)
* Minor improvements

- Make RH interval configurable
- Fix double to decimal casts
- Fix FDQ

* Revert safe decimal usage
2020-08-21 21:18:29 -03:00
Stefano Raggi
14dd52ba00 Add zero TotalPortfolioValue check in BrokerageSetupHandler (#4642)
* Add empty cashbook check in BrokerageSetupHandler

* Update check for zero TotalPortfolioValue

* Move check for zero TPV after setting currency conversions

* Fix zero conversion rate for account currency + add unit tests

* Fix unit test
2020-08-21 15:09:29 -03:00
Mathieu Paquette
2d46674fb7 feat(Toolbox\IQFeed): optimized download history for IQFeed (#4302)
* feat(Toolbox\IQFeed): optimized download history for IQFeed

Fixes #4301

* feat(IQFeed/ToolBox): code review comments

* feat(IQFeed/ToolBox): add support for quotes and trades

* feat(IQFeed/ToolBox): trade constructor change

* feat(IQFeed/ToolBox): always apply timezone conversion

* feat(IQFeed/ToolBox): fix interval start
2020-08-21 11:26:46 -03:00
Mathieu Paquette
554b7345bb feat(IQFeed/ToolBox): add IQFeed support for docker (#4632)
* feat(IQFeed/ToolBox): add IQFeed support for docker

#4631

* feat(IQFeed/ToolBox): add IQFeed documentation for docker

#4631

* feat(IQFeed/ToolBox): code review comments

#4631
2020-08-19 18:14:37 -07:00
Martin-Molinero
4348e830ba Revert "Add zero TotalPortfolioValue check in BrokerageSetupHandler (#4639)" (#4641)
This reverts commit c85f608444.
2020-08-19 15:30:13 -07:00
Stefano Raggi
c85f608444 Add zero TotalPortfolioValue check in BrokerageSetupHandler (#4639)
* Add empty cashbook check in BrokerageSetupHandler

* Update check for zero TotalPortfolioValue
2020-08-19 12:55:43 -03:00
Martin-Molinero
9cdb4a91c5 Refactor live data feed (#4636)
* Live Coarse universe refactor

- Live trading will source Coarse and Fine fundamental data directly
  from disk. Updating unit tests.

* Adds ILiveDataProvider interface

  * Adds wrapper for IDataQueueHandler implementations

  * Replaces IDataQueueHandler with ILiveDataProvider in
    LiveTradingDataFeed

  * Edits IDataQueueHandler documentation

* Maintains aggregation for current IDQH impls and skips for ILDF impls

  * Note: No unit test was created for this method, go back and TODO

* Protobuf Market data

- Adding protobuf support for Ticks, TradeBars and QuoteBars. Adding
  unit tests.

* Adds unit tests for LiveDataAggregator changes

  * Fixes bug where custom data was not handled as it was before
  * Fixes race condition bug because of variable reuse in class

* Add protobuf extension serialization

* Fixes for protobuf serialization

* Refactor

* Fix OptionChainUniverse

* replace BaseDataExchange pumping ticks with consolidators

* AlpacaBrokerage

* BitfinexBrokerage

* GDAXBrokerage

* OandaBrokerage

* InteractiveBrokers

* TradierBrokerage

* FxcmBrokerage

* PaperBrokerage

* etc

* WIP fixes for existing LTDF unit tests

* Fixes more LTDF unit tests

* make IDataAggregator.Update recieving Generic BaseData rather than Tick

* Change IDataQueueHandler.Subscribe method

* Some fixes after adding new commits

* Adds protobuf (de)serialization support for Dividend and Split

* Serialize protobuf with length prefix

* Fix missing LTDF unit tests

* Adds TiingoNews protobuf definitions

* fix comments

* more fixes on IQFeedDataQueueHandler

* disallow putting ticks into enumerator directly

* ScannableEnumerator tests

* fix OandaBrokerage

* AggregationManager unit tests

* fix AlpacaBrokerage tests

* fix InteractiveBrokers

* fix FxcmBrokerage tests

* call AggregationManager.Remove method on unsubscribe

* fix GDAX existing tests

* Fixes, refactor adding more tests for AggregatorManager

* Adds BenzingaNews protobuf definitions and round trip unit test

* Adds missing TiingoNews unit test to Protobuf round trip tests

* Improve sleep sequence of LiveSynchronizer

* need start aggregating first, and then can subscribe

* More test fixes and refactor

- Refactoring AggregationManager and ScannableEnumerator so the last is
  the one that owns the consolidator
- Adding pulse on the main LiveSynchronizer

* Improve performance of LEquityDataSynchronizingEnu

* Add missing Set job packet method

* Minor performance improvements

* Improvements add test timeout

- Improvements adding test timeout to find blocking test in travis

* Improve aggregationManager performance

* Testing improvements for travis

* Remove test timeouts

* More test fixes

- Adding more missing dispose calls and improving determinism

* fix IEXDataQueueHandler and tests

* Final tweaks to LTDF tests

* more AggregationManager tests

* consume and log ticks

* fix test: couldn't subscribe to Forex tickers

* change Resolution for all bar configs

* Improve RealTimeScheduleEventServiceAccuracy

* refactoring: move common code to base class

* fixed bug; unsubscribe SubscriptionDataConfig

* Small performance improvement

* Minor fixes

* Avoid Symbol serialization

* Fixes coarse selection in live mode

* Fix for live coarse

* Adds protobuf (de)serialization support for Robintrack

  * Adds round-trip unit test

* Minor performance improvements

* More minor performance improvements

* pass LiveNodePacket through to OandaBrokerage

* Fixes empty list becoming null value when deserializing with protobuf

* Reverts BZ live trading exception removal and fixes tests

* Refactor WorkQueue making it abstract

* Add try catch for composer

* Adds optional data batching period to LiveFillForwardEnumerator

* Override data-queue-handler with config

* Improve PeriodCountConsolidator.Scan performance

* Move batching delay to main Synchornizer thread

* Reverts addition of Robintrack protobuf definitions

* Give priority to config history provider if set

* Add Estimize protobuffing

- Add Estimize protobuffing support. Adding unit tests

* Always dispose of data queue handler

Co-authored-by: Gerardo Salazar <gsalaz9800@gmail.com>
Co-authored-by: Adalyat Nazirov <aenazirov@gmail.com>
2020-08-18 20:21:10 -03:00
michael-sena
a128f8bb2e Allow LeanDataWriter to create zip files for futures data (#4569)
* Allow LeanDataWriter to append to zip data files

* Use the data directory provided to the writer instead of the global value

* Disregard the time-portion of an input date

* Overwrite zip entries when creating futures data files

* Minor tweak and adding unit test

Co-authored-by: Martin Molinero <martin.molinero1@gmail.com>
2020-08-18 17:44:02 -03:00
Colton Sellers
3ef6a761ad Feature research docker scripts (#4622)
* Add research docker launch script

* Internalize creation of cfg and dir to dockerfile

* Implement bash version of notebook run script

* quick fix to use docker.cfg

* update readme

* typo fix

* Review tweaks

* Tweaks
2020-08-17 14:35:34 -03:00
Gerardo Salazar
b866c8b893 Removes Robintrack data source (#4628) 2020-08-14 19:46:30 -03:00
Colton Sellers
64a99d1194 Feature shorcut helper for STC (#4623)
* Shorcut helper for STC

* Use name variable
2020-08-12 14:41:20 -03:00
Gerardo Salazar
57cbfa2f26 Fixes stalling of LiveFillForwardEnumerator (#4620)
* Adds unit test containing previously failing test case
2020-08-10 18:58:46 -03:00
Stefano Raggi
bc44e23322 Upgrade IBAutomater to v1.0.29 (#4616)
* Upgrade IBAutomater to v1.0.28

* Upgrade IBAutomater to v1.0.29
2020-08-07 12:56:31 -03:00
Juan José D'Ambrosio
6c051cd816 Update symbol property database with latest crypto pairs (#4612) 2020-08-06 10:23:20 -03:00
Stefano Raggi
4c04efc237 Fix KeyNotFoundException in Cash.EnsureCurrencyDataFeed (#4610) 2020-08-06 09:49:27 -03:00
Colton Sellers
a83388ab1a case matching compatibility improvement (#4613) 2020-08-06 09:38:59 -03:00
Adalyat Nazirov
1c9b817960 Track indicator previous input per symbol individually (#4607)
* track previous input per symbol

* improve Arms Index period checks

* don't need to be thread safe due to consolidators update are sequential

* Use TryGetValue for performance

- Minor update for AdvanceDeclineIndicator to use TryGetValue to reduce
  amount of dictionary access

Co-authored-by: Martin Molinero <martin.molinero1@gmail.com>
2020-08-02 20:13:27 -03:00
Colton Sellers
c5c57a33c1 IDE & Docker Integration (#4576)
* Mount custom algorithms to container

attach algorithms with bash script

* VS Code Integration

* PyCharm Integration

* Simplify the run docker script

* Mono C# Debugging is broken, removed related tasks

* add OSX config for run-docker

* Update readme.md

Reflect latest changes to configuration

* Update to move pdb for debugging algos

* VS Code C# Debugging fix

* Visual Studio fixes for debugging C#

* rework of launch scripts; also allows inline args

* Documentation overhaul

* Add python directory arg

* address review

* List debugging options in config

* Undo unnecessary change

* Address review and bughunt

* remove python debugging method
2020-08-02 19:45:18 -03:00
Martin-Molinero
47ec1ba8be Merge pull request #4570 from AdalyatNazirov/feature-4168-arms-index-indicator
Add Arms Index Indicator
2020-07-31 17:09:45 -03:00
Adalyat Nazirov
e37c9dbb1a fix CreateIndicatorName; add unit tests 2020-07-31 22:50:31 +03:00
Adalyat Nazirov
c2cac7fbee remove unused using 2020-07-31 22:03:57 +03:00
Adalyat Nazirov
df9c1973da fix warmup process; handle not ordered bars 2020-07-31 21:39:31 +03:00
Adalyat Nazirov
bfb13e46c8 improve warming indicator up 2020-07-31 21:13:56 +03:00
Adalyat Nazirov
59286bb750 handle missing values 2020-07-31 21:13:56 +03:00
Adalyat Nazirov
939b334478 test RemoveStock method 2020-07-31 21:13:56 +03:00
Adalyat Nazirov
22155bf3ce add extension methods for new indicators 2020-07-31 21:13:56 +03:00
Adalyat Nazirov
33bb1e8984 improve performance 2020-07-31 17:53:56 +03:00
Adalyat Nazirov
fb483365ae refactor class 2020-07-31 17:53:56 +03:00
Adalyat Nazirov
b0fcf9f7ac fixup data 2020-07-31 17:53:56 +03:00
Adalyat Nazirov
a044cd6416 fix TRIN 2020-07-31 17:53:56 +03:00
Adalyat Nazirov
3f556d70ec A/D Volume Ratio: wip 2020-07-31 17:53:55 +03:00
Adalyat Nazirov
220ccbae7c A/D Ratio : wip 2020-07-31 17:53:55 +03:00
Adalyat Nazirov
a6d1908aa9 TRIN 2020-07-31 17:53:55 +03:00
Adalyat Nazirov
99aa1eadd7 create A/D Volume Ratio indicator 2020-07-31 17:53:55 +03:00
Adalyat Nazirov
d53f79b271 create A/D Ratio indicator class 2020-07-31 17:53:55 +03:00
Adalyat Nazirov
78d30b23cb new status 2020-07-31 17:53:55 +03:00
Adalyat Nazirov
a8d6857407 test data 2020-07-31 17:53:55 +03:00
Adalyat Nazirov
fad38f8ed4 [tmp] generate equity, but need generic method to parse symbol 2020-07-31 17:53:55 +03:00
Adalyat Nazirov
c7091dbf6b parse Symbol if exists 2020-07-31 17:53:55 +03:00
Adalyat Nazirov
ea9007601d fix date parsing: TwelveCharacter dateformat can't be parsed properly;
more String Extensions: extract substring safely
add more US formats
2020-07-31 17:53:55 +03:00
Adalyat Nazirov
5278a3dd02 too many code duplications
reuse existing GetCsvFileStream for streaming file data
2020-07-31 17:53:54 +03:00
Adalyat Nazirov
ebf4d21bd9 reuse existing TradeBarIndicator instead of Generic one 2020-07-31 17:53:54 +03:00
Adalyat Nazirov
c83627a89c fix BollingerBands indicator comments 2020-07-31 17:53:54 +03:00
Martin-Molinero
27e0ce7a57 Merge pull request #4586 from QuantConnect/bug-4568-iex-data-queue-handler-fix
IEX DataQueueHandler updates
2020-07-31 10:52:49 -03:00
Jared
457418e7bc Merge pull request #4603 from QuantConnect/fix-factor-files-missing-file-check
Fix factor files missing file dir check
2020-07-31 06:46:00 -07:00
Martin Molinero
db1bf686b9 Fix factor files missing file dir check 2020-07-31 10:44:57 -03:00
Stefano Raggi
bc41b4461e Add logging for missing IEX api key 2020-07-31 08:49:03 +02:00
Stefano Raggi
036d8684c0 IEX DataQueueHandler updates
- Add parameterless constructor (for usage in LEAN config)
- Added config setting for IEX Cloud api key (required for history requests)
2020-07-30 17:32:00 +02:00
Martin-Molinero
d1e38b33a6 Merge pull request #4599 from QuantConnect/fix-smartinsider-intention-raw-data-read
Fix SmartInsiderTests failing test
2020-07-30 11:09:14 -03:00
Juan José D'Ambrosio
a28cde3633 Fix failing test
SmartInsiderIntention.FromRawData method doesn't read the raw data as they come from SmartInsider, it needs a filtering of some columns that is performed in SmartInsiderConverter.Process method.

That's added to the failing test.
2020-07-30 13:49:05 +00:00
Martin-Molinero
2360e4c961 Merge pull request #4598 from michael-sena/bug-4597-allow-markethoursdatabase-to-be-used-without-data-folder
Allow use of the MarketHoursDatabase class without requiring the Data folder
2020-07-30 10:08:09 -03:00
Martin-Molinero
839b38d904 Merge pull request #4573 from QuantConnect/alpaca-brokerage-updates
Alpaca Brokerage updates
2020-07-30 09:57:46 -03:00
Martin-Molinero
443ec46c89 Merge pull request #4590 from michael-sena/bug-4589-move-margin-files-for-sgx-and-hkfe
Move the margin files for SGX and HKFE into the correct folder
2020-07-30 09:46:25 -03:00
Stefano Raggi
38ce10c723 Remove unused references to WebSocketSharpFork 2020-07-30 14:06:22 +02:00
Stefano Raggi
ab8d95f627 Remove redundant logging 2020-07-30 14:06:22 +02:00
Stefano Raggi
f44eb64c97 Remove WebSocketSharp from AlpacaBrokerage 2020-07-30 14:06:22 +02:00
Michael Sena
b0c21b605c Allow use of the MarketHoursDatabase class without requiring the Data folder 2020-07-30 16:16:25 +10:00
Jared
103a8e8a0a Merge pull request #4593 from AlexCatarino/bug-report-32-bit
AnyCPU Prefer 64-bit for Report Project
2020-07-29 21:34:40 -07:00
Jared
c4140d3644 Merge pull request #4595 from QuantConnect/issue-4594-smartinsider-unexpected-field
Add Plan Re-started to SmartInsiderEventType
2020-07-29 17:38:47 -07:00
Juan José D'Ambrosio
211f1144b5 Implement NotSpecified SmartInsiderEventType 2020-07-29 21:08:52 +00:00
JJD
e7682cbd37 Add Plan Re-started to SmartInsiderEventType 2020-07-29 11:24:44 -03:00
Alexandre Catarino
68455fe19c AnyCPU Prefer 64-bit for Report Project
All projects that depends on Python.Runtime.dll need to be compiled in 64-bit.
2020-07-29 12:41:44 +01:00
Jared
920e4cba85 Merge pull request #4557 from C-SELLERS/feature-4167-Schaff-Trend-Cycle-Indicator
Feature 4167 Schaff Trend Cycle indicator
2020-07-28 15:35:25 -07:00
Colton Sellers
1eb40d0b6b Remove images 2020-07-28 15:05:47 -07:00
Colton Sellers
07d51a16aa Move indicator documentation 2020-07-28 14:34:08 -07:00
Colton Sellers
2484a85eda Format fixes 2020-07-28 14:34:08 -07:00
Colton Sellers
69e2a0eef0 Create a readme for indicators 2020-07-28 14:34:08 -07:00
Colton Sellers
798b92eef1 Copy over test file 2020-07-28 14:34:08 -07:00
Colton Sellers
493cad42ad Name fix 2020-07-28 14:34:08 -07:00
Colton Sellers
6283266da1 Add indicator pictures 2020-07-28 14:34:08 -07:00
Colton Sellers
a3db5d8710 Cleanup before PR 2020-07-28 14:34:08 -07:00
Colton Sellers
835658ec3e Overwriting assertion to allow a greater variance 2020-07-28 14:34:08 -07:00
Colton Sellers
b70173de22 Changed to intraday points, lots more data. 2020-07-28 14:34:08 -07:00
Colton Sellers
2f7fa4cbc5 Fix Reset and IsReady 2020-07-28 14:34:07 -07:00
Colton Sellers
f031f6a1c0 Rework of indicator 2020-07-28 14:34:07 -07:00
Colton Sellers
c171431e3f Got a test file for Schaffs Trend Cycle 2020-07-28 14:34:07 -07:00
Colton Sellers
c611e65f1e Addition of SchaffTrendCycle +Tests 2020-07-28 14:34:07 -07:00
Martin-Molinero
2a82cd87f5 Merge pull request #4562 from StefanoRaggi/ibgateway-v978-upgrade-lean-foundation
Upgrade IBGateway from v974.4g to v978.2c
2020-07-28 11:47:54 -03:00
Jared
48db57d224 Merge pull request #4537 from C-SELLERS/bug-4524-Update-API-Node-Endpoints
Add Node API Functions
2020-07-28 07:30:12 -07:00
Michael Sena
c7f0f6f769 Move the margin files for SGX and HKFE into the correct folder 2020-07-28 15:15:29 +10:00
Colton Sellers
dc82c15c18 Address review 2020-07-27 14:11:40 -07:00
Martin-Molinero
7133e62745 Merge pull request #4541 from JonathanWheeler/bug-4540-heikinashi-indicator-fix-for-symbol-and-volume
Heikin-Ashi Indicator Fix for Volume Information
2020-07-25 16:22:11 -03:00
Jonathan Wheeler
0cd0a77034 Remove Symbol and CurrentBar from Heikin-Ashi Indicator
...in order to make the indicator more consistent with others.
2020-07-24 12:20:26 -04:00
Jonathan Wheeler
8903942e3d Merge branch 'master' of https://github.com/QuantConnect/Lean into bug-4540-heikinashi-indicator-fix-for-symbol-and-volume 2020-07-24 12:05:13 -04:00
Jonathan Wheeler
460bf9301d Remove Comment 2020-07-24 12:05:04 -04:00
Jared
815d4bf0a1 Merge pull request #4579 from QuantConnect/bug-cpu-usage
Fix Mono reporting double CPU usage
2020-07-16 07:56:07 -07:00
Martin Molinero
5faf7a0b55 Fix Mono reporting double CPU usage 2020-07-16 11:40:32 -03:00
Martin-Molinero
8b91283fff Merge pull request #4564 from QuantConnect/ib-null-currency-fix
Add null currency check in IB CreateHolding
2020-07-15 10:30:35 -03:00
Colton Sellers
935db4ed3e Address new pricing structure when deserializing node objects 2020-07-10 14:04:41 -07:00
Colton Sellers
5188d0cb7f Documentation update 2020-07-10 12:28:38 -07:00
Jared
d1624ab899 Merge pull request #4560 from QuantConnect/bug-4547-pandas-data-list-index
Adds Support to List of Symbol and String (Ticker)
2020-07-08 17:29:40 -07:00
Jared
3efb39e313 Increase the load time of the algorithm slightly.
Reduce the probability of timeouts loading the algorithm.
2020-07-08 16:55:51 -07:00
Jared
6c09a17d13 Merge pull request #4566 from shilewenuw/patch-1
meged->merged in contributing.md
2020-07-08 14:52:48 -07:00
Colton Sellers
df7bc89d9b Address review 2020-07-08 14:37:58 -07:00
Shile Wen
3c6d3e7d88 meged->merged in contributing.md 2020-07-08 14:37:50 -07:00
Jared
0f8e4122cd Merge pull request #4539 from QuantConnect/ib-brokerage-updates-2
IB Brokerage Updates
2020-07-08 14:20:26 -07:00
Jared
117825ba55 Merge pull request #4565 from QuantConnect/bug-add-null-check
Bug add null checks
2020-07-08 11:08:23 -07:00
Martin Molinero
bab635856d Create empty result packet for live trading 2020-07-08 11:47:28 -03:00
Martin Molinero
aa0dfc7b3b Create empty result packet for failed inits
- Backtesting will create an empty packet for failed inits
2020-07-08 11:03:04 -03:00
Martin Molinero
e217caef47 Adding null checks for failed initializations
- Adding null checks to handle failed algorithm initializations
2020-07-08 10:18:43 -03:00
Stefano Raggi
2ff1b7d12f Add null currency check in CreateHolding 2020-07-07 18:49:56 +02:00
Stefano Raggi
be7730c186 Upgrade IBGateway from v974.4g to v978.2c 2020-07-06 15:13:59 +02:00
Alexandre Catarino
75a5f267f1 Adds Support to List of Symbol and String (Ticker)
Adds case in the mapper method to handled list type.
2020-07-04 00:11:19 +01:00
Stefano Raggi
76e16c1163 Restart and reconnect when IBGateway closed
- This is required with IBGateway v978 because of the daily/weekly automatic logoff
2020-07-02 16:24:20 +02:00
Stefano Raggi
709b6f53dc Update IBAutomater to v1.0.26
- https://github.com/QuantConnect/IBAutomater/pull/18
2020-07-01 15:35:56 +02:00
Stefano Raggi
b897f12e66 Minor log message fixes 2020-07-01 15:35:56 +02:00
Stefano Raggi
1af01b8b26 Restore BrokerageMessageEvent.Reconnected 2020-07-01 15:35:56 +02:00
Stefano Raggi
3b92a1c6e6 Remove IBGateway restart handling 2020-07-01 15:35:56 +02:00
Stefano Raggi
50b7f434bb Add connection checks in PlaceOrder/UpdateOrder/CancelOrder 2020-07-01 15:35:56 +02:00
Stefano Raggi
bb147042df Update IBAutomater to v1.0.25
- https://github.com/QuantConnect/IBAutomater/pull/18
2020-07-01 15:35:56 +02:00
Martin-Molinero
23c3d48e8a Merge pull request #4551 from StefanoRaggi/bug-4550-alpaca-rejected-order-event
Add handler for Alpaca rejected order events
2020-06-30 15:47:13 -03:00
Stefano Raggi
495cf7171f Add handler for Alpaca TradeEvent.Expired 2020-06-30 20:27:00 +02:00
Martin-Molinero
c6157a79ac Merge pull request #4543 from C-SELLERS/bug-4434-Update-FXCM-Error-Message
Bug 4434 update fxcm error message
2020-06-30 12:13:17 -03:00
Stefano Raggi
af59e57f66 Add handler for Alpaca rejected order events 2020-06-30 17:09:30 +02:00
Martin-Molinero
290342e910 Merge pull request #4549 from Adalyat/feature-4108-more-bollinger-indicators
Add BandWidth and %B to Bollinger Bands indicator
2020-06-30 11:48:23 -03:00
Adalyat Nazirov
5f7b58bc09 More Bollinger Indicators 2020-06-30 11:02:59 +03:00
Martin-Molinero
44a82b82cf Merge pull request #4521 from AnandVishnu/feature-add-sgx-hkfe-exchange-contracts
Add future contracts for NK, IN, TW and HSI
2020-06-29 18:42:53 -03:00
Anand Vishnu
ec6abfacc8 Add future contracts for NK, IN, TW and HSI 2020-06-29 17:35:40 +01:00
Martin-Molinero
5131b948dd Merge pull request #4542 from C-SELLERS/test-4044-extended-market-regression-algorithm
Test 4044 extended market regression algorithm
2020-06-26 17:16:43 -03:00
Colton Sellers
3ae3244318 Update contact info to disable hedging 2020-06-26 12:19:52 -07:00
Colton Sellers
d9902231db Update API access error message and include new email template 2020-06-26 12:19:35 -07:00
Colton Sellers
cf888028af Address review 2020-06-26 09:45:33 -07:00
Jonathan Wheeler
be5ab2c0f4 Remove Commented Alternative Method For Calling Volume Getter 2020-06-26 12:34:48 -04:00
Jonathan Wheeler
d80dc2b49b Heikin-Ashi Indicator Fix for Symbol and Volume Information 2020-06-26 12:24:04 -04:00
Colton Sellers
828b2424c6 Simplification of the time constraints 2020-06-25 17:43:13 -07:00
Colton Sellers
7058254cc7 Addition of ExtendedMarketTradingRegressionAlgorithm in Python 2020-06-25 17:27:30 -07:00
Colton Sellers
086432c3c6 Creation of Extended Market Trading Regression Algorithm 2020-06-25 16:38:23 -07:00
Jared
9cfeb36d4f Update readme.md 2020-06-25 16:13:48 -07:00
Colton Sellers
a72e3f0598 Add new regression trading algorithm 2020-06-25 15:26:30 -07:00
Martin-Molinero
a4a504ce6b Merge pull request #4538 from Martin-Molinero/bug-2923-custom-data-market
Fix custom data market hours db
2020-06-25 15:29:22 -03:00
Colton Sellers
676f335ee8 Update to CRUD test, asserts update and delete through verification 2020-06-25 11:07:16 -07:00
Martin Molinero
74485c32ba Fix custom data market hours db
- Fix adding custom data from market other than USA. Adding unit test
2020-06-25 10:57:53 -03:00
Colton Sellers
4f393e8dbf Small coding standards fixes 2020-06-24 21:02:11 -07:00
Colton Sellers
831e1c0b78 Address reviews v2 2020-06-24 18:02:13 -07:00
Colton Sellers
053925829c Address review 2020-06-24 17:44:15 -07:00
Colton Sellers
4263afab9f Removed all unnecessary new lines 2020-06-24 17:06:21 -07:00
Colton Sellers
341067986c added Node api tests 2020-06-24 16:00:15 -07:00
Colton Sellers
da89f6f3d1 RAM can be decimal, GetSKU is static for direct method calls, & commented out bug on CreateNode response wrapper. 2020-06-24 15:53:20 -07:00
Colton Sellers
d0fdae71b4 addition of stopNode & new return type for createNode 2020-06-24 15:52:45 -07:00
Colton Sellers
c548bd7085 Creation of NodeTests.cs, also added Sku tests, ReadAndStop test 2020-06-24 15:51:53 -07:00
C-SELLERS
efb2667285 Move all Node related tests to NodeTests.cs 2020-06-24 14:45:38 -07:00
Martin-Molinero
c3062e4c0e Merge pull request #4479 from QuantConnect/update-margins
Update futures margins
2020-06-24 18:00:16 -03:00
C-SELLERS
b28ed7c9f2 Add GetSKU helper and CreatedNode response wrapper 2020-06-24 12:22:57 -07:00
Martin-Molinero
a29bdc7f0a Merge pull request #4535 from QuantConnect/bug-4534-store-order-events-path-fix
Fix path bug in StoreOrderEvents
2020-06-24 13:41:14 -03:00
Jared
8924d203e5 Merge pull request #4536 from QuantConnect/bug-coinapi-process-only-spot
CoinAPI converter will only process SPOT files.
2020-06-24 08:54:31 -07:00
JJD
d7bb8a2018 CoinAPI converter will only process SPOT files. 2020-06-24 12:17:43 -03:00
Stefano Raggi
bf3f71ca6c Fix path bug in StoreOrderEvents 2020-06-24 16:01:14 +02:00
Colton Sellers
917db3c89a Tweaking of CRUD test 2020-06-23 17:34:04 -07:00
Colton Sellers
b7ba768371 Addition of API Node classes 2020-06-23 16:55:18 -07:00
Colton Sellers
a9a37c1647 Node & NodeList classes for API response 2020-06-23 16:53:48 -07:00
Colton Sellers
172f086d07 Using new NodeList for NodeRead 2020-06-23 16:50:27 -07:00
Martin-Molinero
353961a088 Merge pull request #4531 from QuantConnect/bug-4522-previous-quote-close-should-equal-current-open-bar
Previous QuoteBar Close is not equal to Current QuoteBar Open
2020-06-23 19:45:00 -03:00
C-SELLERS
0249f51a89 Add CRUD Tests for Node endpoint and TestOrg variable 2020-06-23 12:14:03 -07:00
C-SELLERS
62aac8e516 Addition of Node endpoint functions for CRUD 2020-06-23 12:13:29 -07:00
Martin Molinero
c18b1af5ce Address reviews
- Add new comment expanding on the QuoteBar ask and bid fill forward behavior for new bars, which are not a fill forward bar.
2020-06-23 14:50:23 -03:00
Martin Molinero
febc4b50ea Fix QuoteBarConsolidator
- TickQuoteBarConsolidator will use previous bar. Updating unit tests
- QuoteBarConsolidator open ask and bid will match previous bar close
  bid and ask. Adding unit tests
2020-06-23 14:42:56 -03:00
Anand Vishnu
79a05ebd27 Quote bar previous close and current open should be same 2020-06-23 14:42:56 -03:00
Martin-Molinero
98cde3479a Merge pull request #4518 from QuantConnect/bitfinex-brokerage-updates
Bitfinex Brokerage Updates
2020-06-23 11:02:00 -03:00
Stefano Raggi
36c59d41bc Address review 2020-06-23 15:33:17 +02:00
Martin-Molinero
768764030e Merge pull request #4533 from michael-sena/bug-4532-prevent-nullpointerexception-in-livetradingrealtimehandler
Fix LiveTradingRealTimeHandler pack-up creating the potential for a N…
2020-06-23 10:28:06 -03:00
Michael Sena
dbf3248f53 Fix LiveTradingRealTimeHandler pack-up creating the potential for a NullReferenceException 2020-06-23 12:58:58 +10:00
Martin-Molinero
615bdff3dd Merge pull request #4530 from C-SELLERS/bug-update-out-of-date-documentation
Update out of date documentation
2020-06-22 22:18:39 -03:00
C-SELLERS
e6ea8525f6 add . for niceness 2020-06-22 18:00:27 -07:00
C-SELLERS
87095577e3 Place Python setup at top of doc 2020-06-22 17:58:35 -07:00
C-SELLERS
06e165fd3b Typo Fixed 2020-06-22 17:19:49 -07:00
C-SELLERS
cc20f8be66 More formatting for appearance 2020-06-22 16:03:57 -07:00
C-SELLERS
71ab27384b Format 2020-06-22 16:02:35 -07:00
C-SELLERS
b117090ba7 Formatting fixes 2020-06-22 16:01:08 -07:00
C-SELLERS
65a4bb6a83 Started a readme for Tests directory 2020-06-22 15:58:44 -07:00
C-SELLERS
e9d69eba74 Update Pandas version for Python Algorithms 2020-06-22 15:16:16 -07:00
Gerardo Salazar
8d0d27253a Address review: Cleans up percentage margins and adds missing margins 2020-06-18 10:20:15 -07:00
Martin-Molinero
17b03a7d28 Merge pull request #4519 from jmerle/bug-unclosed-summary
Fix unclosed summary tag
2020-06-17 16:24:05 -03:00
Jasper van Merle
2d022fadff Fix unclosed summary tag 2020-06-17 20:27:40 +02:00
Martin-Molinero
2a1da92dc5 Merge pull request #4517 from hsm207/bug-typo-readme
Fix typo in readme.md
2020-06-17 09:51:43 -03:00
Stefano Raggi
3737049dde Update Bitfinex symbol list 2020-06-17 14:03:58 +02:00
Stefano Raggi
4c7cbd42ca Update rate limit for new websocket connections 2020-06-17 14:03:58 +02:00
Stefano Raggi
b606c3dbaa Replace WebSocketSharp with System.Net.WebSockets in BitfinexBrokerage 2020-06-17 14:03:57 +02:00
hsm207
5aa5b33594 Fix typo in readme.md 2020-06-16 16:09:48 +00:00
Martin-Molinero
3ed1815c94 Merge pull request #4513 from QuantConnect/feature-coarse-universe-selection-adding-tiingo-news
Coarse TiingoNews universe selection algorithm
2020-06-16 11:49:17 -03:00
Martin Molinero
39e56ea7c0 Address reviews
- Removing the need to call MHDB.SetEntry, this will be handled by the
  data manager
2020-06-15 20:05:12 -03:00
Martin Molinero
b575880739 Coarse tiingo new universe selection algorithm
- Adding an example algorithm of a custom universe selection using
  coarse data and adding tiingo news. If conditions are met will add the
  underlying and trade it
- Adding required UniversePythonWrapper
2020-06-15 20:05:08 -03:00
Gerardo Salazar
3baf8c3959 Address review: Removes changing percentage margins
* Only the first margin of a percentage margin will be
    used from now onwards
2020-06-15 16:00:38 -07:00
Martin-Molinero
5455c34a9b Merge pull request #4516 from Martin-Molinero/bug-4511-fix-docker-ignore
Fix for dockerignore
2020-06-15 18:33:28 -03:00
Martin Molinero
1defd2d4ac Fix for dockerignore 2020-06-15 18:18:37 -03:00
Martin-Molinero
47a4f875ff Merge pull request #4506 from QuantConnect/feature-data-permission-manager
Adding new DataPermissionManager
2020-06-15 15:08:18 -03:00
Martin-Molinero
2865824194 Merge pull request #4512 from AlexCatarino/bug-minimumpricevariation-decimal-parse
Fixes Decimal Parse of MinimumPriceVariation
2020-06-15 14:09:22 -03:00
Alexandre Catarino
c4dfa588ba Fixes Unit Tests 2020-06-15 16:12:07 +01:00
Alexandre Catarino
2ca4ba694e Fixes Decimal Parse of MinimumPriceVariation
`MinimumPriceVariation` values in `SymbolPropertiesDatabase` can be represented as a exponent number. `ToDecimal` method fails to parse it correctly. A new method, `ToDecimalAllowExponent` is used instead.
2020-06-13 01:38:31 +01:00
Martin Molinero
bcc67d2457 DataPermissionManager is used by history provider
- DataPermissionManager will be used by the history provider
- Moving interfaces from Engine to Common
2020-06-12 12:51:14 -03:00
Martin Molinero
0672d2082d Add resolution deserialization unit test 2020-06-12 12:34:10 -03:00
Martin Molinero
452bf27bd9 Adding new DataPermissionManager
- Adding new DataPermissionManager that will own the existing
  datachannelProvider. Will assert configurations before added to the
  data feed. Adding unit tests
2020-06-12 12:34:10 -03:00
Martin-Molinero
164035a4d4 Merge pull request #4508 from hsm207/bug-typo-leanfoundation
Fix typo
2020-06-12 12:07:16 -03:00
hsm207
8acd8d3eac Undo newline 2020-06-12 15:40:23 +08:00
hsm207
4522602ec9 Fix typo 2020-06-12 15:12:05 +08:00
Jared
94678d5810 Merge pull request #4504 from QuantConnect/feature-4366-add-security-by-symbol
Adds Overload to AddSecurity with Symbol Parameter
2020-06-11 13:23:17 -07:00
Jared
90240704c1 Merge pull request #4503 from QuantConnect/bug-fix-jupyterhub-dockerfile
Fix for research dockerfile
2020-06-11 13:21:54 -07:00
Martin-Molinero
23bdbf6706 Merge pull request #4497 from QuantConnect/bug-4435-tick-resolution-history-request-api
Fix Resolution.Tick TradeBar history request
2020-06-10 20:37:05 -03:00
AlexCatarino
dfc55e9380 Adds Overload to AddSecurity with Symbol Parameter 2020-06-11 00:20:38 +01:00
Martin Molinero
3d6f45a1dc Empty commit 2020-06-10 20:17:57 -03:00
Martin Molinero
f826ea016a Address reviews
- Build docker research image from a lean tag. C# and Py kernels working
2020-06-10 20:06:03 -03:00
Martin Molinero
2d0a046c1e Reviews: Add unit test and improve exception message 2020-06-10 19:20:21 -03:00
Martin Molinero
a8524f6179 Fix for research dockerfile
- Do not delete PythonNet.dll used by C# kernels
- Do not delete linux clr.so
- Adding docker to readmes
2020-06-10 18:30:23 -03:00
Martin-Molinero
9931940de8 Merge pull request #4496 from QuantConnect/bug-4446-delisted-future-liquidate-on-expiry
Fix Delisted.Warning event time
2020-06-10 15:07:20 -03:00
Martin-Molinero
6735c2baf4 Merge pull request #4498 from QuantConnect/feature-storage-write-permissions
Add permission control for Storage
2020-06-09 21:21:19 -03:00
Martin Molinero
35f849254e Improvements
- Replace bitwise And operation for .HasFlag call
- Minor change in object store permission error message
2020-06-09 20:55:21 -03:00
Jared
ac07e0a301 Merge pull request #4500 from QuantConnect/bug-fix-progress-report
Fix backtesting progress int division
2020-06-09 16:47:34 -07:00
Martin Molinero
7d99b9de6c Fix backtesting progress int division 2020-06-09 20:45:07 -03:00
Martin Molinero
170d12859f Address reviews
- Reduce code duplication. Handle some missing History<TradeBar> for Tick
  resolution.
2020-06-09 19:49:36 -03:00
Martin Molinero
7a7ad8e7e7 Address review: improve error messaging 2020-06-09 19:29:59 -03:00
Martin Molinero
e782ffa4c6 Reuse existing FileAccess permissions 2020-06-09 18:13:12 -03:00
Martin Molinero
5bd11ebd9d Add permission control for Storage
- Adding `Controls.StoragePermissions` to govern permissions for storing into
  the object store. Adding unit tests
2020-06-09 17:24:00 -03:00
Gerardo Salazar
89015db955 Address self-review: Fixes FuturesMarginBuyingPowerModelTests 2020-06-09 09:37:15 -07:00
Gerardo Salazar
81f2c43d0a Updates margins using new contract selection strategy
* Fixes previously incorrect margins
2020-06-08 17:55:12 -07:00
Martin Molinero
a3c5fd9871 Fix Resolution.Tick TradeBar history request
- Throw exception if requesting Resolution.Tick using the TradeBar
  history request API
- Adding unit tests, asserting current behavior
2020-06-08 21:46:13 -03:00
Martin Molinero
03e10101cc Fix Delisted.Warning event time
- Fix Delisted.Warning event time, some futures add hours to their
  expiration date. Adding regression algorithm
2020-06-08 20:01:12 -03:00
Jared
d812dd43ae Merge pull request #4495 from QuantConnect/feature-store-sys-logs
FactorFileRow.Parse should not be public
2020-06-08 13:15:42 -07:00
Martin Molinero
69194bfbe9 Minor improvements
- Makeing FactorFileRow.Parse private to avoid wrong usages
- Avoid end of stream check while unzipping
2020-06-08 14:33:52 -03:00
Martin-Molinero
370685447d Merge pull request #4486 from AlexCatarino/feature-add-ema-cross-front-contract-algorithm
Adds EmaCrossFuturesFrontMonthAlgorithm
2020-06-05 19:10:23 -03:00
Martin-Molinero
dadaf9bf68 Merge pull request #4485 from QuantConnect/bug-4480-fix-runtime-errors-during-ib-reset-times
Update IBAutomater to v1.0.23
2020-06-05 18:55:01 -03:00
Stefano Raggi
05bc28d2fd Revert "Add server reset time checks in PlaceOrder/UpdateOrder/CancelOrder"
This reverts commit d1963fe32e.
2020-06-05 23:44:34 +02:00
Martin-Molinero
2e1a5925fd Update EmaCrossFuturesFrontMonthAlgorithm.py 2020-06-05 10:55:39 -03:00
Jared
d28b6c9ea7 Update EmaCrossFuturesFrontMonthAlgorithm.cs 2020-06-04 18:04:43 -07:00
AlexCatarino
7f1e764211 Addresses Peer-Review
- Adds comment explaining `OnlyApplyFilterAtMarketOpen` usage;
- Fix custom plot bug.
- Use `WarmUpIndicator`.
2020-06-05 01:39:35 +01:00
Martin-Molinero
ba2feb02b7 Merge pull request #4477 from QuantConnect/refactor-remove-deprecated-projects
Refactor remove deprecated projects
2020-06-04 19:40:43 -03:00
Stefano Raggi
d1963fe32e Add server reset time checks in PlaceOrder/UpdateOrder/CancelOrder 2020-06-04 11:42:20 +02:00
Gerardo Salazar
b638c450cb Removes bad margin files and fixes unit tests 2020-06-03 16:48:18 -07:00
AlexCatarino
f008e90202 Adds EmaCrossFuturesFrontMonthAlgorithm
This example shows how to create an EMA cross algorithm for a futures' front contract. Once the contract is added, the indicators are registered to a new consolidator and warmed up with historical data. When a contract is removed, the consolidator is removed and the indicators are reseted. We don't need to liquidate it, because it's liquidated automatically since it has expired.
2020-06-04 00:21:49 +01:00
Gerardo Salazar
b0f787abd8 Address review - removes duplicates in margins and skip non-USD margins 2020-06-03 15:20:43 -07:00
Stefano Raggi
c01352468e Update IBAutomater to v1.0.23
- moved IB reset times handling from IB brokerage to IBAutomater
2020-06-03 22:53:39 +02:00
JJD
a3356904b0 Update futures margins 2020-06-02 17:39:12 -03:00
Martin Molinero
7fc21e52dd Add QC.Common as dependency for nuget QC.Launcher 2020-06-02 13:56:59 -03:00
Martin Molinero
8d1a8d767b Remove depreceted projects
- Remove Java and VisualStudioPlugin deprecated projects
- Removing VS 15 solution file
- Nuget .nuspec fixes
2020-06-01 21:27:45 -03:00
1870 changed files with 104244 additions and 50722 deletions

View File

@@ -1,4 +1,6 @@
*/packages/*
*/.git/*
*/.vs/*
*/.nuget/*
packages/*
.git/*
.github/*
.vs/*
.nuget/*
Tests/*

31
.github/workflows/gh-actions.yml vendored Normal file
View File

@@ -0,0 +1,31 @@
name: Build & Test Lean
on:
push:
branches: ['*']
pull_request:
branches: [master]
jobs:
build:
runs-on: ubuntu-16.04
container:
image: quantconnect/lean:foundation
steps:
- uses: actions/checkout@v2
- name: Restore nuget dependencies
run: |
nuget restore QuantConnect.Lean.sln -v quiet
nuget install NUnit.Runners -Version 3.11.1 -OutputDirectory testrunner
- name: Build
run: msbuild /p:Configuration=Release /p:VbcToolExe=vbnc.exe /v:quiet /p:WarningLevel=1 QuantConnect.Lean.sln
- name: Run Tests
run: 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
- name: Generate & Publish python stubs
run: |
chmod +x ci_build_stubs.sh
./ci_build_stubs.sh -d -t -g #Ignore Publish as of since credentials are missing on CI

10
.gitignore vendored
View File

@@ -34,8 +34,9 @@
# QC Cloud Setup Bash Files
*.sh
# Include docker build scripts for Mac/Linux
# Include docker launch scripts for Mac/Linux
!run_docker.sh
!research/run_docker_notebook.sh
# QC Config Files:
# config.json
@@ -143,6 +144,7 @@ $tf/
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings
*.DotSettings.user
# JustCode is a .NET coding addin-in
@@ -267,3 +269,9 @@ Launcher/Plugins/*
/ApiPython/quantconnect.egg-info/*
QuantConnect.Lean.sln.DotSettings*
#User notebook files
Research/Notebooks
#Docker result files
Results/

144
.idea/readme.md generated Normal file
View File

@@ -0,0 +1,144 @@
<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 Normal file
View File

@@ -0,0 +1,37 @@
<?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>

View File

@@ -1,11 +1,12 @@
sudo: required
language: csharp
dotnet: 5.0
mono:
- 5.12.0
solution: QuantConnect.Lean.sln
before_install:
- export PATH="$HOME/miniconda3/bin:$PATH"
- wget https://cdn.quantconnect.com/miniconda/Miniconda3-4.5.12-Linux-x86_64.sh
- 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
- sudo ln -s $HOME/miniconda3/lib/libpython3.6m.so /usr/lib/libpython3.6m.so
@@ -17,8 +18,9 @@ before_install:
- conda install -y scipy=1.4.1
- conda install -y wrapt=1.12.1
install:
- nuget restore QuantConnect.Lean.sln
- nuget install NUnit.Runners -Version 3.11.1 -OutputDirectory testrunner
script:
- msbuild /p:Configuration=Release /p:VbcToolExe=vbnc.exe 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
- dotnet build /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

136
.vs/readme.md Normal file
View File

@@ -0,0 +1,136 @@
<h1>Local Development & Docker Integration with Visual Studio</h1>
This document contains information regarding ways to use Visual Studio to work with the Lean's Docker image.
<br />
<h1>Getting Setup</h1>
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
<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 for the following languages:
<h3>Python:</h3>
"algorithm-type-name": "**AlgorithmName**",
"algorithm-language": "Python",
"algorithm-location": "../../../Algorithm.Python/**AlgorithmName**.py",
<h3>C#:</h3>
"algorithm-type-name": "**AlgorithmName**",
"algorithm-language": "CSharp",
"algorithm-location": "QuantConnect.Algorithm.CSharp.dll",
<br />
<h2>Important Note About C#</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.
<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.

82
.vscode/launch.json vendored Normal file
View File

@@ -0,0 +1,82 @@
{
/*
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.
*/
"version": "0.2.0",
"configurations": [
{
"name": "Launch w/ Mono (Local)",
"type": "mono",
"request": "launch",
"preLaunchTask": "build",
"cwd": "${workspaceFolder}/Launcher/bin/Debug/",
"program": "${workspaceFolder}/Launcher/bin/Debug/QuantConnect.Lean.Launcher.exe",
"args": [
"--data-folder",
"${workspaceFolder}/Data",
"--config",
"${workspaceFolder}/Launcher/config.json"],
"console": "externalTerminal"
},
{
"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)",
"type": "python",
"request": "attach",
"port": 5678,
"pathMappings":[{
"localRoot": "${workspaceFolder}",
"remoteRoot": "${workspaceFolder}"
}]
}
]
}

206
.vscode/readme.md vendored Normal file
View File

@@ -0,0 +1,206 @@
<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 using Leans Docker image in conjunction with local development as well as running Lean locally.
<br />
<h1>Getting Setup</h1>
Before anything we need to ensure a few things have been done:
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
2. Get [Docker](https://docs.docker.com/get-docker/):
* Follow the instructions for your Operating System
* New to Docker? Try docker getting-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_
4. Pull Leans latest image from a terminal
* _docker pull quantconnect/lean_
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
**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 />
<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.
Your configuration file should look something like this for the following languages:
<h3>Python:</h3>
"algorithm-type-name": "**AlgorithmName**",
"algorithm-language": "Python",
"algorithm-location": "../../../Algorithm.Python/**AlgorithmName**.py",
<h3>C#:</h3>
"algorithm-type-name": "**AlgorithmName**",
"algorithm-language": "CSharp",
"algorithm-location": "QuantConnect.Algorithm.CSharp.dll",
<h3>Important Note About C#</h3>
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”._
Python **does not** have this requirement as the engine will compile it on the fly.
<br />
<h2>Running Lean in the Container</h2>
This section will cover how to actually launch Lean in the container with your desired configuration.
<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.
<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>
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",
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>
Now that Lean is configured for the python debugger we can make use of the programmed launch options to connect.
<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.
<br />
_Figure 2: Python Debugger Messages_
```
20200715 17:12:06.546 Trace:: PythonInitializer.Initialize(): ended
20200715 17:12:06.547 Trace:: DebuggerHelper.Initialize(): python initialization done
20200715 17:12:06.547 Trace:: DebuggerHelper.Initialize(): starting...
20200715 17:12:06.548 Trace:: DebuggerHelper.Initialize(): waiting for debugger to attach at localhost:5678...
```
<br />
<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.

139
.vscode/tasks.json vendored Normal file
View File

@@ -0,0 +1,139 @@
{
/*
VS Code Tasks for the LEAN engine
In order to use the build tasks you need msbuild on your system path.
*/
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "msbuild",
"args": [
"/p:Configuration=Debug",
"/p:DebugType=portable",
"/t:build",
],
"group": "build",
"presentation": {
"reveal": "silent"
},
"problemMatcher": "$msCompile"
},
{
"label": "rebuild",
"type": "shell",
"command": "msbuild",
"args": [
"/p:Configuration=Debug",
"/p:DebugType=portable",
"/t:rebuild",
],
"group": "build",
"presentation": {
"reveal": "silent"
},
"problemMatcher": "$msCompile"
},
{
"label": "clean",
"type": "shell",
"command": "msbuild",
"args": [
"/t:clean",
],
"group": "build",
"presentation": {
"reveal": "silent"
},
"problemMatcher": "$msCompile"
},
{
"label": "force build linux",
"type": "shell",
"command": "msbuild",
"args": [
"/property:GenerateFullPaths=true",
"/p:Configuration=Debug",
"/p:DebugType=portable",
"/t:build",
"/p:ForceLinuxBuild=true"
],
"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",
"args" : [
"--data-folder",
"${workspaceFolder}/Data",
"--config",
"${workspaceFolder}/Launcher/config.json"
],
"options": {
"cwd": "${workspaceFolder}/Launcher/bin/Debug/"
}
}
]
}

View File

@@ -94,6 +94,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Tracking Error", "0.212"},
{"Treynor Ratio", "-2.13"},
{"Total Fees", "$199.00"},
{"Estimated Strategy Capacity", "$280000000.00"},
{"Fitness Score", "0.002"},
{"Kelly Criterion Estimate", "38.64"},
{"Kelly Criterion Probability Value", "0.229"},
@@ -113,7 +114,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Mean Population Magnitude", "54.5455%"},
{"Rolling Averaged Population Direction", "59.8056%"},
{"Rolling Averaged Population Magnitude", "59.8056%"},
{"OrderListHash", "1256341962"}
{"OrderListHash", "0a28eedf6304023f5002ef672b489b88"}
};
}
}

View File

@@ -130,6 +130,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Tracking Error", "0.367"},
{"Treynor Ratio", "-4.079"},
{"Total Fees", "$14.33"},
{"Estimated Strategy Capacity", "$29000000.00"},
{"Fitness Score", "0.408"},
{"Kelly Criterion Estimate", "16.447"},
{"Kelly Criterion Probability Value", "0.315"},
@@ -149,7 +150,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "100%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "-887015098"}
{"OrderListHash", "506e9fe18984ba6e569b2e327030de3a"}
};
}
}

View File

@@ -0,0 +1,211 @@
/*
* 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.Market;
using QuantConnect.Interfaces;
using QuantConnect.Securities;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// This regression algorithm tests that we receive the expected data when
/// we add future option contracts individually using <see cref="AddFutureOptionContract"/>
/// </summary>
public class AddFutureOptionContractDataStreamingRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
{
private bool _onDataReached;
private bool _invested;
private Symbol _es20h20;
private Symbol _es19m20;
private readonly HashSet<Symbol> _symbolsReceived = new HashSet<Symbol>();
private readonly HashSet<Symbol> _expectedSymbolsReceived = new HashSet<Symbol>();
private readonly Dictionary<Symbol, List<QuoteBar>> _dataReceived = new Dictionary<Symbol, List<QuoteBar>>();
public override void Initialize()
{
SetStartDate(2020, 1, 5);
SetEndDate(2020, 1, 6);
_es20h20 = AddFutureContract(
QuantConnect.Symbol.CreateFuture(Futures.Indices.SP500EMini, Market.CME, new DateTime(2020, 3, 20)),
Resolution.Minute).Symbol;
_es19m20 = AddFutureContract(
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));
foreach (var optionContract in optionChains)
{
_expectedSymbolsReceived.Add(AddFutureOptionContract(optionContract, Resolution.Minute).Symbol);
}
if (_expectedSymbolsReceived.Count == 0)
{
throw new InvalidOperationException("Expected Symbols receive count is 0, expected >0");
}
}
public override void OnData(Slice data)
{
if (!data.HasData)
{
return;
}
_onDataReached = true;
var hasOptionQuoteBars = false;
foreach (var qb in data.QuoteBars.Values)
{
if (qb.Symbol.SecurityType != SecurityType.FutureOption)
{
continue;
}
hasOptionQuoteBars = true;
_symbolsReceived.Add(qb.Symbol);
if (!_dataReceived.ContainsKey(qb.Symbol))
{
_dataReceived[qb.Symbol] = new List<QuoteBar>();
}
_dataReceived[qb.Symbol].Add(qb);
}
if (_invested || !hasOptionQuoteBars)
{
return;
}
if (data.ContainsKey(_es20h20) && data.ContainsKey(_es19m20))
{
SetHoldings(_es20h20, 0.2);
SetHoldings(_es19m20, 0.2);
_invested = true;
}
}
public override void OnEndOfAlgorithm()
{
base.OnEndOfAlgorithm();
if (!_onDataReached)
{
throw new Exception("OnData() was never called.");
}
if (_symbolsReceived.Count != _expectedSymbolsReceived.Count)
{
throw new AggregateException($"Expected {_expectedSymbolsReceived.Count} option contracts Symbols, found {_symbolsReceived.Count}");
}
var missingSymbols = new List<Symbol>();
foreach (var expectedSymbol in _expectedSymbolsReceived)
{
if (!_symbolsReceived.Contains(expectedSymbol))
{
missingSymbols.Add(expectedSymbol);
}
}
if (missingSymbols.Count > 0)
{
throw new Exception($"Symbols: \"{string.Join(", ", missingSymbols)}\" were not found in OnData");
}
foreach (var expectedSymbol in _expectedSymbolsReceived)
{
var data = _dataReceived[expectedSymbol];
var nonDupeDataCount = data.Select(x =>
{
x.EndTime = default(DateTime);
return x;
}).Distinct().Count();
if (nonDupeDataCount < 1000)
{
throw new Exception($"Received too few data points. Expected >=1000, found {nonDupeDataCount} for {expectedSymbol}");
}
}
}
/// <summary>
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
/// </summary>
public bool CanRunLocally { get; } = true;
/// <summary>
/// This is used by the regression test system to indicate which languages this algorithm is written in.
/// </summary>
public Language[] Languages { get; } = { Language.CSharp, Language.Python };
/// <summary>
/// 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"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "217.585%"},
{"Drawdown", "0.600%"},
{"Expectancy", "0"},
{"Net Profit", "0.635%"},
{"Sharpe 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", "-14.395"},
{"Tracking Error", "0.043"},
{"Treynor Ratio", "0"},
{"Total Fees", "$7.40"},
{"Estimated Strategy Capacity", "$28000000.00"},
{"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", "35738733ff791eeeaf508faec804cab0"}
};
}
}

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 System.Collections.Generic;
using System.Linq;
using QuantConnect.Data;
using QuantConnect.Data.Market;
using QuantConnect.Interfaces;
using QuantConnect.Securities;
using QuantConnect.Securities.Future;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// This regression algorithm tests that we only receive the option chain for a single future contract
/// in the option universe filter.
/// </summary>
public class AddFutureOptionSingleOptionChainSelectedInUniverseFilterRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
{
private bool _invested;
private bool _onDataReached;
private bool _optionFilterRan;
private readonly HashSet<Symbol> _symbolsReceived = new HashSet<Symbol>();
private readonly HashSet<Symbol> _expectedSymbolsReceived = new HashSet<Symbol>();
private readonly Dictionary<Symbol, List<QuoteBar>> _dataReceived = new Dictionary<Symbol, List<QuoteBar>>();
private Future _es;
public override void Initialize()
{
SetStartDate(2020, 1, 5);
SetEndDate(2020, 1, 6);
_es = AddFuture(Futures.Indices.SP500EMini, Resolution.Minute, Market.CME);
_es.SetFilter((futureFilter) =>
{
return futureFilter.Expiration(0, 365).ExpirationCycle(new[] { 3, 6 });
});
AddFutureOption(_es.Symbol, optionContracts =>
{
_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`
// 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();
if (expiry == null || symbol == null)
{
throw new InvalidOperationException("Expected a single Option contract in the chain, found 0 contracts");
}
var enumerator = optionContracts.GetEnumerator();
while (enumerator.MoveNext())
{
_expectedSymbolsReceived.Add(enumerator.Current);
}
return optionContracts;
});
}
public override void OnData(Slice data)
{
if (!data.HasData)
{
return;
}
_onDataReached = true;
var hasOptionQuoteBars = false;
foreach (var qb in data.QuoteBars.Values)
{
if (qb.Symbol.SecurityType != SecurityType.FutureOption)
{
continue;
}
hasOptionQuoteBars = true;
_symbolsReceived.Add(qb.Symbol);
if (!_dataReceived.ContainsKey(qb.Symbol))
{
_dataReceived[qb.Symbol] = new List<QuoteBar>();
}
_dataReceived[qb.Symbol].Add(qb);
}
if (_invested || !hasOptionQuoteBars)
{
return;
}
foreach (var chain in data.OptionChains.Values)
{
var futureInvested = false;
var optionInvested = false;
foreach (var option in chain.Contracts.Keys)
{
if (futureInvested && optionInvested)
{
return;
}
var future = option.Underlying;
if (!optionInvested && data.ContainsKey(option))
{
MarketOrder(option, 1);
_invested = true;
optionInvested = true;
}
if (!futureInvested && data.ContainsKey(future))
{
MarketOrder(future, 1);
_invested = true;
futureInvested = true;
}
}
}
}
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.");
}
if (_symbolsReceived.Count != _expectedSymbolsReceived.Count)
{
throw new AggregateException($"Expected {_expectedSymbolsReceived.Count} option contracts Symbols, found {_symbolsReceived.Count}");
}
var missingSymbols = new List<Symbol>();
foreach (var expectedSymbol in _expectedSymbolsReceived)
{
if (!_symbolsReceived.Contains(expectedSymbol))
{
missingSymbols.Add(expectedSymbol);
}
}
if (missingSymbols.Count > 0)
{
throw new Exception($"Symbols: \"{string.Join(", ", missingSymbols)}\" were not found in OnData");
}
foreach (var expectedSymbol in _expectedSymbolsReceived)
{
var data = _dataReceived[expectedSymbol];
var nonDupeDataCount = data.Select(x =>
{
x.EndTime = default(DateTime);
return x;
}).Distinct().Count();
if (nonDupeDataCount < 1000)
{
throw new Exception($"Received too few data points. Expected >=1000, found {nonDupeDataCount} for {expectedSymbol}");
}
}
}
/// <summary>
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
/// </summary>
public bool CanRunLocally { get; } = true;
/// <summary>
/// This is used by the regression test system to indicate which languages this algorithm is written in.
/// </summary>
public Language[] Languages { get; } = { Language.CSharp, Language.Python };
/// <summary>
/// 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"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "-15.625%"},
{"Drawdown", "0.200%"},
{"Expectancy", "0"},
{"Net Profit", "-0.093%"},
{"Sharpe Ratio", "-11.181"},
{"Probabilistic Sharpe Ratio", "0%"},
{"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"},
{"Estimated Strategy Capacity", "$12000.00"},
{"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", "9347e3b610cfa21f7cbd968a0135c8af"}
};
}
}

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>
/// We add an option contract using <see cref="QCAlgorithm.AddOptionContract"/> and place a trade and wait till it expires
/// later will liquidate the resulting equity position and assert both option and underlying get removed
/// </summary>
public class AddOptionContractExpiresRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
{
private DateTime _expiration = new DateTime(2014, 06, 21);
private Symbol _option;
private Symbol _twx;
private bool _traded;
public override void Initialize()
{
SetStartDate(2014, 06, 05);
SetEndDate(2014, 06, 30);
_twx = QuantConnect.Symbol.Create("TWX", SecurityType.Equity, Market.USA);
AddUniverse("my-daily-universe-name", time => new List<string> { "AAPL" });
}
public override void OnData(Slice data)
{
if (_option == null)
{
var option = OptionChainProvider.GetOptionContractList(_twx, Time)
.OrderBy(symbol => symbol.ID.Symbol)
.FirstOrDefault(optionContract => optionContract.ID.Date == _expiration
&& optionContract.ID.OptionRight == OptionRight.Call
&& optionContract.ID.OptionStyle == OptionStyle.American);
if (option != null)
{
_option = AddOptionContract(option).Symbol;
}
}
if (_option != null && Securities[_option].Price != 0 && !_traded)
{
_traded = true;
Buy(_option, 1);
foreach (var symbol in new [] { _option, _option.Underlying })
{
var config = SubscriptionManager.SubscriptionDataConfigService.GetSubscriptionDataConfigs(symbol).ToList();
if (!config.Any())
{
throw new Exception($"Was expecting configurations for {symbol}");
}
if (config.Any(dataConfig => dataConfig.DataNormalizationMode != DataNormalizationMode.Raw))
{
throw new Exception($"Was expecting DataNormalizationMode.Raw configurations for {symbol}");
}
}
}
if (Time.Date > _expiration)
{
if (SubscriptionManager.SubscriptionDataConfigService.GetSubscriptionDataConfigs(_option).Any())
{
throw new Exception($"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}");
}
// first we liquidate the option exercised position
Liquidate(_twx);
}
}
else if (Time.Date > _expiration && !Securities[_twx].Invested)
{
if (SubscriptionManager.SubscriptionDataConfigService.GetSubscriptionDataConfigs(_twx).Any())
{
throw new Exception($"Unexpected configurations for {_twx} after it has been liquidated");
}
}
}
/// <summary>
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
/// </summary>
public bool CanRunLocally { get; } = true;
/// <summary>
/// This is used by the regression test system to indicate which languages this algorithm is written in.
/// </summary>
public Language[] Languages { get; } = { Language.CSharp, Language.Python };
/// <summary>
/// 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"},
{"Average Win", "2.73%"},
{"Average Loss", "-2.98%"},
{"Compounding Annual Return", "-4.619%"},
{"Drawdown", "0.300%"},
{"Expectancy", "-0.042"},
{"Net Profit", "-0.332%"},
{"Sharpe Ratio", "-3.7"},
{"Probabilistic Sharpe Ratio", "0.563%"},
{"Loss Rate", "50%"},
{"Win Rate", "50%"},
{"Profit-Loss Ratio", "0.92"},
{"Alpha", "-0.021"},
{"Beta", "-0.01"},
{"Annual Standard Deviation", "0.006"},
{"Annual Variance", "0"},
{"Information Ratio", "-3.374"},
{"Tracking Error", "0.058"},
{"Treynor Ratio", "2.133"},
{"Total Fees", "$2.00"},
{"Estimated Strategy Capacity", "$6400000.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", "486118a60d78f74811fe8d927c2c6b43"}
};
}
}

View File

@@ -0,0 +1,217 @@
/*
* 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;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// We add an option contract using <see cref="QCAlgorithm.AddOptionContract"/> and place a trade, the underlying
/// gets deselected from the universe selection but should still be present since we manually added the option contract.
/// Later we call <see cref="QCAlgorithm.RemoveOptionContract"/> and expect both option and underlying to be removed.
/// </summary>
public class AddOptionContractFromUniverseRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
{
private DateTime _expiration = new DateTime(2014, 06, 21);
private SecurityChanges _securityChanges = SecurityChanges.None;
private Symbol _option;
private Symbol _aapl;
private Symbol _twx;
private bool _traded;
public override void Initialize()
{
_twx = QuantConnect.Symbol.Create("TWX", SecurityType.Equity, Market.USA);
_aapl = QuantConnect.Symbol.Create("AAPL", SecurityType.Equity, Market.USA);
UniverseSettings.Resolution = Resolution.Minute;
UniverseSettings.DataNormalizationMode = DataNormalizationMode.Raw;
SetStartDate(2014, 06, 05);
SetEndDate(2014, 06, 09);
AddUniverse(enumerable => new[] { Time.Date <= new DateTime(2014, 6, 5) ? _twx : _aapl },
enumerable => new[] { Time.Date <= new DateTime(2014, 6, 5) ? _twx : _aapl });
}
public override void OnData(Slice data)
{
if (_option != null && Securities[_option].Price != 0 && !_traded)
{
_traded = true;
Buy(_option, 1);
}
if (Time.Date > new DateTime(2014, 6, 5))
{
if (Time < new DateTime(2014, 6, 6, 14, 0, 0))
{
var configs = SubscriptionManager.SubscriptionDataConfigService.GetSubscriptionDataConfigs(_twx);
// 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}" +
$" even after it has been deselected from coarse universe because we still have the option contract.");
}
}
else if (Time == new DateTime(2014, 6, 6, 14, 0, 0))
{
// liquidate & remove the option
RemoveOptionContract(_option);
}
// assert underlying was finally removed
else if(Time > new DateTime(2014, 6, 6, 14, 0, 0))
{
foreach (var symbol in new[] { _option, _option.Underlying })
{
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.");
}
}
}
}
}
public override void OnSecuritiesChanged(SecurityChanges changes)
{
if (_securityChanges.RemovedSecurities.Intersect(changes.RemovedSecurities).Any())
{
throw new Exception($"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!");
}
// keep track of all removed and added securities
_securityChanges += changes;
if (changes.AddedSecurities.Any(security => security.Symbol.SecurityType == SecurityType.Option))
{
return;
}
foreach (var addedSecurity in changes.AddedSecurities)
{
var option = OptionChainProvider.GetOptionContractList(addedSecurity.Symbol, Time)
.OrderBy(symbol => symbol.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 })
{
var config = SubscriptionManager.SubscriptionDataConfigService.GetSubscriptionDataConfigs(symbol).ToList();
if (!config.Any())
{
throw new Exception($"Was expecting configurations for {symbol}");
}
if (config.Any(dataConfig => dataConfig.DataNormalizationMode != DataNormalizationMode.Raw))
{
throw new Exception($"Was expecting DataNormalizationMode.Raw configurations for {symbol}");
}
}
// just keep the first we got
if (_option == null)
{
_option = option;
}
}
}
public override void OnEndOfAlgorithm()
{
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");
}
if (SubscriptionManager.Subscriptions.All(dataConfig => dataConfig.Symbol != _aapl))
{
throw new Exception($"Was expecting configurations for {_aapl}");
}
if (SubscriptionManager.Subscriptions.All(dataConfig => dataConfig.Symbol.Underlying != _aapl))
{
throw new Exception($"Was expecting options configurations for {_aapl}");
}
}
/// <summary>
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
/// </summary>
public bool CanRunLocally { get; } = true;
/// <summary>
/// This is used by the regression test system to indicate which languages this algorithm is written in.
/// </summary>
public Language[] Languages { get; } = { Language.CSharp, Language.Python };
/// <summary>
/// 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"},
{"Average Win", "0%"},
{"Average Loss", "-0.23%"},
{"Compounding Annual Return", "-15.596%"},
{"Drawdown", "0.200%"},
{"Expectancy", "-1"},
{"Net Profit", "-0.232%"},
{"Sharpe Ratio", "-7.739"},
{"Probabilistic Sharpe Ratio", "1.216%"},
{"Loss Rate", "100%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "0.027"},
{"Beta", "-0.174"},
{"Annual Standard Deviation", "0.006"},
{"Annual Variance", "0"},
{"Information Ratio", "-11.586"},
{"Tracking Error", "0.042"},
{"Treynor Ratio", "0.286"},
{"Total Fees", "$2.00"},
{"Estimated Strategy Capacity", "$1400000.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", "ae0b430e9c728966e3736fb352a689c6"}
};
}
}

View File

@@ -230,6 +230,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Tracking Error", "0"},
{"Treynor Ratio", "0"},
{"Total Fees", "$6.00"},
{"Estimated Strategy Capacity", "$3000.00"},
{"Fitness Score", "0"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
@@ -249,7 +250,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "731140098"}
{"OrderListHash", "cf8f76fa441c2a5e3b2dbbabcab32cd2"}
};
}
}

View File

@@ -131,6 +131,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Tracking Error", "0.072"},
{"Treynor Ratio", "2.933"},
{"Total Fees", "$26.39"},
{"Estimated Strategy Capacity", "$2200000.00"},
{"Fitness Score", "0.374"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
@@ -150,7 +151,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "1779055144"}
{"OrderListHash", "5f7ba8b5defb310a2eaf98b11abd3b74"}
};
}
}

View File

@@ -84,6 +84,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Tracking Error", "0.006"},
{"Treynor Ratio", "2.029"},
{"Total Fees", "$9.77"},
{"Estimated Strategy Capacity", "$28000000.00"},
{"Fitness Score", "0.747"},
{"Kelly Criterion Estimate", "38.64"},
{"Kelly Criterion Probability Value", "0.229"},
@@ -103,7 +104,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Mean Population Magnitude", "54.5455%"},
{"Rolling Averaged Population Direction", "59.8056%"},
{"Rolling Averaged Population Magnitude", "59.8056%"},
{"OrderListHash", "-887190565"}
{"OrderListHash", "0b8cbbafdb77bae2f7abe3cf5e05ac5c"}
};
}
}

View File

@@ -103,6 +103,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Tracking Error", "0.376"},
{"Treynor Ratio", "-0.084"},
{"Total Fees", "$13.98"},
{"Estimated Strategy Capacity", "$31000000.00"},
{"Fitness Score", "0.146"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "1"},
@@ -122,7 +123,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "1917702312"}
{"OrderListHash", "8971c92ba163cec8526379865d9b9ee4"}
};
}
}

View File

@@ -110,6 +110,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Tracking Error", "0.194"},
{"Treynor Ratio", "-0.962"},
{"Total Fees", "$25.92"},
{"Estimated Strategy Capacity", "$16000000.00"},
{"Fitness Score", "0.004"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "1"},
@@ -129,7 +130,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "-1674230481"}
{"OrderListHash", "ce59e51c8e404b5dbbc02911473aed1c"}
};
}
}

View File

@@ -0,0 +1,237 @@
/*
* 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.Data;
using QuantConnect.Data.Shortable;
using QuantConnect.Data.UniverseSelection;
using QuantConnect.Interfaces;
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] }
};
public override void Initialize()
{
SetStartDate(2014, 3, 25);
SetEndDate(2014, 3, 29);
SetCash(10000000);
AddUniverse(CoarseSelection);
UniverseSettings.Resolution = Resolution.Daily;
SetBrokerageModel(new AllShortableSymbolsRegressionAlgorithmBrokerageModel());
}
public override void OnData(Slice data)
{
if (Time.Date == _lastTradeDate)
{
return;
}
foreach (var symbol in ActiveSecurities.Keys)
{
if (!Portfolio.ContainsKey(symbol) || !Portfolio[symbol].Invested)
{
if (!Shortable(symbol))
{
throw new Exception($"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(symbol));
_lastTradeDate = Time.Date;
}
}
}
private IEnumerable<Symbol> CoarseSelection(IEnumerable<CoarseFundamental> coarse)
{
var shortableSymbols = AllShortableSymbols();
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 Exception("Expected unmapped GME in shortable symbols list on 2014-03-27");
}
if (!coarse.Select(x => x.Symbol.Value).Contains("GME"))
{
throw new Exception("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 Exception($"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()
{
ShortableProvider = new RegressionTestShortableProvider();
}
}
private class RegressionTestShortableProvider : LocalDiskShortableProvider
{
public RegressionTestShortableProvider() : base(SecurityType.Equity, "testbrokerage", Market.USA)
{
}
}
/// <summary>
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
/// </summary>
public bool CanRunLocally { get; } = true;
/// <summary>
/// This is used by the regression test system to indicate which languages this algorithm is written in.
/// </summary>
public Language[] Languages { get; } = { Language.CSharp, Language.Python };
/// <summary>
/// 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%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "36.294%"},
{"Drawdown", "0%"},
{"Expectancy", "0"},
{"Net Profit", "0.340%"},
{"Sharpe Ratio", "21.2"},
{"Probabilistic Sharpe Ratio", "99.990%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "0.274"},
{"Beta", "0.138"},
{"Annual Standard Deviation", "0.011"},
{"Annual Variance", "0"},
{"Information Ratio", "7.202"},
{"Tracking Error", "0.068"},
{"Treynor Ratio", "1.722"},
{"Total Fees", "$307.50"},
{"Estimated Strategy Capacity", "$710000.00"},
{"Fitness Score", "0.173"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "79228162514264337593543950335"},
{"Return Over Maximum Drawdown", "79228162514264337593543950335"},
{"Portfolio Turnover", "0.173"},
{"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", "6b1b205e5a6461ffd5bed645099714cd"}
};
}
}

View File

@@ -19,28 +19,27 @@ 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
namespace QuantConnect.Algorithm.CSharp.Alphas
{
/// <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
///<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
///</summary>
public class MortgageRateVolatilityAlgorithm : QCAlgorithm
{
public override void Initialize()
{
@@ -51,8 +50,8 @@ namespace QuantConnect.Algorithm.CSharp
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();
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));
@@ -64,8 +63,6 @@ namespace QuantConnect.Algorithm.CSharp
SetRiskManagement(new NullRiskManagementModel());
}
public void OnData(QuandlMortgagePriceColumns data) { }
private class MortgageRateVolatilityAlphaModel : AlphaModel
{
@@ -79,7 +76,7 @@ namespace QuantConnect.Algorithm.CSharp
private readonly StandardDeviation _mortgageRateStd;
public MortgageRateVolatilityAlphaModel(
QCAlgorithmFramework algorithm,
QCAlgorithm algorithm,
int indicatorPeriod = 15,
double insightMagnitude = 0.0005,
int deviations = 2,
@@ -102,7 +99,7 @@ namespace QuantConnect.Algorithm.CSharp
WarmUpIndicators(algorithm);
}
public override IEnumerable<Insight> Update(QCAlgorithmFramework algorithm, Slice data)
public override IEnumerable<Insight> Update(QCAlgorithm algorithm, Slice data)
{
var insights = new List<Insight>();
@@ -141,7 +138,7 @@ namespace QuantConnect.Algorithm.CSharp
return insights;
}
private void WarmUpIndicators(QCAlgorithmFramework algorithm)
private void WarmUpIndicators(QCAlgorithm algorithm)
{
// Make a history call and update the indicators
algorithm.History(new[] { _mortgageRate }, _indicatorPeriod, _resolution).PushThrough(bar =>

View File

@@ -0,0 +1,62 @@
/*
* 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,74 +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.Robintrack;
namespace QuantConnect.Algorithm.CSharp.AltData
{
/// <summary>
/// Looks at users holding the stock AAPL at a given point in time
/// and keeps track of changes in retail investor sentiment.
///
/// We go long if the sentiment increases by 0.5%, and short if it decreases by -0.5%
/// </summary>
public class RobintrackHoldingsAlgorithm : QCAlgorithm
{
private Symbol _aapl;
private Symbol _aaplHoldings;
private decimal _lastValue;
private bool _isLong;
public override void Initialize()
{
SetStartDate(2018, 5, 1);
SetEndDate(2020, 5, 5);
SetCash(100000);
_aapl = AddEquity("AAPL", Resolution.Daily).Symbol;
_aaplHoldings = AddData<RobintrackHoldings>(_aapl).Symbol;
_isLong = false;
}
public override void OnData(Slice data)
{
foreach (var kvp in data.Get<RobintrackHoldings>())
{
var holdings = kvp.Value;
if (_lastValue != 0)
{
var percentChange = (holdings.UsersHolding - _lastValue) / _lastValue;
var holdingInfo = $"There are {holdings.UsersHolding} unique users holding {kvp.Key.Underlying} - users holding % of U.S. equities universe: {holdings.UniverseHoldingPercent * 100m}%";
if (percentChange >= 0.005m && !_isLong)
{
Log($"{UtcTime} - Buying AAPL - {holdingInfo}");
SetHoldings(_aapl, 0.5);
_isLong = true;
}
else if (percentChange <= -0.005m && _isLong)
{
Log($"{UtcTime} - Shorting AAPL - {holdingInfo}");
SetHoldings(_aapl, -0.5);
_isLong = false;
}
}
_lastValue = holdings.UsersHolding;
}
}
}
}

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;
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);
EnableAutomaticIndicatorWarmUp = 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 Language[] Languages { get; } = { Language.CSharp, Language.Python };
/// <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", "65"},
{"Average Win", "0.00%"},
{"Average Loss", "0.00%"},
{"Compounding Annual Return", "0.145%"},
{"Drawdown", "0.100%"},
{"Expectancy", "2.190"},
{"Net Profit", "0.134%"},
{"Sharpe Ratio", "0.993"},
{"Probabilistic Sharpe Ratio", "49.669%"},
{"Loss Rate", "29%"},
{"Win Rate", "71%"},
{"Profit-Loss Ratio", "3.50"},
{"Alpha", "0.001"},
{"Beta", "0"},
{"Annual Standard Deviation", "0.001"},
{"Annual Variance", "0"},
{"Information Ratio", "-2.168"},
{"Tracking Error", "0.099"},
{"Treynor Ratio", "-5.187"},
{"Total Fees", "$65.00"},
{"Estimated Strategy Capacity", "$2300000000.00"},
{"Fitness Score", "0"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "1.51"},
{"Return Over Maximum Drawdown", "1.819"},
{"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", "c4c9c272037cfd8f6887052b8d739466"}
};
}
}

View File

@@ -168,6 +168,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Tracking Error", "0.441"},
{"Treynor Ratio", "-0.008"},
{"Total Fees", "$20.35"},
{"Estimated Strategy Capacity", "$19000000.00"},
{"Fitness Score", "0.138"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
@@ -187,7 +188,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "-1453269600"}
{"OrderListHash", "7c841ca58a4385f42236838e5bf0c382"}
};
}
}

View File

@@ -130,6 +130,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Tracking Error", "0.001"},
{"Treynor Ratio", "1.922"},
{"Total Fees", "$3.26"},
{"Estimated Strategy Capacity", "$15000000.00"},
{"Fitness Score", "0.248"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
@@ -149,7 +150,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "491919591"}
{"OrderListHash", "25885f979ca8c7b44f5d0f7daf00b241"}
};
}
}

View File

@@ -0,0 +1,342 @@
/*
* 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.Market;
using QuantConnect.Interfaces;
using QuantConnect.Orders;
using QuantConnect.Orders.Fees;
using QuantConnect.Orders.Fills;
using QuantConnect.Securities;
using QuantConnect.Securities.Option;
using System;
using System.Collections.Generic;
using System.Linq;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// This regression algorithm tests the order processing of the backtesting brokerage.
/// We open an equity position that should fill in two parts, on two different bars.
/// We open a long option position and let it expire so we can exercise the position.
/// To check the orders we use OnOrderEvent and throw exceptions if verification fails.
/// </summary>
/// <meta name="tag" content="backtesting brokerage" />
/// <meta name="tag" content="regression test" />
/// <meta name="tag" content="options" />
class BacktestingBrokerageRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
{
private Security _security;
private Symbol _spy;
private OrderTicket _equityBuy;
private Option _option;
private Symbol _optionSymbol;
private OrderTicket _optionBuy;
private bool _optionBought = false;
private bool _equityBought = false;
private decimal _optionStrikePrice;
/// <summary>
/// Initialize the algorithm
/// </summary>
public override void Initialize()
{
SetCash(100000);
SetStartDate(2015, 12, 24);
SetEndDate(2015, 12, 28);
// Get our equity
_security = AddEquity("SPY", Resolution.Hour);
_security.SetFillModel(new PartialMarketFillModel(2));
_spy = _security.Symbol;
// Get our option
_option = AddOption("GOOG");
_option.SetFilter(u => u.IncludeWeeklys()
.Strikes(-2, +2)
.Expiration(TimeSpan.Zero, TimeSpan.FromDays(10)));
_optionSymbol = _option.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)
{
if (!_equityBought && data.ContainsKey(_spy)) {
//Buy our Equity
var quantity = CalculateOrderQuantity(_spy, .1m);
_equityBuy = MarketOrder(_spy, quantity, asynchronous: true);
_equityBought = true;
}
if (!_optionBought)
{
// Buy our option
OptionChain chain;
if (data.OptionChains.TryGetValue(_optionSymbol, out chain))
{
// Find the second call strike under market price expiring today
var contracts = (
from optionContract in chain.OrderByDescending(x => x.Strike)
where optionContract.Right == OptionRight.Call
where optionContract.Expiry == Time.Date
where optionContract.Strike < chain.Underlying.Price
select optionContract
).Take(2);
if (contracts.Any())
{
var optionToBuy = contracts.FirstOrDefault();
_optionStrikePrice = optionToBuy.Strike;
_optionBuy = MarketOrder(optionToBuy.Symbol, 1);
_optionBought = true;
}
}
}
}
/// <summary>
/// All order events get pushed through this function
/// </summary>
/// <param name="orderEvent">OrderEvent object that contains all the information about the event</param>
public override void OnOrderEvent(OrderEvent orderEvent)
{
// Get the order from our transactions
var order = Transactions.GetOrderById(orderEvent.OrderId);
// Based on the type verify the order
switch(order.Type)
{
case OrderType.Market:
VerifyMarketOrder(order, orderEvent);
break;
case OrderType.OptionExercise:
VerifyOptionExercise(order, orderEvent);
break;
default:
throw new ArgumentOutOfRangeException();
}
}
/// <summary>
/// To verify Market orders is process correctly
/// </summary>
/// <param name="order">Order object to analyze</param>
public void VerifyMarketOrder(Order order, OrderEvent orderEvent)
{
switch(order.Status)
{
case OrderStatus.Submitted:
break;
// All PartiallyFilled orders should have a LastFillTime
case OrderStatus.PartiallyFilled:
if (order.LastFillTime == null)
{
throw new Exception("LastFillTime should not be null");
}
if (order.Quantity/2 != orderEvent.FillQuantity)
{
throw new Exception("Order size should be half");
}
break;
// All filled equity orders should have filled after creation because of our fill model!
case OrderStatus.Filled:
if (order.SecurityType == SecurityType.Equity && order.CreatedTime == order.LastFillTime)
{
throw new Exception("Order should not finish during the CreatedTime bar");
}
break;
default:
throw new ArgumentOutOfRangeException();
}
}
/// <summary>
/// To verify OptionExercise orders is process correctly
/// </summary>
/// <param name="order">Order object to analyze</param>
public void VerifyOptionExercise(Order order, OrderEvent orderEvent)
{
// 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!!");
}
if (orderEvent.Quantity != -1)
{
throw new Exception("OrderEvent Quantity should be -1");
}
}
/// <summary>
/// Runs after algorithm, used to check our portfolio and orders
/// </summary>
public override void OnEndOfAlgorithm()
{
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");
}
//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");
}
//Check the option underlying symbol since we should have bought it at exercise
//Quantity should be 100, AveragePrice should be option strike price
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");
}
//Check equity holding, should be invested, profit should be
//Quantity should be 50, AveragePrice should be ticket AverageFillPrice
var equityHolding = Portfolio[_equityBuy.Symbol];
if (!equityHolding.Invested || equityHolding.Quantity != 50 || equityHolding.AveragePrice != _equityBuy.AverageFillPrice)
{
throw new Exception("Equity holding does not match expected outcome");
}
}
/// <summary>
/// PartialMarketFillModel that allows the user to set the number of fills and restricts
/// the fill to only one per bar.
/// </summary>
private class PartialMarketFillModel : ImmediateFillModel
{
private readonly decimal _percent;
private readonly Dictionary<long, decimal> _absoluteRemainingByOrderId = new Dictionary<long, decimal>();
/// <param name="numberOfFills"></param>
public PartialMarketFillModel(int numberOfFills = 1)
{
_percent = 1m / numberOfFills;
}
/// <summary>
/// Performs partial market fills once per time step
/// </summary>
/// <param name="asset">The security being ordered</param>
/// <param name="order">The order</param>
/// <returns>The order fill</returns>
public override OrderEvent MarketFill(Security asset, MarketOrder order)
{
var currentUtcTime = asset.LocalTime.ConvertToUtc(asset.Exchange.TimeZone);
// Only fill once a time slice
if (order.LastFillTime != null && currentUtcTime <= order.LastFillTime)
{
return new OrderEvent(order, currentUtcTime, OrderFee.Zero);
}
decimal absoluteRemaining;
if (!_absoluteRemainingByOrderId.TryGetValue(order.Id, out absoluteRemaining))
{
absoluteRemaining = order.AbsoluteQuantity;
_absoluteRemainingByOrderId.Add(order.Id, order.AbsoluteQuantity);
}
var fill = base.MarketFill(asset, order);
var absoluteFillQuantity = (int)(Math.Min(absoluteRemaining, (int)(_percent * order.Quantity)));
fill.FillQuantity = Math.Sign(order.Quantity) * absoluteFillQuantity;
if (absoluteRemaining == absoluteFillQuantity)
{
fill.Status = OrderStatus.Filled;
_absoluteRemainingByOrderId.Remove(order.Id);
}
else
{
absoluteRemaining = absoluteRemaining - absoluteFillQuantity;
_absoluteRemainingByOrderId[order.Id] = absoluteRemaining;
fill.Status = OrderStatus.PartiallyFilled;
}
return fill;
}
}
/// <summary>
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
/// </summary>
public bool CanRunLocally { get; } = true;
/// <summary>
/// This is used by the regression test system to indicate which languages this algorithm is written in.
/// </summary>
public Language[] Languages { get; } = { Language.CSharp };
/// <summary>
/// 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"},
{"Average Win", "0%"},
{"Average Loss", "-0.40%"},
{"Compounding Annual Return", "-22.335%"},
{"Drawdown", "0.400%"},
{"Expectancy", "-1"},
{"Net Profit", "-0.323%"},
{"Sharpe Ratio", "-11.098"},
{"Probabilistic Sharpe Ratio", "0%"},
{"Loss Rate", "100%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "-0.002"},
{"Beta", "0.099"},
{"Annual Standard Deviation", "0.002"},
{"Annual Variance", "0"},
{"Information Ratio", "9.899"},
{"Tracking Error", "0.019"},
{"Treynor Ratio", "-0.23"},
{"Total Fees", "$2.00"},
{"Estimated Strategy Capacity", "$0"},
{"Fitness Score", "0.213"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "79228162514264337593543950335"},
{"Return Over Maximum Drawdown", "-73.456"},
{"Portfolio Turnover", "0.426"},
{"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", "72a6ced0ed0c2da7136f3be652eb4744"}
};
}
}

View File

@@ -88,6 +88,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Tracking Error", "0"},
{"Treynor Ratio", "0"},
{"Total Fees", "$0.00"},
{"Estimated Strategy Capacity", "$85000.00"},
{"Fitness Score", "0.506"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
@@ -107,7 +108,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "498372354"}
{"OrderListHash", "18dc611407abec4ea47092e71f33f983"}
};
}
}

View File

@@ -97,6 +97,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Tracking Error", "0.001"},
{"Treynor Ratio", "1.922"},
{"Total Fees", "$3.26"},
{"Estimated Strategy Capacity", "$15000000.00"},
{"Fitness Score", "0.248"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
@@ -116,7 +117,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "491919591"}
{"OrderListHash", "25885f979ca8c7b44f5d0f7daf00b241"}
};
}
}

View File

@@ -222,12 +222,13 @@ namespace QuantConnect.Algorithm.CSharp
{"Information Ratio", "0"},
{"Tracking Error", "0"},
{"Treynor Ratio", "0"},
{"Total Fees", "$85.33"},
{"Total Fees", "$85.34"},
{"Estimated Strategy Capacity", "$0"},
{"Fitness Score", "0.5"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "79228162514264337593543950335"},
{"Return Over Maximum Drawdown", "-43.917"},
{"Return Over Maximum Drawdown", "-43.943"},
{"Portfolio Turnover", "1.028"},
{"Total Insights Generated", "0"},
{"Total Insights Closed", "0"},
@@ -242,7 +243,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "1073240275"}
{"OrderListHash", "1bf1a6d9dd921982b72a6178f9e50e68"}
};
}
}

View File

@@ -88,6 +88,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Tracking Error", "0.221"},
{"Treynor Ratio", "-13.568"},
{"Total Fees", "$3.26"},
{"Estimated Strategy Capacity", "$130000000.00"},
{"Fitness Score", "0.111"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
@@ -107,7 +108,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "1268340653"}
{"OrderListHash", "82fee25cd17100c53bb173834ab5f0b2"}
};
}
}

View File

@@ -109,6 +109,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Tracking Error", "0.002"},
{"Treynor Ratio", "1.839"},
{"Total Fees", "$9.77"},
{"Estimated Strategy Capacity", "$20000000.00"},
{"Fitness Score", "0.747"},
{"Kelly Criterion Estimate", "38.64"},
{"Kelly Criterion Probability Value", "0.229"},
@@ -128,7 +129,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Mean Population Magnitude", "54.5455%"},
{"Rolling Averaged Population Direction", "59.8056%"},
{"Rolling Averaged Population Magnitude", "59.8056%"},
{"OrderListHash", "951346025"}
{"OrderListHash", "17e29d58e5dabd93569da752c4552c70"}
};
}
}

View File

@@ -147,6 +147,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Tracking Error", "0.504"},
{"Treynor Ratio", "1.011"},
{"Total Fees", "$15207.00"},
{"Estimated Strategy Capacity", "$8800000.00"},
{"Fitness Score", "0.033"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
@@ -166,7 +167,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "-1197265007"}
{"OrderListHash", "35b3f4b7a225468d42ca085386a2383e"}
};
}
}

View File

@@ -155,6 +155,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Tracking Error", "0.188"},
{"Treynor Ratio", "-3.318"},
{"Total Fees", "$3.70"},
{"Estimated Strategy Capacity", "$13000000.00"},
{"Fitness Score", "0.009"},
{"Kelly Criterion Estimate", "-112.972"},
{"Kelly Criterion Probability Value", "0.671"},
@@ -174,7 +175,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "-1624258832"}
{"OrderListHash", "18ffd3a774c68da83d867e3b09e3e05d"}
};
}
}

View File

@@ -1,4 +1,4 @@
/*
/*
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
*
@@ -160,6 +160,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Tracking Error", "0"},
{"Treynor Ratio", "0"},
{"Total Fees", "$0.00"},
{"Estimated Strategy Capacity", "$0"},
{"Fitness Score", "0"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
@@ -179,7 +180,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "371857150"}
{"OrderListHash", "d41d8cd98f00b204e9800998ecf8427e"}
};
}
}
}

View File

@@ -134,6 +134,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Tracking Error", "0"},
{"Treynor Ratio", "0"},
{"Total Fees", "$778.00"},
{"Estimated Strategy Capacity", "$180000.00"},
{"Fitness Score", "0"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
@@ -153,7 +154,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "-702975961"}
{"OrderListHash", "5484aef1443064c826e0071f757cb0f7"}
};
}
}

View File

@@ -131,6 +131,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Tracking Error", "0"},
{"Treynor Ratio", "0"},
{"Total Fees", "$2.00"},
{"Estimated Strategy Capacity", "$2600000.00"},
{"Fitness Score", "0"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
@@ -150,7 +151,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "1130102123"}
{"OrderListHash", "9d9f9248ee8fe30d87ff0a6f6fea5112"}
};
}
}

View File

@@ -1,4 +1,4 @@
/*
/*
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
*
@@ -15,9 +15,11 @@
*/
using System;
using System.Collections.Generic;
using System.Linq;
using QuantConnect.Data;
using QuantConnect.Data.Market;
using QuantConnect.Interfaces;
using QuantConnect.Orders;
using QuantConnect.Securities;
@@ -31,7 +33,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <meta name="tag" content="using data" />
/// <meta name="tag" content="options" />
/// <meta name="tag" content="filter selection" />
public class BasicTemplateOptionsFilterUniverseAlgorithm : QCAlgorithm
public class BasicTemplateOptionsFilterUniverseAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
{
private const string UnderlyingTicker = "GOOG";
public Symbol OptionSymbol;
@@ -40,20 +42,17 @@ namespace QuantConnect.Algorithm.CSharp
{
SetStartDate(2015, 12, 24);
SetEndDate(2015, 12, 24);
SetCash(10000);
SetCash(100000);
var equity = AddEquity(UnderlyingTicker);
var option = AddOption(UnderlyingTicker);
OptionSymbol = option.Symbol;
// set our custom filter for this option chain
option.SetFilter(universe => from symbol in universe
.WeeklysOnly()
// Expiration method accepts TimeSpan objects or integer for days.
// The following statements yield the same filtering criteria
.Expiration(0, 10)
// .Expiration(TimeSpan.Zero, TimeSpan.FromDays(10))
// Set our custom universe filter, Expires today, is a call, and is within 10 dollars of the current price
option.SetFilter(universe => from symbol in universe.WeeklysOnly().Expiration(0, 1)
where symbol.ID.OptionRight != OptionRight.Put &&
universe.Underlying.Price - symbol.ID.StrikePrice < 60
-10 < universe.Underlying.Price - symbol.ID.StrikePrice &&
universe.Underlying.Price - symbol.ID.StrikePrice < 10
select symbol);
// use the underlying equity as the benchmark
@@ -67,14 +66,13 @@ namespace QuantConnect.Algorithm.CSharp
OptionChain chain;
if (slice.OptionChains.TryGetValue(OptionSymbol, out chain))
{
// find the second call strike under market price expiring today
// Get the first ITM call expiring today
var contract = (
from optionContract in chain.OrderByDescending(x => x.Strike)
where optionContract.Right == OptionRight.Call
where optionContract.Expiry == Time.Date
where optionContract.Strike < chain.Underlying.Price
select optionContract
).Skip(2).FirstOrDefault();
).FirstOrDefault();
if (contract != null)
{
@@ -88,5 +86,63 @@ namespace QuantConnect.Algorithm.CSharp
{
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 Language[] Languages { get; } = { Language.CSharp, Language.Python };
/// <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"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "0%"},
{"Drawdown", "0%"},
{"Expectancy", "0"},
{"Net Profit", "0%"},
{"Sharpe 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", "$1.00"},
{"Estimated Strategy Capacity", "$0"},
{"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", "92d8a50efe230524512404dab66b19dd"}
};
}
}

View File

@@ -160,7 +160,8 @@ namespace QuantConnect.Algorithm.CSharp
{"Information Ratio", "0"},
{"Tracking Error", "0"},
{"Treynor Ratio", "0"},
{"Total Fees", "$4.00"},
{"Total Fees", "$3.00"},
{"Estimated Strategy Capacity", "$74000.00"},
{"Fitness Score", "0"},
{"Kelly Criterion Estimate", "0.327"},
{"Kelly Criterion Probability Value", "1"},
@@ -180,7 +181,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "50.0482%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "352959406"}
{"OrderListHash", "ce06ddfa4b2ffeb666a8910ac8836992"}
};
}
}

View File

@@ -94,6 +94,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Tracking Error", "0.09"},
{"Treynor Ratio", "0.82"},
{"Total Fees", "$41.70"},
{"Estimated Strategy Capacity", "$2000000.00"},
{"Fitness Score", "0.634"},
{"Kelly Criterion Estimate", "13.656"},
{"Kelly Criterion Probability Value", "0.228"},
@@ -113,7 +114,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Mean Population Magnitude", "50%"},
{"Rolling Averaged Population Direction", "12.6429%"},
{"Rolling Averaged Population Magnitude", "12.6429%"},
{"OrderListHash", "-2004493274"}
{"OrderListHash", "3edd51956c7c97af4863aa6059c11f1a"}
};
}
}

View File

@@ -0,0 +1,181 @@
/*
* 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.IO;
using QuantConnect.Data;
using QuantConnect.Data.Custom.CBOE;
using QuantConnect.Indicators;
using QuantConnect.Interfaces;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Tests the consolidation of custom data with random data
/// </summary>
public class CBOECustomDataConsolidationRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
{
private Symbol _vix;
private BollingerBands _bb;
private bool _invested;
/// <summary>
/// Initializes the algorithm with fake VIX data
/// </summary>
public override void Initialize()
{
SetStartDate(2013, 10, 7);
SetEndDate(2013, 10, 11);
SetCash(100000);
_vix = AddData<IncrementallyGeneratedCustomData>("VIX", Resolution.Daily).Symbol;
_bb = BB(_vix, 30, 2, MovingAverageType.Simple, 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 data)
{
if (_bb.Current.Value == 0)
{
throw new Exception("Bollinger Band value is zero when we expect non-zero value.");
}
if (!_invested && _bb.Current.Value > 0.05m)
{
MarketOrder(_vix, 1);
_invested = true;
}
}
/// <summary>
/// Incrementally updating data
/// </summary>
private class IncrementallyGeneratedCustomData : CBOE
{
private const decimal _start = 10.01m;
private static decimal _step;
/// <summary>
/// Gets the source of the subscription. In this case, we set it to existing
/// equity data so that we can pass fake data from Reader
/// </summary>
/// <param name="config">Subscription configuration</param>
/// <param name="date">Date we're making this request</param>
/// <param name="isLiveMode">Is live mode</param>
/// <returns>Source of subscription</returns>
public override SubscriptionDataSource GetSource(SubscriptionDataConfig config, DateTime date, bool isLiveMode)
{
return new SubscriptionDataSource(Path.Combine(Globals.DataFolder, "equity", "usa", "minute", "spy", $"{date:yyyyMMdd}_trade.zip#{date:yyyyMMdd}_spy_minute_trade.csv"), SubscriptionTransportMedium.LocalFile, FileFormat.Csv);
}
/// <summary>
/// Reads the data, which in this case is fake incremental data
/// </summary>
/// <param name="config">Subscription configuration</param>
/// <param name="line">Line of data</param>
/// <param name="date">Date of the request</param>
/// <param name="isLiveMode">Is live mode</param>
/// <returns>Incremental BaseData instance</returns>
public override BaseData Reader(SubscriptionDataConfig config, string line, DateTime date, bool isLiveMode)
{
var vix = new CBOE();
_step += 0.10m;
var open = _start + _step;
var close = _start + _step + 0.02m;
var high = close;
var low = open;
return new IncrementallyGeneratedCustomData
{
Open = open,
High = high,
Low = low,
Close = close,
Time = date,
Symbol = new Symbol(
SecurityIdentifier.GenerateBase(typeof(IncrementallyGeneratedCustomData), "VIX", Market.USA, false),
"VIX"),
Period = vix.Period,
DataType = vix.DataType
};
}
}
/// <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>
/// <remarks>
/// Unable to be tested in Python, due to pythonnet not supporting overriding of methods from Python
/// </remarks>
public Language[] Languages { get; } = { Language.CSharp };
/// <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"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "0.029%"},
{"Drawdown", "0%"},
{"Expectancy", "0"},
{"Net Profit", "0.000%"},
{"Sharpe Ratio", "28.4"},
{"Probabilistic Sharpe Ratio", "88.597%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "0"},
{"Beta", "0"},
{"Annual Standard Deviation", "0"},
{"Annual Variance", "0"},
{"Information Ratio", "-7.067"},
{"Tracking Error", "0.193"},
{"Treynor Ratio", "7.887"},
{"Total Fees", "$0.00"},
{"Estimated Strategy Capacity", "$0"},
{"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", "918912ee4f64cd0290f3d58deca02713"}
};
}
}

View File

@@ -147,12 +147,13 @@ namespace QuantConnect.Algorithm.CSharp
{"Tracking Error", "0"},
{"Treynor Ratio", "0"},
{"Total Fees", "$0.00"},
{"Estimated Strategy Capacity", "$370000.00"},
{"Fitness Score", "0.501"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "79228162514264337593543950335"},
{"Return Over Maximum Drawdown", "-30.28"},
{"Portfolio Turnover", "1.029"},
{"Return Over Maximum Drawdown", "-30.158"},
{"Portfolio Turnover", "1.033"},
{"Total Insights Generated", "0"},
{"Total Insights Closed", "0"},
{"Total Insights Analysis Completed", "0"},
@@ -166,7 +167,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "-1708974186"}
{"OrderListHash", "aea2e321d17414c1f3c6fa2491f10c88"}
};
}
}

View File

@@ -0,0 +1,102 @@
/*
* 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>
/// Tests capacity by trading SPY (beast) alongside a small cap stock ABUS (penny)
/// </summary>
public class BeastVsPenny : QCAlgorithm, IRegressionAlgorithmDefinition
{
private Symbol _spy;
public override void Initialize()
{
SetStartDate(2020, 1, 1);
SetEndDate(2020, 3, 31);
SetCash(10000);
_spy = AddEquity("SPY", Resolution.Hour).Symbol;
var penny = AddEquity("ABUS", Resolution.Hour).Symbol;
Schedule.On(DateRules.EveryDay(_spy), TimeRules.AfterMarketOpen(_spy, 1, false), () =>
{
SetHoldings(_spy, 0.5m);
SetHoldings(penny, 0.5m);
});
}
/// <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; } = false;
/// <summary>
/// This is used by the regression test system to indicate which languages this algorithm is written in.
/// </summary>
public Language[] Languages { get; } = { Language.CSharp };
/// <summary>
/// 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", "70"},
{"Average Win", "0.07%"},
{"Average Loss", "-0.51%"},
{"Compounding Annual Return", "-89.548%"},
{"Drawdown", "49.900%"},
{"Expectancy", "-0.514"},
{"Net Profit", "-42.920%"},
{"Sharpe Ratio", "-0.797"},
{"Probabilistic Sharpe Ratio", "9.019%"},
{"Loss Rate", "57%"},
{"Win Rate", "43%"},
{"Profit-Loss Ratio", "0.13"},
{"Alpha", "-0.24"},
{"Beta", "1.101"},
{"Annual Standard Deviation", "1.031"},
{"Annual Variance", "1.063"},
{"Information Ratio", "-0.351"},
{"Tracking Error", "0.836"},
{"Treynor Ratio", "-0.747"},
{"Total Fees", "$81.45"},
{"Estimated Strategy Capacity", "$21000.00"},
{"Fitness Score", "0.01"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "-1.284"},
{"Return Over Maximum Drawdown", "-1.789"},
{"Portfolio Turnover", "0.038"},
{"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", "67c9083f604ed16fb68481e7c26878dc"}
};
}
}

View File

@@ -0,0 +1,147 @@
/*
* 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.Indicators;
using QuantConnect.Interfaces;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Tests an illiquid asset that has bursts of liquidity around 11:00 A.M. Central Time
/// with an hourly in and out strategy.
/// </summary>
public class CheeseMilkHourlyRebalance : QCAlgorithm, IRegressionAlgorithmDefinition
{
private ExponentialMovingAverage _fast;
private ExponentialMovingAverage _slow;
private Symbol _contract;
private DateTime _lastTrade;
public override void Initialize()
{
SetStartDate(2021, 1, 1);
SetEndDate(2021, 2, 17);
SetTimeZone(TimeZones.Chicago);
SetCash(100000);
SetWarmup(1000);
var dc = AddFuture("DC", Resolution.Minute, Market.CME);
dc.SetFilter(0, 10000);
}
public override void OnData(Slice data)
{
var contract = data.FutureChains.Values.SelectMany(c => c.Contracts.Values)
.OrderBy(c => c.Symbol.ID.Date)
.FirstOrDefault()?
.Symbol;
if (contract == null)
{
return;
}
if (_contract != contract || (_fast == null && _slow == null))
{
_fast = EMA(contract, 600);
_slow = EMA(contract, 1200);
_contract = contract;
}
if (!_fast.IsReady || !_slow.IsReady)
{
return;
}
if (Time - _lastTrade <= TimeSpan.FromHours(1) || Time.TimeOfDay <= new TimeSpan(10, 50, 0) || Time.TimeOfDay >= new TimeSpan(12, 30, 0))
{
return;
}
if (!Portfolio.ContainsKey(contract) || (Portfolio[contract].Quantity <= 0 && _fast > _slow))
{
SetHoldings(contract, 0.5);
_lastTrade = Time;
}
else if (Portfolio.ContainsKey(contract) && Portfolio[contract].Quantity >= 0 && _fast < _slow)
{
SetHoldings(contract, -0.5);
_lastTrade = 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; } = false;
/// <summary>
/// This is used by the regression test system to indicate which languages this algorithm is written in.
/// </summary>
public Language[] Languages { get; } = { Language.CSharp };
/// <summary>
/// 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", "19"},
{"Average Win", "39.16%"},
{"Average Loss", "-8.81%"},
{"Compounding Annual Return", "-99.857%"},
{"Drawdown", "82.900%"},
{"Expectancy", "-0.359"},
{"Net Profit", "-57.725%"},
{"Sharpe Ratio", "-0.555"},
{"Probabilistic Sharpe Ratio", "10.606%"},
{"Loss Rate", "88%"},
{"Win Rate", "12%"},
{"Profit-Loss Ratio", "4.45"},
{"Alpha", "-1.188"},
{"Beta", "0.603"},
{"Annual Standard Deviation", "1.754"},
{"Annual Variance", "3.075"},
{"Information Ratio", "-0.759"},
{"Tracking Error", "1.753"},
{"Treynor Ratio", "-1.612"},
{"Total Fees", "$2558.55"},
{"Estimated Strategy Capacity", "$20000.00"},
{"Fitness Score", "0.351"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "-0.602"},
{"Return Over Maximum Drawdown", "-1.415"},
{"Portfolio Turnover", "14.226"},
{"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", "4f5fd2fb25e957bd0cb7cb6d275ddb97"}
};
}
}

View File

@@ -0,0 +1,231 @@
/*
* 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.Indicators;
using QuantConnect.Interfaces;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Tests a wide variety of liquid and illiquid stocks together, with bins
/// of 20 ranging from micro-cap to mega-cap stocks.
/// </summary>
public class EmaPortfolioRebalance100 : QCAlgorithm, IRegressionAlgorithmDefinition
{
public List<SymbolData> Data;
public override void Initialize()
{
SetStartDate(2020, 1, 1);
SetEndDate(2020, 2, 5);
SetWarmup(1000);
SetCash(100000);
Data = new List<SymbolData> {
new SymbolData(this, AddEquity("AADR", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("AAMC", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("AAU", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("ABDC", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("ABIO", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("ABUS", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("AC", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("ACER", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("ACES", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("ACGLO", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("ACH", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("ACHV", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("ACIO", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("ACIU", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("ACNB", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("ACRS", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("ACSI", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("ACT", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("ACT", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("ACTG", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("ZYNE", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("ZYME", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("ZUO", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("ZUMZ", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("ZTR", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("ZSL", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("ZSAN", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("ZROZ", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("ZLAB", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("ZIXI", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("ZIV", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("ZIOP", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("ZGNX", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("ZG", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("ZEUS", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("ZAGG", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("YYY", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("YRD", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("YRCW", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("YPF", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("AA", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("AAN", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("AAP", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("AAXN", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("ABB", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("ABC", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("ACAD", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("ACC", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("ACGL", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("ACIW", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("ACM", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("ACWV", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("ACWX", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("ADM", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("ADPT", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("ADS", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("ADUS", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("AEM", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("AEO", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("AEP", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("ZTS", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("YUM", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("XLY", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("XLV", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("XLRE", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("XLP", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("XLNX", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("XLF", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("XLC", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("XLB", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("XEL", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("XBI", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("X", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("WYNN", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("WW", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("WORK", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("WMB", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("WM", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("WELL", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("WEC", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("AAPL", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("ADBE", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("AGG", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("AMD", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("AMZN", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("BA", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("BABA", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("BAC", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("BMY", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("C", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("CMCSA", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("CRM", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("CSCO", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("DIS", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("EEM", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("EFA", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("FB", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("GDX", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("GE", Resolution.Minute).Symbol),
new SymbolData(this, AddEquity("SPY", Resolution.Minute).Symbol)
};
}
public override void OnData(Slice data)
{
var fastFactor = 0.005m;
foreach (var sd in Data)
{
if (!Portfolio.Invested && sd.Fast * (1 + fastFactor) > sd.Slow)
{
SetHoldings(sd.Symbol, 0.01);
}
else if (Portfolio.Invested && sd.Fast * (1 - fastFactor) < sd.Slow)
{
Liquidate(sd.Symbol);
}
}
}
public class SymbolData
{
public Symbol Symbol;
public ExponentialMovingAverage Fast;
public ExponentialMovingAverage Slow;
public bool IsCrossed => Fast > Slow;
public SymbolData(QCAlgorithm algorithm, Symbol symbol) {
Symbol = symbol;
Fast = algorithm.EMA(symbol, 20);
Slow = algorithm.EMA(symbol, 300);
}
}
/// <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; } = false;
/// <summary>
/// This is used by the regression test system to indicate which languages this algorithm is written in.
/// </summary>
public Language[] Languages { get; } = { Language.CSharp };
/// <summary>
/// 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", "1015"},
{"Average Win", "0.01%"},
{"Average Loss", "0.00%"},
{"Compounding Annual Return", "-12.674%"},
{"Drawdown", "1.400%"},
{"Expectancy", "-0.761"},
{"Net Profit", "-1.328%"},
{"Sharpe Ratio", "-12.258"},
{"Probabilistic Sharpe Ratio", "0.000%"},
{"Loss Rate", "95%"},
{"Win Rate", "5%"},
{"Profit-Loss Ratio", "3.67"},
{"Alpha", "-0.142"},
{"Beta", "0.038"},
{"Annual Standard Deviation", "0.01"},
{"Annual Variance", "0"},
{"Information Ratio", "-4.389"},
{"Tracking Error", "0.123"},
{"Treynor Ratio", "-3.359"},
{"Total Fees", "$1125.52"},
{"Estimated Strategy Capacity", "$300.00"},
{"Fitness Score", "0.007"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "-14.315"},
{"Return Over Maximum Drawdown", "-9.589"},
{"Portfolio Turnover", "0.406"},
{"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", "4c165e8d648d54a85bb7b564050a6f85"}
};
}
}

View File

@@ -0,0 +1,117 @@
/*
* 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.Indicators;
using QuantConnect.Interfaces;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Scalps SPY using an EMA cross strategy at minute resolution.
/// This tests equity strategies that trade at a higher frequency, which
/// should have a reduced capacity estimate as a result.
/// </summary>
public class IntradayMinuteScalping : QCAlgorithm, IRegressionAlgorithmDefinition
{
private Symbol _spy;
private ExponentialMovingAverage _fast;
private ExponentialMovingAverage _slow;
public override void Initialize()
{
SetStartDate(2020, 1, 1);
SetEndDate(2020, 1, 30);
SetCash(100000);
SetWarmup(100);
_spy = AddEquity("SPY", Resolution.Minute).Symbol;
_fast = EMA(_spy, 20);
_slow = EMA(_spy, 40);
}
public override void OnData(Slice data)
{
if (Portfolio[_spy].Quantity <= 0 && _fast > _slow)
{
SetHoldings(_spy, 1);
}
else if (Portfolio[_spy].Quantity >= 0 && _fast < _slow)
{
SetHoldings(_spy, -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; } = false;
/// <summary>
/// This is used by the regression test system to indicate which languages this algorithm is written in.
/// </summary>
public Language[] Languages { get; } = { Language.CSharp };
/// <summary>
/// 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", "150"},
{"Average Win", "0.16%"},
{"Average Loss", "-0.11%"},
{"Compounding Annual Return", "-19.320%"},
{"Drawdown", "3.900%"},
{"Expectancy", "-0.193"},
{"Net Profit", "-1.730%"},
{"Sharpe Ratio", "-1.606"},
{"Probabilistic Sharpe Ratio", "21.397%"},
{"Loss Rate", "67%"},
{"Win Rate", "33%"},
{"Profit-Loss Ratio", "1.45"},
{"Alpha", "-0.357"},
{"Beta", "0.635"},
{"Annual Standard Deviation", "0.119"},
{"Annual Variance", "0.014"},
{"Information Ratio", "-4.249"},
{"Tracking Error", "0.106"},
{"Treynor Ratio", "-0.302"},
{"Total Fees", "$449.14"},
{"Estimated Strategy Capacity", "$27000000.00"},
{"Fitness Score", "0.088"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "-3.259"},
{"Return Over Maximum Drawdown", "-7.992"},
{"Portfolio Turnover", "14.605"},
{"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", "f5a0e9547f7455004fa6c3eb136534e9"}
};
}
}

View File

@@ -0,0 +1,123 @@
/*
* 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.Indicators;
using QuantConnect.Interfaces;
using QuantConnect.Securities;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Scalps BTCETH using an EMA cross strategy at minute resolution.
/// This tests crypto strategies that trade at a higher frequency, which
/// should have a reduced capacity estimate as a result. This also tests
/// that currency conversions are handled properly in the strategy capacity
/// calculation class.
/// </summary>
public class IntradayMinuteScalpingBTCETH : QCAlgorithm, IRegressionAlgorithmDefinition
{
private Symbol _ethbtc;
private ExponentialMovingAverage _fast;
private ExponentialMovingAverage _slow;
public override void Initialize()
{
SetStartDate(2021, 1, 1);
SetEndDate(2021, 1, 30);
SetCash(100000);
SetWarmup(100);
var ethbtc = AddCrypto("ETHBTC", Resolution.Minute, Market.GDAX);
ethbtc.BuyingPowerModel = new BuyingPowerModel();
_ethbtc = ethbtc.Symbol;
_fast = EMA(_ethbtc, 20);
_slow = EMA(_ethbtc, 40);
}
public override void OnData(Slice data)
{
if (Portfolio[_ethbtc].Quantity <= 0 && _fast > _slow)
{
SetHoldings(_ethbtc, 1);
}
else if (Portfolio[_ethbtc].Quantity >= 0 && _fast < _slow)
{
SetHoldings(_ethbtc, -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; } = false;
/// <summary>
/// This is used by the regression test system to indicate which languages this algorithm is written in.
/// </summary>
public Language[] Languages { get; } = { Language.CSharp };
/// <summary>
/// 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", "1005"},
{"Average Win", "0.96%"},
{"Average Loss", "-0.33%"},
{"Compounding Annual Return", "76.267%"},
{"Drawdown", "77.100%"},
{"Expectancy", "-0.012"},
{"Net Profit", "4.768%"},
{"Sharpe Ratio", "1.01909630017278E+24"},
{"Probabilistic Sharpe Ratio", "93.814%"},
{"Loss Rate", "75%"},
{"Win Rate", "25%"},
{"Profit-Loss Ratio", "2.95"},
{"Alpha", "1.3466330963256E+25"},
{"Beta", "25.59"},
{"Annual Standard Deviation", "13.214"},
{"Annual Variance", "174.61"},
{"Information Ratio", "1.02164274756513E+24"},
{"Tracking Error", "13.181"},
{"Treynor Ratio", "5.2622435344112E+23"},
{"Total Fees", "$0.00"},
{"Estimated Strategy Capacity", "$1300000.00"},
{"Fitness Score", "0.38"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "-0.239"},
{"Return Over Maximum Drawdown", "-1.385"},
{"Portfolio Turnover", "81.433"},
{"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", "6a779e7a8d12b4808845c75b88d43b3a"}
};
}
}

View File

@@ -0,0 +1,117 @@
/*
* 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.Indicators;
using QuantConnect.Interfaces;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Scalps EURUSD using an EMA cross strategy at minute resolution.
/// This tests FOREX strategies that trade at a higher frequency, which
/// should have a reduced capacity estimate as a result.
/// </summary>
public class IntradayMinuteScalpingEURUSD : QCAlgorithm, IRegressionAlgorithmDefinition
{
private Symbol _eurusd;
private ExponentialMovingAverage _fast;
private ExponentialMovingAverage _slow;
public override void Initialize()
{
SetStartDate(2021, 1, 1);
SetEndDate(2021, 1, 30);
SetCash(100000);
SetWarmup(100);
_eurusd = AddForex("EURUSD", Resolution.Minute, Market.Oanda).Symbol;
_fast = EMA(_eurusd, 20);
_slow = EMA(_eurusd, 40);
}
public override void OnData(Slice data)
{
if (Portfolio[_eurusd].Quantity <= 0 && _fast > _slow)
{
SetHoldings(_eurusd, 1);
}
else if (Portfolio[_eurusd].Quantity >= 0 && _fast < _slow)
{
SetHoldings(_eurusd, -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; } = false;
/// <summary>
/// This is used by the regression test system to indicate which languages this algorithm is written in.
/// </summary>
public Language[] Languages { get; } = { Language.CSharp };
/// <summary>
/// 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", "671"},
{"Average Win", "0.07%"},
{"Average Loss", "-0.04%"},
{"Compounding Annual Return", "-80.820%"},
{"Drawdown", "12.200%"},
{"Expectancy", "-0.447"},
{"Net Profit", "-12.180%"},
{"Sharpe Ratio", "-13.121"},
{"Probabilistic Sharpe Ratio", "0%"},
{"Loss Rate", "79%"},
{"Win Rate", "21%"},
{"Profit-Loss Ratio", "1.61"},
{"Alpha", "-0.746"},
{"Beta", "-0.02"},
{"Annual Standard Deviation", "0.057"},
{"Annual Variance", "0.003"},
{"Information Ratio", "-4.046"},
{"Tracking Error", "0.161"},
{"Treynor Ratio", "37.346"},
{"Total Fees", "$0.00"},
{"Estimated Strategy Capacity", "$44000000.00"},
{"Fitness Score", "0.025"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "-16.609"},
{"Return Over Maximum Drawdown", "-7.115"},
{"Portfolio Turnover", "52.476"},
{"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", "74ee44736b9300c0262dc75c0cd140e1"}
};
}
}

View File

@@ -0,0 +1,143 @@
/*
* 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.Indicators;
using QuantConnect.Interfaces;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Scalps ES futures contracts (E-mini SP500) using an EMA cross strategy at minute resolution.
/// This tests futures strategies that trade at a higher frequency, which
/// should have a reduced capacity estimate as a result.
/// </summary>
/// <remarks>
/// The insanely high capacity estimate of this strategy is realistic.
/// ES notional contract value traded is around $600 Billion USD per day (!!!), which
/// is what the capacity is set to.
/// </remarks>
public class IntradayMinuteScalpingFuturesES : QCAlgorithm, IRegressionAlgorithmDefinition
{
private ExponentialMovingAverage _fast;
private ExponentialMovingAverage _slow;
private Symbol _contract;
public override void Initialize()
{
SetStartDate(2021, 1, 1);
SetEndDate(2021, 1, 31);
SetCash(100000);
SetWarmup(1000);
var a = AddFuture("ES", Resolution.Minute, Market.CME);
a.SetFilter(0, 10000);
}
public override void OnData(Slice data)
{
var contract = data.FutureChains.Values.SelectMany(c => c.Contracts.Values)
.OrderBy(c => c.Symbol.ID.Date)
.FirstOrDefault()?
.Symbol;
if (contract == null)
{
return;
}
if (_contract != contract || (_fast == null && _slow == null))
{
_fast = EMA(contract, 10);
_slow = EMA(contract, 20);
_contract = contract;
}
if (!_fast.IsReady || !_slow.IsReady)
{
return;
}
if (!Portfolio.ContainsKey(contract) || (Portfolio[contract].Quantity <= 0 && _fast > _slow))
{
SetHoldings(contract, 1);
}
else if (Portfolio.ContainsKey(contract) && Portfolio[contract].Quantity >= 0 && _fast < _slow)
{
SetHoldings(contract, -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; } = false;
/// <summary>
/// This is used by the regression test system to indicate which languages this algorithm is written in.
/// </summary>
public Language[] Languages { get; } = { Language.CSharp };
/// <summary>
/// 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", "1217"},
{"Average Win", "2.69%"},
{"Average Loss", "-0.93%"},
{"Compounding Annual Return", "-99.756%"},
{"Drawdown", "77.200%"},
{"Expectancy", "-0.047"},
{"Net Profit", "-40.013%"},
{"Sharpe Ratio", "-0.52"},
{"Probabilistic Sharpe Ratio", "19.865%"},
{"Loss Rate", "75%"},
{"Win Rate", "25%"},
{"Profit-Loss Ratio", "2.88"},
{"Alpha", "-1.279"},
{"Beta", "-3.686"},
{"Annual Standard Deviation", "1.85"},
{"Annual Variance", "3.422"},
{"Information Ratio", "-0.463"},
{"Tracking Error", "1.895"},
{"Treynor Ratio", "0.261"},
{"Total Fees", "$19843.10"},
{"Estimated Strategy Capacity", "$560000000.00"},
{"Fitness Score", "0.334"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "-0.837"},
{"Return Over Maximum Drawdown", "-1.402"},
{"Portfolio Turnover", "1174.125"},
{"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", "f353843132df7b0604eff3a37b134ca2"}
};
}
}

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 System.Collections.Generic;
using QuantConnect.Data;
using QuantConnect.Indicators;
using QuantConnect.Interfaces;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Scalps GBPJPY using an EMA cross strategy at minute resolution.
/// This tests FOREX strategies that trade at a higher frequency, which
/// should have a reduced capacity estimate as a result. This test also
/// tests that currency conversion rates are applied and calculated correctly.
/// </summary>
public class IntradayMinuteScalpingGBPJPY : QCAlgorithm, IRegressionAlgorithmDefinition
{
private Symbol _gbpjpy;
private ExponentialMovingAverage _fast;
private ExponentialMovingAverage _slow;
public override void Initialize()
{
SetStartDate(2021, 1, 1);
SetEndDate(2021, 1, 30);
SetCash(100000);
SetWarmup(100);
_gbpjpy = AddForex("GBPJPY", Resolution.Minute, Market.Oanda).Symbol;
_fast = EMA(_gbpjpy, 20);
_slow = EMA(_gbpjpy, 40);
}
public override void OnData(Slice data)
{
if (Portfolio[_gbpjpy].Quantity <= 0 && _fast > _slow)
{
SetHoldings(_gbpjpy, 1);
}
else if (Portfolio[_gbpjpy].Quantity >= 0 && _fast < _slow)
{
SetHoldings(_gbpjpy, -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; } = false;
/// <summary>
/// This is used by the regression test system to indicate which languages this algorithm is written in.
/// </summary>
public Language[] Languages { get; } = { Language.CSharp };
/// <summary>
/// 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", "735"},
{"Average Win", "0.08%"},
{"Average Loss", "-0.05%"},
{"Compounding Annual Return", "-93.946%"},
{"Drawdown", "19.900%"},
{"Expectancy", "-0.592"},
{"Net Profit", "-19.794%"},
{"Sharpe Ratio", "-10.054"},
{"Probabilistic Sharpe Ratio", "0%"},
{"Loss Rate", "84%"},
{"Win Rate", "16%"},
{"Profit-Loss Ratio", "1.56"},
{"Alpha", "-0.895"},
{"Beta", "0.068"},
{"Annual Standard Deviation", "0.09"},
{"Annual Variance", "0.008"},
{"Information Ratio", "-4.929"},
{"Tracking Error", "0.164"},
{"Treynor Ratio", "-13.276"},
{"Total Fees", "$0.00"},
{"Estimated Strategy Capacity", "$49000000.00"},
{"Fitness Score", "0.049"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "-10.846"},
{"Return Over Maximum Drawdown", "-4.904"},
{"Portfolio Turnover", "58.921"},
{"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", "66f04c9622ab242993c8ce951418e6d9"}
};
}
}

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 System.Collections.Generic;
using QuantConnect.Data;
using QuantConnect.Indicators;
using QuantConnect.Interfaces;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Scalps TRYJPY using an EMA cross strategy at minute resolution.
/// This tests FOREX strategies that trade at a higher frequency, which
/// should have a reduced capacity estimate as a result. This tests that
/// currency conversions are applied properly to the capacity estimate calculation.
/// </summary>
public class IntradayMinuteScalpingTRYJPY : QCAlgorithm, IRegressionAlgorithmDefinition
{
private Symbol _tryjpy;
private ExponentialMovingAverage _fast;
private ExponentialMovingAverage _slow;
public override void Initialize()
{
SetStartDate(2021, 1, 1);
SetEndDate(2021, 1, 30);
SetCash(100000);
SetWarmup(100);
_tryjpy = AddForex("TRYJPY", Resolution.Minute, Market.Oanda).Symbol;
_fast = EMA(_tryjpy, 20);
_slow = EMA(_tryjpy, 40);
}
public override void OnData(Slice data)
{
if (Portfolio[_tryjpy].Quantity <= 0 && _fast > _slow)
{
SetHoldings(_tryjpy, 1);
}
else if (Portfolio[_tryjpy].Quantity >= 0 && _fast < _slow)
{
SetHoldings(_tryjpy, -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; } = false;
/// <summary>
/// This is used by the regression test system to indicate which languages this algorithm is written in.
/// </summary>
public Language[] Languages { get; } = { Language.CSharp };
/// <summary>
/// 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", "603"},
{"Average Win", "0.20%"},
{"Average Loss", "-0.26%"},
{"Compounding Annual Return", "-100.000%"},
{"Drawdown", "73.200%"},
{"Expectancy", "-0.849"},
{"Net Profit", "-73.118%"},
{"Sharpe Ratio", "-2.046"},
{"Probabilistic Sharpe Ratio", "0%"},
{"Loss Rate", "91%"},
{"Win Rate", "9%"},
{"Profit-Loss Ratio", "0.75"},
{"Alpha", "-0.95"},
{"Beta", "0.541"},
{"Annual Standard Deviation", "0.489"},
{"Annual Variance", "0.239"},
{"Information Ratio", "-1.863"},
{"Tracking Error", "0.487"},
{"Treynor Ratio", "-1.849"},
{"Total Fees", "$0.00"},
{"Estimated Strategy Capacity", "$4400000.00"},
{"Fitness Score", "0.259"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "-2.135"},
{"Return Over Maximum Drawdown", "-1.389"},
{"Portfolio Turnover", "49.501"},
{"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", "4eb4d703a9f200b6bb3d8b0ebbc9db7f"}
};
}
}

View File

@@ -0,0 +1,111 @@
/*
* 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>
/// Rebalances ultra-liquid stocks monthly, testing
/// bursts of orders centered around the start of the month at Daily resolution
/// </summary>
public class MonthlyRebalanceDaily : QCAlgorithm, IRegressionAlgorithmDefinition
{
public override void Initialize()
{
SetStartDate(2019, 12, 31);
SetEndDate(2020, 4, 5);
SetCash(100000);
var spy = AddEquity("SPY", Resolution.Daily).Symbol;
AddEquity("GE", Resolution.Daily);
AddEquity("FB", Resolution.Daily);
AddEquity("DIS", Resolution.Daily);
AddEquity("CSCO", Resolution.Daily);
AddEquity("CRM", Resolution.Daily);
AddEquity("C", Resolution.Daily);
AddEquity("BAC", Resolution.Daily);
AddEquity("BABA", Resolution.Daily);
AddEquity("AAPL", Resolution.Daily);
Schedule.On(DateRules.MonthStart(spy), TimeRules.Noon, () =>
{
foreach (var symbol in Securities.Keys)
{
SetHoldings(symbol, 0.10);
}
});
}
/// <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; } = false;
/// <summary>
/// This is used by the regression test system to indicate which languages this algorithm is written in.
/// </summary>
public Language[] Languages { get; } = { Language.CSharp };
/// <summary>
/// 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", "35"},
{"Average Win", "0.07%"},
{"Average Loss", "-0.07%"},
{"Compounding Annual Return", "-68.407%"},
{"Drawdown", "32.400%"},
{"Expectancy", "-0.309"},
{"Net Profit", "-25.901%"},
{"Sharpe Ratio", "-1.503"},
{"Probabilistic Sharpe Ratio", "2.878%"},
{"Loss Rate", "64%"},
{"Win Rate", "36%"},
{"Profit-Loss Ratio", "0.90"},
{"Alpha", "-0.7"},
{"Beta", "-0.238"},
{"Annual Standard Deviation", "0.386"},
{"Annual Variance", "0.149"},
{"Information Ratio", "-0.11"},
{"Tracking Error", "0.712"},
{"Treynor Ratio", "2.442"},
{"Total Fees", "$38.99"},
{"Estimated Strategy Capacity", "$19000000.00"},
{"Fitness Score", "0.003"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "-2.021"},
{"Return Over Maximum Drawdown", "-2.113"},
{"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", "76d8164a3c0d4a7d45e94367c4ba5be1"}
};
}
}

View File

@@ -0,0 +1,111 @@
/*
* 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>
/// Rebalances ultra-liquid stocks monthly, testing
/// bursts of orders centered around the start of the month at Hourly resolution
/// </summary>
public class MonthlyRebalanceHourly : QCAlgorithm, IRegressionAlgorithmDefinition
{
public override void Initialize()
{
SetStartDate(2019, 12, 31);
SetEndDate(2020, 4, 5);
SetCash(100000);
var spy = AddEquity("SPY", Resolution.Hour).Symbol;
AddEquity("GE", Resolution.Hour);
AddEquity("FB", Resolution.Hour);
AddEquity("DIS", Resolution.Hour);
AddEquity("CSCO", Resolution.Hour);
AddEquity("CRM", Resolution.Hour);
AddEquity("C", Resolution.Hour);
AddEquity("BAC", Resolution.Hour);
AddEquity("BABA", Resolution.Hour);
AddEquity("AAPL", Resolution.Hour);
Schedule.On(DateRules.MonthStart(spy), TimeRules.Noon, () =>
{
foreach (var symbol in Securities.Keys)
{
SetHoldings(symbol, 0.10);
}
});
}
/// <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; } = false;
/// <summary>
/// This is used by the regression test system to indicate which languages this algorithm is written in.
/// </summary>
public Language[] Languages { get; } = { Language.CSharp };
/// <summary>
/// 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", "35"},
{"Average Win", "0.05%"},
{"Average Loss", "-0.10%"},
{"Compounding Annual Return", "-72.444%"},
{"Drawdown", "36.500%"},
{"Expectancy", "-0.449"},
{"Net Profit", "-28.406%"},
{"Sharpe Ratio", "-1.369"},
{"Probabilistic Sharpe Ratio", "4.398%"},
{"Loss Rate", "64%"},
{"Win Rate", "36%"},
{"Profit-Loss Ratio", "0.51"},
{"Alpha", "-0.175"},
{"Beta", "0.892"},
{"Annual Standard Deviation", "0.503"},
{"Annual Variance", "0.253"},
{"Information Ratio", "-0.822"},
{"Tracking Error", "0.138"},
{"Treynor Ratio", "-0.772"},
{"Total Fees", "$38.83"},
{"Estimated Strategy Capacity", "$6000000.00"},
{"Fitness Score", "0.004"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "-2.033"},
{"Return Over Maximum Drawdown", "-2.079"},
{"Portfolio Turnover", "0.018"},
{"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", "1de9bcf6cda0945af6ba1f74c4dcb22c"}
};
}
}

View File

@@ -0,0 +1,112 @@
/*
* 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>
/// Tests that splits do not cause the algorithm to report capacity estimates
/// above or below the actual capacity due to splits. The stock HTGM is illiquid,
/// trading only $1.2 Million per day on average with sparse trade frequencies.
/// </summary>
public class SplitTestingStrategy : QCAlgorithm, IRegressionAlgorithmDefinition
{
private Symbol _htgm;
public override void Initialize()
{
SetStartDate(2020, 11, 1);
SetEndDate(2020, 12, 5);
SetCash(100000);
var htgm = AddEquity("HTGM", Resolution.Hour);
htgm.SetDataNormalizationMode(DataNormalizationMode.Raw);
_htgm = htgm.Symbol;
}
public override void OnData(Slice data)
{
if (!Portfolio.Invested)
{
SetHoldings(_htgm, 1);
}
else
{
SetHoldings(_htgm, -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; } = false;
/// <summary>
/// This is used by the regression test system to indicate which languages this algorithm is written in.
/// </summary>
public Language[] Languages { get; } = { Language.CSharp };
/// <summary>
/// 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", "162"},
{"Average Win", "0.10%"},
{"Average Loss", "-0.35%"},
{"Compounding Annual Return", "-94.432%"},
{"Drawdown", "30.400%"},
{"Expectancy", "-0.564"},
{"Net Profit", "-23.412%"},
{"Sharpe Ratio", "-1.041"},
{"Probabilistic Sharpe Ratio", "12.971%"},
{"Loss Rate", "66%"},
{"Win Rate", "34%"},
{"Profit-Loss Ratio", "0.29"},
{"Alpha", "-4.827"},
{"Beta", "1.43"},
{"Annual Standard Deviation", "0.876"},
{"Annual Variance", "0.767"},
{"Information Ratio", "-4.288"},
{"Tracking Error", "0.851"},
{"Treynor Ratio", "-0.637"},
{"Total Fees", "$2655.91"},
{"Estimated Strategy Capacity", "$11000.00"},
{"Fitness Score", "0.052"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "-2.2"},
{"Return Over Maximum Drawdown", "-3.481"},
{"Portfolio Turnover", "0.307"},
{"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", "54f571c11525656e9b383e235e77002e"}
};
}
}

View File

@@ -0,0 +1,103 @@
/*
* 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>
/// Rebalances between SPY and BND. Tests capacity of the weakest link, which in this
/// case is BND, dragging down the capacity estimate.
/// </summary>
public class SpyBondPortfolioRebalance : QCAlgorithm, IRegressionAlgorithmDefinition
{
private Symbol _spy;
public override void Initialize()
{
SetStartDate(2020, 1, 1);
SetEndDate(2020, 3, 31);
SetCash(10000);
_spy = AddEquity("SPY", Resolution.Hour).Symbol;
var bnd = AddEquity("BND", Resolution.Hour).Symbol;
Schedule.On(DateRules.EveryDay(_spy), TimeRules.AfterMarketOpen(_spy, 1, false), () =>
{
SetHoldings(_spy, 0.5m);
SetHoldings(bnd, 0.5m);
});
}
/// <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; } = false;
/// <summary>
/// This is used by the regression test system to indicate which languages this algorithm is written in.
/// </summary>
public Language[] Languages { get; } = { Language.CSharp };
/// <summary>
/// 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", "21"},
{"Average Win", "0.02%"},
{"Average Loss", "-0.03%"},
{"Compounding Annual Return", "-33.564%"},
{"Drawdown", "19.700%"},
{"Expectancy", "-0.140"},
{"Net Profit", "-9.655%"},
{"Sharpe Ratio", "-0.99"},
{"Probabilistic Sharpe Ratio", "13.754%"},
{"Loss Rate", "50%"},
{"Win Rate", "50%"},
{"Profit-Loss Ratio", "0.72"},
{"Alpha", "-0.022"},
{"Beta", "0.538"},
{"Annual Standard Deviation", "0.309"},
{"Annual Variance", "0.096"},
{"Information Ratio", "0.826"},
{"Tracking Error", "0.269"},
{"Treynor Ratio", "-0.569"},
{"Total Fees", "$21.00"},
{"Estimated Strategy Capacity", "$1100000.00"},
{"Fitness Score", "0.005"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "-1.524"},
{"Return Over Maximum Drawdown", "-1.688"},
{"Portfolio Turnover", "0.02"},
{"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", "95a130426900aaf227a08a5d1c617b2b"}
};
}
}

View File

@@ -95,6 +95,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Tracking Error", "0"},
{"Treynor Ratio", "0"},
{"Total Fees", "$0.00"},
{"Estimated Strategy Capacity", "$0"},
{"Fitness Score", "0.5"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
@@ -114,7 +115,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "1456907343"}
{"OrderListHash", "6ea6184a2a8d0d69e552ad866933bfb6"}
};
}
}

View File

@@ -181,6 +181,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Tracking Error", "0.149"},
{"Treynor Ratio", "-1.405"},
{"Total Fees", "$2.00"},
{"Estimated Strategy Capacity", "$6000000.00"},
{"Fitness Score", "0.076"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
@@ -200,7 +201,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "-1465929889"}
{"OrderListHash", "edd9e9ffc8a1cdfb7a1e6ae601e61b12"}
};
}
}

View File

@@ -0,0 +1,190 @@
/*
* 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;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Demonstration of how to chain a coarse and fine universe selection with an option chain universe selection model
/// that will add and remove an <see cref="OptionChainUniverse"/> for each symbol selected on fine
/// </summary>
public class CoarseFineOptionUniverseChainRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
{
// initialize our changes to nothing
private SecurityChanges _changes = SecurityChanges.None;
private int _optionCount;
private Symbol _lastEquityAdded;
private Symbol _aapl;
private Symbol _twx;
public override void Initialize()
{
_twx = QuantConnect.Symbol.Create("TWX", SecurityType.Equity, Market.USA);
_aapl = QuantConnect.Symbol.Create("AAPL", SecurityType.Equity, Market.USA);
UniverseSettings.Resolution = Resolution.Minute;
SetStartDate(2014, 06, 05);
SetEndDate(2014, 06, 06);
var selectionUniverse = AddUniverse(enumerable => new[] { Time.Date <= new DateTime(2014, 6, 5) ? _twx : _aapl },
enumerable => new[] { Time.Date <= new DateTime(2014, 6, 5) ? _twx : _aapl });
AddUniverseOptions(selectionUniverse, universe =>
{
if (universe.Underlying == null)
{
throw new Exception("Underlying data point is null! This shouldn't happen, each OptionChainUniverse handles and should provide this");
}
return universe.IncludeWeeklys()
.FrontMonth()
.Contracts(universe.Take(5));
});
}
public override void OnData(Slice data)
{
// if we have no changes, do nothing
if (_changes == SecurityChanges.None ||
_changes.AddedSecurities.Any(security => security.Price == 0))
{
return;
}
// liquidate removed securities
foreach (var security in _changes.RemovedSecurities)
{
if (security.Invested)
{
Liquidate(security.Symbol);
}
}
foreach (var security in _changes.AddedSecurities)
{
if (!security.Symbol.HasUnderlying)
{
_lastEquityAdded = security.Symbol;
}
else
{
// options added should all match prev added security
if (security.Symbol.Underlying != _lastEquityAdded)
{
throw new Exception($"Unexpected symbol added {security.Symbol}");
}
_optionCount++;
}
SetHoldings(security.Symbol, 0.05m);
var config = SubscriptionManager.SubscriptionDataConfigService.GetSubscriptionDataConfigs(security.Symbol).ToList();
if (!config.Any())
{
throw new Exception($"Was expecting configurations for {security.Symbol}");
}
if (config.Any(dataConfig => dataConfig.DataNormalizationMode != DataNormalizationMode.Raw))
{
throw new Exception($"Was expecting DataNormalizationMode.Raw configurations for {security.Symbol}");
}
}
_changes = SecurityChanges.None;
}
public override void OnSecuritiesChanged(SecurityChanges changes)
{
_changes += changes;
}
public override void OnEndOfAlgorithm()
{
var config = SubscriptionManager.Subscriptions.ToList();
if (config.Any(dataConfig => dataConfig.Symbol == _twx || dataConfig.Symbol.Underlying == _twx))
{
throw new Exception($"Was NOT expecting any configurations for {_twx} or it's options, since coarse/fine should have deselected it");
}
if (_optionCount == 0)
{
throw new Exception("Option universe chain did not add any option!");
}
}
/// <summary>
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
/// </summary>
public bool CanRunLocally { get; } = true;
/// <summary>
/// This is used by the regression test system to indicate which languages this algorithm is written in.
/// </summary>
public Language[] Languages { get; } = { Language.CSharp, Language.Python };
/// <summary>
/// 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", "13"},
{"Average Win", "0.65%"},
{"Average Loss", "-0.05%"},
{"Compounding Annual Return", "3216040423556140000000000%"},
{"Drawdown", "0.500%"},
{"Expectancy", "1.393"},
{"Net Profit", "32.840%"},
{"Sharpe Ratio", "7.14272222483913E+15"},
{"Probabilistic Sharpe Ratio", "0%"},
{"Loss Rate", "83%"},
{"Win Rate", "17%"},
{"Profit-Loss Ratio", "13.36"},
{"Alpha", "2.59468989671647E+16"},
{"Beta", "67.661"},
{"Annual Standard Deviation", "3.633"},
{"Annual Variance", "13.196"},
{"Information Ratio", "7.24987266907741E+15"},
{"Tracking Error", "3.579"},
{"Treynor Ratio", "383485597312030"},
{"Total Fees", "$13.00"},
{"Estimated Strategy Capacity", "$3000000.00"},
{"Fitness Score", "0.232"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "79228162514264337593543950335"},
{"Return Over Maximum Drawdown", "79228162514264337593543950335"},
{"Portfolio Turnover", "0.232"},
{"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", "12470afd9a74ad9c9802361f6f092777"}
};
}
}

View File

@@ -136,6 +136,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Tracking Error", "0.126"},
{"Treynor Ratio", "-0.607"},
{"Total Fees", "$11.63"},
{"Estimated Strategy Capacity", "$13000000.00"},
{"Fitness Score", "0.013"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
@@ -155,7 +156,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "-1623759093"}
{"OrderListHash", "3d1ae61492b34c39115b76757510c058"}
};
}
}

View File

@@ -114,6 +114,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Tracking Error", "0.096"},
{"Treynor Ratio", "0"},
{"Total Fees", "$0.00"},
{"Estimated Strategy Capacity", "$0"},
{"Fitness Score", "0"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
@@ -133,7 +134,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "371857150"}
{"OrderListHash", "d41d8cd98f00b204e9800998ecf8427e"}
};
}
}

View File

@@ -120,6 +120,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Tracking Error", "0.105"},
{"Treynor Ratio", "1.667"},
{"Total Fees", "$2.91"},
{"Estimated Strategy Capacity", "$96000000.00"},
{"Fitness Score", "0.141"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
@@ -139,7 +140,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "-1959413055"}
{"OrderListHash", "718d73fbddccb63aeacbf4659938b4b8"}
};
}
}

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 QuantConnect.Interfaces;
using System.Collections.Generic;
using System.Linq;
using QuantConnect.Data;
using QuantConnect.Data.Custom.Tiingo;
using QuantConnect.Data.UniverseSelection;
using QuantConnect.Securities;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Example algorithm of a custom universe selection using coarse data and adding TiingoNews
/// If conditions are met will add the underlying and trade it
/// </summary>
public class CoarseTiingoNewsUniverseSelectionAlgorithm : QCAlgorithm
{
private const int NumberOfSymbols = 3;
private List<Symbol> _symbols;
public override void Initialize()
{
SetStartDate(2014, 03, 24);
SetEndDate(2014, 04, 07);
UniverseSettings.FillForward = false;
AddUniverse(new CustomDataCoarseFundamentalUniverse(UniverseSettings, SecurityInitializer, CoarseSelectionFunction));
_symbols = new List<Symbol>();
}
// sort the data by daily dollar volume and take the top 'NumberOfSymbols'
public IEnumerable<Symbol> CoarseSelectionFunction(IEnumerable<CoarseFundamental> coarse)
{
// sort descending by daily dollar volume
var sortedByDollarVolume = coarse.OrderByDescending(x => x.DollarVolume);
// take the top entries from our sorted collection
var top = sortedByDollarVolume.Take(NumberOfSymbols);
// we need to return only the symbol objects
return top.Select(x => QuantConnect.Symbol.CreateBase(typeof(TiingoNews), x.Symbol, x.Symbol.ID.Market));
}
public override void OnData(Slice data)
{
var articles = data.Get<TiingoNews>();
foreach (var kvp in articles)
{
var news = kvp.Value;
if (news.Title.IndexOf("Stocks Drop", 0, StringComparison.CurrentCultureIgnoreCase) != -1)
{
if (!Securities.ContainsKey(kvp.Key.Underlying))
{
// add underlying we want to trade
AddSecurity(kvp.Key.Underlying);
_symbols.Add(kvp.Key.Underlying);
}
}
}
foreach (var symbol in _symbols)
{
if (Securities[symbol].HasData)
{
SetHoldings(symbol, 1m / _symbols.Count);
}
}
}
public override void OnSecuritiesChanged(SecurityChanges changes)
{
changes.FilterCustomSecurities = false;
Log($"{Time} {changes}");
}
private class CustomDataCoarseFundamentalUniverse : CoarseFundamentalUniverse
{
public CustomDataCoarseFundamentalUniverse(UniverseSettings universeSettings, ISecurityInitializer securityInitializer, Func<IEnumerable<CoarseFundamental>, IEnumerable<Symbol>> selector)
: base(universeSettings, securityInitializer, selector)
{ }
public override IEnumerable<SubscriptionRequest> GetSubscriptionRequests(Security security, DateTime currentTimeUtc, DateTime maximumEndTimeUtc,
ISubscriptionDataConfigService subscriptionService)
{
var config = subscriptionService.Add(
typeof(TiingoNews),
security.Symbol,
UniverseSettings.Resolution,
UniverseSettings.FillForward,
UniverseSettings.ExtendedMarketHours,
dataNormalizationMode: UniverseSettings.DataNormalizationMode);
return new[]{new SubscriptionRequest(isUniverseSubscription: false,
universe: this,
security: security,
configuration: config,
startTimeUtc: currentTimeUtc,
endTimeUtc: maximumEndTimeUtc)};
}
}
}
}

View File

@@ -91,6 +91,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Tracking Error", "0.101"},
{"Treynor Ratio", "5.409"},
{"Total Fees", "$67.00"},
{"Estimated Strategy Capacity", "$2400000.00"},
{"Fitness Score", "0.501"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
@@ -110,7 +111,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "-28636839"}
{"OrderListHash", "ba44309886ea8ff515ef593a24456c47"}
};
}
}

View File

@@ -85,6 +85,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Tracking Error", "0.009"},
{"Treynor Ratio", "1.575"},
{"Total Fees", "$22.77"},
{"Estimated Strategy Capacity", "$19000000.00"},
{"Fitness Score", "0.999"},
{"Kelly Criterion Estimate", "38.64"},
{"Kelly Criterion Probability Value", "0.229"},
@@ -104,7 +105,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Mean Population Magnitude", "54.5455%"},
{"Rolling Averaged Population Direction", "59.8056%"},
{"Rolling Averaged Population Magnitude", "59.8056%"},
{"OrderListHash", "-1225025518"}
{"OrderListHash", "e0f388bf9e88b34388c866150b292573"}
};
}
}

View File

@@ -94,6 +94,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Tracking Error", "0.165"},
{"Treynor Ratio", "1.212"},
{"Total Fees", "$6.00"},
{"Estimated Strategy Capacity", "$32000000.00"},
{"Fitness Score", "0.063"},
{"Kelly Criterion Estimate", "38.64"},
{"Kelly Criterion Probability Value", "0.229"},
@@ -113,7 +114,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Mean Population Magnitude", "54.5455%"},
{"Rolling Averaged Population Direction", "59.8056%"},
{"Rolling Averaged Population Magnitude", "59.8056%"},
{"OrderListHash", "501060991"}
{"OrderListHash", "07eb3e2c199575b547459a534057eb5e"}
};
}
}

View File

@@ -164,6 +164,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Tracking Error", "0.441"},
{"Treynor Ratio", "-0.008"},
{"Total Fees", "$20.35"},
{"Estimated Strategy Capacity", "$19000000.00"},
{"Fitness Score", "0.138"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
@@ -183,7 +184,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "-1453269600"}
{"OrderListHash", "7c841ca58a4385f42236838e5bf0c382"}
};
}
}

View File

@@ -190,6 +190,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Tracking Error", "0.176"},
{"Treynor Ratio", "-1.46"},
{"Total Fees", "$7.82"},
{"Estimated Strategy Capacity", "$6000000.00"},
{"Fitness Score", "0.1"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
@@ -209,7 +210,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "-611289773"}
{"OrderListHash", "71984e154883ece4aef1d71bafbfccaf"}
};
}
}

View File

@@ -144,8 +144,9 @@ namespace QuantConnect.Algorithm.CSharp
{"Annual Variance", "0.027"},
{"Information Ratio", "-0.391"},
{"Tracking Error", "0.239"},
{"Treynor Ratio", "-1.416"},
{"Treynor Ratio", "-1.435"},
{"Total Fees", "$755.29"},
{"Estimated Strategy Capacity", "$150000000.00"},
{"Fitness Score", "0.024"},
{"Kelly Criterion Estimate", "-0.84"},
{"Kelly Criterion Probability Value", "0.53"},
@@ -165,7 +166,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "48.2217%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "1370210213"}
{"OrderListHash", "95f34359f25a7a7a2725f0343a75a105"}
};
}
}

View File

@@ -38,6 +38,10 @@ namespace QuantConnect.Algorithm.CSharp
// Find more symbols here: http://quantconnect.com/data
AddSecurity(SecurityType.Equity, "SPY", Resolution.Second);
// Disabling the benchmark / setting to a fixed value
// SetBenchmark(time => 0);
// Set the benchmark to AAPL US Equity
SetBenchmark("AAPL");
}
@@ -95,6 +99,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Tracking Error", "0.168"},
{"Treynor Ratio", "2.38"},
{"Total Fees", "$3.26"},
{"Estimated Strategy Capacity", "$75000000.00"},
{"Fitness Score", "0.245"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
@@ -114,7 +119,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "2069976135"}
{"OrderListHash", "9cd604d2c1e3c273697e2ff2cc7faef1"}
};
}
}

View File

@@ -96,6 +96,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Tracking Error", "0"},
{"Treynor Ratio", "0.988"},
{"Total Fees", "$7.78"},
{"Estimated Strategy Capacity", "$2200000.00"},
{"Fitness Score", "0.031"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
@@ -115,7 +116,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "519536519"}
{"OrderListHash", "be3334e4aeb9dd7cca4ecc07419d0f95"}
};
}
}

View File

@@ -0,0 +1,139 @@
/*
* 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.Securities;
using System.Collections.Generic;
using QuantConnect.Data;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Demonstration of using custom buying power model in backtesting.
/// QuantConnect allows you to model all orders as deeply and accurately as you need.
/// </summary>
/// <meta name="tag" content="trading and orders" />
/// <meta name="tag" content="transaction fees and slippage" />
/// <meta name="tag" content="custom buying power models" />
public class CustomBuyingPowerModelAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
{
private Symbol _spy;
public override void Initialize()
{
SetStartDate(2013, 10, 01);
SetEndDate(2013, 10, 31);
var security = AddEquity("SPY", Resolution.Hour);
_spy = security.Symbol;
// set the buying power model
security.SetBuyingPowerModel(new CustomBuyingPowerModel());
}
public void OnData(Slice slice)
{
if (Portfolio.Invested)
{
return;
}
var quantity = CalculateOrderQuantity(_spy, 1m);
if (quantity % 100 != 0)
{
throw new Exception($"CustomBuyingPowerModel only allow quantity that is multiple of 100 and {quantity} was found");
}
// We normally get insufficient buying power model, but the
// CustomBuyingPowerModel always says that there is sufficient buying power for the orders
MarketOrder(_spy, quantity * 10);
}
public class CustomBuyingPowerModel : BuyingPowerModel
{
public override GetMaximumOrderQuantityResult GetMaximumOrderQuantityForTargetBuyingPower(
GetMaximumOrderQuantityForTargetBuyingPowerParameters parameters)
{
var quantity = base.GetMaximumOrderQuantityForTargetBuyingPower(parameters).Quantity;
quantity = Math.Floor(quantity / 100) * 100;
return new GetMaximumOrderQuantityResult(quantity);
}
public override HasSufficientBuyingPowerForOrderResult HasSufficientBuyingPowerForOrder(
HasSufficientBuyingPowerForOrderParameters parameters)
{
return new HasSufficientBuyingPowerForOrderResult(true);
}
}
/// <summary>
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
/// </summary>
public bool CanRunLocally { get; } = true;
/// <summary>
/// This is used by the regression test system to indicate which languages this algorithm is written in.
/// </summary>
public Language[] Languages { get; } = { Language.CSharp, Language.Python };
/// <summary>
/// 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"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "5672.520%"},
{"Drawdown", "22.500%"},
{"Expectancy", "0"},
{"Net Profit", "40.601%"},
{"Sharpe Ratio", "40.201"},
{"Probabilistic Sharpe Ratio", "77.339%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "41.848"},
{"Beta", "9.224"},
{"Annual Standard Deviation", "1.164"},
{"Annual Variance", "1.355"},
{"Information Ratio", "44.459"},
{"Tracking Error", "1.04"},
{"Treynor Ratio", "5.073"},
{"Total Fees", "$30.00"},
{"Estimated Strategy Capacity", "$2800000.00"},
{"Fitness Score", "0.418"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "113.05"},
{"Return Over Maximum Drawdown", "442.81"},
{"Portfolio Turnover", "0.418"},
{"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", "b88362c462e9ab2942cbcb8dfddc6ce0"}
};
}
}

View File

@@ -119,6 +119,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Tracking Error", "0.112"},
{"Treynor Ratio", "-6.121"},
{"Total Fees", "$3.50"},
{"Estimated Strategy Capacity", "$6900000.00"},
{"Fitness Score", "0"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
@@ -138,7 +139,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "559673838"}
{"OrderListHash", "6b05339bfcb5bd93bfd66e32a1d2181a"}
};
}
}

View File

@@ -124,6 +124,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Tracking Error", "0.112"},
{"Treynor Ratio", "-6.121"},
{"Total Fees", "$3.50"},
{"Estimated Strategy Capacity", "$6900000.00"},
{"Fitness Score", "0"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
@@ -143,7 +144,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "559673838"}
{"OrderListHash", "6b05339bfcb5bd93bfd66e32a1d2181a"}
};
}
}

View File

@@ -131,6 +131,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Tracking Error", "0.19"},
{"Treynor Ratio", "2.159"},
{"Total Fees", "$1.00"},
{"Estimated Strategy Capacity", "$14000000.00"},
{"Fitness Score", "0.1"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
@@ -150,7 +151,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "1531253381"}
{"OrderListHash", "214f38f9084bc350c93010aa2fb69822"}
};
}
}

View File

@@ -0,0 +1,261 @@
/*
* 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.Globalization;
using Newtonsoft.Json;
using QuantConnect.Data;
using QuantConnect.Interfaces;
using QuantConnect.Securities;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Regression test to demonstrate setting custom Symbol Properties and Market Hours for a custom data import
/// </summary>
/// <meta name="tag" content="using data" />
/// <meta name="tag" content="custom data" />
/// <meta name="tag" content="crypto" />
/// <meta name="tag" content="regression test" />
public class CustomDataPropertiesRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
{
private string _ticker = "BTC";
private Security _bitcoin;
/// <summary>
/// Initialize 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(2011, 9, 13);
SetEndDate(2015, 12, 01);
//Set the cash for the strategy:
SetCash(100000);
// Define our custom data properties and exchange hours
var properties = new SymbolProperties("Bitcoin", "USD", 1, 0.01m, 0.01m, _ticker);
var exchangeHours = SecurityExchangeHours.AlwaysOpen(TimeZones.NewYork);
// Add the custom data to our algorithm with our custom properties and exchange hours
_bitcoin = AddData<Bitcoin>(_ticker, properties, exchangeHours);
//Verify our symbol properties were changed and loaded into this security
if (_bitcoin.SymbolProperties != properties)
{
throw new Exception("Failed to set and retrieve custom SymbolProperties for BTC");
}
//Verify our exchange hours were changed and loaded into this security
if (_bitcoin.Exchange.Hours != exchangeHours)
{
throw new Exception("Failed to set and retrieve custom ExchangeHours for BTC");
}
// For regression purposes on AddData overloads, this call is simply to ensure Lean can accept this
// with default params and is not routed to a breaking function.
AddData<Bitcoin>("BTCUSD");
}
/// <summary>
/// Event Handler for Bitcoin Data Events: These Bitcoin objects are created from our
/// "Bitcoin" type below and fired into this event handler.
/// </summary>
/// <param name="data">One(1) Bitcoin Object, streamed into our algorithm synchronized in time with our other data streams</param>
public void OnData(Bitcoin data)
{
//If we don't have any bitcoin "SHARES" -- invest"
if (!Portfolio.Invested)
{
//Bitcoin used as a tradable asset, like stocks, futures etc.
if (data.Close != 0)
{
//Access custom data symbols using <ticker>.<custom-type>
Order("BTC.Bitcoin", Portfolio.MarginRemaining / Math.Abs(data.Close + 1));
}
}
}
public override void OnEndOfAlgorithm()
{
// Reset our Symbol property value, for testing purposes.
SymbolPropertiesDatabase.SetEntry(Market.USA, MarketHoursDatabase.GetDatabaseSymbolKey(_bitcoin.Symbol), SecurityType.Base,
SymbolProperties.GetDefault("USD"));
}
/// <summary>
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
/// </summary>
public bool CanRunLocally { get; } = true;
/// <summary>
/// This is used by the regression test system to indicate which languages this algorithm is written in.
/// </summary>
public Language[] Languages { get; } = { Language.CSharp, Language.Python };
/// <summary>
/// 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"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "155.262%"},
{"Drawdown", "84.800%"},
{"Expectancy", "0"},
{"Net Profit", "5123.242%"},
{"Sharpe Ratio", "2.067"},
{"Probabilistic Sharpe Ratio", "68.833%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "1.732"},
{"Beta", "0.037"},
{"Annual Standard Deviation", "0.841"},
{"Annual Variance", "0.707"},
{"Information Ratio", "1.902"},
{"Tracking Error", "0.848"},
{"Treynor Ratio", "46.992"},
{"Total Fees", "$0.00"},
{"Estimated Strategy Capacity", "$0"},
{"Fitness Score", "0"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "2.238"},
{"Return Over Maximum Drawdown", "1.832"},
{"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", "1f54fb75ebcc0daafa5d45bfbaa4fbcb"}
};
/// <summary>
/// Custom Data Type: Bitcoin data from Quandl - http://www.quandl.com/help/api-for-bitcoin-data
/// </summary>
public class Bitcoin : BaseData
{
[JsonProperty("timestamp")]
public int Timestamp = 0;
[JsonProperty("open")]
public decimal Open = 0;
[JsonProperty("high")]
public decimal High = 0;
[JsonProperty("low")]
public decimal Low = 0;
[JsonProperty("last")]
public decimal Close = 0;
[JsonProperty("bid")]
public decimal Bid = 0;
[JsonProperty("ask")]
public decimal Ask = 0;
[JsonProperty("vwap")]
public decimal WeightedPrice = 0;
[JsonProperty("volume")]
public decimal VolumeBTC = 0;
public decimal VolumeUSD = 0;
/// <summary>
/// 1. DEFAULT CONSTRUCTOR: Custom data types need a default constructor.
/// We search for a default constructor so please provide one here. It won't be used for data, just to generate the "Factory".
/// </summary>
public Bitcoin()
{
Symbol = "BTC";
}
/// <summary>
/// 2. RETURN THE STRING URL SOURCE LOCATION FOR YOUR DATA:
/// This is a powerful and dynamic select source file method. If you have a large dataset, 10+mb we recommend you break it into smaller files. E.g. One zip per year.
/// We can accept raw text or ZIP files. We read the file extension to determine if it is a zip file.
/// </summary>
/// <param name="config">Configuration object</param>
/// <param name="date">Date of this source file</param>
/// <param name="isLiveMode">true if we're in live mode, false for backtesting mode</param>
/// <returns>String URL of source file.</returns>
public override SubscriptionDataSource GetSource(SubscriptionDataConfig config, DateTime date, bool isLiveMode)
{
if (isLiveMode)
{
return new SubscriptionDataSource("https://www.bitstamp.net/api/ticker/", SubscriptionTransportMedium.Rest);
}
//return "http://my-ftp-server.com/futures-data-" + date.ToString("Ymd") + ".zip";
// OR simply return a fixed small data file. Large files will slow down your backtest
return new SubscriptionDataSource("https://www.quantconnect.com/api/v2/proxy/quandl/api/v3/datasets/BCHARTS/BITSTAMPUSD.csv?order=asc&api_key=WyAazVXnq7ATy_fefTqm", SubscriptionTransportMedium.RemoteFile);
}
/// <summary>
/// 3. READER METHOD: Read 1 line from data source and convert it into Object.
/// Each line of the CSV File is presented in here. The backend downloads your file, loads it into memory and then line by line
/// feeds it into your algorithm
/// </summary>
/// <param name="line">string line from the data source file submitted above</param>
/// <param name="config">Subscription data, symbol name, data type</param>
/// <param name="date">Current date we're requesting. This allows you to break up the data source into daily files.</param>
/// <param name="isLiveMode">true if we're in live mode, false for backtesting mode</param>
/// <returns>New Bitcoin Object which extends BaseData.</returns>
public override BaseData Reader(SubscriptionDataConfig config, string line, DateTime date, bool isLiveMode)
{
var coin = new Bitcoin();
if (isLiveMode)
{
//Example Line Format:
//{"high": "441.00", "last": "421.86", "timestamp": "1411606877", "bid": "421.96", "vwap": "428.58", "volume": "14120.40683975", "low": "418.83", "ask": "421.99"}
try
{
coin = JsonConvert.DeserializeObject<Bitcoin>(line);
coin.EndTime = DateTime.UtcNow.ConvertFromUtc(config.ExchangeTimeZone);
coin.Value = coin.Close;
}
catch { /* Do nothing, possible error in json decoding */ }
return coin;
}
//Example Line Format:
//Date Open High Low Close Volume (BTC) Volume (Currency) Weighted Price
//2011-09-13 5.8 6.0 5.65 5.97 58.37138238, 346.0973893944 5.929230648356
try
{
string[] data = line.Split(',');
coin.Time = DateTime.Parse(data[0], CultureInfo.InvariantCulture);
coin.Open = Convert.ToDecimal(data[1], CultureInfo.InvariantCulture);
coin.High = Convert.ToDecimal(data[2], CultureInfo.InvariantCulture);
coin.Low = Convert.ToDecimal(data[3], CultureInfo.InvariantCulture);
coin.Close = Convert.ToDecimal(data[4], CultureInfo.InvariantCulture);
coin.VolumeBTC = Convert.ToDecimal(data[5], CultureInfo.InvariantCulture);
coin.VolumeUSD = Convert.ToDecimal(data[6], CultureInfo.InvariantCulture);
coin.WeightedPrice = Convert.ToDecimal(data[7], CultureInfo.InvariantCulture);
coin.Value = coin.Close;
}
catch { /* Do nothing, skip first title row */ }
return coin;
}
}
}
}

View File

@@ -101,6 +101,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Tracking Error", "0.848"},
{"Treynor Ratio", "46.996"},
{"Total Fees", "$0.00"},
{"Estimated Strategy Capacity", "$0"},
{"Fitness Score", "0"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
@@ -120,7 +121,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "-541549381"}
{"OrderListHash", "0e7d560d0db2829adb19d3e403c30d97"}
};
/// <summary>

View File

@@ -141,6 +141,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Tracking Error", "0.726"},
{"Treynor Ratio", "0.142"},
{"Total Fees", "$0.00"},
{"Estimated Strategy Capacity", "$0"},
{"Fitness Score", "0.127"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
@@ -160,7 +161,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "-1014157203"}
{"OrderListHash", "1c319ae4b15416184a247bb47b31aabc"}
};
/// <summary>

View File

@@ -26,11 +26,12 @@ using QuantConnect.Securities;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Demonstration of using custom fee, slippage and fill models for modelling transactions in backtesting.
/// Demonstration of using custom fee, slippage, fill, and buying power models for modelling transactions in backtesting.
/// QuantConnect allows you to model all orders as deeply and accurately as you need.
/// </summary>
/// <meta name="tag" content="trading and orders" />
/// <meta name="tag" content="transaction fees and slippage" />
/// <meta name="tag" content="custom buying power models" />
/// <meta name="tag" content="custom transaction models" />
/// <meta name="tag" content="custom slippage models" />
/// <meta name="tag" content="custom fee models" />
@@ -50,6 +51,7 @@ namespace QuantConnect.Algorithm.CSharp
_security.SetFeeModel(new CustomFeeModel(this));
_security.SetFillModel(new CustomFillModel(this));
_security.SetSlippageModel(new CustomSlippageModel(this));
_security.SetBuyingPowerModel(new CustomBuyingPowerModel(this));
}
public void OnData(TradeBars data)
@@ -60,13 +62,13 @@ namespace QuantConnect.Algorithm.CSharp
if (Time.Day > 10 && _security.Holdings.Quantity <= 0)
{
var quantity = CalculateOrderQuantity(_spy, .5m);
Log("MarketOrder: " + quantity);
Log($"MarketOrder: {quantity}");
MarketOrder(_spy, quantity, asynchronous: true); // async needed for partial fill market orders
}
else if (Time.Day > 20 && _security.Holdings.Quantity >= 0)
{
var quantity = CalculateOrderQuantity(_spy, -.5m);
Log("MarketOrder: " + quantity);
Log($"MarketOrder: {quantity}");
MarketOrder(_spy, quantity, asynchronous: true); // async needed for partial fill market orders
}
}
@@ -109,7 +111,7 @@ namespace QuantConnect.Algorithm.CSharp
fill.Status = OrderStatus.PartiallyFilled;
}
_algorithm.Log("CustomFillModel: " + fill);
_algorithm.Log($"CustomFillModel: {fill}");
return fill;
}
@@ -131,7 +133,7 @@ namespace QuantConnect.Algorithm.CSharp
1m,
parameters.Security.Price*parameters.Order.AbsoluteQuantity*0.00001m);
_algorithm.Log("CustomFeeModel: " + fee);
_algorithm.Log($"CustomFeeModel: {fee}");
return new OrderFee(new CashAmount(fee, "USD"));
}
}
@@ -150,11 +152,31 @@ namespace QuantConnect.Algorithm.CSharp
// custom slippage math
var slippage = asset.Price*0.0001m*(decimal) Math.Log10(2*(double) order.AbsoluteQuantity);
_algorithm.Log("CustomSlippageModel: " + slippage);
_algorithm.Log($"CustomSlippageModel: {slippage}");
return slippage;
}
}
public class CustomBuyingPowerModel : BuyingPowerModel
{
private readonly QCAlgorithm _algorithm;
public CustomBuyingPowerModel(QCAlgorithm algorithm)
{
_algorithm = algorithm;
}
public override HasSufficientBuyingPowerForOrderResult HasSufficientBuyingPowerForOrder(
HasSufficientBuyingPowerForOrderParameters parameters)
{
// custom behavior: this model will assume that there is always enough buying power
var hasSufficientBuyingPowerForOrderResult = new HasSufficientBuyingPowerForOrderResult(true);
_algorithm.Log($"CustomBuyingPowerModel: {hasSufficientBuyingPowerForOrderResult.IsSufficient}");
return hasSufficientBuyingPowerForOrderResult;
}
}
/// <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>
@@ -190,6 +212,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Tracking Error", "0.118"},
{"Treynor Ratio", "-0.591"},
{"Total Fees", "$62.24"},
{"Estimated Strategy Capacity", "$100000000.00"},
{"Fitness Score", "0.147"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
@@ -209,7 +232,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "852026186"}
{"OrderListHash", "71c17655bd0731eb25433727526e95ba"}
};
}
}

View File

@@ -103,6 +103,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Tracking Error", "0.251"},
{"Treynor Ratio", "9.323"},
{"Total Fees", "$3.26"},
{"Estimated Strategy Capacity", "$220000000.00"},
{"Fitness Score", "0.201"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
@@ -122,7 +123,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "1268340653"}
{"OrderListHash", "82fee25cd17100c53bb173834ab5f0b2"}
};
}
}

View File

@@ -193,6 +193,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Tracking Error", "0.211"},
{"Treynor Ratio", "0"},
{"Total Fees", "$0.00"},
{"Estimated Strategy Capacity", "$0"},
{"Fitness Score", "0"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
@@ -212,7 +213,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "371857150"}
{"OrderListHash", "d41d8cd98f00b204e9800998ecf8427e"}
};
}
}

View File

@@ -0,0 +1,144 @@
/*
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using QuantConnect.Data;
using QuantConnect.Data.Market;
using QuantConnect.Interfaces;
using QuantConnect.Securities;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Algorithm simply fetch one-day history prior current time.
/// </summary>
public class DailyHistoryForDailyResolutionRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
{
private Symbol[] _symbols = {
QuantConnect.Symbol.Create("GBPUSD", SecurityType.Forex, market: Market.FXCM),
QuantConnect.Symbol.Create("EURUSD", SecurityType.Forex, market: Market.Oanda),
QuantConnect.Symbol.Create("AAPL", SecurityType.Equity, market: Market.USA),
QuantConnect.Symbol.Create("BTCUSD", SecurityType.Crypto, market: Market.GDAX),
QuantConnect.Symbol.Create("XAUUSD", SecurityType.Cfd, market: Market.Oanda)
};
private HashSet<Symbol> _received = new HashSet<Symbol>();
public override void Initialize()
{
SetStartDate(2018, 3, 26);
SetEndDate(2018, 4, 10);
foreach (var symbol in _symbols)
{
AddSecurity(symbol, Resolution.Daily);
}
}
public override void OnData(Slice data)
{
using (var enumerator = data.GetEnumerator())
{
while (enumerator.MoveNext())
{
var current = enumerator.Current;
var symbol = current.Key;
_received.Add(symbol);
List<BaseData> history;
if (current.Value.DataType == MarketDataType.QuoteBar)
{
history = History(1, Resolution.Daily).Get<QuoteBar>(symbol).Cast<BaseData>().ToList();
}
else
{
history = History(1, Resolution.Daily).Get<TradeBar>(symbol).Cast<BaseData>().ToList();
}
if (!history.Any()) throw new Exception($"No {symbol} data on the eve of {Time} {Time.DayOfWeek}");
}
}
}
public override void OnEndOfAlgorithm()
{
if (_received.Count != _symbols.Length)
{
throw new Exception($"Data for symbols {string.Join(",", _symbols.Except(_received))} were not received");
}
}
/// <summary>
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
/// </summary>
public bool CanRunLocally { get; } = true;
/// <summary>
/// This is used by the regression test system to indicate which languages this algorithm is written in.
/// </summary>
public Language[] Languages { get; } = { Language.CSharp };
/// <summary>
/// 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", "0"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "0%"},
{"Drawdown", "0%"},
{"Expectancy", "0"},
{"Net Profit", "0%"},
{"Sharpe 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.084"},
{"Tracking Error", "0.183"},
{"Treynor Ratio", "0"},
{"Total Fees", "$0.00"},
{"Estimated Strategy Capacity", "$0"},
{"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", "d41d8cd98f00b204e9800998ecf8427e"}
};
}
}

View File

@@ -0,0 +1,144 @@
/*
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using QuantConnect.Data;
using QuantConnect.Data.Market;
using QuantConnect.Interfaces;
using QuantConnect.Securities;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Algorithm simply fetch one-day history prior current time.
/// </summary>
public class DailyHistoryForMinuteResolutionRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
{
private Symbol[] _symbols = {
QuantConnect.Symbol.Create("GBPUSD", SecurityType.Forex, market: Market.FXCM),
QuantConnect.Symbol.Create("EURUSD", SecurityType.Forex, market: Market.Oanda),
QuantConnect.Symbol.Create("AAPL", SecurityType.Equity, market: Market.USA),
QuantConnect.Symbol.Create("BTCUSD", SecurityType.Crypto, market: Market.GDAX),
QuantConnect.Symbol.Create("XAUUSD", SecurityType.Cfd, market: Market.Oanda)
};
private HashSet<Symbol> _received = new HashSet<Symbol>();
public override void Initialize()
{
SetStartDate(2018, 3, 26);
SetEndDate(2018, 4, 10);
foreach (var symbol in _symbols)
{
AddSecurity(symbol, Resolution.Minute);
}
Schedule.On(DateRules.EveryDay(), TimeRules.Every(TimeSpan.FromHours(1)), MakeHistoryCall);
}
private void MakeHistoryCall()
{
foreach (var symbol in _symbols)
{
_received.Add(symbol);
bool hasHistory = false;
foreach (var dataType in SubscriptionManager.AvailableDataTypes[symbol.SecurityType])
{
if (dataType == TickType.Quote)
{
hasHistory |= History(1, Resolution.Daily).Get<QuoteBar>(symbol).Any();
}
else
{
hasHistory |= History(1, Resolution.Daily).Get<TradeBar>(symbol).Any();
}
}
if (!hasHistory) throw new Exception($"No {symbol} data on the eve of {Time} {Time.DayOfWeek}");
}
}
public override void OnEndOfAlgorithm()
{
if (_received.Count != _symbols.Length)
{
throw new Exception($"Data for symbols {string.Join(",", _symbols.Except(_received))} were not received");
}
}
/// <summary>
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
/// </summary>
public bool CanRunLocally { get; } = true;
/// <summary>
/// This is used by the regression test system to indicate which languages this algorithm is written in.
/// </summary>
public Language[] Languages { get; } = { Language.CSharp };
/// <summary>
/// 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", "0"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "0%"},
{"Drawdown", "0%"},
{"Expectancy", "0"},
{"Net Profit", "0%"},
{"Sharpe 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.096"},
{"Tracking Error", "0.212"},
{"Treynor Ratio", "0"},
{"Total Fees", "$0.00"},
{"Estimated Strategy Capacity", "$0"},
{"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", "d41d8cd98f00b204e9800998ecf8427e"}
};
}
}

View File

@@ -0,0 +1,137 @@
/*
* 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.Market;
using QuantConnect.Interfaces;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Regression test algorithm simply fetch history on boarder of Daylight Saving Time shift
/// </summary>
public class DaylightSavingTimeHistoryRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
{
private Symbol[] _symbols = new[]
{
QuantConnect.Symbol.Create("EURUSD", SecurityType.Forex, Market.FXCM),
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(2011, 11, 10); //Set Start Date
SetEndDate(2011, 11, 11); //Set End Date
SetCash(100000); //Set Strategy Cash
for (int i = 0; i < _symbols.Length; i++)
{
var symbol = _symbols[i];
IEnumerable<BaseData> history;
if (symbol.SecurityType == SecurityType.Equity)
{
try
{
history = History<QuoteBar>(symbol, 10, Resolution.Daily).Select(bar => bar as BaseData);
throw new Exception("We were expecting an argument exception to be thrown. Equity does not have daily QuoteBars!");
}
catch (ArgumentException)
{
// expected
}
history = History<TradeBar>(symbol, 10, Resolution.Daily).Select(bar => bar as BaseData);
}
else
{
history = History<QuoteBar>(symbol, 10, Resolution.Daily)
.Select(bar => bar as BaseData);
}
var duplications = history
.GroupBy(k => k.Time)
.Where(g => g.Count() > 1);
if (duplications.Any())
{
var time = duplications.First().Key;
throw new Exception($"Duplicated bars were issued for time {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 Language[] Languages { get; } = { Language.CSharp };
/// <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", "0"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "0%"},
{"Drawdown", "0%"},
{"Expectancy", "0"},
{"Net Profit", "0%"},
{"Sharpe 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"},
{"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", "d41d8cd98f00b204e9800998ecf8427e"}
};
}
}

View File

@@ -136,6 +136,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Tracking Error", "0"},
{"Treynor Ratio", "0"},
{"Total Fees", "$0.00"},
{"Estimated Strategy Capacity", "$0"},
{"Fitness Score", "0"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
@@ -155,7 +156,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "371857150"}
{"OrderListHash", "d41d8cd98f00b204e9800998ecf8427e"}
};
}
}

View File

@@ -0,0 +1,139 @@
/*
* 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;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Regression algorithm which reproduces GH issue 4446
/// </summary>
public class DelistedFutureLiquidateRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
{
private Symbol _contractSymbol;
/// <summary>
/// Initialize your algorithm and add desired assets.
/// </summary>
public override void Initialize()
{
SetStartDate(2013, 10, 08);
SetEndDate(2013, 12, 30);
var futureSP500 = AddFuture(Futures.Indices.SP500EMini);
futureSP500.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 (_contractSymbol == null)
{
foreach (var chain in slice.FutureChains)
{
var contract = chain.Value.OrderBy(x => x.Expiry).FirstOrDefault();
// if found, trade it
if (contract != null)
{
_contractSymbol = contract.Symbol;
MarketOrder(_contractSymbol, 1);
}
}
}
}
public override void OnEndOfAlgorithm()
{
Log($"{_contractSymbol}: {Securities[_contractSymbol].Invested}");
if (Securities[_contractSymbol].Invested)
{
throw new Exception($"Position should be closed when {_contractSymbol} got delisted {_contractSymbol.ID.Date}");
}
}
public override void OnOrderEvent(OrderEvent orderEvent)
{
Log($"{orderEvent}. Delisting on: {_contractSymbol.ID.Date}");
}
/// <summary>
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
/// </summary>
public bool CanRunLocally { get; } = true;
/// <summary>
/// This is used by the regression test system to indicate which languages this algorithm is written in.
/// </summary>
public Language[] Languages { get; } = { Language.CSharp };
/// <summary>
/// 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"},
{"Average Win", "1.63%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "7.292%"},
{"Drawdown", "1.300%"},
{"Expectancy", "0"},
{"Net Profit", "1.634%"},
{"Sharpe Ratio", "2.495"},
{"Probabilistic Sharpe Ratio", "92.298%"},
{"Loss Rate", "0%"},
{"Win Rate", "100%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "0.006"},
{"Beta", "0.158"},
{"Annual Standard Deviation", "0.033"},
{"Annual Variance", "0.001"},
{"Information Ratio", "-4.942"},
{"Tracking Error", "0.08"},
{"Treynor Ratio", "0.517"},
{"Total Fees", "$3.70"},
{"Estimated Strategy Capacity", "$38000000.00"},
{"Fitness Score", "0.019"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "1.362"},
{"Return Over Maximum Drawdown", "9.699"},
{"Portfolio Turnover", "0.023"},
{"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", "00d6dc8775da38f7f79defad06de240a"}
};
}
}

View File

@@ -45,7 +45,7 @@ namespace QuantConnect.Algorithm.CSharp
SetEndDate(2007, 05, 25); //Set End Date
SetCash(100000); //Set Strategy Cash
// Find more symbols here: http://quantconnect.com/data
AddSecurity(SecurityType.Equity, "AAA", Resolution.Daily);
AddSecurity(SecurityType.Equity, "AAA.1", Resolution.Daily);
AddSecurity(SecurityType.Equity, "SPY", Resolution.Daily);
}
@@ -58,7 +58,7 @@ namespace QuantConnect.Algorithm.CSharp
_dataCount += data.Bars.Count;
if (Transactions.OrdersCount == 0)
{
SetHoldings("AAA", 1);
SetHoldings("AAA.1", 1);
Debug("Purchased Stock");
}
@@ -71,7 +71,7 @@ namespace QuantConnect.Algorithm.CSharp
// the slice can also contain delisting data: data.Delistings in a dictionary string->Delisting
var aaa = Securities["AAA"];
var aaa = Securities["AAA.1"];
if (aaa.IsDelisted && aaa.IsTradable)
{
throw new Exception("Delisted security must NOT be tradable");
@@ -160,6 +160,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Tracking Error", "0.155"},
{"Treynor Ratio", "1.589"},
{"Total Fees", "$55.05"},
{"Estimated Strategy Capacity", "$0"},
{"Fitness Score", "0.002"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
@@ -179,7 +180,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "-2022527947"}
{"OrderListHash", "61f4d3c109fc4b6b9eb14d2e4eec4843"}
};
}
}

View File

@@ -0,0 +1,149 @@
/*
* 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 QuantConnect.Securities;
using System.Collections.Generic;
using System.Linq;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Regression algorithm reproducing issue #5160 where delisting order would be cancelled because it was placed at the market close on the delisting day
/// </summary>
public class DelistingFutureOptionRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
{
private bool _traded;
private int _lastMonth;
public override void Initialize()
{
SetStartDate(2012, 1, 1);
SetEndDate(2013, 1, 1);
SetCash(10000000);
var dc = AddFuture(Futures.Dairy.ClassIIIMilk, Resolution.Minute, Market.CME);
dc.SetFilter(1, 120);
AddFutureOption(dc.Symbol, universe => universe.Strikes(-2, 2));
_lastMonth = -1;
}
public override void OnData(Slice data)
{
if (Time.Month != _lastMonth)
{
_lastMonth = Time.Month;
var investedSymbols = Securities.Values
.Where(security => security.Invested)
.Select(security => security.Symbol)
.ToList();
var delistedSecurity = investedSymbols.Where(symbol => symbol.ID.Date.AddDays(1) < Time).ToList();
if (delistedSecurity.Count > 0)
{
throw new Exception($"[{UtcTime}] We hold a delisted securities: {string.Join(",", delistedSecurity)}");
}
Log($"Holdings({Time}): {string.Join(",", investedSymbols)}");
}
if (Portfolio.Invested)
{
return;
}
foreach (var chain in data.OptionChains.Values)
{
foreach (var contractsValue in chain.Contracts.Values)
{
MarketOrder(contractsValue.Symbol, 1);
_traded = true;
}
}
}
public override void OnEndOfAlgorithm()
{
if (!_traded)
{
throw new Exception("We expected some FOP trading to happen");
}
if (Portfolio.Invested)
{
throw new Exception("We shouldn't be invested anymore");
}
}
/// <summary>
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
/// </summary>
public bool CanRunLocally { get; } = true;
/// <summary>
/// This is used by the regression test system to indicate which languages this algorithm is written in.
/// </summary>
public Language[] Languages { get; } = { Language.CSharp };
/// <summary>
/// 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", "16"},
{"Average Win", "0.01%"},
{"Average Loss", "-0.02%"},
{"Compounding Annual Return", "-0.111%"},
{"Drawdown", "0.100%"},
{"Expectancy", "-0.679"},
{"Net Profit", "-0.112%"},
{"Sharpe Ratio", "-1.052"},
{"Probabilistic Sharpe Ratio", "0.000%"},
{"Loss Rate", "80%"},
{"Win Rate", "20%"},
{"Profit-Loss Ratio", "0.61"},
{"Alpha", "-0.001"},
{"Beta", "-0.001"},
{"Annual Standard Deviation", "0.001"},
{"Annual Variance", "0"},
{"Information Ratio", "-1.187"},
{"Tracking Error", "0.115"},
{"Treynor Ratio", "1.545"},
{"Total Fees", "$37.00"},
{"Estimated Strategy Capacity", "$58000.00"},
{"Fitness Score", "0"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "-0.128"},
{"Return Over Maximum Drawdown", "-0.995"},
{"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", "de309ab56d2fcd80ff03df2802d9feda"}
};
}
}

View File

@@ -186,6 +186,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Tracking Error", "0.204"},
{"Treynor Ratio", "-8.165"},
{"Total Fees", "$46.75"},
{"Estimated Strategy Capacity", "$96000000.00"},
{"Fitness Score", "0.002"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
@@ -205,7 +206,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "-807056289"}
{"OrderListHash", "7c4fcd79dd817a9cd3bf44525eaed96c"}
};
}
}

View File

@@ -187,12 +187,12 @@ namespace QuantConnect.Algorithm.CSharp
{"Total Trades", "6441"},
{"Average Win", "0.07%"},
{"Average Loss", "-0.07%"},
{"Compounding Annual Return", "13.284%"},
{"Compounding Annual Return", "13.331%"},
{"Drawdown", "10.700%"},
{"Expectancy", "0.061"},
{"Net Profit", "13.284%"},
{"Sharpe Ratio", "0.96"},
{"Probabilistic Sharpe Ratio", "46.111%"},
{"Net Profit", "13.331%"},
{"Sharpe Ratio", "0.963"},
{"Probabilistic Sharpe Ratio", "46.232%"},
{"Loss Rate", "46%"},
{"Win Rate", "54%"},
{"Profit-Loss Ratio", "0.97"},
@@ -200,15 +200,16 @@ namespace QuantConnect.Algorithm.CSharp
{"Beta", "-0.066"},
{"Annual Standard Deviation", "0.121"},
{"Annual Variance", "0.015"},
{"Information Ratio", "0.004"},
{"Information Ratio", "0.006"},
{"Tracking Error", "0.171"},
{"Treynor Ratio", "-1.754"},
{"Total Fees", "$8669.33"},
{"Treynor Ratio", "-1.761"},
{"Total Fees", "$8669.41"},
{"Estimated Strategy Capacity", "$170000.00"},
{"Fitness Score", "0.675"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "1.124"},
{"Return Over Maximum Drawdown", "1.242"},
{"Sortino Ratio", "1.127"},
{"Return Over Maximum Drawdown", "1.246"},
{"Portfolio Turnover", "1.64"},
{"Total Insights Generated", "0"},
{"Total Insights Closed", "0"},
@@ -223,7 +224,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "-1120327913"}
{"OrderListHash", "0b6746b5759ecd45ab21360fd40858bb"}
};
}
}

View File

@@ -160,12 +160,12 @@ namespace QuantConnect.Algorithm.CSharp
{"Total Trades", "5059"},
{"Average Win", "0.08%"},
{"Average Loss", "-0.08%"},
{"Compounding Annual Return", "14.901%"},
{"Compounding Annual Return", "14.950%"},
{"Drawdown", "10.600%"},
{"Expectancy", "0.075"},
{"Net Profit", "14.901%"},
{"Sharpe Ratio", "1.068"},
{"Probabilistic Sharpe Ratio", "50.201%"},
{"Net Profit", "14.950%"},
{"Sharpe Ratio", "1.072"},
{"Probabilistic Sharpe Ratio", "50.327%"},
{"Loss Rate", "45%"},
{"Win Rate", "55%"},
{"Profit-Loss Ratio", "0.97"},
@@ -173,15 +173,16 @@ namespace QuantConnect.Algorithm.CSharp
{"Beta", "-0.066"},
{"Annual Standard Deviation", "0.121"},
{"Annual Variance", "0.015"},
{"Information Ratio", "0.08"},
{"Information Ratio", "0.083"},
{"Tracking Error", "0.171"},
{"Treynor Ratio", "-1.963"},
{"Total Fees", "$6806.57"},
{"Treynor Ratio", "-1.971"},
{"Total Fees", "$6806.67"},
{"Estimated Strategy Capacity", "$150000.00"},
{"Fitness Score", "0.694"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "1.261"},
{"Return Over Maximum Drawdown", "1.404"},
{"Sortino Ratio", "1.265"},
{"Return Over Maximum Drawdown", "1.409"},
{"Portfolio Turnover", "1.296"},
{"Total Insights Generated", "0"},
{"Total Insights Closed", "0"},
@@ -196,7 +197,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "974523768"}
{"OrderListHash", "a7a893a17a5afa7c2f73a444a7aea507"}
};
}
}

View File

@@ -110,6 +110,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Tracking Error", "0.193"},
{"Treynor Ratio", "0"},
{"Total Fees", "$0.00"},
{"Estimated Strategy Capacity", "$0"},
{"Fitness Score", "0"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
@@ -129,7 +130,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "371857150"}
{"OrderListHash", "d41d8cd98f00b204e9800998ecf8427e"}
};
}
}

View File

@@ -0,0 +1,122 @@
/*
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
using QuantConnect.Data;
using QuantConnect.Data.Consolidators;
using QuantConnect.Data.UniverseSelection;
using QuantConnect.Indicators;
using QuantConnect.Securities;
using System.Linq;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// This example demonstrates how to implement a cross moving average for the futures front contract
/// </summary>
/// <meta name="tag" content="using data" />
/// <meta name="tag" content="indicator" />
/// <meta name="tag" content="futures" />
public class EmaCrossFuturesFrontMonthAlgorithm : QCAlgorithm
{
private const decimal _tolerance = 0.001m;
private Symbol _symbol;
private ExponentialMovingAverage _fast;
private ExponentialMovingAverage _slow;
private IDataConsolidator _consolidator;
public override void Initialize()
{
SetStartDate(2013, 10, 08);
SetEndDate(2013, 10, 10);
SetCash(1000000);
var future = AddFuture(Futures.Metals.Gold);
// Only consider the front month contract
// Update the universe once per day to improve performance
future.SetFilter(x => x.FrontMonth().OnlyApplyFilterAtMarketOpen());
// Create two exponential moving averages
_fast = new ExponentialMovingAverage(100);
_slow = new ExponentialMovingAverage(300);
// Add a custom chart to track the EMA cross
var chart = new Chart("EMA Cross");
chart.AddSeries(new Series("Fast", SeriesType.Line, 0));
chart.AddSeries(new Series("Slow", SeriesType.Line, 0));
AddChart(chart);
}
public override void OnData(Slice slice)
{
SecurityHolding holding;
if (Portfolio.TryGetValue(_symbol, out holding))
{
// Buy the futures' front contract when the fast EMA is above the slow one
if (_fast > _slow * (1 + _tolerance))
{
if (!holding.Invested)
{
SetHoldings(_symbol, .1);
PlotEma();
}
}
else if (holding.Invested)
{
Liquidate(_symbol);
PlotEma();
}
}
}
public override void OnSecuritiesChanged(SecurityChanges changes)
{
if (changes.RemovedSecurities.Count > 0)
{
// Remove the consolidator for the previous contract
// and reset the indicators
if (_symbol != null && _consolidator != null)
{
SubscriptionManager.RemoveConsolidator(_symbol, _consolidator);
_fast.Reset();
_slow.Reset();
}
// We don't need to call Liquidate(_symbol),
// since its positions are liquidated because the contract has expired.
}
// Only one security will be added: the new front contract
_symbol = changes.AddedSecurities.SingleOrDefault().Symbol;
// Create a new consolidator and register the indicators to it
_consolidator = ResolveConsolidator(_symbol, Resolution.Minute);
RegisterIndicator(_symbol, _fast, _consolidator);
RegisterIndicator(_symbol, _slow, _consolidator);
// Warm up the indicators
WarmUpIndicator(_symbol, _fast, Resolution.Minute);
WarmUpIndicator(_symbol, _slow, Resolution.Minute);
PlotEma();
}
private void PlotEma()
{
Plot("EMA Cross", "Fast", _fast);
Plot("EMA Cross", "Slow", _slow);
}
}
}

View File

@@ -90,13 +90,14 @@ namespace QuantConnect.Algorithm.CSharp
{"Information Ratio", "0"},
{"Tracking Error", "0"},
{"Treynor Ratio", "0"},
{"Total Fees", "$14.91"},
{"Total Fees", "$14.92"},
{"Estimated Strategy Capacity", "$85000.00"},
{"Fitness Score", "0.258"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "79228162514264337593543950335"},
{"Return Over Maximum Drawdown", "-27.251"},
{"Portfolio Turnover", "0.515"},
{"Return Over Maximum Drawdown", "-27.228"},
{"Portfolio Turnover", "0.516"},
{"Total Insights Generated", "1"},
{"Total Insights Closed", "1"},
{"Total Insights Analysis Completed", "1"},
@@ -110,7 +111,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "221046152"}
{"OrderListHash", "21ac8e4179b36d9658f0080868c0e552"}
};
}
}

View File

@@ -131,6 +131,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Tracking Error", "0.29"},
{"Treynor Ratio", "4.005"},
{"Total Fees", "$18.28"},
{"Estimated Strategy Capacity", "$200000000.00"},
{"Fitness Score", "0.052"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
@@ -150,7 +151,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "1300818910"}
{"OrderListHash", "17245c38f1b192d2041ca1f3e88250be"}
};
}
}

View File

@@ -127,6 +127,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Tracking Error", "0.204"},
{"Treynor Ratio", "-1.424"},
{"Total Fees", "$16.26"},
{"Estimated Strategy Capacity", "$250000000.00"},
{"Fitness Score", "0.003"},
{"Kelly Criterion Estimate", "12.539"},
{"Kelly Criterion Probability Value", "0.367"},
@@ -146,7 +147,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Mean Population Magnitude", "50%"},
{"Rolling Averaged Population Direction", "50%"},
{"Rolling Averaged Population Magnitude", "50%"},
{"OrderListHash", "-218498072"}
{"OrderListHash", "4178a84209934b1eb6d03c2267654f32"}
};
}
}

View File

@@ -148,6 +148,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Tracking Error", "1.441"},
{"Treynor Ratio", "-0.15"},
{"Total Fees", "$33.30"},
{"Estimated Strategy Capacity", "$4200000.00"},
{"Fitness Score", "0.079"},
{"Kelly Criterion Estimate", "-9.366"},
{"Kelly Criterion Probability Value", "0.607"},
@@ -167,7 +168,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "25.058%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "-1105779454"}
{"OrderListHash", "f4c4b763b5ade918cfb7932e276d069f"}
};
}
}

View File

@@ -0,0 +1,129 @@
/*
* 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.Interfaces;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Checks that the Tick BidPrice and AskPrices are adjusted like Value.
/// </summary>
public class EquityTickQuoteAdjustedModeRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
{
private Symbol _ibm;
private bool _bought;
private bool _sold;
public override void Initialize()
{
SetStartDate(2013, 10, 7);
SetEndDate(2013, 10, 11);
SetCash(100000);
_ibm = AddEquity("IBM", Resolution.Tick).Symbol;
}
public override void OnData(Slice data)
{
if (!data.Ticks.ContainsKey(_ibm))
{
return;
}
var security = Securities[_ibm];
if (!security.HasData)
{
return;
}
foreach (var tick in data.Ticks[_ibm])
{
if (tick.BidPrice != 0 && !_bought && ((tick.Value - tick.BidPrice) <= 0.05m))
{
SetHoldings(_ibm, 1);
_bought = true;
return;
}
if (tick.AskPrice != 0 && _bought && !_sold && Math.Abs((double)tick.Value - (double)tick.AskPrice) <= 0.05)
{
Liquidate(_ibm);
_sold = true;
return;
}
}
}
/// <summary>
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
/// </summary>
public bool CanRunLocally { get; } = true;
/// <summary>
/// This is used by the regression test system to indicate which languages this algorithm is written in.
/// </summary>
public Language[] Languages { get; } = { Language.CSharp };
/// <summary>
/// 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"},
{"Average Win", "0%"},
{"Average Loss", "-0.12%"},
{"Compounding Annual Return", "-9.062%"},
{"Drawdown", "0.100%"},
{"Expectancy", "-1"},
{"Net Profit", "-0.121%"},
{"Sharpe Ratio", "0"},
{"Probabilistic Sharpe Ratio", "0%"},
{"Loss Rate", "100%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "0"},
{"Beta", "0"},
{"Annual Standard Deviation", "0"},
{"Annual Variance", "0"},
{"Information Ratio", "-8.769"},
{"Tracking Error", "0.22"},
{"Treynor Ratio", "0"},
{"Total Fees", "$6.41"},
{"Estimated Strategy Capacity", "$0"},
{"Fitness Score", "0.249"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "79228162514264337593543950335"},
{"Return Over Maximum Drawdown", "-79.031"},
{"Portfolio Turnover", "0.498"},
{"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", "af92d7f4e0810bc4a95d5ccb5542b438"}
};
}
}

View File

@@ -184,6 +184,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Tracking Error", "0.123"},
{"Treynor Ratio", "-1.288"},
{"Total Fees", "$669.76"},
{"Estimated Strategy Capacity", "$8100000.00"},
{"Fitness Score", "0.021"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
@@ -203,7 +204,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "1040964928"}
{"OrderListHash", "2cd87d138f8f9f5fcab28b6f983f68b1"}
};
}
}

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