Compare commits

..

1963 Commits

Author SHA1 Message Date
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
Martin-Molinero
b4e7f4ce46 Merge pull request #4460 from michael-sena/bug-4459-python-postbuildevent
Adjust Algorithm.Python PostBuildEvent location and ensure scripts pass
2020-06-04 19:40:31 -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
Jared
ac8781dbfd Feature sponsorship button (#4484)
* Create FUNDING.yml
2020-06-03 13:57:39 -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
b5a9494a9b Fix for python build scripts 2020-06-02 12:52:28 -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
Martin-Molinero
fe503bbeb1 Merge pull request #4476 from AlexCatarino/bug-4475-kama
Adds Optional Parameters to KaufmanAdaptiveMovingAverage
2020-06-01 10:51:37 -03:00
AlexCatarino
fffd6a8493 Adds Optional Parameters to KaufmanAdaptiveMovingAverage
Our reference, http://stockcharts.com/school/doku.php?id=chart_school:technical_indicators:kaufman_s_adaptive_moving_average, points to three parameters, but only one is defined. The missing parameters were added to reflect the reference.
2020-05-31 14:44:53 +01:00
Jared
d77a557254 Merge pull request #4472 from QuantConnect/bug-4471-history-data-day-change
Fixes History Request Data Time Zone
2020-05-29 16:00:51 -07:00
AlexCatarino
7a9778f9fd Addresses Peer-Review
- Do not reuse parameter variables `start` and `end`. Create new variables with meaningful names and rename them to `startUtc` and `endUtc`.
- Use `EachTradeableDayInTimeZone` to calculate `tradableDates`.
- Adds another test/assertion in the regression algorithms to ensure tests in the scheduled event were performed.
2020-05-29 14:56:10 +01:00
AlexCatarino
8b1afdb083 Fixes History Request Data Time Zone
The tradable days of the history request should respect the data time zone since the data source files also do.

Upgrade `BasicTemplateFuturesHistoryAlgorithm` to a regression algorithm and add a schedule event to test history requests every hour.
2020-05-29 00:31:12 +01:00
Jared
4efefa59eb Merge pull request #4469 from QuantConnect/feature-max-cpu-allocation
Add CPU max allocation to Controls
2020-05-28 12:47:09 -07:00
Martin Molinero
8c0235617b Add CPU max allocation to Controls
- Add CPU max allocation to Controls
- Rename json field ram allocation from iRamAllocation to iMaxRamAllocation
2020-05-28 15:53:28 -03:00
Jared
9c4b468470 Merge pull request #4464 from QuantConnect/feature-rename-pcm-python-parameter
Renames rebalancingParam to rebalance in PCMs
2020-05-28 08:45:03 -07:00
Martin-Molinero
441bbd326a Merge pull request #4467 from QuantConnect/bug-4466-sharpziplib-consolidate
Consolidate SharpZipLib library usage
2020-05-28 11:10:14 -03:00
Stefano Raggi
0a046699fc Consolidate SharpZipLib library usage 2020-05-28 11:18:44 +02:00
Martin-Molinero
d5213a3551 Merge pull request #4463 from QuantConnect/feature-specify-log-file-location
Specify system log file location
2020-05-27 17:07:48 -03:00
AlexCatarino
961f2292c2 Renames rebalancingParam to rebalance in PCMs 2020-05-27 20:48:29 +01:00
Martin Molinero
eb6e0a141c Specify log file location
- Respect "results-destination-folder", if provided, for system log
2020-05-27 14:33:44 -03:00
Jared
beca5a1c46 Merge pull request #4462 from QuantConnect/bug-docker-file-copy
Fix for docker file copy
2020-05-27 10:00:15 -07:00
Martin Molinero
e82c47f738 Fix for docker file copy 2020-05-27 12:37:58 -03:00
Jared
f9cad3dc0c Merge pull request #4451 from QuantConnect/bug-pandasdata-misaligned-series-indexes-crash
Fixes alignment of Series objects created in PandasData causing crash
2020-05-26 14:02:17 -07:00
Jared
692bae1d6f Update readme.md 2020-05-26 11:06:11 -07:00
Michael Sena
bb67bd4d0d Adjust Algorithm.Python PostBuildEvent location and ensure scripts pass 2020-05-26 15:45:09 +10:00
Martin-Molinero
02ebd7e7df Merge pull request #4452 from QuantConnect/feature-4425-lean-docker-file
Adding Lean dockerfile
2020-05-25 16:13:19 -03:00
Martin Molinero
9ac44e1c5b Remove docker push 2020-05-25 13:57:45 -03:00
Gerardo Salazar
833c0540e0 Address review - short circuit the PandasData field/property type check 2020-05-25 09:46:58 -07:00
Martin-Molinero
df76f70afa Merge pull request #4454 from QuantConnect/bug-4453-pandasdata-wrapper-query
Fixes PandasData Wrapper Support for Query Method
2020-05-25 13:18:14 -03:00
Martin-Molinero
3e161838f2 Merge pull request #4456 from QuantConnect/bug-4431-websocket-thread-safety
Fix thread safety in WebSocketClientWrapper.Send
2020-05-25 13:17:58 -03:00
Stefano Raggi
385a8209a0 Fix thread safety in WebSocketClientWrapper.Send 2020-05-25 15:26:31 +02:00
AlexCatarino
7bb7d6487f Fixes PandasData Wrapper Support for Query Method
query/eval methods needs to look for a scope variable at a higher level since the wrapper classes are children of pandas classes.
2020-05-23 02:19:52 +01:00
Gerardo Salazar
6333081f7d Address self review - Adds missing license header/removes unused imports 2020-05-22 17:20:13 -07:00
Gerardo Salazar
a20ac26eb7 Fixes rounding of Time property in SubscriptionData for data that has no time delta.
* The original implementation was made with the idea in mind that bars
    have a time range that they encompass. When the `Time` property is
    rounded down, the period added to `EndTime` ensures that the data
    will not have look-ahead bias.

    However, multiple data sources do not have a time range that the data
    applies to, and is actually point-in-time. For these kinds of
    data, rounding of the data is not preferred since they are supposed
    to represent a point in time.
2020-05-22 17:13:18 -07:00
Martin Molinero
e696ab8cfd Adding Lean dockerfile
- Adding Lean Dockerfile to be used as latest.
- Updating run_docker scripts
- Updating travis for docker CI
2020-05-22 21:00:41 -03:00
Gerardo Salazar
bb2947d941 Fixes alignment of Series objects created in PandasData causing crash
* When a BaseData instance has Nullable fields, the number of data
    points per Series is inconsistent, and results in a Series with
    a length different from the other Series we produce, resulting
    in an error "ValueError: cannot handle a non-unique multi-index!"
    when we were constructing the final DataFrame.
2020-05-22 15:57:16 -07:00
Martin-Molinero
61a8ace34c Merge pull request #4448 from QuantConnect/system-net-http-updates
Update System.Net.Http to latest version
2020-05-22 18:04:17 -03:00
Stefano Raggi
cfb3329f33 Update System.Net.Http to latest version
- also removed unused references
2020-05-22 22:55:18 +02:00
Jared
10596fad44 Merge pull request #4449 from QuantConnect/bug-rename-jupyter-add-nuget
Rename Jupyter to Research add nuget
2020-05-22 10:27:25 -07:00
Martin Molinero
8a63a1ac32 Rename Jupyter to Research add nuget
- Rename Jupyter to Research and add it's nuget package
2020-05-22 12:42:59 -03:00
Martin-Molinero
34f5e6d427 Merge pull request #4439 from QuantConnect/bug-smartinsider-history-dropped-points
Updates Smart Insider transactions and intentions to use different time index
2020-05-22 11:12:07 -03:00
Jared
7d5cb6c402 Merge pull request #4447 from QuantConnect/bug-add-backtest-exit-logs-fix-controls
Logging improvements
2020-05-21 17:10:29 -07:00
Martin Molinero
57ea4683d4 Log fixes
- Revert change in Controls getting settings from log, moving to the
  QuantBook
- Adding a couple of logs to BRH exit
2020-05-21 20:08:51 -03:00
Martin-Molinero
facf00d460 Merge pull request #4444 from Martin-Molinero/bug-nuget-lean-dependency-version
Fix nuget QC dependency version
2020-05-21 18:27:56 -03:00
Martin Molinero
9631cd6749 Fix nuget QC dependency version 2020-05-21 16:21:59 -03:00
Martin-Molinero
b6e0316640 Merge pull request #4443 from QuantConnect/bug-nuget-assembly-descriptions
Add assembly description to nuspec
2020-05-21 15:08:19 -03:00
Martin Molinero
09c17b71ed Add assembly description to nuspec
- Due to bug in nuget failing to replace description and copyright token, setting
  .nuspec description to match assembly description
2020-05-21 14:42:12 -03:00
Gerardo Salazar
9087b0f782 Address review - designate Smart Insider timezone as UTC 2020-05-21 10:01:32 -07:00
Jared
83663e0df1 Merge pull request #4441 from QuantConnect/feature-4284-pandas-override
PandasData Speed Improvement
2020-05-21 09:43:04 -07:00
Martin-Molinero
1d0d4f4d7b Add assembly descriptions (#4442)
Add assembly descriptions
2020-05-21 09:35:12 -07:00
AlexCatarino
2ab7eefd63 PandasData Speed Improvement
Use the original `pandas.Series` to create `Series` objects before `DataFrame` (wrapper version) creation.
It improves the speed because it avoids unnecessary and expensive index wrapping operations of the `DataFrame` creation.
2020-05-21 15:55:00 +01:00
Martin-Molinero
9d0fdd1acc Merge pull request #4433 from QuantConnect/bug-fix-alpaca-history-requests
Fixes Second, Tick Resolution history requests for Alpaca
2020-05-21 10:30:34 -03:00
Martin-Molinero
cf276ad081 Update readme.md 2020-05-20 21:02:15 -03:00
Gerardo Salazar
f610b3a4fb Updates Smart Insider transactions and intentions to use different time index
* We now use the time at which Smart Insider added a given event to
   their database. Because time indexes for Smart Insider are now
   non-duplicated per symbol, the History request will properly work.
2020-05-20 14:55:28 -07:00
Martin-Molinero
8cc69aafa6 Merge pull request #4431 from QuantConnect/bug-4324-gdax-brokerage-stability
Replace WebSocketSharp with System.Net.WebSockets in GDAXBrokerage
2020-05-20 17:58:40 -03:00
Martin-Molinero
770f8b593f Merge pull request #4429 from simonsonjack/update-AlphaStreamsSlippageModel
Updated AlphaStreamsSlippageModel
2020-05-20 17:46:20 -03:00
Jared
3ca41c46d4 Merge pull request #4438 from QuantConnect/bug-typo-option-contract-style
Fixes Typo OptionContract.Style
2020-05-20 08:59:53 -07:00
Alexandre Catarino
9de6740438 Fixes Typo OptionContract.Style 2020-05-20 16:57:05 +01:00
Stefano Raggi
0478daccd3 Address review 2020-05-20 17:04:42 +02:00
Jared
59ed3f58e9 Merge pull request #4436 from gsalaz98/bug-4424-report-generator-decimal-deserialization
Fixes issue in Report project where decimal.MaxValue made Json.NET deserialization fail
2020-05-19 17:57:03 -07:00
Gerardo Salazar
1910e8e233 Fixes issue in Report project where decimal.MaxValue made Json.NET deserialization fail 2020-05-19 17:17:35 -07:00
Gerardo Salazar
2c8825a0ef Fixes Second, Tick Resolution history requests for Alpaca 2020-05-19 15:21:18 -07:00
Jared
88cb12ae8c Update SmartInsiderEventType.cs 2020-05-19 08:09:47 -07:00
Stefano Raggi
d19953c21e Add missing Dispose 2020-05-19 16:53:26 +02:00
Stefano Raggi
b86a729ccb Address review 2020-05-19 14:52:38 +02:00
Stefano Raggi
1fe660a35f Update GDAXBrokerage to use System.Net.WebSockets instead of WebSocketSharp 2020-05-19 08:40:34 +02:00
Jack Simonson
9f53e65472 Reinstate slippage 2020-05-18 15:50:12 -07:00
Jack Simonson
ac4d1107d9 Updated AlphaStreamsSlippageModel 2020-05-18 09:46:59 -07:00
Martin-Molinero
b89e2ef9c2 Merge pull request #4427 from AlexCatarino/feature-adds-optionstyle-contract
Adds Style Property to OptionContract
2020-05-18 12:54:09 -03:00
Martin-Molinero
666214590e Merge pull request #4422 from QuantConnect/feature-4284-pandas-override
Implements New PandasData Remapper
2020-05-18 12:48:38 -03:00
Martin-Molinero
9385707061 Merge pull request #4407 from michael-sena/feature-open-interest-future-universe
Add a futures universe selection model that uses open interest
2020-05-18 12:47:52 -03:00
AlexCatarino
34c337e766 Addresses Peer-Review 2020-05-18 16:28:19 +01:00
Michael Sena
a5d7bdafde Add a futures universe selection model that uses open interest 2020-05-19 00:30:58 +10:00
Martin-Molinero
86794a9e78 Merge pull request #4423 from QuantConnect/refactor-update-to-net-4-6-2
Update to .Net 4.6.2
2020-05-18 10:39:25 -03:00
AlexCatarino
f668bc4c73 Adds Style Property to OptionContract
The information on option style type was not present in OptionContract object.
2020-05-18 14:09:33 +01:00
AlexCatarino
f1b1474462 Adds unit test for all DataFrame and Series
- Adds unit tests for parameterless methods
- Adds unit tests for operations between two DataFrames or Series

- Adds unit tests for 'add_prefix', 'add_suffix', 'agg', 'aggregate', 'align', 'apply', 'applymap', 'asfreq', 'asof', 'assign', 'astype', 'at_time', 'axes', 'between_time', 'clip_lower', 'clip_upper', 'columns', 'combine', 'combine_first', 'corrwith', 'drop', 'droplevel', 'dtypes',
'eval', 'explode', 'fillna', 'filter', 'first', 'ftypes', 'get_value_index', 'get_value_column', 'groupby', 'isin', 'items', 'iterrows' and 'T'. (Ref.: #4365, #4368, #4370, #4372, #4373, #4377, #4380)
2020-05-15 23:31:38 +01:00
AlexCatarino
e9eba27e6e Implements New PandasData.Remapper
In this implementation, we dynamically create new classes that wraps key functions and properties. The wrappers will map/convert any parameter that are convertible to the string representation of Symbol.ID before they are used by the original function/property.
2020-05-15 23:30:19 +01:00
Jared
c82ad8638a Merge pull request #4399 from gsalaz98/bug-4382-smartinsider-new-eventtypes
Adds missing fields from intentions dataset to SmartInsiderEventType enum
2020-05-15 14:38:25 -07:00
Jared
1403b2370d Update SmartInsiderEventType.cs 2020-05-15 14:38:12 -07:00
Martin Molinero
891cf4d69b Update to .Net 4.6.2 2020-05-15 17:32:46 -03:00
Martin-Molinero
7bcd648f86 Merge pull request #4409 from QuantConnect/bug-3936-tiingonews-data-points-drop-v2
Fix TiingoNews Time
2020-05-15 10:13:49 -03:00
Martin-Molinero
a2a6e0d265 Merge pull request #4421 from QuantConnect/update-qlnet-to-1.11.3-release
Update QLNet to 1.11.3 release
2020-05-15 10:06:14 -03:00
Martin Molinero
c1b1d828f6 Update QLNet to 1.11.3 release 2020-05-14 18:55:50 -03:00
Martin-Molinero
c5a575092a Merge pull request #4416 from gsalaz98/bug-benzinga-data-converter-existing-zip-files
Fixes data destination issue in BenzingaNewsDataConverter
2020-05-14 18:15:12 -03:00
Gerardo Salazar
9ad876ff31 Fixes data destination issue in BenzingaNewsDataConverter 2020-05-14 13:01:29 -07:00
Martin-Molinero
173eac334d Merge pull request #4411 from QuantConnect/futures-data-downloading-and-saving
Add support for saving Futures/Options data in LeanDataWriter
2020-05-14 16:30:56 -03:00
Martin-Molinero
bf8297050b Merge pull request #4415 from Martin-Molinero/refactor-improve-security-price-is-zero-message
Normalize and improve Zero security price message
2020-05-14 11:37:49 -03:00
Martin Molinero
1576886d94 Address reviews 2020-05-14 11:36:29 -03:00
Martin Molinero
49abcd08b3 Normalize and improve Zero security price message 2020-05-13 21:19:37 -03:00
Stefano Raggi
bef8011327 Address review 2020-05-14 01:14:19 +02:00
Jared
210f67fa8c Merge pull request #4414 from Martin-Molinero/bug-4375-4332-mean-variance-optimization-pcm
Fix exceptions in ReturnsSymbolData
2020-05-13 14:13:29 -07:00
Martin Molinero
afa39cc0b1 Fix exceptions in ReturnsSymbolData
- Fix out of range exception, if the returns array is smaller for some
  of the Symbols it will use double.NaN, similar behavior to when a date
  isn't found for a Symbol. Adding unit test
- Fix duplicate key exception at ReturnsSymbolData.Returns, this could
  happen with FF in history requests. Adding unit test
2020-05-13 17:22:14 -03:00
Stefano Raggi
c68a478261 Merge pull request #4413 from Martin-Molinero/bug-alpaca-brokerage-unit-test
Fix Alpaca unit test after error change
2020-05-13 18:31:28 +02:00
Martin Molinero
16fdd1eb4f Fix Alpaca unit test after error change 2020-05-13 12:44:53 -03:00
Jared
b8e78e4802 Merge pull request #4412 from StefanoRaggi/alpaca-brokerage-model-better-error-messages
Improve error messages in AlpacaBrokerageModel
2020-05-13 07:19:42 -07:00
Stefano Raggi
fd9aa2dbd2 Improve error messages in AlpacaBrokerageModel 2020-05-13 16:04:31 +02:00
Martin-Molinero
ee1c97b06c Merge pull request #4410 from QuantConnect/bug-unit-test-python-setup
Moves Python Path Environment Variable Setting to AdjustCurrentDirectory
2020-05-13 10:36:00 -03:00
Stefano Raggi
541421f290 Fix extended market hours flag 2020-05-13 11:38:53 +02:00
Stefano Raggi
d7ca05c541 Save future/option daily/hourly data in LeanDataWriter 2020-05-13 11:38:53 +02:00
Stefano Raggi
880afae4b7 Add futures download and save to IBDataDownloader 2020-05-13 11:38:53 +02:00
Stefano Raggi
0831f2052d Add future/option support to LeanDataWriter 2020-05-13 11:38:53 +02:00
Stefano Raggi
b3cf6315de Add IncludeExpired flag to IDataQueueUniverseProvider.Lookup
This flag was added to enable history requests for expired futures and options contracts.
2020-05-13 11:38:53 +02:00
AlexCatarino
74395566eb Moves Python Path Environment Variable Setting to AdjustCurrentDirectory
Removes PythonSetup.
2020-05-13 00:48:01 +01:00
Martin Molinero
6009e3ffeb Fix TiingoNews Time
- Fix TiingoNews time for backtesting, converter will store and organize
  data based on the 'QC time' which is crawldate or publish data plus an
  offset
2020-05-12 16:15:26 -03:00
Jared
ad018ba4c6 Merge pull request #4398 from QuantConnect/bug-4032-future-research-filter
QuantBook Future History Filter
2020-05-12 10:56:06 -07:00
Martin-Molinero
8511235bcd Merge pull request #4401 from gsalaz98/bug-estimize-estimates-reader-crashing
Fix Estimize processing issues that prevented two downloaders from completing
2020-05-11 20:18:07 -03:00
Jared
af601a9abe Merge pull request #4406 from QuantConnect/revert-4404-bug-4402-us-futures-index-data
Revert "Removes us index futures data property"
2020-05-11 15:41:02 -07:00
Jared
df8697dc1e Revert "Removes us index futures data property" 2020-05-11 15:40:50 -07:00
Jared
e4c2c9b268 Merge pull request #4400 from Martin-Molinero/bug-compression-add-missing-dispose-call
Add missing dispose call for MemoryStream
2020-05-11 15:20:30 -07:00
Gerardo Salazar
7036a3e99c Address review - add missing continue statement and extends unit tests 2020-05-11 15:14:43 -07:00
Jared
4a4e2d11bd Merge pull request #4404 from DerekMelchin/bug-4402-us-futures-index-data
Removes us index futures data property
2020-05-11 15:14:04 -07:00
Jared
0958da6571 Merge pull request #4403 from QuantConnect/refactor-remove-psychsignal
Remove PsychSignal data
2020-05-11 15:11:32 -07:00
Derek Melchin
c4c3bf915c Removes us index futures data property 2020-05-11 15:51:00 -06:00
Martin Molinero
269b8ba204 Remove PsychSignal data
- Remove PsychSignal data since it's no longer available
2020-05-11 18:48:13 -03:00
Gerardo Salazar
4a923e3e43 Address review - add tests and reduce code duplication
* Refactors the delimiter detection method to make adding new
    values quick and easy.
2020-05-11 13:46:08 -07:00
Gerardo Salazar
5d6c5c6235 Fix processing issue that stopped Estimize from completing successfully
* We made an assumption that all tickers marked as "defunct" from
    Estimize would have a dash '-' separating the defunct indicator
    from the ticker. However, there was a ticker where the defunct
    separator was actually an underscore '_'. There are now
    additional checks in place to ensure that we do not pass the
    Substring method an invalid 'length' value.
2020-05-11 12:22:06 -07:00
Jared
4fea6128a7 Merge pull request #4390 from gsalaz98/feature-alternative-data-robintrack
Implements Robintrack BaseData and example algorithms
2020-05-11 12:06:53 -07:00
Gerardo Salazar
51cbbf404b Adds missing fields from intentions dataset to SmartInsiderEventType enum 2020-05-11 11:50:59 -07:00
Martin Molinero
5c721b1248 Add missing dispose call for MemoryStream
- Add missing dispose call for MemoryStream. Covered by existing tests
2020-05-11 15:44:22 -03:00
Martin Molinero
52a732cbe0 Research Future History Filter
- QuantBook future history request will now apply contract filtering.
  Adding unit tests
2020-05-11 15:11:47 -03:00
Gerardo Salazar
d2eb0482fa Address reviews - refactors portions of code and adds tests 2020-05-08 18:22:16 -07:00
Jared
17a904753c Merge pull request #4396 from QuantConnect/bug-4190-4392-fillforward-enumerator
Fix for fillforward enumerator
2020-05-08 14:23:47 -07:00
Martin Molinero
21475b327b Address reviews
- Add a comment explaning why we need to round down in data time zone
  and not exchange timezone.
- Keep subscription EndTime RoundDown by DataResolution since it won't
  change and it's expensive.
2020-05-08 15:57:13 -03:00
Martin Molinero
f72bb3d513 Fix invalid round down operation
- RoundDown was being performed in exchange time zone but should be done
  in data time zone
2020-05-08 15:10:43 -03:00
Martin Molinero
63bf4e72a0 Revert "Revert "Fix market open missing FillForward bar""
This reverts commit 1ac8146eae.
2020-05-08 12:46:02 -03:00
Martin-Molinero
c46b3c77b1 Merge pull request #4394 from QuantConnect/bug-zipdatacacheprovider-unhandled-exception
Fix unhandled exception in ZipDataCacheProvider
2020-05-08 12:21:17 -03:00
Stefano Raggi
ad9949d460 Fix unhandled exception in ZipDataCacheProvider 2020-05-08 17:11:53 +02:00
Stefano Raggi
d32ce197e5 Merge pull request #4393 from QuantConnect/revert-4207-bug-4190-fillforward-on-market-open
Revert "Fix market open missing FillForward bar"
2020-05-08 16:53:17 +02:00
Martin-Molinero
1ac8146eae Revert "Fix market open missing FillForward bar" 2020-05-08 11:38:59 -03:00
Gerardo Salazar
d3a5f52fe9 Implements Robintrack BaseData and example algorithms 2020-05-07 16:26:15 -07:00
Jared
1c8ad79674 Merge pull request #4389 from DerekMelchin/bug-4378-talib-example-algorithm
Adds talib indicators example algorithm
2020-05-07 13:40:18 -07:00
Derek Melchin
5b48138f4d Adds talib indicators example algorithm 2020-05-07 13:57:57 -06:00
Martin-Molinero
90668e3992 Merge pull request #4387 from QuantConnect/revert-4368-bug-4284-pandas-data-remapper
Revert "Adds pandas Methods (Part I)"
2020-05-06 20:16:14 -03:00
Martin-Molinero
85cc7b13dc Revert "Adds pandas Methods (Part I)" 2020-05-06 20:16:04 -03:00
Martin-Molinero
394b332588 Merge pull request #4386 from QuantConnect/revert-4370-bug-4284-pandas-data-remapper
Revert "Adds pandas Methods (Part II)"
2020-05-06 20:15:51 -03:00
Martin-Molinero
31ed6e349b Revert "Adds pandas Methods (Part II)" 2020-05-06 20:15:41 -03:00
Martin-Molinero
5eb36581e7 Merge pull request #4385 from QuantConnect/revert-4372-bug-4284-pandas-data-remapper-iii
Revert "Adds pandas Methods (Part III)"
2020-05-06 20:15:29 -03:00
Martin-Molinero
3d9a24ff5c Revert "Adds pandas Methods (Part III)" 2020-05-06 20:15:17 -03:00
Martin-Molinero
8dc00f92c1 Merge pull request #4384 from QuantConnect/revert-4373-bug-4284-pandas-data-remapper
Revert "Adds pandas Methods (Part IV)"
2020-05-06 20:15:08 -03:00
Martin-Molinero
07ef201f01 Revert "Adds pandas Methods (Part IV)" 2020-05-06 20:14:57 -03:00
Martin-Molinero
3fd04d2768 Merge pull request #4383 from QuantConnect/revert-4377-bug-4284-pandas-data-remapper-v
Revert "Adds pandas Methods (Part V)"
2020-05-06 20:14:41 -03:00
Martin-Molinero
07bf7f48e4 Revert "Adds pandas Methods (Part V)" 2020-05-06 20:14:17 -03:00
Martin-Molinero
fbc4a880c8 Merge pull request #4376 from QuantConnect/performance-4347-3283-option-improvements
Performance improvements for Options
2020-05-06 15:30:37 -03:00
Martin-Molinero
2f0f5f306c Merge pull request #4377 from QuantConnect/bug-4284-pandas-data-remapper-v
Adds pandas Methods (Part V)
2020-05-06 12:42:01 -03:00
Martin Molinero
01689afd31 keep cache option filter unique strike list 2020-05-06 12:04:31 -03:00
AlexCatarino
c1baf7da1a Addresses Peer-Review
`first_valid_index´ has been removed for now as it doesn't have a satifactory init test. It will be added in a future commit.
2020-05-06 14:28:59 +01:00
Martin-Molinero
2709799571 Merge pull request #4373 from QuantConnect/bug-4284-pandas-data-remapper
Adds pandas Methods (Part IV)
2020-05-06 10:00:39 -03:00
AlexCatarino
1538d0f134 Adds pandas Methods (Part V)
Methods: 'eq', 'eval', 'explode', 'ffill', 'fillna', 'filter', 'first', 'floordiv', 'ftypes', 'ge'
2020-05-06 02:05:20 +01:00
Martin Molinero
714b98f832 Performance improvements for Options
- Replace Enum to string operations on Options enums, since it's
  expensive
- Replace Enum IsDefined check since it uses reflection
- Improve OptionFilterUniverse linq operations
- Improve performance of SecurityIdentifier properties to avoid having
  to extract them from properties always
- Avoid calling ToList for already list data collections (it creates a
  copy)
- Avoid iterating over securities for which we have no holdings when
  calculating TPV or MarginUsed
2020-05-05 21:14:12 -03:00
AlexCatarino
b7b54ffa0b Adds pandas Methods (Part IV)
Methods: 'diff', 'div', 'divide', 'drop', 'drop_duplicates', 'droplevel', 'dropna', 'dtypes', 'duplicated'

`BackwardsCompatibilityDataFrame_binary_operator` replaces `BackwardsCompatibilityDataFrame_add` to handle all operations (more to be added in future commits)
2020-05-05 21:43:12 +01:00
Jared
6588defc8b Merge pull request #4372 from QuantConnect/bug-4284-pandas-data-remapper-iii
Adds pandas Methods (Part III)
2020-05-05 13:12:16 -07:00
AlexCatarino
02d90c4fb0 Adds pandas Methods (Part III)
Methods: 'columns', 'combine', 'combine_first', 'compound', 'copy', 'corr', 'corrwith', 'count', 'cov', 'cummax', 'cummin', 'cumprod', 'cumsum'
2020-05-05 17:15:30 +01:00
Martin-Molinero
6456794e3d Merge pull request #4370 from QuantConnect/bug-4284-pandas-data-remapper
Adds pandas Methods (Part II)
2020-05-05 12:54:16 -03:00
AlexCatarino
a14c41bb97 Addresses Peer-Review
Removes `bool` because it doesn't return a pandas object with an index.
2020-05-05 15:24:34 +01:00
Jared
72c734308e Merge pull request #4371 from QuantConnect/ib-sugar-future-mapping-fix
Remove incorrect IB mapping for Sugar Future N.11
2020-05-05 07:15:15 -07:00
Stefano Raggi
082de97026 Remove incorrect IB mapping for Sugar Future N.11
- IB supports the SB symbol on ICE/NYBOT
- IB does not support the YO symbol on CME/NYMEX
2020-05-05 14:02:45 +02:00
AlexCatarino
321603926a Adds pandas Methods (Part II)
Methods: 'asfreq', 'asof', 'assign', 'astype', 'at', 'at_time', 'axes', 'between_time', 'bfill', 'bool', 'clip', 'clip_lower', 'clip_upper'.
2020-05-05 12:40:14 +01:00
Jared
3fb9848184 Merge pull request #4369 from QuantConnect/ib-brokerage-futures-mapping-fix
Fix IB brokerage futures mapping
2020-05-04 18:13:43 -07:00
Martin-Molinero
ba2d313534 Merge pull request #4368 from QuantConnect/bug-4284-pandas-data-remapper
Adds pandas Methods (Part I)
2020-05-04 21:55:55 -03:00
Stefano Raggi
efc5c3c519 Fix IB brokerage futures mapping 2020-05-05 02:34:14 +02:00
AlexCatarino
ff32b8e15e Adds pandas Methods (Part I)
Methods: 'abs', 'add', 'add_prefix', 'add_suffix', 'agg', 'aggregate', 'align', 'all', 'any', 'append', 'apply', 'applymap'.
2020-05-05 01:32:49 +01:00
Martin-Molinero
b66df2bf55 Merge pull request #4365 from QuantConnect/bug-4298-pandas-data-remapper
Fixes Not Wrapped pandas.Dataframe
2020-05-04 17:27:09 -03:00
Martin Molinero
439b32dc4d Address reviews 2020-05-04 16:58:47 -03:00
AlexCatarino
ca9f0cc2d3 Refactors PandasConverterTests Unit Tests
Use `TestCase` for BackwardsCompatibilityDataFrame to avoid code duplication and test the three possible pandas.Dataframe index options.
2020-05-04 20:07:43 +01:00
Jared
5efe7b81b8 Merge pull request #4364 from adam-may/bug-4363-use-prices-current-for-stoplimitfill
FillModel.StopLimitFill should use prices.Current instead…
2020-05-04 08:52:09 -07:00
Martin Molinero
44b0ab3b1c Fix unit test 2020-05-04 11:43:06 -03:00
Martin-Molinero
2cd659ab3c Merge pull request #4360 from QuantConnect/bug-4338-datetime-thread-safety-zipcache
Value types thread safety changes
2020-05-04 10:37:25 -03:00
Adam May
1f57631299 Bug #4363 - FillModel.StopLimitFill should use prices.Current instead of asset.Price to see if fill has occured 2020-05-03 15:07:23 +10:00
Martin-Molinero
6a53688e77 Merge pull request #4351 from QuantConnect/feature-4331-updates-python-libraries
Updates DockerfileFoundation For Python Packages
2020-05-01 20:49:06 -03:00
Martin Molinero
c226914322 Value types thread safety changes
- Refactor ZipDataCacheProvider to avoid value types thread issues, it
  will now use a timer. Add missing dispose calls.
- Synchronizer won't share the `SubscriptionFrontierTimeProvider`
  instance since it's not thread safe and shouldn't be called
- Fix BacktestingResultHandler `_daysProcessed` thread safety
- Fixing `RealTimeScheduleEventService` thread safety
2020-05-01 16:58:29 -03:00
Martin-Molinero
eb5d380f5a Merge pull request #4356 from QuantConnect/bug-4338-value-type-thread-safety
Adding new ReferenceWrapper for structs
2020-05-01 12:16:07 -03:00
Martin Molinero
649b9f010f Fix thread race conditions reading and writing
- Fix for thread race condition reading and writing current time loop.
  Adding unit test
2020-05-01 11:47:19 -03:00
Jared
df9a7d3abf Merge pull request #4355 from QuantConnect/bug-4353-market-hours-data-base-json-round-trip
Fix MHDB json round trip
2020-05-01 06:25:46 -07:00
AlexCatarino
a892173710 Fixes Not Wrapped pandas.Dataframe
`Remapper.__getitem__`  was not returns a `Remapper` object when the result was `pandas.DataFrame`. It is needed for a sequence of `.loc.` calls.
Refactors `Remapper._self_mapper` to handle tuples where the key can be found in both first and second position.

Update unit tests that should test `Symbol` object as key, but were using `str(Symbol)`.
2020-05-01 00:25:46 +01:00
Martin Molinero
3e09d2f3c9 Adding new ReferenceWrapper
- Adding new ReferenceWrapper for structs, value types, to avoid thread
  race conditions while reading and writting. In C# reference type
  assignments are atomic, so it allows us avoid using locks.
2020-04-30 19:56:15 -03:00
Martin Molinero
1e221c514b Unit test race condition fixes 2020-04-30 17:19:43 -03:00
Martin Molinero
4712b3ea24 Fix MHDB json round trip
- Fix MarketHoursDataBase Json round trip, updating unit test
2020-04-30 16:53:49 -03:00
Jared
5c4c256a0d Merge pull request #4354 from QuantConnect/bug-4155-quant-book-objectstore
Fix ObjectStore for QuantBook
2020-04-30 12:15:04 -07:00
Jared
c939c68f21 Merge pull request #4350 from QuantConnect/feature-4348-extend-idqh
Add Dispose and IsConnected to IDataQueueHandler
2020-04-30 11:24:50 -07:00
Martin Molinero
f86af05227 Fix for ObjectStore for QuantBook 2020-04-29 21:03:35 -03:00
Martin-Molinero
24dfa910d7 Merge pull request #4352 from QuantConnect/bug-early-closes-equity
Revert removing equity early closes in MHDB
2020-04-29 18:29:55 -03:00
JJD
7a30346349 Add generic entry for CBOE
tidy up JSON
2020-04-29 18:23:34 -03:00
JJD
a2304bed33 Fix invalid JSON + generic futures exchanges entries 2020-04-29 18:09:58 -03:00
JJD
f4b814f98c Revert removing equity early closes in MHDB 2020-04-29 20:21:57 +00:00
AlexCatarino
a972502609 Updates .travis.yml Python Packages 2020-04-29 01:00:26 +01:00
AlexCatarino
7573286a70 Updates DockerfileFoundation For Python Packages
Adds new and updates Python Packages:
Closes #2707 (mplfinance)
Closes #3541 (CuffLinks IpyWidgets)
Closes #3975 (Jax)
Closes #3982 (gluonts astropy gplearn tigramite ssm auto_ks)
Closes #3983 (H2O AutoML)
Closes #4050 (neural-tangent)
Closes #4125 (CNTK)
Closes #4129 (updates)
Closes #4170 (NLTK Vader Sentiments)
Closes #4246 (riskparity pyrb)
Closes #4256 (Copulae)
Closes #4282 (featuretools)
Closes #4331 (keras-rl pennylane)
2020-04-29 00:28:36 +01:00
Martin-Molinero
5625acbd6f Merge pull request #4328 from QuantConnect/refactor-future-symbol-market
Refactor Future Market
2020-04-28 19:40:04 -03:00
Martin-Molinero
571fc2e3b0 Merge pull request #4349 from QuantConnect/performance-tick-streamreader
Add StreamReader for Tick
2020-04-28 18:40:40 -03:00
Martin Molinero
183aac039d Address reviews 2020-04-28 18:12:26 -03:00
Stefano Raggi
e151991c91 Add timer dispose in FakeDataQueue.Dispose 2020-04-28 23:08:34 +02:00
Martin Molinero
6d9cd4bde4 Small fix for unit test 2020-04-28 16:53:38 -03:00
Martin-Molinero
24998c2c03 Merge pull request #4207 from QuantConnect/bug-4190-fillforward-on-market-open
Fix market open missing FillForward bar
2020-04-28 16:47:52 -03:00
Martin Molinero
1c3c2e810e Address review
- Minor fixes
- Adding regression algorithm adding futures with the same ticker
  different market
2020-04-28 16:29:54 -03:00
JJD
13f54e7ffe Remove exchange from tick files 2020-04-28 16:29:17 -03:00
JJD
eff06b86eb Look for exchange on SPDB instead of the raw filename 2020-04-28 16:29:17 -03:00
Martin Molinero
fa77c33fed Address reviews. Update unit tests
- Updating unit tests which were still using Market.USA for futures
2020-04-28 16:29:17 -03:00
JJD
97239777ae Include generic by exchange in MHDB 2020-04-28 16:29:17 -03:00
JJD
0e5f2b7e07 Add future generic for all exchanges in MHDB 2020-04-28 16:29:17 -03:00
Martin Molinero
07f36ad3e9 Update IQFeedDataQueueHandler future market check 2020-04-28 16:29:16 -03:00
Martin Molinero
4a99eb11c6 Fix regression tests
- Fix regression tests. Future symbol contains the market which was used
  un the order hash list
2020-04-28 16:29:16 -03:00
Martin Molinero
5bc9651dc8 Fix more unit tests 2020-04-28 16:29:16 -03:00
JJD
9ecc6b008b Fix issue in AlgoSeekFuturesReader 2020-04-28 16:29:16 -03:00
JJD
800e283de7 Add generic entries for all future's exchanges 2020-04-28 16:29:16 -03:00
JJD
80165b67b9 Fix Sugar futures entry 2020-04-28 16:29:16 -03:00
Martin Molinero
62e192f9cd Improve MHDB Future Market.Usa exception
- MHDB will now throw exceptions for Futures using Market.Usa, improving
  the exception adding new message and providing a suggested market
2020-04-28 16:29:16 -03:00
JJD
5a9886bcdb Order symbols propeties by exchange - symbol 2020-04-28 16:29:16 -03:00
JJD
2ef5129e9d Move margins to its respective exchanges folders 2020-04-28 16:29:16 -03:00
Martin Molinero
9a8b1dc8fd Fixes for unit tests 2020-04-28 16:29:15 -03:00
JJD
cbcc20a22b Remove all references to Market.USA in AlgoSeek futures converter 2020-04-28 16:29:15 -03:00
Martin Molinero
149d30f020 Fixes and Improvements
- Removing spaces in MHDB.json file reducing size
- Update tests using wrong future market
2020-04-28 16:29:15 -03:00
JJD
4ab5d8fc34 Update future data sample 2020-04-28 16:29:15 -03:00
Juan José D'Ambrosio
41955297f0 Parse the exchange from raw data filename 2020-04-28 16:29:14 -03:00
Martin Molinero
cd2ef13d38 Update FuturesExpiryFunctions
- Update FuturesExpiryFunctions to be keyed by symbol. Updating unit
  tests
2020-04-28 16:29:14 -03:00
Juan José D'Ambrosio
ebf7084d9a Fix issue removing NTY
NTY was not found in symbol properties, nor in CME Group product list.
2020-04-28 16:29:14 -03:00
Juan José D'Ambrosio
ffe19d048f Update MHDB
with the specific exchange for each future
2020-04-28 16:29:14 -03:00
Juan José D'Ambrosio
5309a56372 Remove undefined future AC
Remove comma from EXR description.
2020-04-28 16:29:14 -03:00
Martin Molinero
88d4719327 Fixes for future market users
- Update consumers using Market.USA for future symbols
- Fix for SymbolPropertiesDatabase changes
2020-04-28 16:29:14 -03:00
JJD
d2e42409d3 Update Futures converter for new exchanges 2020-04-28 16:29:14 -03:00
JJD
60249b783d Restore deleted comment 2020-04-28 16:29:14 -03:00
JJD
016c101fe0 Update symbol propeties with exchanges and description for futures. 2020-04-28 16:29:14 -03:00
Martin Molinero
b1d6d21d07 Refactor Future symbol Market
- Replacing usage of Market.USA as market for Future Symbols. Will now
  check SymbolPropertiesDatabase
2020-04-28 16:29:14 -03:00
Martin Molinero
f78142fe32 Fix rebase after data update 2020-04-28 15:53:01 -03:00
Martin Molinero
075e82629a Add more unit tests
- Add more fill forward unit test including a weekend using different
combinations of resolutions
- Add required AIG second data file
- Avoid list in most common FF case
2020-04-28 15:23:07 -03:00
Martin Molinero
bf1e4ae19c Fix market open FillForward
- Fix bar not being fill forward on market open
- Adding unit tests which fail in master
2020-04-28 15:23:06 -03:00
Martin Molinero
7a90f03eef Self review
- Avoid null fills case could happen on FillModel exception
- Smarter ConcurrentQueue.Count call at BaseResultHandler
2020-04-28 14:44:50 -03:00
Martin Molinero
a8173589c7 Add StreamReader for Tick
- Add StreamReader Reader for Tick data type.
- Adding stream reader GetString extension, adding tests.
- BacktestingBrokerage will not create unnecessary order events
2020-04-28 13:32:40 -03:00
Stefano Raggi
7554babad8 Add Dispose and IsConnected to IDataQueueHandler 2020-04-28 17:39:13 +02:00
Martin-Molinero
9dc2f0220e Merge pull request #4346 from QuantConnect/performance-skip-python-for-onframeworkdata
Python OnFrameworkData performance and slice.Get()
2020-04-27 20:56:01 -03:00
Martin Molinero
889fc0ce68 Fix config unit test 2020-04-27 19:39:18 -03:00
Martin Molinero
8e71e48c07 PythonSlice
- AlgorithmPythonWrapper will directly call base OnFrameworkData()
  implementation skipping going through python and it's overhead
- Small performance improvement for adding Tick data points into a Ticks
  collection
- For python always wrap slice with PythonSlice, so that slice.Get()
  works even when no custom data is present, adding test.
2020-04-27 19:03:03 -03:00
Jared
73ce2afebd Merge pull request #4337 from QuantConnect/parallel-unit-testing
Enable parallel unit testing
2020-04-27 14:04:43 -07:00
Jared
5d48bbdb52 Merge pull request #4341 from prasadsom/feature-4307-Add-Feature-to-Identify-Weekly-Option
Added IsWeekly function to class OptionSymbol
2020-04-27 13:54:24 -07:00
Jared
83499ea68f Merge pull request #4345 from QuantConnect/bug-4344-ib-history-no-data-error-filter
Fix IB Historical Data Request Error "HMDS query returned no data"
2020-04-27 13:53:37 -07:00
Martin Molinero
1fcd9588d6 Dispose Timers and threads in tests 2020-04-27 17:46:16 -03:00
Martin Molinero
9ee9cf9fc5 Address reviews 2020-04-27 17:46:10 -03:00
Martin Molinero
e73e927c0f Enable parallel unit testing 2020-04-27 17:45:53 -03:00
Martin-Molinero
c94cca3f75 Merge pull request #4339 from QuantConnect/add-server-statistics-for-backtesting
Add server statistics for backtesting
2020-04-27 17:26:41 -03:00
Martin-Molinero
70b123d448 Merge pull request #4343 from QuantConnect/refactor-remove-streaming-api
Remove QC StreamingApi client
2020-04-27 17:26:07 -03:00
Stefano Raggi
2485b474b8 Fix IB Historical Data Request Error "HMDS query returned no data" 2020-04-27 22:14:51 +02:00
Prasad Somwanshi
f239520111 Added IsWeekly function to class OptionSymbol and renamed existing IsStandardContract function to IsStandard 2020-04-27 18:31:44 +01:00
Martin Molinero
f01185227b Remove QC StreamingApi client
- Removing unused QC StreamingApi client
2020-04-27 12:23:28 -03:00
Jared
f25b2dbc64 Merge pull request #4340 from AlexCatarino/feature-options-price-model-example
Adds BasicTemplateOptionsPriceModel
2020-04-24 17:49:58 -07:00
AlexCatarino
cc3f2416ff Adds BasicTemplateOptionsPriceModel
Show how to define an options price model and the available options. Tests whether the options contracts has a valid (non-zero) `Greeks.Delta`
2020-04-25 01:46:29 +01:00
Martin Molinero
ab81859896 Remove drive space information 2020-04-24 20:56:20 -03:00
Martin Molinero
97f8f50230 Add server statistics for backtesting 2020-04-24 20:33:19 -03:00
Jared
ac0a6a3c4c Merge pull request #4330 from QuantConnect/bug-4127-python-add-universe
Fix AddUniverse(Universe, FineFunc)
2020-04-24 15:26:21 -07:00
Martin Molinero
de05f15a12 Address review
- Adding live trading unit test
2020-04-24 19:04:41 -03:00
Martin Molinero
b3970bdc3b Fixes and rebase
- FineFundamentalSubscriptionEnumeratorFactory will not emit empty fine
  points
2020-04-24 17:21:28 -03:00
Martin Molinero
89a73a5671 Fix and regression tests
- Fix FineFundamentalFilteredUniverse for a custom universe
- Adding regression test
2020-04-24 17:21:28 -03:00
Huai Chun Shih
fa79fc8a41 Let Python can AddUniverse(universe, fineFunc) 2020-04-24 17:21:28 -03:00
Martin-Molinero
8eace12fb5 Merge pull request #4334 from QuantConnect/feature-4201-nunit-update
Updating NUnit to 3.12
2020-04-24 17:12:03 -03:00
Jared
32a6eac08c Merge pull request #4336 from QuantConnect/bug-update-python-version
Update FSharp to PythonNet 1.0.5.30
2020-04-24 13:09:31 -07:00
Martin Molinero
3552ecee90 Update FSharp PythonNet 2020-04-24 17:02:01 -03:00
Martin Molinero
658b8c6a10 Reset config after updating current dir 2020-04-23 15:18:38 -03:00
Martin Molinero
3fef5b7deb Fix Travis and brokerages unit tests 2020-04-23 11:13:56 -03:00
Martin Molinero
886e5e6445 Test fixes and updates 2020-04-23 09:59:31 -03:00
Leonardo-Ferreira
951c973d5b Adjusted the OneTimeSetup attribute usage 2020-04-22 18:19:08 -03:00
Leonardo-Ferreira
6b40d1be6d Code clean-up 2020-04-22 18:19:08 -03:00
Leonardo-Ferreira
1c00bcb69e Replace nunit's IS operation 2020-04-22 18:19:08 -03:00
Leonardo-Ferreira
8d31b4ee8e Update the Expected Exception 2020-04-22 18:19:08 -03:00
Leonardo-Ferreira
9a907d4178 Updated Ignored tests 2020-04-22 18:19:06 -03:00
Leonardo-Ferreira
a9b356d7ff Replaced TestFixtureTearDown 2020-04-22 18:16:58 -03:00
Leonardo-Ferreira
37b1906022 Updated to OneTimeSetUp 2020-04-22 18:16:58 -03:00
Leonardo-Ferreira
2904b8219d Update to latest nUnit and test adapter 2020-04-22 18:16:55 -03:00
Jared
357729521d Merge pull request #4326 from QuantConnect/feature-3952-objectstore-python
Adds Python Example of ObjectStore Feature
2020-04-22 09:40:44 -07:00
Martin-Molinero
1bb477f598 Merge pull request #4318 from QuantConnect/bug-4275-improve-implict-conversion-failure
WIP/To Discuss: Improve Implicit Conversion Failure Message
2020-04-22 13:30:22 -03:00
Jared
1bc8b3f673 Merge pull request #4327 from QuantConnect/reduce-packet-number-size
Reduce Result packet number and size
2020-04-21 15:50:50 -07:00
AlexCatarino
dc79810c3f Modifies KerasNeuralNetworkAlgorithm to Include ObjectStore Example 2020-04-21 23:14:21 +01:00
AlexCatarino
2e5eddfc29 Adds Python Example of ObjectStoreExampleAlgorithm
Minor change in C# version to keep consistency between examples.
2020-04-21 23:14:21 +01:00
Jared
76b7f530bc Merge pull request #4322 from michael-sena/bug-4321-addmissingreferences
Remove unused references to IKVM.Reflection
2020-04-21 12:04:36 -07:00
Martin-Molinero
77e9f07c9e Merge pull request #4323 from QuantConnect/bug-3709-update-gdax-unit-tests
Update Coinbase brokerage unit tests
2020-04-21 14:54:45 -03:00
Michael Sena
fce5d9d2e6 Remove references to IKVM.Reflection in Brokerages and ToolBox 2020-04-22 01:31:53 +10:00
Stefano Raggi
7462934efa Update Coinbase brokerage unit tests
- should have been included in PR #4317
2020-04-21 17:23:40 +02:00
Jared
45e7a26e03 Merge pull request #4319 from QuantConnect/ib-csharp-api-update
Update IB C# API DLL to Apr 3, 2020
2020-04-20 15:01:26 -07:00
Stefano Raggi
b509e84bb4 Update IB C# API DLL to Apr 3, 2020
9ca5b3d294
2020-04-20 15:12:36 +02:00
Martin Molinero
47b5178c0b Reduce Result packet number and size
- Reduce ResultHandler amount of packets sent and their size.
- Only send order and orderEvents packet if there is actually data in them.
- Don't send Holdings fields if value is 0
- Don't send AlphaRuntimeStatistics fields if default values
2020-04-20 10:03:59 -03:00
Martin Molinero
fa819126c9 Improve implicit conversion failure message
- Improve string to Symbol implicit conversion exceptions message
2020-04-17 22:11:24 -03:00
Jared
93bac6f694 Merge pull request #4317 from QuantConnect/bug-3709-gdax-brokerage-updates
GDAX brokerage updates
2020-04-17 18:04:59 -07:00
Stefano Raggi
72ff7773cc GDAX brokerage updates
- fixed websocket authentication failure for "user" channel
- removed "matches" channel, now using authenticated "user" channel for order fills
- send BrokerageMessageEvent as error for subscription and authentication failures
2020-04-17 17:47:01 +02:00
Jared
0b3ecea4d7 Merge pull request #4311 from QuantConnect/merge-intraday-history-data-v2
Add optional intraday historical enumerator
2020-04-16 13:05:41 -07:00
Jared
33b6e5e4f3 Merge pull request #4315 from QuantConnect/refactor-order-fee-serialized-orderevent
SerializedOrderEvent will not serialize Null order fee
2020-04-16 13:05:13 -07:00
Jared
6188bdd368 Merge pull request #4316 from QuantConnect/ib-automater-v978-fix
Update IBAutomater to v1.0.22
2020-04-16 13:04:37 -07:00
Stefano Raggi
2dd6396faa Update IBAutomater to v1.0.22 2020-04-16 17:50:00 +02:00
Martin Molinero
c7d0f90490 Do not serialize Null order fee
- SerializedOrderEvent will ignore order fee with null currency. Adding
  unit tests
2020-04-16 12:29:40 -03:00
Jared
defc4834b1 Merge pull request #4314 from QuantConnect/alpaca-improved-order-event-logging
Add missing fields in Alpaca order event log
2020-04-16 08:20:00 -07:00
Stefano Raggi
23d35d251e Add missing fields in Alpaca order event log 2020-04-16 16:39:59 +02:00
Martin-Molinero
5f087fcd55 Merge pull request #4313 from laur89/bug-fix-streamingMessageHandler
fix StreamingMessageHandler - null reference
2020-04-16 09:20:26 -03:00
Laur Aliste
47748a9a61 fix StreamingMessageHandler - null reference
- assign value to _orderEventJsonConverter in SetAuthentication()
  _before_ it's referenced by Transmit(), fixing nullpointer;
2020-04-16 03:00:25 +02:00
Martin-Molinero
b5077f415e Merge pull request #4303 from gsalaz98/bug-report-generator-ordertype-deserialization
Fixes issue when parsing LiveResult JSON with string OrderType values
2020-04-15 15:23:49 -03:00
Gerardo Salazar
581eafb551 Address review - remove unused code in OrderTypeNormalizingJsonConverter 2020-04-15 09:59:21 -07:00
Martin-Molinero
f368071af0 Merge pull request #4310 from scalptrader/bug-4309-iqfeed-loadsymbolondemand-fix
Ignore symbols with the new continuous contract symbol
2020-04-15 12:16:31 -03:00
Martin Molinero
793cc15cd3 Add optional intraday historical enumerator
- Adding new ConcatEnumerator that will join enumerators together
  secuentially. Adding unit tests
- SubscriptionDataReaderHistoryProvider will consume an optional
  intraday enumerator that will be concatenated with the existing
  SubscriptionDataReader
2020-04-15 10:48:04 -03:00
ScalpTrader
f0147e38ff Ignore symbols with the new continuous contract symbol 2020-04-14 16:25:09 -10:00
Gerardo Salazar
558779949d Address review - trim unecessary code and ignore case on Enum parse 2020-04-14 11:08:40 -07:00
Jared
944e4c642e Merge pull request #4305 from adam-may/feature-4176-rework-dockerfile
Remove Dockerfile and replace with Docker scripts
2020-04-13 15:28:02 -07:00
Jared
26c8483bc5 Merge pull request #4306 from QuantConnect/feature-4287-partial-fill-model-algo
Adds CustomPartialFillModelAlgorithm
2020-04-13 13:03:24 -07:00
AlexCatarino
e23d7e4486 Adds CustomPartialFillModelAlgorithm
This basic algorithm implements a `CustomPartialFillModel` class that chnages the behavior of the `FillModel.MarketFill` to simulate partially fill orders.
2020-04-13 18:50:03 +01:00
AlexCatarino
8564a29d8a Updates PythonTools Project
Adds missing project files and removed old ones.
2020-04-13 18:48:04 +01:00
Adam May
8a5ec23d9a Adding Mac/Linux script 2020-04-14 01:36:55 +10:00
Adam May
d88783ffad Adding Windows batch file 2020-04-13 20:47:19 +10:00
Adam May
9074e9f742 Removing Dockerfile 2020-04-13 14:14:35 +10:00
Gerardo Salazar
093ddc848d Fixes issue when parsing LiveResult JSON with string OrderType values 2020-04-10 17:24:20 -07:00
Jared
2684f551fb Merge pull request #4300 from QuantConnect/performance-3850-stream-reader-quotebars
Extend StreamReader for QuoteBars
2020-04-10 16:28:50 -07:00
Martin Molinero
47795f1c90 Extend StreamReader for QuoteBars
- Adding performance tests for StreamReader QuoteBars
2020-04-10 15:39:51 -03:00
Jared
8a98910d7a Merge pull request #4296 from QuantConnect/performance-batch-logs
Reducing message count sent
2020-04-09 11:08:26 -07:00
Jared
fe6b6102f9 Merge pull request #4295 from Martin-Molinero/test-add-new-order-submission-data-regression-algorithm
Add OrderSubmission data regression algorithm
2020-04-09 10:55:00 -07:00
Martin Molinero
0173288f06 Batch algorithm logs
- Algorithms logs of the same type will be batched together when sent
- Increasing backtesting update to 3 seconds same as LiveTrading
- Increasing insight sending interval from 1 second to 3
- Reducing code duplication for retrieving and sending algorithm logs
2020-04-09 14:18:39 -03:00
Martin Molinero
58f91b872a Add OrderSubmission data regression algorithm
- Add OrderSubmission data regression algorithm asserting it's correctly
  set and does not use static data
2020-04-09 11:42:23 -03:00
Jared
81e16c6f38 Merge pull request #4294 from QuantConnect/bug-4196-default-data-type
SecurityCache default data type
2020-04-08 17:04:41 -07:00
Martin Molinero
6ad123ad8c Update regression algorithms stats
- Update regression algorithms stats after making SecurityCache ignore
  QuoteBars for equity for OHCL values and GetLastData(). They were
  affected since the `BenchmarkSecurity` used `.Price` which was QB for
  equities. Order list hashes changed because SubmissionLastPrice will
  now be TB instead of QB
2020-04-08 19:31:42 -03:00
Martin Molinero
7989d41aa7 Fix SecurityCache OHLC data type
- Fix for Equity SecurityCache OHLC default data type to be used. Will
  ignore QuoteBars
2020-04-08 19:31:37 -03:00
Jared
c8d435d6a5 Merge pull request #4292 from adam-may/feature-4291-make-insight-clone-virtual
Make Insight.Clone() virtual to proper cloning
2020-04-08 07:30:40 -07:00
Martin Molinero
50f0723fe0 Add missing new file license 2020-04-08 10:47:32 -03:00
Adam May
58949b8d4d Make Insight.Clone() virtual to allow GeneratedInsightsCollection to clone derived types properly 2020-04-08 13:05:21 +10:00
Jared
1d599e0253 Merge pull request #4289 from QuantConnect/bug-add-missing-quantity-order-event-constructor
Fix OrderEvent from serialized
2020-04-07 16:26:16 -07:00
Martin Molinero
b380c71493 Fix OrderEvent from serialized 2020-04-07 20:23:57 -03:00
Martin-Molinero
7ba1765012 Merge pull request #4288 from QuantConnect/refactor-order-event-serialization
Add SerializedOrder and SerializedOrderEvent
2020-04-07 18:38:11 -03:00
Martin Molinero
24b6cc6d9a Refactor Order and OrderEvent json
- Adding new SerializedOrderEvent and SerializedOrder with new
  JsonConverters
- Specifying OrderEvent json converter when storing, streaming data
- Adding unit tests
2020-04-07 17:40:25 -03:00
Juan José D'Ambrosio
9867102c4f Merge pull request #4218 from QuantConnect/feature-3589-support-equity-quotes-v2
Adding Support for Equity L1 Quote Data
2020-04-07 11:43:52 -03:00
Martin Molinero
4eac5e4142 Add comment in Slice.cs
- Add a comment in Slice.cs about temporary patch until GH issue 4196 is
  fixed
2020-04-07 11:30:41 -03:00
Jared
a9db470914 Merge pull request #4286 from gsalaz98/bug-report-generator-cumulative-percentage
Fixes Report Generator Calculation (Cumulative Return)
2020-04-07 07:18:15 -07:00
Jared
40afea5074 Merge pull request #4281 from mathpaquette/fix-iqfeed-future
fix(ToolBox\IQFeed): new unsupported continuous symbol pattern
2020-04-06 16:55:34 -07:00
Gerardo Salazar
bd62a76a35 Fixes calculation of Cumulative Returns
* Updates outdated documentation
2020-04-06 10:45:52 -07:00
Martin-Molinero
bcf7ed628a Merge pull request #4272 from QuantConnect/bug-4271-indicator-update-endtime
Fixes IndicatorBase.Update Method Time-stamping
2020-04-06 11:15:59 -03:00
Martin Molinero
25ecb55732 Fix rebase 2020-04-06 10:57:06 -03:00
Martin Molinero
058c9e4eac Revert Crypto Hour/Daily QuoteBars
- Reverting removal of Crypto Hour/Daily QuoteBars
- Updating tests
- Adding unit test where Equities ignore QuoteBars
2020-04-06 10:33:02 -03:00
Martin Molinero
5671a3293a Slice dynamic accessors ignore Quote for equities
- Slice dynamic data accessors will ignore QuoteBars and
Ticks TickType.QuoteBars for equities. This is to make slice dynamic
accessors deterministic and avoid breaking backwards compatibility when
adding QuoteBars for equities.
2020-04-06 10:33:02 -03:00
Martin Molinero
499248fe12 Revert "Revert "Adding Support for Equity L1 Quote Data""
This reverts commit 8cd8d206ca.
2020-04-06 10:32:59 -03:00
AlexCatarino
4beddaafa7 Fixes IndicatorBase.Update Method Timestamping
`IndicatorBase.Update` use `input.EndTime` instead of `input.Time` so that `input.Current.Time` (and `EndTime`) matches the `input.EndTime` and achieve consistent behavior across different indicator types (`IndicatorDataPoint`, `IBaseDataBar` and `TradeBar`)
2020-04-04 23:01:24 +01:00
Mathieu Paquette
beb4db60ff fix(ToolBox\IQFeed): new unsupported continuous symbol pattern
Fixes #4280
2020-04-04 11:17:33 -04:00
Jared
c198824661 Merge pull request #4276 from QuantConnect/bug-4274-fill-message-tostringinvariant
Fixes FillModel Stale Price Message
2020-04-03 15:53:07 -07:00
Jared
4f6043e9f2 Merge pull request #4277 from QuantConnect/fix-order-fees-deserialization
Fix OrderFee round trip serialization
2020-04-03 15:52:27 -07:00
Martin Molinero
52d6a20f85 Fix OrderFee round trip serialization
- Making OrderFee.Value setter public to fix deserialization
- Adding unit tests
2020-04-03 19:11:29 -03:00
AlexCatarino
6df0dc1408 Fixes FillModel Stale Price Message
The stale price message should use `ToStringInvariant` with `price.EndTime` for string represenation across different cultures. The former behavior has impact on the order list hash calculation.
2020-04-03 21:54:29 +01:00
Jared
7e092674a5 Merge pull request #4268 from QuantConnect/bug-4267-expity-endof-month-year
Fixes Expiry.EndOfMonth and Expiry.EndOfYear Methods
2020-04-02 15:06:11 -07:00
Jared
6f84000ef1 Merge pull request #4266 from QuantConnect/refactor-4135-broker-transaction-handler
Small refactor for BrokerageTransactionHandler
2020-04-02 13:41:53 -07:00
Martin Molinero
aac426fd63 Refactor BrokerageTransactionHandler
- Rename 'fill' to 'orderEvent'.
- Remove duplicate order event log
- Move 'NewOrderEvent' invoke so it applies for all order event types
2020-04-02 17:07:37 -03:00
Jared
5b12859be3 Merge pull request #4269 from Martin-Molinero/bug-4135-alpha-result-packet-order-batch
Improve AlphaResultPacket order batching
2020-04-02 12:08:17 -07:00
Jared
55e13068a1 Merge pull request #4265 from QuantConnect/remove-order-based-insight-generator
Remove order based insight generator
2020-04-02 11:53:41 -07:00
Martin Molinero
00f2997a4d Improve AlphaResultPacket order batching
- AlphaResultPacket Order batching will just keep the last Order
instance per Order id, which is the latest. Adding unit test
2020-04-02 12:04:12 -03:00
AlexCatarino
55a5e8e860 Fixes Expiry.EndOfMonth and Expiry.EndOfYear Methods
Adds unit tests for `Expiry.EndOf*` methods.
2020-04-02 02:35:47 +01:00
Martin Molinero
2a0b73e1cf Update regression algorithms
- Update regression algorithms after removing order based insights
2020-04-01 20:37:20 -03:00
Martin Molinero
982ab3099f Remove Order based insights
- Removing order based insight generator.
- Removing regression and unit tests.
2020-04-01 20:21:19 -03:00
Martin-Molinero
eb6fc563fa Merge pull request #4251 from QuantConnect/feature-4243-python-dict-support
Adds ExtendedDictionary That Implements Python Dict Methods
2020-04-01 15:19:10 -03:00
AlexCatarino
64b78df045 Addresses Peer-Review
- Fixes:
 - `Slice.GetValues`
    Not returning the `Value` but the `KeyValuePair`
 - `ExtendedDictionary.update(PyObject)`
    Paramenter type should be `PyObject` not `PyDict`
- Adds unit test for `update()`
- Fixes `OrderListHash` of `PythonDictionaryFeatureRegressionAlgorithm` test.
2020-04-01 16:15:05 +01:00
AlexCatarino
2c0d7e9ebe Implements Logic in ExtendedDictionary.this[string]
And removes it from chidren implementation.
2020-04-01 16:15:05 +01:00
AlexCatarino
72f0f44f60 Updates Pythonnet Version
From 1.0.5.29 to 1.0.5.30
Ref.: https://github.com/QuantConnect/pythonnet/pull/42
2020-04-01 16:15:05 +01:00
AlexCatarino
f47c469cc5 IExtendedDictionary.items() Method Returns PyList 2020-04-01 16:15:04 +01:00
Martin Molinero
e17326ead7 Address Review
- Small performance improvement to avoid intermediate collection when
enumerating ConcurrentDictionary
- Fix bug for `ToList` implementation
2020-04-01 16:15:04 +01:00
AlexCatarino
27d31b7846 Renames BaseDictionary to ExtendedDictionary
Changes the return type of `keys()` and `values()` methods to `PyList`. Since `Keys` and `Values` return `ICollection` in some cases, the Python type was not consistently of `list` type.
2020-04-01 16:15:04 +01:00
AlexCatarino
6d91137749 Adds Perfirmance Tests
Rebases with master and fixes regression test.
2020-04-01 16:15:04 +01:00
AlexCatarino
a59bd17fb9 Adds BaseDictionary That Implements Python Dict Methods
`BaseDictionary` is an abstract implementation of `IExtendedDictionary` keyed by `Symbol` that implements Python `dict` methods. `Slice`, `DataDictionary`, `SecurityManager`, and `SecurityPortfolioManager` derives from it in order to behave like Python `dict`.
2020-04-01 16:15:04 +01:00
Martin Molinero
07a4285baf Test approach 2020-04-01 16:15:04 +01:00
AlexCatarino
c1e18f82bb WIP 2020-04-01 16:15:04 +01:00
AlexCatarino
5e37a8b259 Implements IExtendedDictionary
`PythonSlice` implements `IExtendedDictionary`
2020-04-01 16:15:04 +01:00
Martin-Molinero
66dbcdccff Merge pull request #4262 from QuantConnect/add-support-ibgateway-v978
Update IBAutomater to v1.0.20
2020-04-01 12:01:25 -03:00
Martin-Molinero
502cee27ba Merge pull request #4261 from QuantConnect/order-event-alpha-packet-integrated
OrderEvent stream and store integrated
2020-04-01 10:39:45 -03:00
Martin Molinero
f47e361227 Fixes for OrderJsonConverter
- Add missing PriceCurrency, CanceledTime and OrderSubmissionData when deserializing
an order. Adding unit test
2020-03-31 20:53:19 -03:00
Martin Molinero
e76dcc4055 Add Order and OrderEvents to AlphaPacket 2020-03-31 20:53:19 -03:00
Martin-Molinero
b606d6c1c0 Merge pull request #4260 from QuantConnect/refactor-4135-improve-order-and-orderevent-serialization-v2
Improve Order and OrderEvent serialization
2020-03-31 20:52:46 -03:00
Martin-Molinero
ae927677f3 Merge pull request #4159 from QuantConnect/feature-4135-order-event-storing-streaming
Live and backtest OrderEvent store and stream
2020-03-31 19:03:42 -03:00
Stefano Raggi
f70dcf7db3 Update IBAutomater to v1.0.20 2020-03-31 21:34:51 +02:00
Jared
55ec6680b8 Merge pull request #4255 from haxdds/adds-dropbox-coarse-fine-algo
Adds Dropbox Coarse Fine algorithm
2020-03-31 11:41:13 -07:00
Rahul
8be8839194 Added Open Source Header and Changed File Extension 2020-03-31 09:39:17 -07:00
Jared
5b50204605 Merge pull request #4252 from haxdds/delete-weather-based-rebalancing
Deleted QCUWeatherBasedRebalancing.py
2020-03-31 09:34:23 -07:00
Jared
bf637213d1 Merge pull request #4259 from QuantConnect/bug-4258-estimize-consensus-serialization
Fix EstimizeConsensus.Symbol serialization
2020-03-31 09:33:48 -07:00
Martin Molinero
486b2e6641 Update regression stats
- Update expected OrderListHash in regression algorithms due to
serialization improvements
2020-03-31 12:21:13 -03:00
Martin Molinero
3289a2a968 Order and OrderEvents serialization improvements
- Remove unnecessary files from json serialization for Order and
OrderEvents.
- Adding unit tests
2020-03-31 12:21:12 -03:00
Stefano Raggi
90a8ed8198 Add serialization unit tests for custom data types 2020-03-31 16:37:12 +02:00
Stefano Raggi
9034da2716 Fix EstimizeConsensus.Symbol serialization 2020-03-31 16:36:21 +02:00
Martin Molinero
8e14aa7a89 Replace IsUpdate for OrderStatus.UpdateSubmitted 2020-03-30 20:03:58 -03:00
Rahul
06aadffd44 Added dropbox algo to project file 2020-03-30 10:38:46 -07:00
Rahul
987a899b81 Created Dropbox Coarse-Fine Algo 2020-03-30 10:37:15 -07:00
Martin Molinero
50b3efe12e Address reviews
- Disable order event streaming in backtest
- Add new OrderEvent IsUpdate flag to be set by the different brokerage
implementations
- Update regression test stats after rebase
2020-03-30 13:40:49 -03:00
Rahul
697494898d Removed algorithm from python project file 2020-03-30 09:33:22 -07:00
Martin Molinero
78ae2d7e1b Add Price and Quantity to OrderEvent
- Adding order current Quantity, StopPrice and LimitPrice to the
OrderEvent instance
- Adding OrderTicketDemoAlgorithm as a regression test
2020-03-30 11:07:18 -03:00
Martin Molinero
d2486a0590 Address review
- Live Trading will update order events every minute, same as
result.json
2020-03-30 11:07:18 -03:00
Martin Molinero
6e40ce5300 Add OrderEvent id
- Adding incremental OrderEvent Id per Order instance. Adding unit test
2020-03-30 11:07:18 -03:00
Martin Molinero
bd862cff61 Live and backtest OrderEvent store and stream
- Live and backtesting will send delta order events updates
- Live will store order events every 10 minutes per day
- Backtesting will store last 100 order events on every update and will
store all order events in the end of the backtest
2020-03-30 11:07:18 -03:00
Rahul
a5d9a16ac3 Delete QCUWeatherBasedRebalancing.py 2020-03-27 13:14:28 -07:00
Jared
10861126f0 Merge pull request #4248 from simonsonjack/bug-update-Lean-statistics-unittests
Update Lean Statistics
2020-03-27 11:50:27 -07:00
Jack Simonson
0d791ec39a Update Unit Tests and Portfolio Statistics
Updated new unit tests to use TestFixtureSetUp and TestFixtureTearDown. Changed updated PortfolioStatistics to call methods from Statistics.
2020-03-27 10:41:52 -07:00
Martin-Molinero
86b969056f Merge pull request #4210 from QuantConnect/bug-4200-slice-internall-refactor
Refactor and fixes for Slice
2020-03-27 13:24:11 -03:00
Martin Molinero
47aaa37740 Adding more data types for unit test 2020-03-27 13:06:47 -03:00
Martin Molinero
b28f9f501a Refactor and fix Slice bugs
- Fixing Python slice enumeration which would not happen when custom
data was present. Adding unit test
- Fix Slice constructor which would fail to create data collections due
to relying on non-deterministic 'slice._data'. Adding unit test
- Improving custom data retrieval for symbols which have more than 1
data type in a slice. Adding unit test
- First step refactoring slice internally, no behavior changed
2020-03-27 12:44:05 -03:00
Jack Simonson
c6767780c2 Update regression test statistics 2020-03-26 18:29:29 -07:00
Jack Simonson
61432ffc29 Update Lean Statistics
Clean branch to update Tracking Error and Annual Performance statistics.
2020-03-26 16:54:59 -07:00
Jared
5e0ba87f1a Merge pull request #4244 from QuantConnect/refactor-4205-reduce-code-duplication
Reduce code duplication in QCAlgorithm.Indicators
2020-03-26 16:23:12 -07:00
Martin-Molinero
10effeb8cb Merge pull request #4247 from gsalaz98/bug-4163-update-future-regression-algorithms
Update regression algorithm statistics for futures algorithms
2020-03-26 18:18:54 -03:00
Gerardo Salazar
c1371ea9e7 Update regression algorithm statistics for futures algorithms
* Follows the updates done to futures margins in PR #4145
2020-03-26 13:34:52 -07:00
Gerardo Salazar
64e0d6f0ad Merge pull request #4241 from QuantConnect/ib-brokerage-two-factor-authentication
IB Brokerage Two-Factor Authentication support
2020-03-26 12:19:08 -07:00
Gerardo Salazar
992595bf8b Merge pull request #4245 from gsalaz98/bug-report-generator-empty-deedle-series-crash
Fixes issue where PortfolioLooper would crash generating certain reports
2020-03-26 12:18:29 -07:00
Gerardo Salazar
208e6eb03e Address review - revert change to backtest sharpe if live not found 2020-03-26 12:17:03 -07:00
Gerardo Salazar
e5ed489e0b Fixes issue where PortfolioLooper would crash generating certain reports
* Updates SharpeRatioReportElement calculation
2020-03-26 11:50:08 -07:00
Martin Molinero
bed8817482 Fix toolbox building always 2020-03-26 15:04:18 -03:00
Martin Molinero
20909a9569 Reduce some code duplication
- Small refactor to reduce some code duplication in
QCAlgorithm.Indicators Consolidate and ResolveConsolidator
2020-03-26 11:06:47 -03:00
Jared
ed14904cc7 Merge pull request #4242 from nazbrok/add-tls12-support-to-websocket
add Tls12 support on websocket
2020-03-26 06:00:28 -07:00
Martin-Molinero
e0f595cfd2 Merge pull request #4238 from QuantConnect/bug-4205-warmup-indicator-type
IndicatorWarmup data type fixes
2020-03-25 21:25:57 -03:00
Martin Molinero
2c950bc740 Improve comments
- Improve comments with an example
- Remove reference to regression algorithm
2020-03-25 21:21:13 -03:00
Martin Molinero
f4e9b0cc3d Address reviews
- Add more and improve existing comments
2020-03-25 20:38:22 -03:00
Stefano Raggi
c24eb0a432 Update IBAutomater to v1.0.18 2020-03-26 00:37:57 +01:00
Martin-Molinero
5521ca69d0 Merge pull request #4240 from QuantConnect/refactor-4205-getsubscription-add-warmup-warning
Refactor QCAlgorithm.Indicators - Add WarmUpIndicator warning
2020-03-25 19:53:47 -03:00
nazbrok
2f2b2624d4 add Tls12 support on websocket 2020-03-25 23:32:57 +01:00
Martin Molinero
2a2711d056 IndicatorWarmup fixes
- WarmupIndicator will be able to determine the correct type to use
- Fix bug in `History.GetMatchingSubscriptions()` which would use the
same TZ for exchange and data. Covered by regression algorithm.
- Consolidate will only infer `TickType` from `T` is not abstract
- Adding regression algorithm
- Slice will expose `Get(Type)` to get data by type, adding unit tests
2020-03-25 18:52:48 -03:00
Stefano Raggi
b8607c23d5 Update IBAutomater to v1.0.17 2020-03-25 22:17:00 +01:00
Martin Molinero
ccaa643bc7 Address self review
- Remove unrequired symbol check
- Dispose of `ZipDataCacheProvider` used in unit tests.
To avoid issues with other tests since zip files could remain open.
2020-03-25 17:41:11 -03:00
Martin Molinero
15cbe4afa2 Refactor QCAlgorithm.Indicators
- Make `GetSubscription` private and remove unrequired overload
- Add warning message when trying to warm up an indicator which does not
have a warm up period
2020-03-25 16:51:26 -03:00
Stefano Raggi
420392fbf8 Update IBAutomater to v1.0.15
- Add support for IB two-factor authentication
2020-03-25 16:44:06 +01:00
Martin-Molinero
13431b11c1 Merge pull request #4236 from QuantConnect/bug-4205-registerindicator-of-t
Fixes for RegisterIndicator API
2020-03-25 10:55:43 -03:00
Martin Molinero
589c8e9c92 Address review
- Add more comments in regression algorithms
2020-03-24 21:01:40 -03:00
Jared
ba7f39f7d9 Merge pull request #4228 from QuantConnect/bug-fix-alpaca-warmup-requests
Updates deprecated Alpaca RestClient to AlpacaTradeClient/PolygonDataClient
2020-03-24 14:00:43 -07:00
Jared
05f0f52d7e Merge pull request #4234 from QuantConnect/bug-4205-consolidate-respect-type
Fixes for QCAlgorithm.Indicators.Consolidate API
2020-03-24 13:59:58 -07:00
Martin Molinero
a932589de6 Add missing python Consolidate API method test 2020-03-24 17:50:01 -03:00
Jared
f56f288125 Merge pull request #4235 from QuantConnect/feature-3785-add-user-data-subscriptions
Add StreamingDataPermissions for streaming custom data
2020-03-24 13:36:19 -07:00
Martin Molinero
085da7c352 Fixes for RegisterIndicator
- Fixes for C# RegisterIndicator API methods which were ignoring provided
type of T
- Fixes for Py RegisterIndicator API methods which was not using the
provided 'selector' method
- Adding C# and Py regression algorithm
2020-03-24 16:38:46 -03:00
Stefano Raggi
9f75dbcdbb Fix Json property name format 2020-03-24 20:03:05 +01:00
Martin Molinero
c40afbec1f Address review
- Add a couple of missing cases where we explicitly set tick type to
null and assert the default data type used
- Adding custom data consolidate for Py algorithm
2020-03-24 15:33:49 -03:00
Stefano Raggi
6aae5399b7 Rename and move StreamingDataPermissions to Controls 2020-03-24 18:20:01 +01:00
Gerardo Salazar
1c83cc59a1 Address review - remove unused files from Alpaca Markets brokerage 2020-03-24 09:50:07 -07:00
Stefano Raggi
69639b6d44 Add UserDataSubscriptions for streaming custom data 2020-03-24 12:00:33 +01:00
Martin Molinero
eb533b9954 Fixes for QCAlgorithm.Indicators.Consolidate API
- Fixes for 3 QCAlgorithm.Indicators.Consolidate API methods
- Adding C# and Py regression test
2020-03-23 21:16:33 -03:00
Martin-Molinero
899ea03a1c Merge pull request #4227 from QuantConnect/bug-3861-indicator-warmup
Fix WarmupIndicator duplicate consolidator
2020-03-23 18:49:57 -03:00
Gerardo Salazar
ebe084e82f Address review - define NET45 constant in project file 2020-03-23 10:01:40 -07:00
Jared
f0187cebf3 Merge pull request #4233 from QuantConnect/bug-4231-trading-economics-calendar-serialization-fix
Fix TradingEconomicsCalendar.Symbol serialization
2020-03-20 16:38:57 -07:00
Stefano Raggi
acf6f8d6dc Address review - remove Symbol override 2020-03-21 00:23:24 +01:00
Jared
41fd885f70 Merge pull request #4226 from QuantConnect/bug-3997-black-litterman-matrix-exception
Fixes ReturnsSymbolData to Account New Security Additions
2020-03-20 15:02:33 -07:00
Jared
13874c7607 Merge pull request #4230 from adam-may/feature-4229-add-smoothing-factor-to-qcalgo-ema
Adding overload to QCAlgo.EMA to support smoothing factor
2020-03-20 14:33:55 -07:00
Stefano Raggi
4ffcb7cad9 Fix TradingEconomicsCalendar.Symbol serialization 2020-03-20 21:54:25 +01:00
Martin-Molinero
0badbeba52 Merge pull request #4204 from QuantConnect/bug-4203-benzinga-json-serialization
Fix serialization of BenzingaNews Time and EndTime properties
2020-03-20 14:56:28 -03:00
Gerardo Salazar
7750174649 Address review - remove inconsistent line endings (^M) from Benzinga test 2020-03-20 10:11:20 -07:00
Gerardo Salazar
ad3236e0e8 Skips serialization of null values in BenzingaNewsJsonConverter
* Adds new unit tests for BenzingaNewsJsonConverter

* Fixes issue in BenzingaNewsDataConverter where we would
  write data in local time, resulting in non-UTC times from
  the deserialization in BenzingaNews.Reader(...). Unit tests
  were added for this issue as well
2020-03-19 17:56:34 -07:00
Adam May
9049d753aa Adding overload to QCAlgo.EMA to support smoothing factor 2020-03-20 10:48:51 +11:00
Gerardo Salazar
da2ae1bb09 Updates deprecated Alpaca RestClient to AlpacaTradeClient/PolygonDataClient
* Fixes issue with tick warmup history request deserialization
2020-03-19 15:49:43 -07:00
Martin Molinero
5242cc57f4 Fix WarmupIndicator
- WarmupIndicator will remove and dispose added consolidators
- Consolidating duplicated implementation
- Adding regression test
2020-03-19 18:06:05 -03:00
Jared
51bb153c7e Merge pull request #4224 from QuantConnect/refactor-4223-imessaginghandler-idisposable
IMessagingHandler extends from IDisposable
2020-03-19 13:59:41 -07:00
AlexCatarino
12c71ee6f9 Fixes ReturnsSymbolData to Account New Security Additions
When new securities are added to the universe, the `ReturnsSymbolData` is warmed up with historical data that may not have the same timestamp causing an index mismatch that leads to a rejection to several valid data. In this case, we will assume that there is a time correspondence similar to what is done in Python. Unit test was added.

`BlackLittermanOptimizationPortfolioConstructionModel` will consider a new view only if there is a new last active insight by updating the `ReturnsSymbolData` with the `Insight.GeneratedTimeUtc` instead of the `IAlgorithm.Time`. Consequently, the timestamp of the historical data is converted to UTC for consistency.

`BlackLittermanSymbolData` now rejects duplicate keys like its C# version: `ReturnsSymbolData`.

Finally, `BlackLittermanPortfolioOptimizationFrameworkAlgorithm` statistics was updated because of the bug fixes.
2020-03-19 20:59:19 +00:00
Martin-Molinero
8ed815dbb5 Merge pull request #4177 from simonsonjack/update-AlphaStreamsBrokerageModel-leverage
Update AlphaStreamsBrokerageModel.cs
2020-03-19 17:33:01 -03:00
Martin Molinero
300c8c43d9 Use dispose safely, dispose of notify at the end 2020-03-19 12:42:06 -03:00
Adam May
18e481ef58 Make IMessagingHandler extend from IDisposable to allow for packing up of resources 2020-03-19 12:28:10 -03:00
Stefano Raggi
0c70707c9a Add Benzinga serialize round trip unit test without converter 2020-03-19 16:27:14 +01:00
Martin-Molinero
c5b087ceba Merge pull request #4222 from adam-may/feature-4221-expose-adr-from-adrx
Exposing ADX from within ADXR
2020-03-19 12:04:31 -03:00
Martin-Molinero
d347655a28 Merge pull request #4179 from QuantConnect/refactor-corase-generator
Refactor corase generator
2020-03-19 11:21:54 -03:00
Martin Molinero
d100431458 Add missing documentation for new ADX property 2020-03-19 11:05:56 -03:00
Stefano Raggi
48c184344d Fix serialization of BenzingaNews Time and EndTime properties 2020-03-19 12:28:52 +01:00
Adam May
242d087c1d Exposing ADX from within ADXR 2020-03-19 19:55:03 +11:00
Martin-Molinero
1d9d10c2e9 Merge pull request #4219 from gsalaz98/bug-fix-estimize-converter-share-class-tickers-skipped
Fixes bug where share class tickers (e.g. BRK.B) would not be processed for Estimize
2020-03-18 19:48:31 -03:00
Gerardo Salazar
cba9ae2e9e Fixes bug where share class tickers (BRK.B) would not be downloaded and converted
* Removes try/catch around RateGate, since it was fixed in issue #3499
2020-03-18 15:07:30 -07:00
Martin-Molinero
ab8134766f Merge pull request #4175 from gsalaz98/bug-report-generator-add-null-handling-for-valuetype-jsonconverter
Adds null value skipping and handling to Result deserialization via new JsonConverter
2020-03-18 17:25:34 -03:00
Martin-Molinero
78fb93a64b Merge branch 'master' into bug-report-generator-add-null-handling-for-valuetype-jsonconverter 2020-03-18 17:06:19 -03:00
Martin-Molinero
52139ca5f1 Merge pull request #4184 from QuantConnect/bug-4007-rsi-division-by-zero
Fix DivideByZeroException in RSI indicator
2020-03-17 16:36:34 -03:00
Martin-Molinero
f50fef7951 Merge pull request #4198 from QuantConnect/bug-4197-estimize-timestamps-fix
Fix Estimize time zone bug in timestamp deserialization
2020-03-17 16:12:39 -03:00
Stefano Raggi
7e92dbaff9 Update RSI to handle negative averages 2020-03-17 20:12:34 +01:00
Martin-Molinero
889cc8b9c9 Merge pull request #4188 from gsalaz98/bug-4124-report-generator-crashes-with-cash-only-assets
Fixes Report Generator PortfolioLooperAlgorithm Cash Account Crashes
2020-03-17 16:12:31 -03:00
Stefano Raggi
70f90afce0 Fix Estimize time zone bug in timestamp deserialization 2020-03-14 00:30:10 +01:00
Jared
f976b3c8ee Merge pull request #4194 from QuantConnect/bug-4193-trading-economics-time-deserialization
Fix deserialization of TradingEconomicsCalendar Time property
2020-03-13 13:46:08 -07:00
Jared
20c9f7af49 Merge pull request #4195 from QuantConnect/refactor-4111-replace-alpaca-nats-client-with-websockets
Replaces Alpaca brokerage deprecated NAT feed for Polygon.io TAQ feed
2020-03-13 13:45:16 -07:00
Stefano Raggi
319df53535 Fix deserialization of TradingEconomicsCalendar Time property 2020-03-13 17:40:53 +01:00
Jared
e9bdc44fec Merge pull request #4189 from QuantConnect/feature-updates-python-installation
Updates Python Installation Instructions
2020-03-12 17:17:50 -07:00
Jared
3a8d64b1aa Merge pull request #4192 from QuantConnect/bug-4191-estimize-time-deserialization
Fix deserialization of Estimize Time property
2020-03-12 17:16:59 -07:00
Gerardo Salazar
c9e6d52b83 Address review - adds unit tests for NullResultValueTypeJsonConverter
* Downgrades Json.NET to 10.0.3 for project compatibility
* Cleans up unused imports and unused code
2020-03-12 15:34:40 -07:00
Gerardo Salazar
ec3f1cf7d8 Replaces Alpaca brokerage NAT feed for Polygon.io TAQ feed 2020-03-12 14:03:47 -07:00
Stefano Raggi
7e652cba47 Fix deserialization of Estimize Time property 2020-03-12 20:53:22 +01:00
Alexandre Catarino
35e71d8b7f Updates Python Installation Instructions
Updates Python version to 3.6.8 to match QuantConnect Cloud (DockerfileLeanFoundation) as well as pandas and wrapt versions.
2020-03-12 18:59:37 +00:00
Gerardo Salazar
77411a0b09 Fixes issue where setting leverage on cash accounts results in error
* Adds new unit tests
2020-03-12 10:42:30 -07:00
Jared
292aae8cc6 Merge pull request #4187 from QuantConnect/revert-3993-feature-3589-support-equity-quotes
Revert "Adding Support for Equity L1 Quote Data"
2020-03-11 19:16:34 -07:00
Jared
8cd8d206ca Revert "Adding Support for Equity L1 Quote Data" 2020-03-11 19:16:05 -07:00
Jared
460a18faff Merge pull request #4186 from QuantConnect/revert-4185-bug-slice-default-data-type
Revert "Slice[Symbol] return type order"
2020-03-11 19:15:31 -07:00
Jared
57010f2eee Revert "Slice[Symbol] return type order" 2020-03-11 19:14:16 -07:00
Jared
316a367f54 Merge pull request #4185 from QuantConnect/bug-slice-default-data-type
Slice[Symbol] return type order
2020-03-11 18:16:15 -07:00
Martin Molinero
05fc9a5006 Keep track of types and always return based on the same order
- SymbolData at Slice will keep track of the types it has and GetData
will always return in the same order, TradeBars, QuoteBars, Tick, Custom
- Fixing slice.Get(type) for custom type which relied on insertion order
- Updating regression test
2020-03-11 22:13:34 -03:00
Stefano Raggi
623398deb9 Fix DivideByZeroException in RSI indicator 2020-03-12 00:32:39 +01:00
Jared
2ba8dba4a7 Merge pull request #4182 from QuantConnect/feature-disable-missing-data-logs
Add option to disable missing data logs
2020-03-11 15:57:39 -07:00
Martin Molinero
d3730b5c9b Add option to disable missing data logs 2020-03-11 19:45:32 -03:00
Martin-Molinero
2802567bce Merge pull request #3993 from QuantConnect/feature-3589-support-equity-quotes
Adding Support for Equity L1 Quote Data
2020-03-11 19:14:25 -03:00
Martin Molinero
ab43485642 Update tests
- Update tests after daily.zip files update
2020-03-11 18:52:24 -03:00
Jack Simonson
d51ce6b1d9 Update AlphaStreamsBrokerageModel.cs
Implement explicity method for getting security leverage. Adjusted leverage based on available research regarding hedge funds and PBs.
2020-03-11 14:21:35 -07:00
Juan José D'Ambrosio
d4bec86df0 Update daily and hourly sample files 2020-03-11 20:22:13 +00:00
Martin Molinero
f6c687b5f1 Fix regression and unit test
- Reduce MinimumVariancePortfolioOptimizar precision goal so that both
CSharp and Py MeanVarianceOptimizationFrameworkAlgorithm return the same
results
- Limit factor file dates in factor file generator unit test
2020-03-11 16:41:27 -03:00
Juan José D'Ambrosio
951e89314a Update Regression tests 2020-03-11 14:34:16 -03:00
Martin Molinero
95d0d1285f Address review 2020-03-11 14:34:16 -03:00
Martin Molinero
c33c11c9bd Update HourSplitRegressionAlgorithm 2020-03-11 14:34:16 -03:00
Martin Molinero
d5d00f8472 Update tests
- Update regression tests
- Add missing data
- Revert Messaging.cs change
- Update unit tests
2020-03-11 14:34:16 -03:00
D
3b25ea4240 Update test after adding the new sample data 2020-03-11 14:34:16 -03:00
D
336caf9856 Update sample data 2020-03-11 14:34:16 -03:00
Martin Molinero
bfa28bdfba Fix Equity Tick Quote parsing 2020-03-11 14:34:14 -03:00
D
222105f60d Update sample data 2020-03-11 14:34:14 -03:00
Martin Molinero
21f636fecc Fix undeterministic unit test
- Fix underterministic python indicator unit test
- Refactor `QCAlgorithm.Indicators.GetSubscriptions`
2020-03-11 14:34:13 -03:00
Martin Molinero
2190145830 Refactor quote type filtering logic 2020-03-11 14:34:13 -03:00
Martin Molinero
93418d9e72 Fix rebase. Add test
- Fix rebase
- Update tests
- Add new unit test, that asserts fill model uses quote price is present
2020-03-11 14:34:13 -03:00
Martin Molinero
3630e735b0 Update AccumulativeInsightFrameworkAlgorithm stats 2020-03-11 14:34:13 -03:00
Martin Molinero
041c8e6c1c Fix live trading unit tests 2020-03-11 14:34:13 -03:00
Juan José D'Ambrosio
8df6b31e19 Update LiveTradingDataFeedTests
Still failing quotes for equities
2020-03-11 14:34:13 -03:00
Juan José D'Ambrosio
dde502de3b Update BacktestingResultHandlerTests 2020-03-11 14:34:13 -03:00
Juan José D'Ambrosio
b7a503a096 Update Regression algorithms 2020-03-11 14:34:13 -03:00
Juan José D'Ambrosio
1fa733a733 Fix issue with history request asking for Low resolution quotes 2020-03-11 14:34:13 -03:00
Juan José D'Ambrosio
1269966e51 Rebase and squash commits
Update test to the new crypto and equity subscriptions  rules:
- Only consolidates trades
- Low resolution data are only trades.
Update and fix tests

Add missing minute sample files

Update Regression algorithms statistics
2020-03-11 14:34:13 -03:00
Juan José D'Ambrosio
95336d69c5 Add tick sample data 2020-03-11 14:34:13 -03:00
Juan José D'Ambrosio
0794f4d472 Add second sample data 2020-03-11 14:34:05 -03:00
Juan José D'Ambrosio
fd9de5895a Consolidate only trades, low resolution reads trades only, update tests
Crypto and Equities will consolidate trades by default

Daily and hourly resolution will return only trades for crypto and equities. 
Update equity TAQ regression test 

Add minute sample files

Updating regression algorithms

Update SpotMarket test cases

Add regression test for equity trades and quotes
- History request.
- Trades and quotes pumped into OnData.
- Subscriptions are added correctly.

Add sample data

Checks low resolution only subscribes to trade bars
2020-03-11 14:34:05 -03:00
Juan José D'Ambrosio
228aad658b Process Equity quotes
This is just a draft for supporting Equity quotes in Lean
2020-03-11 14:34:05 -03:00
Jared
e6c019cb77 Merge pull request #4180 from QuantConnect/bug-4178-bitfinex-margin-trading-fix
Fix GetCashBalance for Bitfinex margin trading
2020-03-11 07:51:25 -07:00
Juan José D'Ambrosio
ba2e64f9f4 Add blacklisted ticker list
set file as content
2020-03-11 14:45:29 +00:00
Juan José D'Ambrosio
0ee16cbd55 Add blacklisted ticker list
Also, remove obsolete files
2020-03-11 14:25:32 +00:00
Stefano Raggi
365e13fe01 Add unit test for GetCashBalance with open margin position 2020-03-11 02:18:33 +01:00
Stefano Raggi
dec6eaa308 Fix GetCashBalance for Bitfinex margin trading 2020-03-10 23:41:25 +01:00
Juan José D'Ambrosio
92a154be2a Fix issue with listing 2020-03-10 20:43:17 +00:00
Juan José D'Ambrosio
24a43e4832 Address review 2020-03-10 20:31:38 +00:00
Juan José D'Ambrosio
1ab9545262 Fix issues with capitalization and trailing zeroes 2020-03-10 19:28:05 +00:00
Juan José D'Ambrosio
ae2531cf05 Fix issues add xml docs
Concurrent collections concerns 

Reading of fine fundamental folder improvement

Create output folder 

Implement changes in ToolBox and RDG rprograms
2020-03-10 18:26:32 +00:00
Juan José D'Ambrosio
2e4d1fae01 Refactor corase generator
Invert logic, start from map files and look for data in daily folders

Also generate all coarse in in memory and write all coarse files at once

Remove obsolete code

Parallelize reading and writing
2020-03-10 18:25:56 +00:00
Jack Simonson
1c374536e1 Update AlphaStreamsBrokerageModel.cs
Removes fixed leverage from the AS Brokerage Model. Inherits from the Default Brokerage Model.
2020-03-10 08:42:28 -07:00
Gerardo Salazar
2868973a56 Fixes issue where null Series values would default to 0
* Adds a new JsonConverter implementation that handles null
  values in the ChartPoint JSON representation. It skips any
  value that is found to be "null" or unparsable
2020-03-09 12:10:23 -07:00
Martin-Molinero
cd08b8c16c Merge pull request #4156 from adam-may/feature-1330-specify-paths-for-output-files
Feature 1330 specify paths for output files
2020-03-09 12:19:57 -03:00
Martin Molinero
ed6e2fd0a2 Replace ResultPreFix config for custom algorithm id 2020-03-09 11:59:23 -03:00
Adam May
3f45b3ba43 Add .gitignore for JetBrains Rider 2020-03-08 21:06:36 +11:00
Adam May
5d979295ff Fixing unit tests 2020-03-08 19:23:50 +11:00
adam-may
4b95b09ed1 Merge branch 'master' into feature-1330-specify-paths-for-output-files 2020-03-08 16:19:38 +10:00
Adam May
2735e6a0cb Pull out reading of results path so it's only retrieved from Config once and cached 2020-03-08 17:17:14 +11:00
Adam May
262defd8e6 Make IInsightManager inherit from IDisposable 2020-03-08 17:16:33 +11:00
Adam May
86ec8e26fd Removed unused methods on IInsightManager 2020-03-08 17:15:57 +11:00
Adam May
c0c5bda6e9 Remove insights-destination-folder 2020-03-08 17:15:32 +11:00
Adam May
f8ea705c3e Added License banners to files 2020-03-08 17:13:51 +11:00
Jared
f6f7625095 Merge pull request #4162 from Martin-Molinero/bug-4161-fix-failing-factor-files-unit-test
Fix failing factor file unit tests
2020-03-06 16:50:51 -08:00
Martin Molinero
dc3be7158c Fix failing factor file unit test
- MeanVarianceOptimizationPortfolioConstructionModel tests will use
`SingleEntryDataCacheProvider`, instead of `ZipDataCacheProvider`, so
that zip files are not cached into memory and block other usages
2020-03-06 20:18:49 -03:00
Jared
8718ff663f Merge pull request #4093 from QuantConnect/feature-library-update
Add new python libraries
2020-03-06 13:56:09 -08:00
Jared
249fd1561f Update DockerfileLeanFoundation 2020-03-06 11:48:13 -08:00
Martin-Molinero
7ca7061535 Merge pull request #4158 from QuantConnect/refactor-4153-remove-alpha-threads-from-engine
Removing alpha thread from engine
2020-03-06 09:15:25 -03:00
Jared
25c0b74443 Merge pull request #4145 from gsalaz98/feature-4022-update-futures-margins
Updates future margins for CL, ES, GC, HO, NG, NQ, PA, PL, RB, SI, YM
2020-03-05 15:47:06 -08:00
Gerardo Salazar
90060bbbe1 Address review - adds unit tests and fixes various bugs in margins data 2020-03-04 11:24:57 -08:00
Martin-Molinero
6e519e20ee Merge pull request #4157 from haxdds/fix-variable-name-typo
Fixed typo for instances of _isEmitWarmupInsightWarningSent
2020-03-04 15:44:11 -03:00
Martin Molinero
c92c3a3f1b Removing alpha thread from engine
- Moving alpha thread from engine into handler class.
- Normalizing thread stop logic
2020-03-04 15:40:27 -03:00
Adam May
713bc9df3b Fix unit config tests by setting config back to default 2020-03-05 05:16:50 +11:00
Rahul
5f5dee1e24 Renamed all instances of _isEmitWarmupInsightWarningSent
Changed from _isEmitWamrupInsightWarningSent to _isEmitWarmupInsightWarningSent
2020-03-04 09:26:12 -08:00
Martin-Molinero
ee03c1c226 Merge pull request #4154 from QuantConnect/refactor-4153-remove-threads-from-engine
Remove RealTime thread from engine
2020-03-04 13:42:23 -03:00
Adam May
f56d2a9db3 Adding results-destination-folder and results-destination-file-prefix config options 2020-03-04 20:15:33 +11:00
Adam May
98412fcbef Add insights-destination-folder to allow for insights to be stored in a custom directory 2020-03-04 17:01:49 +11:00
Adam May
381105b1df Have Config.Write() refer to config being used. 2020-03-04 15:47:36 +11:00
Gerardo Salazar
c36c67d5fd Adds margin entries for the following futures: 26, 6L, 6M, 6R, 6Z, ...
A0D, A0F, A1L, A1M, A1R, A32, A3G, A7E, A7Q, A8J, A8K, A91, A9N, AA6,
AA8, ABS, ABT, AC0, ACD, AD0, ADB, AE5, AGA, AJ, AJ1, AJL, AJS, AJY,
AKL, AKZ, ANE, ANL, APS, ARE, AVZ, AW, AYV, AYX, AZ1, B7H, BIO, BOO,
BR7, CJY, CSX, CY, D1N, DC, DCB, EAD, ECD, EMD, ESK, FSS, GD, GDK,
GIE, GNF, HRC, LBS, ME, MPX, NFN, NKD, NKN, UB
2020-03-03 14:59:23 -08:00
Martin Molinero
1dc6ed06f7 Address reviews
- Dispose of TimeMonitor on RealTimeHandler exit
2020-03-03 18:45:43 -03:00
Martin Molinero
8e1d0f7e4f Remove RealTime thread from engine
- Remove RealTime thread from the engine
- Engine will call DataFeed.Exit() even if algorithm initialization
failed, to avoid 30 sec delay
2020-03-03 16:50:25 -03:00
Martin-Molinero
3e9bb97224 Merge pull request #4152 from Martin-Molinero/bug-4131-single-scheduled-event-fires
BacktestingRealTimeHandler single scheduled event is fired
2020-03-03 13:20:56 -03:00
Martin-Molinero
ffe4db4d37 Merge pull request #4144 from QuantConnect/refactor-4135-result-handler-use-internal-update-task
Improve result handler update logic
2020-03-03 13:06:35 -03:00
Martin Molinero
7ea241b735 Fix backtesting event bug
- After skipping scheduled events it will re order them
- Fix bug where when only a single scheduled event was present it
wouldn't fire
2020-03-03 12:56:50 -03:00
Martin-Molinero
0a7a4c3277 Merge pull request #4150 from QuantConnect/bug-4131-scheduled-events-fire-order
Scheduled events fire order - Performance
2020-03-03 12:04:45 -03:00
Martin Molinero
5d7d9a14c3 Address reviews
- Revert thread removal for task. Reduce change risk by continue using thread.
2020-03-03 11:59:59 -03:00
Martin Molinero
b45b7e427f Address reviews
- Address review improve regression and unit test
- Fix same time scheduled event order
- Adding comments in unit test
- Increasing unit test sleep time
2020-03-03 10:45:37 -03:00
Martin Molinero
f3f9bc7ece Address reviews
- Simplify interface, make `SendFinalResult()` internal to the
`ResultHandlers`
- Some test code clean up
2020-03-02 20:05:12 -03:00
Martin Molinero
b3feea86a1 Refactor IsolatorLimitResultProvider
- Replace `new Task` at `IsolatorLimitResultProvider.Consume()` for
single instance base timer.
- Adding unit test
2020-03-02 18:23:20 -03:00
Martin Molinero
2f4f7dc2cb ScheduledEvents fire in order
- Scheduled events will fire in order even after market hours
- Improving scheduled events performance
- Adding regression and unit test
2020-03-02 11:05:54 -03:00
Martin Molinero
958540f55c Improve result handler update logic
- Update logic in `Run` method will be executed by an internal Task
handled by the `BaseResultHandler`
- Call `DataFeed.Exit` even if algorithm initialization failed
2020-02-28 12:47:01 -03:00
Martin-Molinero
1866488530 Merge pull request #4143 from QuantConnect/bug-4130-remove-buying-power-margin-check
Remove BuyingPower MaximumOrderQuantity margin check
2020-02-28 10:08:28 -03:00
Gerardo Salazar
daaafae37d Updates future margins for CL, ES, GC, HO, NG, NQ, PA, PL, RB, SI, YM
Adds margins for futures:
1S 22 6A 6B 6C 6E 6J 6N 6S AUP B0 BCF BK BWF BZ CB CC CNH CRB CSC CSW
CT CU DX DY E6 E7 EDP EH EN EPN EVC EWG EWN EXR F1U FO FRC GCU GE
GF HCL HE HG HH HP HTT IBV J7 KC KE LE OJ RTY SB TN
VX YO ZB ZC ZF ZL ZM ZN ZO ZS ZT ZW
2020-02-27 16:32:24 -08:00
Martin Molinero
937b50798f Remove BuyingPower error log
- Remove BuyingPowerModel error logs at HasSufficientBuyingPowerForOrder
since it was duplicated by the brokerage
2020-02-27 20:44:38 -03:00
Martin-Molinero
de05011c55 Merge pull request #4142 from QuantConnect/refactor-4135-result-handler-delta-order-event
ResultHandler delta order events
2020-02-27 20:06:19 -03:00
Martin-Molinero
970b663440 Address review
Update code comment
2020-02-27 19:34:03 -03:00
Martin Molinero
de4acffe00 Refactor
- Add new OrderEvent collection into ITransactionHandler which will be
consumed by the ResultHandler
2020-02-27 18:47:44 -03:00
Martin Molinero
79dec73692 Address reviews
- BacktestResultHandler will limit the amount of order updates sent
- Replace `OrderEvent` collection for `int` order id
2020-02-27 14:20:41 -03:00
Martin Molinero
038bfc6ae1 Remove BuyingPowerMargin check
- Removing this margin precheck entirely to avoid generating unrequired errors.
When the PortfolioConstructionModel is rebalancing and generating new targets,
the check won't allow targets that increase margin usage which should be able to execute,
since the execution model (the next step) will first execute orders which reduce margin usage.
Also, note that this check will later be performed by the brokerage when processing the order.
2020-02-26 12:24:43 -03:00
Martin Molinero
107e117881 Address reviews 2020-02-26 10:47:54 -03:00
Martin Molinero
406155653f ResultHandler delta order events
- Share delta order events logic between backtest and live trading
result handler
2020-02-25 20:41:06 -03:00
Jared
d08d69b459 Merge pull request #4140 from QuantConnect/refactor-4135-result-packet-parameters-class
Add Result parameter class
2020-02-25 15:05:12 -08:00
Martin Molinero
4d0d85ec16 Add Result parameter class
- Add BaseResultParameters and Live/BacktestResultParameters classes
2020-02-25 17:02:30 -03:00
Jared
b19181b610 Merge pull request #4139 from QuantConnect/refactor-4135-result-handlers
IResultHandler API clean up
2020-02-25 11:16:41 -08:00
Martin Molinero
050e550eeb Remove unused var
- Remove unused var
- Fix cherry-pick
2020-02-25 13:50:40 -03:00
Martin Molinero
ecef71cd93 IResultHandler API clean up 2020-02-25 13:41:09 -03:00
Martin-Molinero
f46d5529df Merge pull request #4134 from QuantConnect/revert-4059-getbuyingpower-removal
Revert GetBuyingPower removal
2020-02-24 15:08:50 -03:00
Martin Molinero
6eb08334cd Revert GetBuyingPower removal
- Fix bug where OptioMarginModel would return 0 initial margin required
2020-02-24 14:06:16 -03:00
Jared
dac576f000 Merge pull request #4132 from QuantConnect/feature-3769-portfolio-bias
Portfolio construction model bias
2020-02-21 15:11:30 -08:00
Jared
a22923874c Merge pull request #4133 from QuantConnect/bug-4130-buying-power-model-margin-check
Buying power model margin remaining check
2020-02-21 13:45:57 -08:00
Martin Molinero
32a0624d15 BPM only check margin remaining if increasing
- Buying power model will only check margin remaining if actually going
to increase margin usage.
2020-02-21 16:56:57 -03:00
Martin Molinero
75ca2862e6 Address reviews 2020-02-21 16:13:28 -03:00
Martin Molinero
983d84bf01 Implement PortfolioBias for MVOPCM, BLOPCM, AIPCM
- Implement portfolio bias for
`MeanVarianceOptimizationPortfolioConstructionModel`,
`BlackLittermanOptimizationPortfolioConstructionModel`,
`AccumulativeInsightPortfolioConstructionModel`. Adding unit tests
2020-02-21 12:12:59 -03:00
AlexCatarino
c2ff03caad Implements PortfolioBias in EWPCM and IWPCM
Implements `PortfolioBias` in EWPCM, CWPCM and IWPCM. With this new feature, these PCM will ignore insights that do not respect the desired bias. E.g. for `PortfolioBias.Long`, on Insights with `InsightDirection.Up` will be converted into `PortfolioTarget.Quantity` greater than zero and other `InsightDirection` will result in `PortfolioTarget.Quantity` of zero.
2020-02-20 19:29:12 -03:00
Jared
79b6043b89 Merge pull request #4119 from QuantConnect/refactor-4117-move-ewpcm-logic-to-base
Refactor EqualWeightingPCM into base PortfolioConstructionModel
2020-02-20 13:34:08 -08:00
Martin-Molinero
32c2124df8 Merge pull request #4122 from QuantConnect/testing-4121-regression-assert-order-list-hash
Regression test assert order list hash
2020-02-20 13:19:10 -03:00
Martin Molinero
afed84e1a2 Add new unit test assert and bug fix 2020-02-20 13:01:35 -03:00
Martin Molinero
a8120c197a Improvements
- Adding new unit test for python PCM implementations, asserting each
method is correctly called
- Reverting some unrequired changes in the
`MeanVarianceOptimizationFrameworkAlgorithm`
2020-02-20 12:13:47 -03:00
Martin Molinero
0027ab1e66 Regression test assert order list hash
- Regression tests assert order list hash value
- Normalizing some regression test behavior that had differences between
C# and Py
2020-02-19 20:26:12 -03:00
Martin Molinero
8ff23936d1 Refactor EWPCM into base PCM
- Refactor shared logic from `EqualWeightingPortfolioConstructionModel`
into base `PortfolioConstructionModel` implementation
- `MeanVarianceOptimizationPortfolioConstructionModel` will respect
rebalancing period and will use all active inisights, not just the last
2020-02-19 15:13:20 -03:00
Martin-Molinero
685b231890 Merge pull request #4113 from QuantConnect/refactor-4112-accumulative-portfolio-construction-model
Refactor AccumulativeInsight PCM
2020-02-19 13:19:17 -03:00
Martin-Molinero
7f8add42e0 Merge pull request #4070 from QuantConnect/feature-3984-adds-sector-weighting-pcm
Implements SectorWeightingPortfolioConstructionModel
2020-02-19 13:18:24 -03:00
Jared
eeac0eca8b Merge pull request #4115 from RohanTalip/RT/bug-4114-remove-runmode
Removed the RunMode enum that has been deprecated
2020-02-18 08:27:52 -08:00
AlexCatarino
8a1823de73 Addresses Peer-Review 2020-02-18 16:00:09 +00:00
AlexCatarino
fcf2696809 Rebases With Master and Apply New API
Improves regression algorithm by adding more sanity checks.
2020-02-18 13:47:57 +00:00
AlexCatarino
fa17041ffa Adds Unit Tests
- Creates `BaseWeightingPortfolioConstructionModelTests`
- Refactors EWPCMTests and IWPCMTests to inherit `BaseWeightingPortfolioConstructionModelTests` and prevent code duplication.
- Adds `SectorWeightingPortfolioConstructionModelTests`
2020-02-17 22:08:06 +00:00
AlexCatarino
21ce895c18 Implements SectorWeightingPortfolioConstructionModel
Provides an implementation of `IPortfolioConstructionModel` that generates percent targets based on the `CompanyReference.IndustryTemplateCode`.
2020-02-17 22:08:06 +00:00
Martin Molinero
1fccf4f263 Address reviews
- Use `InsightCollection.GetActiveInsights`
2020-02-17 19:01:18 -03:00
Jared
dfa39ba4ce Merge pull request #4109 from QuantConnect/feature-3945-quarterly-yearly-calendar-types
Added Quarterly & Yearly Calendar
2020-02-17 13:31:59 -08:00
Rohan Talip
66358ac798 Removed the RunMode enum that has been deprecated since the initial commit on 2015-01-12. 2020-02-17 12:50:16 -08:00
Martin Molinero
0ff713d8f9 Refactor AccumulativeInsight PCM
- Refactor AccumulativeInsightPortfolioConstructionModel to inherit from
the EWPCM, reducing code duplication and adding support for rebalancing
period
- Fixing bug where only 1 new insight per symbol was processed per loop
- Adding unit tests
2020-02-17 16:09:16 -03:00
Martin Molinero
b5ac6bffd9 Adding unit tests
- Adding Yearly and Quarterly unit tests
2020-02-17 11:28:34 -03:00
Aytaç Aşan
75717f2e15 Added Examples in DataConsolidationAlgorithm (Python)
Added Examples in DataConsolidationAlgorithm (Python) for Quarterly & Yearly Data Consolidation
2020-02-14 21:08:30 -03:00
Aytaç Aşan
2f3b7f6187 Added Examples in DataConsolidationAlgorithm
Added Examples in DataConsolidationAlgorithm for Quarterly & Yearly Data Consolidation
2020-02-14 21:08:30 -03:00
Aytaç Aşan
d27513c4c4 Added Quarterly & Yearly Calendar Types
Calendar Support Expanded for Quarterly & Yearly Calendar Types.
2020-02-14 21:08:29 -03:00
Jared
ea8da8bde1 Merge pull request #3992 from AlexCatarino/refactor-calendartype-rename
Renames CalendarType to Calendar
2020-02-14 15:38:09 -08:00
Martin Molinero
8f50691927 Update documentation 2020-02-14 19:59:22 -03:00
Martin Molinero
4951dbdea4 Address reviews 2020-02-14 19:53:39 -03:00
AlexCatarino
ceabf93e94 Renames CalendarType to Calendar
Keeps `CalendarType` for backward compatibility.
2020-02-14 19:47:48 -03:00
Jared
1d65640f14 Merge pull request #4105 from QuantConnect/feature-4075-date-rules-period
Adding IDateRule to rebalace PCM
2020-02-14 13:04:53 -08:00
Martin Molinero
3679ad591f Address reviews
- Improve custom rebalance function logic
- Add new PyObject C# PCM constructor overloads for performance
2020-02-14 16:38:16 -03:00
Martin Molinero
e12788375b Adding IDateRule rebalacing PCM
- Adding IDateRule to be used by the PortfolioConstructionModel as
rebalancing function.
- Adding unit tests and C#/Py regression algorithms
2020-02-13 18:23:15 -03:00
Martin Molinero
26c731f895 Add python regression algorithm implementation 2020-02-13 16:11:23 -03:00
Martin Molinero
4584088a9e Address reviews
- Refactor to avoid calling rebalancing function twice in the same loop
- Refactor making portfolio rebalance setting instance based instead of
static
2020-02-13 16:10:52 -03:00
Martin Molinero
0845f0802d Unknown next rebalance time
- Adding new `Func<DateTime, DateTime?>` that allows PCM to return null
if the next rebalance time is null, in which case the function will be
called again in the next loop.
- Adjusting PCM next rebalance time check to perform rebalance once the
time is reached
- Adding new regression test. Updating existing
2020-02-13 16:10:52 -03:00
Jared
a835b17c70 Merge pull request #4102 from AlexCatarino/bug-3602-update-dropbox-algorithms
Updates Dropbox Algorithms
2020-02-12 16:28:34 -08:00
AlexCatarino
3a0640614c Updates Dropbox Algorithms
- Updates `DropboxUniverseSelectionAlgorithm` and `DropboxBaseDataUniverseSelectionAlgorithm` with new links to Dropbox files and date range to match the dates in the files.
- Adds copy of files in `TestData` folder.
2020-02-12 23:58:03 +00:00
Jared
43dba33b89 Merge pull request #4098 from QuantConnect/feature-4091-setfilter-int-overloads
Adds Integer Overload to SetFilter and Expiration Methods (II)
2020-02-12 14:46:20 -08:00
Jared
a975595360 Merge pull request #4095 from QuantConnect/feature-future-symbol-filter
Implement symbol filter in AlgoSeekFuturesConverter processor
2020-02-12 14:29:43 -08:00
AlexCatarino
f6d7e5fcd7 Addresses Peer-Review
- Standarizes basic template algorithms for options and futures
- Fix typo
2020-02-12 22:28:45 +00:00
Rahul
17d8ac1811 Update to GC margins (#4089)
Update GC margins
2020-02-12 14:26:04 -08:00
Jared
5e91820a62 Merge pull request #4092 from QuantConnect/feature-4091-setfilter-int-overloads
Adds Integer Overload to SetFilter and Expiration Methods
2020-02-12 14:24:08 -08:00
Jared
382e27bde4 Typo 2020-02-12 14:23:52 -08:00
Juan José D'Ambrosio
d278227101 Implement symbol filter in AlgoSeekFuturesConverter processor 2020-02-12 19:51:21 +00:00
Martin Molinero
c73da247e5 Add new python libraries
- Adding tslearn=0.3.0, tweepy=3.8.0, dtw-python==1.0.4,
pywavelets=1.1.1, umap-learn=0.3.10.
- Update hmmlearn==0.2.3
2020-02-12 15:12:34 -03:00
AlexCatarino
9690acfd25 Changes Basic Template Algorithms With Options and Futures to Show The New Overloads
Keeps the original overloads in the comments.
2020-02-12 16:49:44 +00:00
AlexCatarino
c802621543 Adds Integer Overload to SetFilter and Expiration Methods
Adds the following method overloads:
`Future.SetFilter(int, int)`
`Option.SetFilter(int, int, int, int)`
`FutureFilterUniverse.Expitarion(int, int)`
`OptionFilterUniverse.Expitarion(int, int)`
to simplify the API since the original methods accept `TimeSpan` that are most used with `AddDays(int)` method.
2020-02-12 16:47:40 +00:00
Jared
4ad832209f Merge pull request #4090 from gsalaz98/feature-2991-add-expirations-to-futures-database-ub-tn
Adds UB, TN Futures to Futures Database
2020-02-12 07:14:55 -08:00
Gerardo Salazar
bfffbc183c Adds UB, TN to FuturesExpiryFunctions, MHDB, and symbol-properties-db 2020-02-11 18:05:59 -08:00
Jared
c3407b3e8c Merge pull request #4088 from gsalaz98/bug-4081-embed-stylesheet-in-report-output
Embeds report stylesheet in the output file.
2020-02-11 17:11:48 -08:00
Jared
7f941edeec Merge pull request #4087 from QuantConnect/bug-4080-fix-report-creator-macosx-pythonpath
Fixes issue where report creator could not be ran in Mac OSX
2020-02-11 16:56:58 -08:00
Jared
873a392546 Merge pull request #4079 from QuantConnect/refactor-4075-portfolio-construction-rebalancing-period
Refactor PCM rebalacing
2020-02-11 16:54:52 -08:00
Jared
7ceb158611 Merge pull request #4082 from QuantConnect/bug-3986-immediate-execution-respects-order-minimum
Order sizing improvements
2020-02-11 16:53:46 -08:00
Martin Molinero
46ac9a2070 Address reviews
- Update unit tests adding expected result as a parameter.
2020-02-11 21:31:18 -03:00
Martin Molinero
d3a2c7ff5a Address reviews
- Moving InsightCollection into base `PortfolioConstructionModel`
- Will call `InsightCollection.GetNextExpiryTime()` on each check, and
for performance `InsightCollection` will keep track of next insight
expiry time
- Removing need for PCM base classes having to call `RefreshRebalance`
- Some refactor clean up at base
PortfolioConstructionModel.IsRebalanceDue()
2020-02-11 21:02:35 -03:00
Gerardo Salazar
d3a34dcd70 Fixes issue where report creator could not be ran in Mac OSX
* Adds `PythonInitializer.SetPythonPathEnvironmentVariable(...?)` method
2020-02-11 15:01:47 -08:00
Martin-Molinero
2f2917e94f Merge pull request #4084 from QuantConnect/bug-4083-str-pandas-data-remapper
Implements Wrappers for __str__ and __repr__ in PandasData.Remapper
2020-02-11 17:53:04 -03:00
Martin Molinero
e6d07d6305 Add new regression algorithms
- Adding new regression algorithms setting PCM.RebalanceOnSecurityChanges
and PCM.RebalanceOnInsightChanges to false
2020-02-11 17:36:27 -03:00
AlexCatarino
8333374e4d Add Unit Tests 2020-02-11 19:37:33 +00:00
Martin Molinero
4fc9a516fd Adding RebalanceOnInsightChanges flag
- Refactoring some PCM methods to be `protected` since they are not required
to be public
- Adding new `PortfolioConstructionModel.RebalanceOnInsightChanges`
flag, that will allow avoiding new insights or insight expirations to
trigger a rebalance
- Updating unit tests
- Fix for the MeanVarianceOptimizationPortfolioConstructionModel that
was skipping, in some cases, 0 magnitude insights
2020-02-11 16:06:27 -03:00
AlexCatarino
0beaab873f Implements Wrappers for __str__ and __repr__ in PandasData.Remapper 2020-02-11 16:54:51 +00:00
Martin Molinero
1dd742d1b8 Order sizing fix
- Improving OrderSizing.Value and Volume to include code in consumers
- OrderSizing.GetUnorderedQuantity() will adjust result by lot size
- ImmediateExecutionModels will use OrderSizing.GetUnorderedQuantity()
- OrderSizing.Value() will take into account ContractMultiplier
- Adding unit tests
2020-02-11 13:17:10 -03:00
Martin Molinero
6cfa19697a Refactor PCM rebalacing
- Add missing PCM constructor methods for the different supported
rebalancing periods overloads
- Normalize rebalance behavior in the base `PortfolioConstructionModel`
- Adding new `PortfolioConstructionModel.RebalanceOnSecurityChanges`
that will allow disabling rebalance on security changes
- Adding unit tests
2020-02-10 22:32:09 -03:00
Gerardo Salazar
2bce084546 Embeds report stylesheet in the output file.
This is done to make the HTML for the report a standalone page
without requiring the user to provide the *.css file along with
their report
2020-02-10 17:27:23 -08:00
Jared
47f6d5bee1 Merge pull request #4073 from QuantConnect/feature-4072-nulldata-custom
Implements NullData Custom Data
2020-02-07 16:02:48 -08:00
Jared
538a2def56 Merge pull request #4074 from gsalaz98/feature-4022-future-margins-readme-tutorial
Add tutorial README.md in Futures margins folder
2020-02-07 16:02:02 -08:00
AlexCatarino
1abe6274db Replace <inheritdoc/> by Hard-Coded Documentation 2020-02-07 23:49:28 +00:00
Gerardo Salazar
7bac21cd13 Add README.md for Futures margins tutorial 2020-02-07 14:17:31 -08:00
AlexCatarino
1d9e719a0b Implements NullData Custom Data
Represents a custom data type that works as a heartbeat of data in live mode
2020-02-07 21:39:24 +00:00
Martin-Molinero
1c4a048f71 Merge pull request #4071 from gsalaz98/bug-fix-tradingeconomics-destination-directory
Fixes issue where Trading Economics Calendar Downloader did not use provided destination directory
2020-02-07 12:27:57 -03:00
Jared
bf45024a54 Merge pull request #4062 from Martin-Molinero/bug-4053-fix-factorfilegenerator-unit-tests
Fix FactorFileGenerator tests
2020-02-06 14:13:42 -08:00
Gerardo Salazar
161ee260f8 Fixes issue where Trading Economics Calendar downloader would not
respect the destination directory provided to it in its ctor
2020-02-06 11:51:16 -08:00
Jared
835c99e55c Merge pull request #4068 from QuantConnect/bug-4067-crypto-margin-account
Sets the Security BuyingPowerModel Before SetLeverage is Called in BrokerageModelSecurityInitializer
2020-02-06 06:41:14 -08:00
AlexCatarino
d9b3bdd08d Sets the Security BuyingPowerModel Before SetLeverage is Called in BrokerageModelSecurityInitializer
Sets the `Security` object `BuyingPowerModel` before its `SetLeverage` method is called in the `BrokerageModelSecurityInitializer`.

Updates `BitfinexBrokerageModelTests` to test the new behavior.
2020-02-06 14:05:15 +00:00
Martin-Molinero
7ea2e6853b Merge pull request #4054 from gsalaz98/feature-refactor-tradingeconomics-calendar-downloader
Refactors Trading Economics Calendar Events Storage
2020-02-05 21:30:21 -03:00
Jared
8fdf0acd2b Merge pull request #4066 from Martin-Molinero/bug-4064-margin-call-closed-market-modelling
Fix margin call on closed market
2020-02-05 16:00:01 -08:00
Martin Molinero
b51ae82900 Address reviews
- Add new regression algorithm which expects no regression call to
happen
2020-02-05 20:26:17 -03:00
Gerardo Salazar
55361cda98 Change TradingEconomicsCalendar to use SetAuthCode(...) pattern 2020-02-05 14:09:09 -08:00
Martin Molinero
9aa6a7062e Fix margin call on closed market
- `FutureMarginModel` and `PatternDayTradingMarginModel` will adjust
margin requirements before market closes using the new `Exchange.ClosingSoon` property
- Adding unit tests and regression algorithm
2020-02-05 18:53:51 -03:00
Gerardo Salazar
01f7629c70 Address review - remove GetNextCsv() in favor of ToCsvData()
* Fixes bug in ToCsvData() where an empty final value would not be
parsed
* Removes GetNextCsv()
* Reworked `Reader` logic in TradingEconomicsCalenda
* Use delimiter var as separator in TradingEconomics.Calendar
* Convert country names to uppercase in TradingEconomics.Calendar
2020-02-05 11:44:57 -08:00
Jared
fa8f4bd54d Merge pull request #4063 from Martin-Molinero/bug-4052-insight-serialization-unit-tests
Fix insight serialization unit test
2020-02-05 10:55:53 -08:00
Martin Molinero
70a0bebfaa Fix unit test
- Fix insight serialization unit test by removing end line characters
from comparison
2020-02-05 13:16:22 -03:00
Martin-Molinero
a697d7380e Merge pull request #4059 from QuantConnect/refactor-4027-buying-power-model-margin
Refactor buying power model
2020-02-05 12:19:35 -03:00
Jared
d038ec4a52 Merge pull request #4047 from QuantConnect/feature-4041-get-last-known-price
Changes GetLastKnownPrice Logic to Increase History Look-back
2020-02-04 14:44:00 -08:00
Gerardo Salazar
c5507fdc17 Address review - adds new test cases for GetNextCsv() and fixes bug 2020-02-04 14:32:52 -08:00
Martin Molinero
03ae58d662 Fix FactorFileGenerator tests
- Yahoo API inverted the returned split factor and changed the split
char
2020-02-04 19:00:27 -03:00
Gerardo Salazar
bbe1416632 Address review - Refactor and add additional tests
* Refactors CountryToCurrencyCode(...) method
* Adds new test cases to GetNextCsv() method
* Refactors GetNextCsv() to prevent code duplication
2020-02-04 13:48:05 -08:00
Gerardo Salazar
5db43205ef Fixes issues for TradingEconomicsCalendar live trading
* Adds new tests for successful continuation of the stream in case of an
error
* Deletes unused `ReadToEndOfLine()` method
2020-02-04 13:48:04 -08:00
Gerardo Salazar
050089a3ae Address review and add TradingEconomics.Event definitions
* Updates TradingEconomics algorithms to use new event definition
* Separated Calendar and Indicator definitions into partial class
* Refactors portions of TradingEconomicsCalendar
* Makes TradingEconomicsCalendar.GetSource return RemoteFile for live
* Fixes bugs in TradingEconomicsEventFilter
* Fixes bugs in StreamReaderExtensions (thanks Martin :))
* Adds new unit tests to cover changes
2020-02-04 13:48:04 -08:00
Gerardo Salazar
f85e59383a Reworks storage of Trading Economics calendar events
* Adds support for live algorithms using TE calendar events
* Modifies TradingEconomics tickers to include country
* Fixes bug where `TECal.Clone(...)` could result in non-deterministic
results
* Fixes bugs in TradingEconomicsEventFilter
* Adds new CSV parsing methods in StreamReaderExtensions
* Moves ToolBox/TradingEconomicsCalendarTests to Common tests folder
* Updates TradingEconomicsCalendar tests to test CSV parsing
* TradingEconomicsCalendarDownloader now writes files to disk as JSON
2020-02-04 13:48:04 -08:00
Martin Molinero
fe78801fca Add future 'EnableIntradayMargins'
- Add `FutureMarginModel.EnableIntradayMargins` false by default to
avoid margin calls with SetHoldings usage
- Updating regression tests
2020-02-04 18:41:15 -03:00
Martin Molinero
85f5b68972 Address reviews
- Revert `OptionMarginModel` behavior change
- Renames
- Refactor future intraday margin modelling
2020-02-04 18:41:15 -03:00
Martin Molinero
6eb45baa59 Refactor GetMaximumOrderQuantityForTargetBuyingPower
- Refactoring `GetMaximumOrderQuantityForTargetValue` into
`GetMaximumOrderQuantityForTargetBuyingPower` which algorithm uses
margin
- Reducing code duplication
- Adding unit tests
- Fixing futures margin model. Adding intra day logic.
2020-02-04 18:41:15 -03:00
Martin Molinero
936af7df7b Refactor BuyingPowerModel
- Remove unrequired `GetBuyingPower`
- Making `BuyingPowerModel.GetMaintenanceMarginRequirement` protected
instead of public
- Adding `GetMaximumOrderQuantityForDeltaBuyingPower` to replace
public `GetMaintenanceMarginRequirement` and improve API experience for
consumers like the `DefaultMarginCallModel`
- Adding new unit tests
2020-02-04 18:41:15 -03:00
Jared
25727aeffc Merge pull request #4061 from Martin-Molinero/bug-filteruniversecorrectlywithdata-unit-test
Fix FiltersUniverseCorrectlyWithValidData unit test
2020-02-04 13:30:24 -08:00
Martin Molinero
ed7f21e05a Fix failing unit test
- Unit test started failing because it was using a future end time at
the time of the merge and once it passed the end time it started failing
because it performed 1 extra selection
2020-02-04 17:53:28 -03:00
Martin-Molinero
a9d15d9afd Merge pull request #4056 from QuantConnect/ib-scheduled-reset-times-saturday-fix
Include full day of Saturday in IB scheduled server reset times
2020-02-04 17:29:52 -03:00
AlexCatarino
8bd65ecc1d Fixes Typos 2020-02-03 21:11:40 +00:00
Stefano Raggi
21046c7db7 Include full day of Saturday in IB scheduled server reset times
Occasionally the disconnection due to the IB reset period might last much longer than expected during weekends (even up to the cash sync time).
2020-02-03 14:16:08 +01:00
Jared
719160542c Merge pull request #4046 from QuantConnect/bug-4045-oanda-brokerage-connection-handling
Update Oanda brokerage connection handling
2020-01-30 13:50:51 -08:00
AlexCatarino
200d3b0271 Changes GetLastKnownPrice Logic to Increase History Look-back
Changes `GetLastKnownPrice` logic to retry to get non-null data after a first attempt. Previously, it would return null in the first attempt and illiquid securities would not have valid data to set its market price. In the second attempt, we increase the look-back period to the equivalent of three trading days worth of data.
2020-01-30 17:53:30 +00:00
Stefano Raggi
08378d4ccb Update Oanda brokerage connection handling
- Fixed detection of no pricing data with two separate connection handlers
- Removed code duplication by reusing the DefaultConnectionHandler
2020-01-30 16:12:52 +01:00
Jared
04a8c6af7e Merge pull request #4034 from QuantConnect/bug-4024-option-chain-universe-selection-data
Validate option universe selection data
2020-01-29 08:07:10 -08:00
Martin-Molinero
c2f2631b27 Merge pull request #4036 from gsalaz98/bug-fix-smartinsider-transactions-date-format-parsing
Fixes parsing of new date format in Smart Insider transactions data
2020-01-29 09:52:05 -03:00
Jared
777049b972 Merge pull request #4040 from QuantConnect/bug-4039-coinbase-market-order-fix
Fix CoinbasePro Rejected Market Orders
2020-01-28 15:53:27 -08:00
Jared
facde50fcd Merge pull request #4038 from simonsonjack/bug-4037-Update-Insight-Constructor
Update Insight.cs
2020-01-28 15:51:48 -08:00
Stefano Raggi
c39a411cdb Fix CoinbasePro Rejected Market Orders 2020-01-29 00:18:36 +01:00
Jack Simonson
64d0ecb1b7 Update Insight.cs
Add Weight to Insight constructors where missing/necessary.
2020-01-28 09:56:57 -08:00
Gerardo Salazar
0a87b78ae8 Address review - update documentation and exception messages 2020-01-28 09:55:47 -08:00
Gerardo Salazar
ec9de51ca3 Address review - Applies new datetime parsing to intentions data
* Moves SmartInsider Transactions DateTime parse method to base class
* Replace "CSV" mentions with "TSV" in documentation
* Update tests
2020-01-28 09:40:10 -08:00
Jared
556d4000d2 Merge pull request #3996 from adam-may/feature-3995-add-new-commodity-instruments
Add HRW Wheat, Brent Crude, Low Sulfur Gasoil and Random Length Lumbe…
2020-01-28 07:27:11 -08:00
Gerardo Salazar
58cf6d57ec Fixes parsing of new date format in Smart Insider transactions data
* Makes converter throw hard error if it fails to parse from raw data
* Adds new unit tests
* Fixes typos where we called data `CSV` instead of `TSV`
2020-01-27 18:20:16 -08:00
Gerardo Salazar
b7e600cf37 Adds and Fixes MHDB entries for KE in: holidays, earlyCloses, and lateOpens 2020-01-27 15:00:41 -08:00
Martin Molinero
20c589f0fe Validate option universe selection data
- Remove unused `OptionChainUniverseDataCollectionAggregatorEnumerator`
- Refactor `BaseDataCollectionAggregatorEnumerator` and
`OptionChainUniverseDataCollectionEnumerator` to avoid emitting invalid
data points
- Updating regression tests statistics
- Adding unit test
2020-01-27 19:11:17 -03:00
Jared
17b1acf6d2 Merge pull request #4033 from gsalaz98/feature-normalize-tradingeconomics-calendar-events-pt1
Implement filtering and normalization of Trading Economics calendar event names
2020-01-27 13:07:11 -08:00
Gerardo Salazar
e7a9d06b16 Implement filtering and normalization of Trading Economics calendar
event names

* Adds unit test for new filter method

NOTE: This is a breaking change for Trading Economics calendar events
property. Any previous string matching might result in a mismatch if
results were not previously being normalized.
2020-01-27 11:32:26 -08:00
Adam May
a1406f463f Touching to force rebuild 2020-01-27 22:32:54 +11:00
Adam May
85fee67290 Add test for regression of current month expiring contracts 2020-01-26 11:10:32 +10:30
Adam May
b4a06aa676 Unit tests for symbol representation checks 2020-01-26 11:05:02 +10:30
Adam May
bc9b6344e0 Code review comments 2020-01-26 08:48:43 +11:00
Jared
ed1c6fdd44 Merge pull request #4030 from gsalaz98/feature-4029-add-createdtime-to-serializedinsight
Adds new property `CreatedTime` to Insight JSON output
2020-01-24 15:06:23 -08:00
Gerardo Salazar
754ce65b2d Fixes issue where old insight objects would not deserialize correctly
* Adds new unit test covering old JSON
2020-01-24 13:09:48 -08:00
Adam May
d5fbded8c6 Trading calendar for Brent Crude and Low Sulfur Gasoil 2020-01-24 15:20:09 +11:00
Adam May
f64e389f97 Trading calendar for Wheat and Lumber 2020-01-24 13:40:53 +11:00
Gerardo Salazar
eb7bd53c64 Adds new property CreatedTime to Insight JSON output
* Deprecates `generated-time` in Insight JSON
* Deprecates `GeneratedTime` in `SerializedInsight` and make pass-through
2020-01-23 17:12:49 -08:00
Adam May
5d2378b826 Fixes for expiries which occur more than a month prior to the contract month 2020-01-22 18:22:16 +11:00
Jared
7c4d60fe25 Merge pull request #4026 from AlexCatarino/feature-4023-futures-margin-model
Adds InitialMarginRequirement and MaintenanceMarginRequirement Properties to FutureMarginModel
2020-01-21 13:36:31 -08:00
AlexCatarino
9172bf0ed2 Addresses Peer-Review
The `AlphaStreamsBrokerageModel` was unnecesarily duplicating the `GetBuyingPowerModel` from the base class. Missing docs were added.
2020-01-21 15:52:54 +00:00
Adam May
f69e704fc8 Merge branch 'feature-3995-add-new-commodity-instruments-gs' into feature-3995-add-new-commodity-instruments 2020-01-21 13:14:24 +11:00
Adam May
3cea8808bf Changing Random Length Lumber group to Forestry 2020-01-21 13:05:14 +11:00
Gerardo Salazar
1773e03b81 Implements GE, CT, CC, KC, SB, OJ futures contract expiries 2020-01-20 17:57:42 -08:00
AlexCatarino
63bd501306 Adds InitialMarginRequirement and MaintenanceMarginRequirement Properties to FutureMarginModel
These properties expose the current margin requirements that can be used to compute the number of contracts manually.
2020-01-20 22:49:03 +00:00
Jared
2d6f34df50 Merge pull request #4019 from QuantConnect/ib-automater-update
IB Brokerage clean up + IBAutomater upgrade
2020-01-20 14:16:37 -08:00
Stefano Raggi
c5e091f901 Minor update to trigger build 2020-01-20 15:51:11 +01:00
Stefano Raggi
e9824bfe27 Update IBAutomater v1.0.14 2020-01-20 15:51:11 +01:00
Stefano Raggi
0603f1ace3 Add missing error check in OnIbAutomaterExited 2020-01-20 15:51:11 +01:00
Stefano Raggi
86c309bfae Remove IBAutomater error handling, initialization and restart checks 2020-01-20 15:51:11 +01:00
Stefano Raggi
3b64c7381a Update IBAutomater v1.0.10 2020-01-20 15:51:11 +01:00
Martin-Molinero
23d97f9f21 Merge pull request #4020 from QuantConnect/alpaca-websocketsharp-logging-redirect
Redirect Alpaca WebSocketSharp log output to Lean logging system
2020-01-17 19:01:04 -03:00
Jared
4e89ed8050 Merge pull request #4017 from QuantConnect/bug-4008-coarse-accumulative-failing-regression
Fix failing regression tests
2020-01-17 11:48:53 -08:00
Martin Molinero
8f14f1bdfa Fix failing regression tests
- After https://github.com/QuantConnect/Lean/pull/4000
CoarseFineFundamentalRegressionAlgorithm started using `MarketCap`, but
this value was always 0 in existing data, so it caused undeterministic
results. Adding new data and update expected result.
- `AccumulativeInsightFrameworkAlgorithm` expected statistic were not
correct, updating.
2020-01-17 11:14:09 -03:00
Jared
c11e2635c0 Merge pull request #4016 from Martin-Molinero/bug-3927-fix-non-daily-beta-live-trading-initial-portfolio-value
Set initial DailyPortfolioValue for LiveTrading
2020-01-16 17:17:13 -08:00
Martin Molinero
0cee9c0829 Set initial DailyPortfolioValue for LiveTrading 2020-01-16 22:07:43 -03:00
Jared
1eb1566474 Merge pull request #4003 from QuantConnect/bug-3927-fix-non-daily-beta
Fix Beta calculation for non-daily algorithms
2020-01-16 17:03:38 -08:00
Martin Molinero
3e98b6ae7f Merge Live and Backtesting Sample implementation
- Merging Live and Backtesting sample implementations, a little refactor
to reduce code duplication
2020-01-16 21:22:57 -03:00
Adam May
0a7f6d11bf Include check for Wheat in unit tests 2020-01-17 10:36:50 +11:00
Adam May
6a4a22d59d Throw exception if future doesn't have an expiry function defined + unit test to check all futures have expiry functions defined 2020-01-17 10:35:50 +11:00
Jared
6b4d9b6944 Merge pull request #4015 from QuantConnect/bug-4014-alpaca-partial-fills-fix
Fix Alpaca partial fill quantity bug
2020-01-16 15:13:36 -08:00
Stefano Raggi
b2af021f29 Remove unnecessary Convert.ToInt64 call 2020-01-17 00:03:24 +01:00
Gerardo Salazar
4102c83e88 Modify and fix select regression algorithms
* OnEndOfDayRegressionAlgorithm - Since the EndTime of the hourly benchmark is during the day,
the OnEndOfDay method gets called one less time than usual. Updates statistics

* CustomUniverseWithBenchmarkRegressionAlgorithm.cs - modified algorithm so
that it works with hourly benchmark. Previously only tested for Daily benchmark

* BasicTemplateAlgorithm.py - Modified resolution to be
Resolution.Minute, just like it is in C#

* CustomDataRegressionAlgorithm.py - Remove warmup call from Initialize

* IndicatorSuiteAlgorithm.py - Adds PythonQuandl import to fix import error
2020-01-16 14:03:55 -08:00
Gerardo Salazar
66e093babb Address review - Remove SampleAssetPrices from IResultHandlers
* Changed variable names of protected members in BaseResultHandler to
match existing variable naming convention
* Changed AlgorithmRunner return type
* Remove AlgorithmResults dictionary from AlgorithmRunner
* Create AlgorithmRunnerResults container class
* Modify Relative Sampling test to accept failure cases
* Misc. updates as a result of changing AlgorithmRunner return type
2020-01-16 14:03:55 -08:00
Gerardo Salazar
61aa0d3a65 Updates regression statistics
Please note that with these changes, any algorithms that
use daily data exclusively will have incorrect statistics.
2020-01-16 14:03:54 -08:00
Gerardo Salazar
6f5e394d52 Address Martin's review - test modifications and cleanup
* Get rid of `previousTime` and use `time` instead in AlgorithmManager
* Refactor variable names in Backtesting and Live IResultHandler impls
* Moves shared variables to BaseResultHandler
* Modifies BacktestNodePacketTests statistics to get tests passing
* Adds new StatisticsBuilder tests
* Modifies BacktestingResultHandler tests to make them passing
    - Regarding these tests, the decision was made to get them
      passing so that if any behavior changes, we will know immediately.

Next commit will contain regression test changes for easy rollback.
2020-01-16 14:03:54 -08:00
Gerardo Salazar
3266b1a4e5 Address Martin's review - code refactoring and cleaning
* Removed Sample[a-zA-Z]+ methods from IResultHandler definition
* Converted Sample[a-zA-Z]+ methods from public to protected
* Updated inheritors of BaseResultHandler to use new accessibility
modifiers
* Removes useless code in ResolutionSwitchingAlgorithm
2020-01-16 14:03:54 -08:00
Gerardo Salazar
dfee825ef6 Refactors sampling strategy in AlgorithmManager loop
* Refactors AlgorithmManager loop
* Refactors StatisticsBuilder methods and strategy for series alignment
* Move sampling logic to the corresponding IResultHandler
* Changes benchmark resolution to Resolution.Hour
* Modifies IResultHandler to enable external sampling
* Adds BacktestResultHandler unit tests
* Adds ResolutionSwitchingAlgorithm to test misalignment
* Adds support to AlgorithmRunner to store algorithm IResultHandler

Warning: this commit breaks accurate calculations for algorithms that
only make use of `Daily` resolution data. Previously, because
the benchmark was added in Daily resolution in backtesting, any
algorithm that only made use of daily data would have an accurate
calculation for beta and various other statistics.

These changes serve to fix the statistics calculations of non-daily
resolution algorithms, with daily resolution to be revisited at a later
time.
2020-01-16 14:03:54 -08:00
Stefano Raggi
67c4c6c50c Redirect Alpaca WebSocketSharp log output to Lean logging system 2020-01-16 22:55:00 +01:00
Jared
0a20f41861 Remove + 2020-01-16 13:24:30 -08:00
Jared
f0cfb1bcad Merge pull request #4013 from QuantConnect/bug-4012-result-handler-orders-delta
BacktestingResultHandler orders delta
2020-01-16 13:21:04 -08:00
Stefano Raggi
074f08cdfc Fix Alpaca partial fill quantity bug 2020-01-16 22:12:32 +01:00
Martin Molinero
14be31d0e5 BacktestingResultHandler orders delta
- BacktestingResultHandler will send a maximum of 50 orders per update
packet and will check `LastFillTime` and `LastUpdateTime` too
- Fix invalid linked file
`AccumulativeInsightPortfolioRegressionAlgorithm`
2020-01-16 17:50:42 -03:00
Jared
e261ce2e89 Merge pull request #4011 from QuantConnect/bug-4010-symbol-equals-emtpy
Fix Symbol Equals emtpy
2020-01-16 10:37:47 -08:00
Martin Molinero
322aa9574d Fix Symbol Equals emtpy
- Fix Symbol Equals Empty implementation
- Improving performance
- Adding unit test
2020-01-16 12:50:30 -03:00
Jared
171ce816f8 Merge pull request #3988 from QuantConnect/ib-brokerage-fixes
IB Brokerage bug fixes
2020-01-14 14:03:15 -08:00
Jared
b95973cf69 Merge pull request #3940 from wardjm/feature-accumulative-model
Feature accumulative model
2020-01-14 13:57:10 -08:00
Adam May
37c30ac96f Default the Wheat contract to SRWWheat for backwards compatibility 2020-01-15 08:47:39 +11:00
Jared
57e57d9ddc Merge pull request #4002 from Martin-Molinero/bug-4001-duplicate-endofdayevent-for-symbol
Remove duplicate EndOfDayEvent for AddData Symbols
2020-01-14 13:18:28 -08:00
Jared
aabb11ef24 Merge pull request #4000 from haxdds/feature-3999-update-to-market-cap
Feature 3999 update to market cap
2020-01-14 13:12:55 -08:00
Martin Molinero
6cd12abff4 Remove duplicate EndOfDayEvent for Symbols
- Remove duplicate EndOfDayEvent for Symbols added with `AddData` calls
- Adding regression test
2020-01-14 18:06:52 -03:00
Adam May
f8c25784db Removing duplicate Future-usa-KE 2020-01-15 07:46:24 +11:00
Rahul
0dcf98d1dd Update to ComputeMarketCapCorrectly 2020-01-14 11:16:38 -08:00
Rahul
0b24d9da8b Update to FiltersUniverseCorrectlyWithValidData
Updated market cap test in accordance with changes to FineFundamental.MarketCap
2020-01-14 10:28:02 -08:00
Jeff Ward
ad642bb951 Fixed typo and type mismatch. 2020-01-14 12:34:45 -05:00
Rahul
f768cd6b38 Merge pull request #2 from QuantConnect/master
Update
2020-01-14 09:34:08 -08:00
Jeff Ward
c738dc7d22 Fixed CI build errors. 2020-01-14 12:10:18 -05:00
Jeff Ward
8d9f68370a Added missing parenthesis. 2020-01-14 11:49:50 -05:00
Jeff Ward
8c7d63e80c Implemented 2nd code review changes. 2020-01-14 11:37:40 -05:00
Jared
e4d34e2c12 Merge pull request #3998 from QuantConnect/python-pre-initialize
Making WorkerThread static
2020-01-14 08:07:30 -08:00
Martin Molinero
cd9bf4cc77 Making WorkerThread static
- Making WorkerThread instance static
- Adding PythonInitialize.AddPythonPaths(), useful to add paths to
python after initialization
2020-01-14 11:31:58 -03:00
Adam May
04f54380f4 Add HRW Wheat, Brent Crude, Low Sulfur Gasoil and Random Length Lumber Futures 2020-01-14 21:39:37 +11:00
Stefano Raggi
32c032a1b5 Cleanup IBAutomater error handling 2020-01-14 11:24:35 +01:00
Stefano Raggi
123de2de3c Add InteractiveBrokersStateManager 2020-01-14 11:24:35 +01:00
Stefano Raggi
cf3ec33fc8 Add BrokerageMessageEvent for IBAutomater errors 2020-01-14 11:24:35 +01:00
Stefano Raggi
b9b2b1fa8a Do not restart after IBAutomater errors 2020-01-14 11:24:34 +01:00
Stefano Raggi
c427902c36 Do not attempt to reconnect after IBAutomater errors 2020-01-14 11:24:34 +01:00
Stefano Raggi
b28ab3a9c3 Always throw if existing session detected
- Removed _performingRelogin flag and re-login checks
2020-01-14 11:24:34 +01:00
Stefano Raggi
1b6449eb7c Reset error flags before restarting IBGateway
All these flags are now being reset for consistency before restarting but the only one considered a bug fix is for `_previouslyInResetTime`.

This flag is normally set to `true` in `TryWaitForReconnect` after a disconnect but it was never being cleared after an IBGateway restart, causing an unnecessary reboot outside of the IB reset period on the next `TryWaitForReconnect` call (which in turn could also cause algorithm termination later on at cash sync time).
2020-01-14 11:24:34 +01:00
Rahul
5c5979a3ec Update to MarketCap 2020-01-13 17:50:43 -08:00
Rahul
31f4e60c63 Merge pull request #1 from QuantConnect/master
Update Fork
2020-01-13 17:47:12 -08:00
Jared
63847a3dc2 Merge pull request #3991 from QuantConnect/bug-3989-universe-subscription-start-end-date
AddUniverse will be deferred to EndOfTimeStep
2020-01-09 15:41:55 -08:00
Martin Molinero
b4b2f90303 AddUniverse will be deferred to EndOfTimeStep
- `AddUniverse` call will add new Universe to the pending collection which
will be consumed at the `OnEndOfTimeStep` where it will be added to the
data feed, same as we do for the `UserDefinedUniverses`. This is
required since the start and end date, during initialize, is consumed by
these universe subscriptions.
-Adding unit test.
2020-01-09 20:39:00 -03:00
Martin-Molinero
6fbe92c341 Merge pull request #3977 from QuantConnect/performance-3976-new-work-scheduling
New data feed work scheduling system
2020-01-09 13:38:38 -03:00
Martin Molinero
b464414597 Address reviews. Pop from end of List
- Will sort the List is reverse order and remove items from the end.
- Add newWorkEvent so that workers are monitoring for new work while sleeping
- Add WorkAvailableEvent for each work queue so that workers can sleep
longer or until the sorting thread notifies them.
2020-01-09 10:09:07 -03:00
Jared
ecfece0ead Merge pull request #3980 from QuantConnect/bug-3964-zerodiv-in-selection
Refactors QC500 Universe and Universe Selection Model
2020-01-08 16:19:49 -08:00
AlexCatarino
898a5c2324 Addresses Peer-Review 2020-01-08 22:21:15 +00:00
Martin Molinero
0d35ca8fb9 New data feed work scheduling system
- The new scheduler will create a dedicated thread pool
- Work will be prioritized based on their weight and new items will have
highest priority. The weight will be determined by the size of the
subscription enqueueable.
- The work queue will be sorted and the weights updated by a dedicated
thread
- There will be a maximum weight value that will 'disable' a work item
until their weight comes down
- Consumer will not know about workers or anything alike anymore.
- Applying a general max work queue size of 400 items, this will reduce
CPU and RAM usage. Can be set by config.
2020-01-07 15:21:47 -03:00
AlexCatarino
f205a7e8cd Refactors QC500 Universe and Universe Selection Model
The class field that tracks the current month is updated only if there are securities that passed the selection criteria. It prevents division by zero and allows the universe selection a new attempt on the next trading day while keeps the universe unchanged
2020-01-07 09:24:58 +00:00
Frank Norman
721e8c2c13 Added a check for zero denominator. 2020-01-07 08:45:17 +00:00
Jared
14d0b47fd2 Merge pull request #3970 from AlexCatarino/feature-3969-adds-marketcap
Adds MarketCap Member to FineFundamental Class
2020-01-06 18:03:16 -08:00
Jared
936a0c9c17 Merge pull request #3974 from QuantConnect/feature-3081-alpaca-brokerage-model-improve-messaging
Improve AlpacaBrokerageModel error messages
2020-01-06 18:02:30 -08:00
AlexCatarino
dc2cac9d8c Adds Unit Tests for Market Cap Calculations 2020-01-06 23:05:39 +00:00
Stefano Raggi
af7868b0dd Improve AlpacaBrokerageModel error messages 2020-01-06 22:14:54 +01:00
AlexCatarino
87b7f229c3 Use FineFundamental.Value for Market Cap Calculations
Uses `MarketCap = Value * EarningReports.BasicAverageShares.ThreeMonths`. Since the previous calculations as using `BasicEPS` that can be negative, market cap got negative values which is not realistic.

Moves `MarketCap` code from the generated file to  another one that shares the partial class.
2020-01-06 18:52:53 +00:00
Jared
0300ca7b8b Merge pull request #3973 from QuantConnect/bug-3081-alpaca-brokerage-model-fix
Fix bug in AlpacaBrokerageModel.CanSubmitOrder
2020-01-06 08:50:25 -08:00
Stefano Raggi
18920a6eee Fix bug in AlpacaBrokerageModel.CanSubmitOrder
- The AlpacaBrokerageModel requires a call to GetOpenOrders() to determine if a new order can be submitted and was not taking the current order into account (which is added to the open orders before CanSubmitOrder() is called).
2020-01-06 16:23:49 +01:00
Jared
c7fe769411 Merge pull request #3971 from Martin-Molinero/performance-gc-server-garbage-collection
Enable GCServer garbage collection
2020-01-04 21:23:55 -08:00
AlexCatarino
9fa415a454 Adds Null Check for MarketCap Calculation
Returns zero if any of the members are null.
2020-01-04 02:39:28 +00:00
Martin Molinero
a6de8e8f73 Enable GCServer garbage collection
- Enable Server garbage collection, which is intended for
server applications that need high throughput and scalability.
2020-01-03 21:55:18 -03:00
AlexCatarino
76c70f1ea2 Adds MarketCap Member to FineFundamental Class
Adds `MarketCap` member to `FineFundamental` class that represents the aggregate market value of a company represented in dollar amount.

Changes `CoarseFineFundamentalRegressionAlgorithm` (C# and Python) to select securities based in its market capitalization. Same result as selecting by P/E ratio.
2020-01-04 00:33:29 +00:00
Jared
c620a4cdfc Merge pull request #3966 from QuantConnect/bug-3949-startdatelimited-history-warning
Limit history StartDateLimited logging
2020-01-03 13:42:51 -08:00
Jared
f0116bb698 Update Engine.cs 2020-01-03 13:42:28 -08:00
Martin Molinero
87747b1cc8 Limit history StartDateLimited loggging
- `StartDateLimited` event will only be logged once for history requests
2020-01-02 21:23:33 -03:00
Jared
571fa49127 Merge pull request #3960 from QuantConnect/bug-3951-reduce-logging
Reduce logging in InteractiveBrokersBrokerage.IsWithinScheduledServerResetTimes
2020-01-02 13:59:05 -08:00
Jared
aa2f875045 Merge pull request #3962 from QuantConnect/bug-3961-remove-ltrh-unnecessary-call-touniversaltime
Remove ToUniversalTime - Fix LocalObjectStore limit
2020-01-02 13:57:17 -08:00
Martin Molinero
24a3c24f55 Remove ToUniversalTime. Fix LocalObjectStore limit
- Removing unnecessary call to `ToUniversalTime()` in the LTRH
- Fix bug in the `LocalObjectStore` limit check. Adding unit test
2020-01-02 15:33:41 -03:00
Jared
891eee6018 Merge pull request #3958 from gsalaz98/bug-improve-report-creator
Fixes various issues with Report Creator
2020-01-02 07:45:11 -08:00
Jared
f3da104493 Merge pull request #3941 from QuantConnect/bug-cloud-565-live-trading-log-store
Fix live trading missing logs
2020-01-02 07:36:13 -08:00
Jared
3c2aee89ea Merge pull request #3957 from gsalaz98/bug-orderjsonconverter-null-lastupdatetime
Adds null checks for OrderJsonConverter LastFillTime and LastUpdateTime
2020-01-02 05:27:33 -08:00
Martin Molinero
514c093689 EntryLog: Avoid Utc time conversion 2020-01-01 18:51:18 -03:00
Gerardo Salazar
5d663e8944 Fixes various issues
* Fixes issue with how cumulative percent change was calculated
* Reworks PercentChange extension method
* Fixes PortfolioLooper leverage calculation
* Disable page 2 of reports
* Fix issue where missing values produced misaligned shape in
AnnualReturnsReportElement.cs
2019-12-31 17:37:19 -08:00
Gerardo Salazar
a6ea225eeb Add test cases for null LastUpdateTime and LastFillTime MOO 2019-12-31 16:45:08 -08:00
Gerardo Salazar
afb4cb5df0 Add null checks for OrderJsonConverter LastFillTime and LastUpdateTime 2019-12-31 15:39:39 -08:00
Jared
949cf9e46e Merge pull request #3956 from QuantConnect/feature-1040-object-store-wrapper
Convert ObjectStore ext class to implement IObjectStore for API
2019-12-31 15:02:53 -08:00
Martin Molinero
100fa99ec5 Address reviews
- Reduce code duplication between live and backtesting
- `LiveTradingResultHandler` will store logs progressively, appending to
the file
- `BacktestingResultHandler` stores logs at end
2019-12-31 19:25:48 -03:00
Michael Handschuh
39935552a3 Convert ObjectStore ext class to implement IObjectStore for API
Since extension methods don't play well with pythonnet, this change converts
the extensions class into a decorator class. Additionally, this ObjectStore
type is the type that gets exposed via QCAlgorithm so users can access these
methods directly without requiring the use of extension methods.

This approach has many good properties. For one, it doesn't force implementors
of IObjectStore to use a base class. Second, it maintains healthy separation of
API level concerns (such as convenient methods) from the  abstraction level conerns
of IObjectStore. Setting it up in this way ensures ANY implementation of IObjectStore
will still get access to these additional methods. Another thing to note is this
prevents using a base class on QCAlgorithm's public interface. Instead, we have a
specific type that is dedicated to fulfilling API level requirements, which also
provides us flexibility in the event the API needs to be updated. If it were a subclass,
you run the risk of breaking the implementors of the subclass.
2019-12-31 15:55:16 -05:00
Jared
7d9c67364b Merge pull request #3954 from gsalaz98/bug-3953-lastfilltime-truncated
Fix LastFillTime being truncated
2019-12-31 12:22:44 -08:00
Gerardo Salazar
01d9da03f7 Expand filter to include fill time of orders in Truncate method
* Add LastFillTime in OrderJsonConverter
2020-01-02 11:54:15 -08:00
Stefano Raggi
2fbff97517 Reduce logging in InteractiveBrokersBrokerage.IsWithinScheduledServerResetTimes
Only log when the return value changes
2019-12-31 19:49:42 +01:00
Jared
a3954482ee Merge pull request #3898 from prasadsom/feature-3895-Add-optional-initial-cash-to-BacktestNodePacket
Added initial CashAmount property to BacktestNodePacket
2019-12-31 09:53:22 -08:00
Jared
1d9973b3c9 Merge pull request #3946 from QuantConnect/feature-3081-alpaca-margin-trading-2
Alpaca Brokerage - Enable Margin Trading + bug fixes
2019-12-31 09:36:13 -08:00
Martin Molinero
5731a804aa Fix live trading missing logs bug
- In some cases we could drop valid logs due to using RoundDown
2019-12-31 13:30:09 -03:00
Martin Molinero
87bc03d71e Address reviews
- When BacktestNodePacket has the inital `CashAmount` set we will clear
all existing cash amounts and set the account currency
- Adding more unit tests
2019-12-31 13:25:58 -03:00
Prasad Somwanshi
a1a2c494cb Modifed code for failing unit test 2019-12-31 13:13:05 -03:00
Prasad Somwanshi
9649da3ee6 Added optional property to BacktestNodePacket 2019-12-31 13:13:05 -03:00
Stefano Raggi
a803827a7f Address review
- In GetBrokerageModel pass IOrderProvider instead of IAlgorithm
2019-12-31 12:42:21 +01:00
Jared
52562b89e3 Merge pull request #3942 from QuantConnect/update-fxcm-mhdb
Update FXCM and Oanda holidays early closes and late opens
2019-12-30 14:02:07 -08:00
Stefano Raggi
da010ffe1d Update Forex market hours for Oanda/FXCM until 2025 2019-12-30 22:43:15 +01:00
Stefano Raggi
5a71ba16d9 Add order validation in AlpacaBrokerageModel 2019-12-27 20:34:09 +01:00
Stefano Raggi
3d568f2da0 Enable Alpaca margin trading 2019-12-27 11:57:13 +01:00
Stefano Raggi
4d61f38614 Update Alpaca unit tests to include shorting 2019-12-27 11:50:32 +01:00
Stefano Raggi
25ad7efa48 Update Alpaca unit tests to not use GetRates
- GetRates can only be used with a funded account
2019-12-27 11:43:58 +01:00
Stefano Raggi
59b65197f5 Fix Alpaca error message deserialization
Some JSON error messages could not be deserialized because they do not contain the "code" property.
2019-12-27 11:43:23 +01:00
Stefano Raggi
8b792fbffb Fix sign bug in ConvertHolding 2019-12-27 11:43:02 +01:00
D
d392c65e60 Update FXCM holidays early close and late open. 2019-12-24 20:12:09 +00:00
Jared
fc6e1fb517 Merge pull request #3932 from QuantConnect/feature-lean-report-mkii
Report Creator
2019-12-23 14:56:34 -08:00
Jared
6f4223cafd Merge pull request #3928 from QuantConnect/bug-3870-ltdf-options-futures-refresh-fix
Fix LiveTradingDataFeed stack for future/option chain universe
2019-12-23 14:55:30 -08:00
Gerardo Salazar
1c4935fc60 Address review - increase performance and refactor
* Deletes NullAlphaHandler, NullLeanManager, NullSynchronizer
* Calculate the backtest and live PointInTimePortfolios only once now
* Refactor Metrics calculations
* Add missing license headers to some files
* Reverts accessibility of AddToUserDefinedAlgorithm to private
* Other misc. fixes and cleanup
2019-12-23 14:13:28 -08:00
Stefano Raggi
33bb10e03a Prevent IB LookupSymbols from being called when disconnected 2019-12-23 22:52:08 +01:00
Jared
978f44a913 Merge pull request #3939 from QuantConnect/bug-3938-alpaca-paper-auth-violation
Fix Alpaca "Authorization Violation" error when using external data feed
2019-12-20 15:24:49 -08:00
Jeffrey Ward
a296d346a4 Pull request fixes. 2019-12-20 18:01:35 -05:00
Jeffrey Ward
a796f30458 Added AccumulativeInsightPortfolioConstructionModel. 2019-12-20 18:01:35 -05:00
Stefano Raggi
a4979de1b6 Fix Alpaca "Authorization Violation" error when using external data feed 2019-12-20 22:39:48 +01:00
Jared
ca0dde5cf5 Merge pull request #3934 from QuantConnect/performance-3925-end-of-day-scheduled-event
Lazy OnEndOfDay ScheduledEvent
2019-12-20 13:08:07 -08:00
Martin Molinero
145a5f43f3 Fix for OptionChainUniverse
- Fix for `DataQueueOptionChainUniverseDataColletionEnumerator`. Last
emit time should rely on the actual last option chain symbol lookup not
on the underlying end time.
- Adjust test so that they fail in `master`
2019-12-20 12:05:01 +01:00
Stefano Raggi
c019b09783 Unit test update 2019-12-20 12:05:01 +01:00
Stefano Raggi
bc0448bbb2 Fix LiveTradingDataFeed stack for future/option chain universe 2019-12-20 12:05:01 +01:00
Martin Molinero
3a5a2c582f Lazy OnEndOfDay ScheduledEvent
- Only add OnEndOfDay ScheduledEvent if the algorithm implements the
method. Adding unit tests
- Avoid creating a new baseData instance at
`SubscriptionDataSourceReader`
- Adding static `FineFundamental` instance since creating new ones is
expensive
2019-12-19 19:07:16 -03:00
Gerardo Salazar
53653fe6ed Address review - Revert version changes to sln file
* Fixes comments on a few report elements
* Fixes wrong name of a report element "psr kpi" -> "ir kpi"
2019-12-19 11:14:24 -08:00
Gerardo Salazar
e7ce60e700 Fix failing tests
* Move config.json to config.example.json to fix tests
2019-12-19 10:11:47 -08:00
Jared
1926dcca87 Merge pull request #3930 from QuantConnect/bug-stack-overflow-exception
Fix Truncate stackoverflow
2019-12-19 08:12:41 -08:00
Martin Molinero
6ae4579c2c Fix Truncate stackoverflow
- Fix TruncateTo3DecimalPlaces() stack overflow
- Adding unit test
2019-12-19 12:41:11 -03:00
Jared
32b7a0cce7 Merge pull request #3911 from QuantConnect/feature-1040-object-store
Add IObjectStore/LocalObjectStore/QCAlgorithm.ObjectStore
2019-12-19 07:06:01 -08:00
Gerardo Salazar
e2c75fa5fa Address review - delete python report creator
* Move PortfolioLooper classes to their own files
* Remove VisualStudioPlugin project
* Add SharedAssemblyInfo
* Add new crisis events
2019-12-18 18:02:04 -08:00
Gerardo Salazar
eb6e13d91f Fixes many issues and refactors some of the report creator
* Can handle null Result packets
* Created utility files
* Added various helper methods to PortfolioLooper
* Fixes build issue by removing System.Collections.Immutable
* Updates plots to show "Insufficient data" when it can't be created
* Hides empty crisis page
* Fixes wkhtmltopdf display bug
* Removes Calculations.cs
* Modifies accessibility of AddToUserDefinedUniverse in QCAlgorithm
* Add null value handling in OrderJsonConverter
* Various bug fixes
* Fixes broken ReportChartTests.py
* Adds leverage to PointInTimePortfolio
2019-12-18 16:10:56 -08:00
Gerardo Salazar
98680be625 Revert PSR report to use backtest result PSR statistic instead 2019-12-18 16:08:41 -08:00
Gerardo Salazar
d3528c2ea2 Polish asset allocation and exposure charts 2019-12-18 16:08:41 -08:00
Gerardo Salazar
55d802a3b6 Implements support for FX pairs that require currency conversion
* Fixes bugs in various plots
2019-12-18 16:08:40 -08:00
Gerardo Salazar
9a2f20493a Finish implementing all graphs, fix bugs in various graphs
* Adds Asset allocation chart
* Fixes issue in monthly returns
* Fixes issue with matplotlib tick lines not being consistent
* Style plots correctly
2019-12-18 16:08:40 -08:00
Gerardo Salazar
a94077f05a Implements exposure chart.
* Fixes bugs with the following plots:
  - Leverage
  - Drawdown
2019-12-18 16:08:40 -08:00
Gerardo Salazar
ef3a688da5 Implements leverage chart 2019-12-18 16:08:40 -08:00
Gerardo Salazar
62714aabf6 Add license to source code files files missing it under Reports project 2019-12-18 16:08:40 -08:00
Gerardo Salazar
7cc4dec6b7 Reworks structure of project
We now will calculate all of the metrics needed to directly plot the
data in C# instead of doing calculations in Python.

This has added benefits in that the code can be easily reused to generate
plots from Result packets and makes the underlying plotting library we
use more extensible and replaceable.

* Adds Calculations.cs
* Refactors some of ReportCharts.py
* Adds Drawdown classes
* Adds Deedle and MathNet.Numerics packages
* Completes calcuations in C# side instead of Python

Side note: I think it's a little funny that we were previously
calculating the plots via Pandas, which uses a C backend. Effectively, we
were transferring data between at least 2 separate FFI
boundaries: C# -> Py -> C -> ? (whatever BLAS is written in)
2019-12-18 16:08:40 -08:00
Gerardo Salazar
e156b6d5ab Implement Rolling Sharpe ratio plot 2019-12-18 16:08:40 -08:00
Gerardo Salazar
3e81cdd07b Implement Rolling Beta (6 month and 12 month) chart 2019-12-18 16:08:40 -08:00
Gerardo Salazar
82429318d8 Implements Daily Returns chart and some styling fixes 2019-12-18 16:08:40 -08:00
Gerardo Salazar
fa54cd9652 Implements Drawdown chart w/ drawdown periods 2019-12-18 16:08:40 -08:00
Gerardo Salazar
a8574d437a Implements Returns Per Trade chart
* Fixes typo in function name in ReportCharts.py
2019-12-18 16:08:40 -08:00
Gerardo Salazar
261f07adef Implement Annual Returns plot section 2019-12-18 16:08:40 -08:00
Gerardo Salazar
d7c7082543 Fixes bug preventing successful execution of the program
* Restyles and reworks some of the cumulative percentage gain graph
2019-12-18 16:08:40 -08:00
Jared Broad
f66a682f63 Debug commit 2019-12-18 16:08:40 -08:00
Jared
683250ffd3 Flip order of raising event and log to ensure log.
Prevent exception in error handler dropping the log.
2019-12-18 09:55:17 -08:00
Jared
d3bcfd5867 Merge pull request #3923 from QuantConnect/bug-3922-warmup-tick-internal-currencies
AlgorithmManager exception fix
2019-12-18 09:50:59 -08:00
Martin Molinero
acb28a6320 Address reviews
- Replace try/catch statement for a smarter precheck
2019-12-18 11:02:36 -03:00
Michael Handschuh
d6f1dd8630 Add ObjectStoreExampleAlgorithm
Shows how to read/save object store entires. In this case, it shows a
use case where a potentially time intensive operation's result is saved
in the object store and on subsequent runs the result is pulled directly
from the object store to enable faster run times
2019-12-18 08:46:14 -05:00
Michael Handschuh
5bda58dfd1 Initialize LocalObjectStore
Seed the LocalObjectStore with files read from the local disk on Initialize
2019-12-18 08:42:04 -05:00
Michael Handschuh
156d3a7d09 Notify user via debug message of object store persistence errors 2019-12-17 23:03:08 -05:00
Michael Handschuh
999cc275b6 Add IObjectStore.ErrorRaised for persistence errors
Errors raised during persistence aren't able to be handled by user code,
and in fact, are swallowed by the implementation after being logged. By
exposing these errors as events we allow the algorithm to be notified of
such an error and take any step necessary to handle the persistence error.
2019-12-17 22:58:27 -05:00
Michael Handschuh
3de807fd05 Move LocalObjectStore to Lean.Engine
There's no reason for algorithms to have direct access to this implementation.
Moving this into the engine prevents algoriths from directly accessing LocalObjectStore
and instead can only reference it through the IObjectStore abstraction
2019-12-17 22:21:11 -05:00
Michael Handschuh
a2b2f889ea Convert object store to in-memory w/ persistence interval
persistenceIntervalSeconds defines the number of seconds between
each save operation. For the local object store, this dictates
how often the contents of the object store is packaged and written
to disk. The PersistData virtual method is provided for subclasses
to provide a different implementation of how/where to persist the
data. The change to be in-memory aims at keeping the object store
performant with reasonable persistence guarantees.
2019-12-17 22:21:11 -05:00
Michael Handschuh
6e9fa0a45c Prevent throwing on missing key, fix storage limit but
Invoking FileInfo.Length when the file does not exist on disk throws an
error. Additionally, it was clunky to use the object store when always
required to perform ContainsKey first.
2019-12-17 22:21:11 -05:00
Michael Handschuh
898e885e00 Implement storage limits via Controls
The job packet is now able to specify a maximum file count as well
as a maximum storage size limit. These controls are enforced in the
LocalObjectStorage implementation.
2019-12-17 22:21:11 -05:00
Stefano Raggi
d407307566 Add IObjectStore interface with LocalObjectStore implementation
This commit is squashed from iterative development:

- More consistent method naming
- Storage root path updated to be absolute and include algorithm name
- Storage root path created only if object store is actually used
- Implemented XML save/load
- Added missing unit tests
- Replaced Log.Trace with Log.Error calls
- Added the object store name logging in Engine.Main
- Read storage root from config
- Create algorithm storage root folder in Initialize
- Remove empty folder in Dispose
- Added null checks in all methods
- Added missing XML parameter docs
- make Initialize and Dispose virtual
- make AlgorithmStorageRoot protected

The IObjectStore abstraction provides algorithms with a persistent
storage mechanism. While the algorithm is running, data is maintained
in memory as a dictionary of raw bytes (string -> byte[]). This ensures
we avoid any reference type shenanigans. Periodically, the data in the
object store is persisted and additionally, when the algorithm shuts
down, the object store's data will again be persisted. This ensures that
when the algorithm starts up again, it will have access to any state
that has been saved into the object store.

A great use case for IObjectStore is saving a compute heavy model.
For example, computing the weights of a deep neural network is very
CPU intensive, but after the weights are computed, evaluation is fairly
quick. An initial backtest can be used to solved for the network's weights
and then subsequent backtests or even in live mode, the weights will be
available to the algorithm provided they were saved into the object store.

Also, some libraries require a file path to load model data. The object
store provides a `GetFilePath(key)` method which will copy the data for
the provided key to the disk and return that path so the library can load
the model data.
2019-12-17 22:21:11 -05:00
Martin Molinero
b036c48805 Adding try catch for Truncate()
- Adding 'try/catch' statement to `TruncateTo3DecimalPlaces()`, that in
some cases throws exceptions.
2019-12-16 18:32:21 -03:00
Martin Molinero
6da8eb7c66 AlgorithmManager exception fix
- `AlgorithmManager` will search for `SubscriptionDataConfigs` using the
`SubcriptionDataConfigService` versus directly checking active `Subscriptions`.
In the case of warmup, subscription have not been added yet. Also will
include internal subscriptions.
- Adding unit tests
2019-12-16 18:20:57 -03:00
Martin-Molinero
8af7297578 Merge pull request #3916 from StefanoRaggi/build-xml-documentation-release
Add XML documentation generation for release builds
2019-12-16 11:05:27 -03:00
Martin-Molinero
ca5e8a4291 Merge pull request #3917 from RohanTalip/RT/minor-comment-fixes-OBA
Minor typo fixes to comments in OpeningBreakoutAlgorithm.
2019-12-16 10:57:57 -03:00
Martin-Molinero
bed462df02 Merge pull request #3918 from RohanTalip/RT/minor-typo-fixes-RCT
Corrected a typo in a test method name in RenkoConsolidatorTests.
2019-12-16 10:56:43 -03:00
Martin-Molinero
2975f26d63 Merge pull request #3919 from RohanTalip/RT/minor-comment-fixes-MSCA
Minor fixes to comments in MultipleSymbolConsolidationAlgorithm.
2019-12-16 10:56:15 -03:00
Rohan Talip
39dd5ea391 Corrected a typo in a test method name in RenkoConsolidatorTests. 2019-12-14 17:12:20 -08:00
Rohan Talip
6307fb142a Minor fixes to comments in MultipleSymbolConsolidationAlgorithm. 2019-12-14 17:12:08 -08:00
Rohan Talip
f421270f39 Minor typo fixes to comments in OpeningBreakoutAlgorithm. 2019-12-14 17:11:33 -08:00
Stefano Raggi
e0a08cbb8d Add XML documentation generation for release builds 2019-12-14 13:50:10 +01:00
Jared
6313c64608 Merge pull request #3903 from AlexCatarino/bug-3896-python-api
Refactors Python Version of the API
2019-12-13 15:59:56 -08:00
Jared
4c8e0eb75b Merge pull request #3906 from QuantConnect/bug-3905-FactorFile.Apply-method-removes-the-factor-file-first-row
Bug 3905 factor file.apply method removes the factor file first row
2019-12-13 15:59:10 -08:00
Jared
86f32e7a26 Merge pull request #3915 from QuantConnect/bug-3877-processsplitsymbols-exception
Fix ProcessSplitSymbols exception
2019-12-13 15:57:39 -08:00
Jared
c356562181 Merge pull request #3913 from QuantConnect/bug-3912-subscription-data-reader-data-point-skip
SubscriptionDataReader wont emit beyond tradable date
2019-12-13 15:56:05 -08:00
Martin Molinero
a06b99c90e Address review
- Renaming `ResolveDataEnumerator` to `UpdateDataEnumerator`, will
update the data enumerator being used internally and return true when
updated
2019-12-13 18:53:02 -03:00
Juan José D'Ambrosio
bbd4fb0e92 Correct implementation of the first row issue
in the previous solution, I basically tried to pass the first row as a split of 1.

That's is not a correct solution, the correct one is treat the first row as a different  _kind_ of row. In fact, the the main usage of the first row is a date reference for the factors defined in the second row
2019-12-12 20:50:51 +00:00
Martin Molinero
491cae2c1d Fix ProcessSplitSymbols exception
- `UserDefinedUniverse` will no longer be removed as a data subscription.
- When `algorithm.AddData()` is called a universe selection data point
will be added to the `UserDefinedUniverse` subscription to trigger
selection and add the requested data.
- `DataManager` will make sure an active subscriptions
`SubscriptionDataConfig` will be present in the configuration collection
- Adding unit and regression tests
2019-12-12 17:14:47 -03:00
Martin-Molinero
2a4fdc6243 Merge pull request #3910 from QuantConnect/bug-3909-api-connection-null-ref-and-get-bytes-encoding
Fix Api connection null ref and UnzipData encoding
2019-12-12 12:32:41 -03:00
Martin Molinero
813d114b7a Empty commit 2019-12-12 12:23:09 -03:00
Juan José D'Ambrosio
653e279d5a Address reviews 2019-12-12 12:33:56 +00:00
Juan José D'Ambrosio
4d0009df86 Address review 2019-12-12 12:09:42 +00:00
AlexCatarino
5ce7abce66 Adds Unit Tests for Compite and Backtest Requests
If any request returns `{'success': False}` or throws an exception, `Api.Execute` will not exit the execution, will log and return the result. This change will enable re-try logic.
2019-12-12 01:31:03 +00:00
Martin Molinero
8172d1c22e SubscriptionDataReader wont emit beyond tradable date
- `SubscriptionDataReader` will not emit data point which are beyond the
current tradable date if the data source has changed.
- Adding unit test
2019-12-11 22:17:13 -03:00
Martin-Molinero
6f9921cd29 Merge pull request #3908 from QuantConnect/feature-3907-dispose-entries-on-removal
NotifiedSecurityChanges: Dispose entries on removal
2019-12-11 16:13:31 -03:00
Martin-Molinero
3667d5a7bf Add missing license banner 2019-12-11 15:17:52 -03:00
AlexCatarino
fe64fada3d Refactors Python Version of the API
- Refactor to simplify `quantconnect.api.Api` class. Adds `Execute` method that accepts a bolean to distinguish a `POST` from a `GET` request.

In the previous version, some methods were using the `params` argument instead of `data` in the `POST` case which threw an exception for big json objects.

- Adds option to save logs and backtest report to disk.
- Adds `Result` class to optionally convert the json objects into `pandas.DataFrame` when getting backtest or live results

- Subversion bump
2019-12-11 16:10:12 +00:00
Jared
eb5993e3eb Merge pull request #3900 from gsalaz98/bug-3899-estimize-consensus-reader-throws
Fixes failing EstimizeConsensus parsing in Reader
2019-12-11 07:53:02 -08:00
Juan José D'Ambrosio
3227ee982a Fix handling of inf and exponential notation in factor files
Previously, if there is an `inf` or exponential notation in a factor file row, the FactorFile.Row method will add a new line with a date equal to the original row date less one day. This is a bug because the dates in factor files row should always be a trading day, the previous logic didn't assure that.

Even more, that new line is useless, without that line addition, the parser still parses the latest row with valid factors and use it as the first row.

This commit removes the addition of a new line. Also, updates the test cases, now the FactorFile minimum date will be the latest row without inf or exponential notation less one day.
2019-12-11 15:29:21 +00:00
Michael Handschuh
9d5ee05826 Support encoding in Compression.UnzipData 2019-12-10 19:20:26 -05:00
Michael Handschuh
bc1629a0fe Prevent null ref and log unsuccessful api responses 2019-12-10 19:09:00 -05:00
Michael Handschuh
1b509f9644 Call dispose on IDisposable entries when removed
This helper is a favorite of mine to use in models to handle OnSecuritiesChanged
event to maintain internal state in light of additions/removals. Sometimes, the
internal state objects implement IDisposable, and without this code, they would
never be disposed. A good usage of IDisposable here would be to remove any items
that are only used by that single security related internal state such as a consolidator
2019-12-10 18:54:39 -05:00
Michael Handschuh
dd9829b646 Dispose removed entries
These entries are often SymbolData classes that may implement dispose
as a means of cleaning up consolidators/indicators/etc
2019-12-10 18:45:11 -05:00
Juan José D'Ambrosio
94c957b3c9 Add support for QQ exponential notation in factor files 2019-12-10 15:39:23 +00:00
Juan José D'Ambrosio
8f756d00f6 FactorFile.Apply ,method can handle duplicated events. 2019-12-10 14:54:37 +00:00
Juan José D'Ambrosio
ff92f846b8 Fixes FactorFile.Apply method
previously, after applying an event, the first row was missing in the returned FactorFile object.
2019-12-10 14:54:37 +00:00
Jared
053dbd5cf9 Merge pull request #3902 from Martin-Molinero/improve-null-job-exception-error-message
Improve null job exception message
2019-12-09 14:39:51 -08:00
Jared
9e56815854 Merge pull request #3901 from QuantConnect/revert-3858-assembly-loading-logs
Revert "Add assembly loading logs"
2019-12-09 14:38:49 -08:00
Martin Molinero
2229f1fab9 Improve null job exception message 2019-12-09 19:17:23 -03:00
Martin-Molinero
60ce6cf437 Revert "Add assembly loading logs" 2019-12-09 17:21:44 -03:00
Gerardo Salazar
55b8447012 Fixes failing EstimizeConsensus parsing in Reader 2019-12-09 11:17:29 -08:00
Martin-Molinero
dc59d9c5ed Merge pull request #3874 from QuantConnect/bug-3870-ib-options-futures-chain-refresh-fix
Fix IB Options/Futures chains daily refresh
2019-12-05 21:16:23 -03:00
Stefano Raggi
28e024ac98 Added extra asserts to HandlesFutureAndOptionChainUniverse unit test 2019-12-06 00:20:51 +01:00
Stefano Raggi
4c92bb4563 HandlesFutureAndOptionChainUniverse unit test updated
- Minor bug fixes
- Restored the CanAdvanceTime filter
- Reduced test run time to a few seconds
2019-12-05 17:39:13 +01:00
Stefano Raggi
82b640e05a Fix time zone bug in FuturesChainUniverse and OptionChainUniverse
- date change detection was done in UTC time zone instead of exchange time zone
2019-12-05 17:34:33 +01:00
Stefano Raggi
cbdc423244 Fix logic bug in DataManager.SubscriptionManagerGetOrAdd 2019-12-05 17:32:54 +01:00
Stefano Raggi
4feb14abb7 Update HandlesFutureAndOptionChainUniverse 2019-12-05 14:31:59 +01:00
Jared
5234cda07d Merge pull request #3892 from AlexCatarino/bug-3891-consolidator-timedelta
Fix Consolidators Python timedelta
2019-12-04 11:41:27 -08:00
AlexCatarino
f615a14155 Fix Consolidators Python timedelta
In `PeriodCountConsolidatorBase`, differentiate the type of the `PyObject` and create an `IPeriodSpecification` accordingly. If the `PyObject` is a C# `Func<DateTime, CalendarInfo>` or a convertable Python method, we create a `FuncPeriodSpecification` with it as a parameter. If the `PyObject` is a `datetime.timedelta`, we create a `TimeSpanPeriodSpecification` with it as a parameter after a conversion to `TimeSpan`.

- Adds example in `DataConsolidationAlgorithm`
- Adds unit test for `timedelta` overload.
2019-12-04 17:59:31 +00:00
Jared
1c4e9379bc Merge pull request #3816 from QuantConnect/feature-3780-consolidator-pyobject
Adds Constructor Overload to PeriodCountConsolidatorBase that Accepts PyObject
2019-12-03 13:44:38 -08:00
Stefano Raggi
12166219d7 Add new LiveTradingDataFeedTests for future/option chains 2019-12-03 00:37:14 +01:00
Jared
683aba4327 Merge pull request #3884 from AlexCatarino/bug-alpha-examples-universe-unchanged
Use Universe.Unchanged in Alpha Example Algorithms
2019-12-02 13:07:05 -08:00
Jared
b305b40c49 Merge pull request #3886 from QuantConnect/bug-3885-enqueueableenumerator-hangs
Fix EnqueueableEnumerator hang
2019-12-02 13:00:19 -08:00
Martin Molinero
95abd6bd3a Fix EnqueueableEnumerator hang
- Adding `CancellationTokenSource` to fix a race condition where the worker could stop
after the consumer had already checked on him, see TriggerProducer,
leaving the consumer waiting for ever GH issue 3885. This cancellation token
works as a flag for this particular case waking up the consumer.
- Adding unit tests
2019-12-02 16:50:20 -03:00
Stefano Raggi
e0ef992033 Post-review updates
- Renamed CanLookupSymbols to CanAdvanceTime
- Updated options/futures chain universe PredicateTimeProvider to use IDataQueueUniverseProvider.CanAdvanceTime
2019-12-02 15:17:00 +01:00
Stefano Raggi
6babf59d04 Fix IB Options/Futures chains daily refresh 2019-12-02 15:17:00 +01:00
AlexCatarino
9e6e2f9b22 Use Universe.Unchanged in Alpha Example Algorithm
In the Coarse Universe Selection of the following algorithms
- ContingentClaimsAnalysisDefaultPredictionAlpha
- GreenblattMagicFormulaAlpha
- PriceGapMeanReversionAlpha
- SykesShortMicroCapAlpha
Universe.Unchanged is now used when the universe is not changed instead of saving a list of symbol and returning it.

Other minor refactoring.
2019-11-30 11:50:01 +00:00
Jared
b1b511347d Merge pull request #3883 from QuantConnect/bug-cloud-536-live-history-requests
Bug cloud 536 live history requests
2019-11-29 13:03:10 -08:00
Martin Molinero
010c6ab799 Address reviews
- Rename history provider parameters `LiveMode` to `ParallelHistoryRequestsEnabled`
- Reduce code duplication
2019-11-29 17:31:19 -03:00
Martin Molinero
9f87ee5391 Disable live parallel history request
- Some IDataCacheProviders are not compatible with parallel history requests,
so disabling for live trading.
2019-11-29 15:55:13 -03:00
Jared
ec4f714799 Merge pull request #3862 from gsalaz98/feature-3775-add-benzinga-custom-data
Implements Benzinga Custom Data
2019-11-27 15:39:22 -08:00
Jared
30d4b8532f Merge pull request #3880 from QuantConnect/bug-3879-subscription-worker-first-loop
Add First loop check
2019-11-27 15:07:25 -08:00
Martin-Molinero
301238af63 Address reviews 2019-11-27 20:00:30 -03:00
Martin Molinero
672b98a409 Add First loop check
- Subscription workers will stop after adding 50 data points in the
first loop. Note that if consumer needs more data points it will trigger
a new worker
2019-11-27 16:17:01 -03:00
Jared
69dac95d3a Merge pull request #3878 from RohanTalip/RT/minor-typo-and-grammar-fixes-PCCB
Minor typo and grammar fixes to comments in PeriodCountConsolidatorBase
2019-11-27 08:11:23 -08:00
Rohan Talip
315c87e24b Minor typo and grammar fixes to comments in PeriodCountConsolidatorBase 2019-11-26 19:19:56 -08:00
Jared
323b59e371 Merge pull request #3873 from RohanTalip/RT/feature-3872-consolidate-single-symbol
Ensure that PeriodCountConsolidatorBase classes only consolidate a single symbol
2019-11-26 15:34:27 -08:00
Jared
ca39929f4b Update PeriodCountConsolidatorBase.cs 2019-11-26 15:34:17 -08:00
Jared
3f4d617032 Merge pull request #3876 from prasadsom/feature-3868-Adds-OrderTicker-UpdateXXX-Methods
Added OrderTicket UpdateXXX methods
2019-11-26 15:24:09 -08:00
Gerardo Salazar
e1ae9807ab Address review - Disable live mode for BenzingaNews 2019-11-26 11:53:27 -08:00
Gerardo Salazar
4bd441bead Address review - Write indexes based on UpdatedAt time instead of
reference

* Code cleanup as per review
2019-11-26 10:51:32 -08:00
Rohan Talip
704e96f0cd Throw and test for an InvalidOperationException instead of a generic Exception. 2019-11-26 04:41:20 -08:00
Prasad Somwanshi
971a08fef6 Changes after code review comment 2019-11-26 11:32:49 +00:00
Gerardo Salazar
8319976133 Extends BenzingaNewsJsonConverter deserialization tests 2019-11-25 16:02:22 -08:00
Gerardo Salazar
9952544cb0 Fix failing test in Travis due to map file for example ticker not being present 2019-11-25 15:03:00 -08:00
Gerardo Salazar
8c16ffde8d Address review - Fixes bug where tags were not being deserialized
* Write files by `UpdatedAt` date instead of the `CreatedAt` date
* Added ability to append to compressed files if file does not exist
* Cleaned up code as per review
* misc. documentation changes
2019-11-25 14:32:45 -08:00
Prasad Somwanshi
faaa494e7a Added OrderTicket UpdateXXX methods 2019-11-25 18:36:39 +00:00
Jared
6e9c5495ff Update readme.md 2019-11-24 16:29:21 -08:00
Rohan Talip
dea85cd91d Ensure that consolidators derived from the PeriodCountConsolidatorBase class only consolidate for a single symbol. 2019-11-24 14:01:03 -08:00
Jared
79a2dc8c06 Merge pull request #3871 from Martin-Molinero/feature-3123-add-example-algorithms
Add Constituent basic template algorithm
2019-11-22 14:31:04 -08:00
Martin Molinero
d34a6f4a67 Add Constituent basic template algorithm 2019-11-22 11:39:03 -03:00
Jared
d719070b9d Merge pull request #3141 from QuantConnect/feature-3123-pre-selected-universes
Adding Constituents Universes
2019-11-21 16:43:08 -08:00
Jared
2d6ae03315 Merge pull request #3869 from QuantConnect/ib-brokerage-updates-2
IB brokerage updates
2019-11-21 11:34:29 -08:00
Martin Molinero
a3526fee84 Add ConstituentUniverseDefinitions 2019-11-21 12:28:51 -03:00
Stefano Raggi
2d9740ab15 Do not wait for timeout when error in GetContractDetails and FindContracts 2019-11-21 15:11:58 +01:00
Gerardo Salazar
a3c96059f7 Address review - Remove RSS converter and only parse API responses
* RSS converter now lives at: https://gist.github.com/gsalaz98/b87992cd5a5a214d01c63dbbefbbf12c
* Removed BenzingaNewsFactory as it is no longer needed
* Cleaned up code as per review to make this more maintainable
* Included new documentation
* Filter articles with no Symbols from being written
* General code improvements (duplication reduction, etc.)
2019-11-20 14:47:32 -08:00
Martin Molinero
394130e58a Revert qc500 constituent - Fix data order
- Reverting qc500 constituent universe
- Fix data parsing order, based on the constituent universe data already
generated
2019-11-20 19:47:19 -03:00
Martin Molinero
fca1b3db45 Revert previous changes. Add unit tests
- Only generate files for week days
2019-11-20 17:32:14 -03:00
Martin Molinero
c95955025f Adjust ConstituentsUniverseData dates for backtesting 2019-11-20 17:31:46 -03:00
Martin Molinero
b75569ab61 Address reviews
- Addressing reviews
- Rebasing
- Reducing unit test time length
2019-11-20 17:22:27 -03:00
Martin Molinero
70358482d4 Add ConstituentsUniverseDataGenerator algorithm
- Fix `ToString` implementation of the `SecurityIdentifier.None`. Adding
unit test
2019-11-20 17:22:27 -03:00
Martin Molinero
0789559402 Add live mode implementation
- Fix bug in live mode custom universe,
`BaseDataCollectionAggregatorEnumerator` returning false was causing the
subscription to be removed completely
- Adding unit test
2019-11-20 17:22:04 -03:00
Martin Molinero
81974b3fb3 Address reviews 2019-11-20 17:20:33 -03:00
Martin Molinero
e2c129a311 Improved version
- Renaming `PreSelected` to `Constituents`
- Adding base `ConstituentsUniverse`
- Adding Py and C# regression algorithm
- Fixing bug in `UniverseSelection`, it wasn't removing pending to be
removed securities unless the universe selection changed
- Adding test data
2019-11-20 17:16:44 -03:00
Martin Molinero
eee4c7cb79 Adding PreSelected data types
- Adding new custom data `PreSelected` type and `PreSelectedQC500` using
it.
- Adding 1 day worth of pre selected data for the QC500
2019-11-20 16:58:43 -03:00
Martin-Molinero
96da867109 Merge pull request #3833 from prasadsom/bug-3435-Factor-Files-unit-test-failing
Corrected unit test
2019-11-20 16:40:25 -03:00
Jared
c3aae4860c Merge pull request #3866 from QuantConnect/bug-3864-pandas-ix-iloc-symbol-access
Improve pandas Symbol key support
2019-11-20 10:42:33 -08:00
Jared
fd32d970c4 Merge pull request #3865 from QuantConnect/ib-history-requests-fix
Reduce frequency of timeouts in IB history requests
2019-11-20 08:51:59 -08:00
Martin Molinero
19edc94f0f Improve pandas Symbol key support
- Add support for Symbol key access for pandas ix and iloc results
- Wrapp pdf merge, join, concat method results
- Wrapp pandas.concat method result with `Remapper`
- Adding unit tests
2019-11-20 13:48:42 -03:00
Stefano Raggi
95d359f32c Reduce frequency of timeouts in IB history requests
- Added missing check on the requested tick type (reducing number of requests with futures and options)
- Updated the error handler to signal request completion for any error
2019-11-20 15:55:28 +01:00
Gerardo Salazar
37fd362c8b Add processedFilesDirectory argument
* Changed to read existing indexes from `processedFilesDirectory`
2019-11-19 17:27:52 -08:00
Martin-Molinero
3992ee6744 Merge pull request #3800 from QuantConnect/bug-3798-psychsignal-time-period-plus-delay
Adds EndTime to PsychSignalSentiment
2019-11-19 21:55:24 -03:00
Gerardo Salazar
51be6ac8a6 Fix Tiingo live trading data feed test 2019-11-19 16:09:22 -08:00
Prasad Somwanshi
6518d02b13 Update using old PR information 2019-11-19 23:02:58 +00:00
Prasad Somwanshi
9401329902 Revert "Corrected unit test"
This reverts commit 4d923ff168.
2019-11-19 22:57:28 +00:00
Gerardo Salazar
d79d720919 Address review - Makes FixedLiveOffset private readonly in PsychSignalSentiment
* Fix styling to follow project guidelines
2019-11-19 14:29:49 -08:00
Gerardo Salazar
791f75389f Fixes bug where time would be output as 15 seconds past the original EndTime
* Avoids boxing of time values (performance)

This fix addresses Martin's review and concerns that the EndTime would
be rounded down before being emitted. Local testing shows that EndTime
and _algorithm.Time are aligned when the data is included in the Slice
at HH:mm:15s.

Regarding the bug fix, previously when Clone was called, we would set
EndTime equal to EndTime, advancing the time by one minute and fifteen
seconds. This would make the time show up as HH:mm:30s and a minute into
the future.

Additional note: the only place where EndTime is being rounded down is in
AlgorithmManager in the method EndTimeIsNativeResolution which is only
used for Consolidators.
2019-11-19 14:29:49 -08:00
Gerardo Salazar
e440efd72d Address review - Increase FixedLiveOffset to 15 seconds
This is done to accurately model live trading. Because PsychSignal
takes approximately 10-15s to aggregate their data for the past minute,
we need to take into account the live delay. Otherwise, we'll have data
emitted before it was actually available.
2019-11-19 14:29:49 -08:00
Gerardo Salazar
0862e0e549 Fixes EndTime of PsychSignalSentiment
* Adds FixedLiveOffset property
* Implements `Period` property for calculating `Time` and `EndTime`
2019-11-19 14:29:49 -08:00
Gerardo Salazar
435735a738 Add support for tickers with share classes
* Documentation changes
2019-11-19 13:56:02 -08:00
Martin-Molinero
ad1b089ab6 Merge pull request #3860 from QuantConnect/bug-3859-mapfileresolver-date-check
Add FirsDate check at ResolveMapFile
2019-11-19 17:09:29 -03:00
Jared
1d9d30c655 Merge pull request #3857 from QuantConnect/performance-3850-format-stream-reader
Add StreamReader BaseData.Reader
2019-11-19 11:47:02 -08:00
Martin Molinero
b56af03c64 Address reviews: more tests 2019-11-19 16:38:46 -03:00
Jared
1dbcb626cb Merge pull request #3858 from QuantConnect/assembly-loading-logs
Add assembly loading logs
2019-11-19 11:33:03 -08:00
Gerardo Salazar
e4789e0b23 Implement Benzinga News Downloader
* Make Benzinga News Converter more efficient (and cleaner!)
* Implement JSON converter for serialization/deserialization process
* Fix bug where duplicate symbols would be added to news.Symbols
* Modify algorithm strategies
2019-11-19 10:28:48 -08:00
Gerardo Salazar
e6a9a3a4d1 Address review Mike's review and Fix timezone issues in BenzingaNews
* Cleaned up code inside BenzingaDataConverter
* Added more documentation to potentially confusing bits around the code

Previously, we would be storing Benzinga time in local time (i.e. with
about a 7hr offset from UTC since I'm in Pacific Time). But now, we
instruct Json.NET to serialize and deserialize dates as UTC.

Additionally, because the data resolution was not set to `Second`,
EndTime would be rounded down with `Time` to the closest minute. We
fixed that by specifying that the data is in `Second` resolution.
2019-11-19 10:28:48 -08:00
Gerardo Salazar
f1e2de03b0 Add symbol removing logic in Benzinga News Converter 2019-11-19 10:28:16 -08:00
Martin Molinero
da99f46b3e Add FirsDate check at ResolveMapFile 2019-11-19 15:19:03 -03:00
Martin Molinero
ace13218ad Add assembly loading logs 2019-11-19 12:52:21 -03:00
Martin Molinero
3aa745ee42 Add StreamReader BaseData.Reader
- Add `BaseData.Reader` implementation which consumes the `StreamReader`
directly, avoiding in between substrings and parsing improving
performance and reducing resource consumption
- Adding unit tests, including performance unit test showing a >50%
improvement
2019-11-18 17:03:27 -03:00
Martin-Molinero
6e9fb85f20 Merge pull request #3855 from QuantConnect/ib-brokerage-updates
IB brokerage updates
2019-11-18 16:58:45 -03:00
Stefano Raggi
5ad912543c Prevent potential race condition between GetOpenOrders and GetNextBrokerageOrderId 2019-11-18 20:33:42 +01:00
Jared
cf1b6c340a Merge pull request #3856 from QuantConnect/bug-3854-livetrading-store-chart-color-unit
LiveTrading stores Series color and unit
2019-11-15 15:27:24 -08:00
Stefano Raggi
3e2592b600 Remove IB codes 2106 and 2108 from WarningCodes list
2106 - A historical data farm is connected.
2108 - A market data farm connection has become inactive but should be available upon demand.
2019-11-16 00:23:52 +01:00
Stefano Raggi
c08583579d Fix potential IB duplicate order id error (ErrorCode: 103)
According to the IB API documentation, when calling reqAllopenOrders we need to ensure that future orderIds will be greater than the ones returned in the call:
https://interactivebrokers.github.io/tws-api/order_submission.html
2019-11-15 21:57:04 +01:00
Stefano Raggi
2993a565a9 Replace BrokerageMessageEvent with Log.Trace for rate limited IB API calls 2019-11-15 21:57:03 +01:00
Stefano Raggi
1ade396251 Remove IB codes 2104 and 2107 from WarningCodes list
2104 - Market data farm connection is OK:usfarm
2107 - HMDS data farm connection is inactive but should be available upon demand.ushmds
2019-11-15 21:57:03 +01:00
Martin Molinero
d401378670 LiveTrading stores Series color and unit
- LiveTradingResultHandler will store `Series` color and unit
2019-11-15 17:17:24 -03:00
Jared
e5bb60a1b9 Merge pull request #3852 from QuantConnect/bug-live-trading-parallel-history-requests-memory-usage
Limit LiveTrading parallel history workers queue
2019-11-15 10:19:26 -08:00
Martin Molinero
0d4aecaac5 Limit LiveTrading parallel history
- Limit workers queue size for parallel history requests
- Small performance fix, use `queue.count` instead of `any`
2019-11-15 13:46:11 -03:00
Jared
73de64bd3a Merge pull request #3848 from QuantConnect/issue-3847-update-morningstar-industry-codes
Update MorningStar helper class with latest clasification
2019-11-15 07:27:24 -08:00
Juan José D'Ambrosio
0b20f2c9fc Fix issue ion documentation 2019-11-15 15:22:55 +00:00
Martin-Molinero
5226f0fb79 Merge pull request #3838 from QuantConnect/issue-3835-equal-indicators-must-be-equal
Fix IndicatorBase.Equal implementation
2019-11-15 12:09:27 -03:00
Juan José D'Ambrosio
2f654bdc8e Address review 2019-11-15 14:43:01 +00:00
Juan José D'Ambrosio
df85d8d876 Update MorningStar helper class with latest clasification
There were updates in categories and codes.
Include documentation from MorningStar documentation.
2019-11-15 13:13:16 +00:00
Juan José D'Ambrosio
4659f919c9 Implement more general robust checking 2019-11-15 10:55:27 +00:00
Jared
8b491f3d9f Merge pull request #3845 from QuantConnect/add-supported-countries-to-trading-economics
Add list of supported countries to Trading Economics
2019-11-14 18:12:27 -08:00
Jared
7f536c78ce Merge pull request #3843 from QuantConnect/refactor-3842-improve-chart-streaming-behavior
Improve chart streaming
2019-11-14 15:24:29 -08:00
Martin Molinero
8965b3ae41 Address reviews 2019-11-14 19:03:36 -03:00
Jared
b8b89ab0b6 Merge pull request #3844 from QuantConnect/add-performance-refactor-pr-template
Add 'performance' and 'refactor' to PR template
2019-11-14 13:41:30 -08:00
Juan José D'Ambrosio
6590495b2e Add list of supported countries to Trading Economics
Those countries can be declared in `config.json`
2019-11-14 21:34:57 +00:00
Martin-Molinero
33192703aa Add performance and refactor PR template 2019-11-14 17:43:59 -03:00
Martin Molinero
88e7645e0f Improve chart streaming
- Remove chart subscription logic. Will stream all chart updates if any
(wont stream empty updates)
- Only serialize properties which are not null
- Adding Chart and Series `IsEmtpy()` extension. Adding unit tests
2019-11-14 17:25:44 -03:00
Juan José D'Ambrosio
78894d40ea Fix IndicatorBase.Equal implementation
Add generic test
2019-11-14 12:24:30 +00:00
Jared
68ad3bb810 Merge pull request #3832 from QuantConnect/bug-cloud-505-python-initialization-hang-fix-update-net-framework
Bump PythonNet to 1.0.5.29
2019-11-13 13:51:19 -08:00
Gerardo Salazar
bc1f608dce Address review - Code cleanup
* Makes BenzingaNewsAlgorithm throw a hard error if the Symbol is not
found inside the BenzingaNews object in OnData
2019-11-13 13:38:37 -08:00
Gerardo Salazar
4a95c36a96 Address Jared's review: Update example algorithms and property types 2019-11-13 13:38:36 -08:00
Gerardo Salazar
938055c13b Address Martin's review: Enable mapping for Benzinga data
* Fixes issue where tickers with no exchange would be skipped
* Fixes issue where tickers that were ETFs were not processed
* Added additional logging
* Removed code duplication
* Reworked Clone method to be more efficient
2019-11-13 13:38:36 -08:00
Gerardo Salazar
629de49b10 Implement Benzinga custom data as ToolBox application and BaseData class 2019-11-13 13:38:36 -08:00
Prasad Somwanshi
4d923ff168 Corrected unit test 2019-11-13 20:52:33 +00:00
Martin Molinero
ec7a8fa906 Bump PythonNet to 1.0.5.29 2019-11-13 17:33:32 -03:00
Jared
dfbbf0aba7 Merge pull request #3828 from AlexCatarino/bug-3771-fixes-nltk-support
Changes NLTK Data Location and Adds mlfinlab Package
2019-11-13 07:49:27 -08:00
Jared
2f995f09af Merge pull request #3826 from prasadsom/bug-3411-CoarseUniverseGenerator-does-not-save-files
Corrected function calls involving iterator function
2019-11-13 07:32:01 -08:00
Jared
b9fcddb603 Merge pull request #3825 from QuantConnect/bug-cloud-505-python-net-initialization
Bump PythonNet to 1.0.5.28
2019-11-12 17:15:15 -08:00
Jared
38c9258df4 Merge pull request #3830 from QuantConnect/bug-3829-disable-live-trading-stockplots
Disable Live Trading Stockplots
2019-11-12 16:42:20 -08:00
Jared
2a0d34d735 Merge pull request #3827 from QuantConnect/bug-3823-ib-existing-orders-created-in-tws
Allow IB Brokerage to cancel/modify existing orders created in TWS
2019-11-12 16:36:38 -08:00
Martin Molinero
0685414da4 Disable LiveTrading Stockplots
- For performance and resource consumption, stockplots will only be
enabled for debug mode
2019-11-12 20:45:58 -03:00
AlexCatarino
c7e4d9798b Changes NLTK Data Location and Adds mlfinlab Package
- Use `/usr/share/nltk_data` instead of `/root/nltk_data`.
- Adds test for NLTK.
- Tidies the root directory of the docker image
- Adds support to mlfinlab
2019-11-12 22:30:04 +00:00
Stefano Raggi
3fe873464e Add new IB warning error codes
- 10147 - OrderId <OrderId> that needs to be cancelled is not found.
- 10148 - OrderId <OrderId> that needs to be cancelled can not be cancelled.
- 10149 - Invalid order id: <OrderId>.

The error code 202 has been removed from the Warning codes, because it is a notification when an order is cancelled.
2019-11-12 21:00:55 +01:00
Prasad Somwanshi
6c5a8f669b Corrected function calls involving iterator function 2019-11-12 19:53:08 +00:00
Martin Molinero
c6ab54f6d2 Bump PythonNet to 1.0.5.28 2019-11-12 16:06:55 -03:00
Stefano Raggi
99f5ccfa81 Allow IB Brokerage to cancel/modify existing orders created in TWS 2019-11-12 17:39:07 +01:00
Jared
3c7a165626 Merge pull request #3815 from QuantConnect/bug-3512-job-start-end-date
Algorithm will respect job dates if present
2019-11-11 14:32:48 -08:00
AlexCatarino
70ffa70092 Removes Reference to Deleted Folder 2019-11-09 00:25:37 +00:00
Jared
106be99471 Merge pull request #3814 from Martin-Molinero/bug-3810-timezone-security-basedata-seed
Fix security seed price timezone
2019-11-08 15:50:06 -08:00
AlexCatarino
5c1ef245a5 Adds Unit Tests For New Consolidator Overload 2019-11-08 23:48:37 +00:00
Jared
f837cf7797 Merge pull request #3813 from AlexCatarino/bug-3807-misplaced-etfs
Fixes LiquidETFUniverse.Treasuries
2019-11-08 15:48:16 -08:00
AlexCatarino
95c9b9327f Fixes Typos in Consolidators 2019-11-08 23:47:53 +00:00
Martin Molinero
e9d1cfd7c9 Fix security seed price timezone
- `BrokerageSetupHandler` and `LiveTradingResultHandler` will seed
security using the correct timezone. Adding unit test
2019-11-08 19:44:49 -03:00
Prasad Somwanshi
f464c2f576 removed code to convert C# delegate to PyObject 2019-11-08 22:06:16 +00:00
Prasad Somwanshi
41f456dfef Added unit test for new constructor, corrected access level in TickConsolidator 2019-11-08 22:06:16 +00:00
Prasad Somwanshi
41f9b17015 Added overloaded constructors to classes derived from PeriodCountConsolidatorBase 2019-11-08 22:06:16 +00:00
Prasad Somwanshi
e431081337 Added constructors taking PyObject 2019-11-08 22:06:16 +00:00
Martin-Molinero
14b91c525f Merge pull request #3812 from QuantConnect/bug-3811-ib-forex-market
Fix IB Forex zero conversion rates
2019-11-08 18:59:12 -03:00
AlexCatarino
7ae63af388 Fixes LiquidETFUniverse Misplaced ETFs
`SHV`, `TBT` and `TBF` are `Inverse` ETF and were listed as `Long`.
`UGAZ` and `DGAZ` were in the opposite list.
`TVIX` was marked as `Inverse`.
2019-11-08 21:36:27 +00:00
Stefano Raggi
54cf7bfd9e Reuse DefaultMarketMap in IB MapSymbol 2019-11-08 22:09:54 +01:00
Martin Molinero
417590ddc2 Add unit test for BacktestNodePacker 2019-11-08 17:51:33 -03:00
Martin Molinero
9afe74a618 Fix rebase 2019-11-08 17:51:33 -03:00
Martin Molinero
2aeed3595d Algorithm will respect job dates if present
- Console and Backtesting setup handler will use job dates if present
(not the brokerage setup handler)
- Adding unit test
2019-11-08 17:51:33 -03:00
Stefano Raggi
68fcd7faaf Remove CopyAlways flag from unit test data file 2019-11-08 20:41:54 +01:00
Stefano Raggi
365a19a474 Fix IB Forex zero conversion rates 2019-11-08 20:39:41 +01:00
Jared
c4287eaa22 Merge pull request #3809 from QuantConnect/performance-3724-parallel-history-request
Parallel history requests
2019-11-08 08:16:22 -08:00
Jared
bd0613f8cb Merge pull request #3804 from Martin-Molinero/bug-3327-invalid-initial-symbol-changed-event
Fix invalid initial SymbolChanged event
2019-11-08 08:07:34 -08:00
Jared
cf0b5a565b Merge pull request #3803 from QuantConnect/bug-3756-consolidators-trigger-deterministically
Make Consolidators Trigger Deterministically
2019-11-08 08:02:54 -08:00
Jared
4b6a63bfde Merge pull request #3799 from QuantConnect/bug-3740-scheduled-universe-selection-model-time-zone
Fix ITimeRules time zone issues
2019-11-08 07:56:50 -08:00
Jared
63076f4a18 Merge branch 'master' into bug-3740-scheduled-universe-selection-model-time-zone 2019-11-08 07:56:41 -08:00
Jared
83c9e78c2c Merge pull request #3782 from QuantConnect/bug-3781-setholdings-market-on-open-orders
SetHoldings will check existing OnMarketOpen orders
2019-11-08 07:49:52 -08:00
Jared
6c385d2c6a Merge pull request #3808 from QuantConnect/bug-3689-option-contract-bidprice-fix
Fix market price initialization in LiveTradingResultHandler
2019-11-08 07:44:08 -08:00
Martin-Molinero
ec6b2bdd5e Merge pull request #3807 from QuantConnect/feature-3806-liquid-etf-helpers
Adds New Static Members to LiquidETFUniverse
2019-11-07 19:54:57 -03:00
AlexCatarino
3fca51e314 Addresses Peer-Review 2019-11-07 22:26:46 +00:00
Martin Molinero
3f8a751cef Parallel history request
- Enable parallel workers for history requests, improving performance.
- Adding SubscriptionUtils to be used by backtesting through the FileSystemDataFeed and
SubscriptionHistoryProvider and live deployments which use the
SubscriptionHistoryProvider in the core
- Fix some timezone issues when using local
start/end time instead of UTC
- Adding missing `Enumerator.Dispose()` to be called by the worker
2019-11-07 18:10:30 -03:00
Stefano Raggi
b179909053 Fix market price initialization in LiveTradingResultHandler
This change prevents the security from being initialized with a quote tick, causing the bid price and ask price to be equal (and potentially remain so -- as can happen with OTM options).
2019-11-07 21:26:12 +01:00
AlexCatarino
fb76003048 Adds New Static Members to LiquidETFUniverse
New members represent the different ETF categories. Each one has a `List<Symbol>` for Long and Inverse ETFs.
2019-11-07 17:01:15 +00:00
Jared
697d4d487e Merge pull request #3805 from Martin-Molinero/bug-3772-fix-fsharp-nullable-resolution
Fix FSharp nullable resolution parameter
2019-11-06 14:15:22 -08:00
Martin Molinero
24a5a29c1f Remove unused references 2019-11-06 15:43:35 -03:00
Martin Molinero
754378756a Fix FSharp nullable resolution parameter
- After PR 3772 resolution is a nullable for `AddData` overloads. Fixing
basic template fs algorithm
2019-11-06 15:40:06 -03:00
Martin Molinero
86ffbcb3f9 Fix invalid initial SymbolChanged event
- EventProvider will receive start date during initialization, this will
be used by the `MappingEventProvider` to correctly set current mapped
symbol
- Adding unit test, updating existing regression test
2019-11-06 14:41:12 -03:00
Martin Molinero
2812ad6f8e Address reviews. Improvement
- Improve mechanism to fetch open orders quantity, based on method used
by the `ImmediateExecutionModel`
- Adding unit test
2019-11-06 12:14:10 -03:00
Martin Molinero
9b507bbf34 Fix SetHoldings OnMarketOpen orders
- `SetHoldings` will take `OnMarketOpen` ordes into account when
determining order quantity
- Adding new regression test. Updating existing algorithms which
suffered of the issue
- Adding a performance improvement, will avoid margin and portfolio
calculations for MarketOnOpen orders that wont be able to fill
2019-11-05 21:05:49 -03:00
Jared
e63ba13016 Merge pull request #3802 from QuantConnect/refactor-synchronizing-history-provider
Refactor SynchronizingHistoryProvider
2019-11-05 16:01:48 -08:00
Jared
5d2f058188 Merge pull request #3794 from QuantConnect/feature-3790-setholdings-multiple-targets
Add SetHoldings for a collection of targets
2019-11-05 16:01:01 -08:00
Martin Molinero
0fb1bf8cc6 Keep ConcurrentSet ordered
- `ConcurrentSet` will use a `OrderedDictionary` internally so that items
are ordered deterministically, respecting insertion order.
- Adding unit tests
2019-11-05 16:02:54 -03:00
Martin Molinero
72c8affbc3 Adding unit tests for OrderTargetsByMarginImpact 2019-11-05 13:47:42 -03:00
Martin Molinero
2f9814f2f9 Add SetHoldings for collection of targets
- Adding `SetHoldings` implemenetation for a collection of portfolio
targets
- Adding regression test
- Some performance improvements
2019-11-05 13:47:42 -03:00
Martin-Molinero
0f18d1a552 Merge pull request #3777 from QuantConnect/bug-3772-custom-data-resolution-fillforwarding
Add BaseData.DefaultResolution and SupportedResolutions
2019-11-05 13:45:07 -03:00
Stefano Raggi
55880d79bd Refactor SynchronizingHistoryProvider
The CreateSubscription method has been moved from the BrokerageHistoryProvider to the SynchronizingHistoryProvider base class, to enable reuse and avoid code duplication.
2019-11-05 16:46:33 +01:00
Martin Molinero
68ad2f51b6 Address reviews
- Replacing `BaseData.AdjustResolution` for `DefaultResolution` and
`SupportedResolutions`
- Making `Resolution` nullable for `Algorithm.AddData` methods
- The `ISubscriptionDataConfigService` will set the default resolution
if none was provided and assert it is supported
- Fix bug with `PythonData` `IsSparseData` and `RequiresMapping`
resolution
2019-11-04 20:42:30 -03:00
Martin Molinero
1d43dcd601 Add BaseData.AdjustResolution
- Adding `BaseData.AdjustResolution()` that should return a valid
resolution for the given data and security type.
This allows us to set a limitation which is useful to avoid invalid data
requests or unnecessary fill forward situations. The user will be
notified through a console message.
- Adding unit and regression test
- Updating example algorithms custom data resolution
- Some performance improvements. Wont change console color if
`SelectedOptimization` is defined
2019-11-04 20:38:26 -03:00
Jared
7e33be1853 Merge pull request #3787 from QuantConnect/bug-3784-algorithm-leverage-precedence
Adding Security.NullLeverage
2019-11-04 13:56:44 -08:00
Jared
9ee98d2a7c Merge pull request #3786 from QuantConnect/feature-3785-ltdf-streaming-custom-data
Add streaming custom data support to LiveTradingDataFeed
2019-11-04 13:46:03 -08:00
Martin Molinero
8d7585416b Fix ScheduleManager multiple enumeration
- Fix `ScheduleManager` multiple enumeration of the event times of a
scheduled event
2019-11-04 17:40:45 -03:00
Martin Molinero
98ae5cdd4e Fix TimeRules time zone issues
- `ITimeRules` are expected to yield time date in UTC, fixing `Noon`,
`Midnight` and `Every`
- `ScheduledUniverseSelectionModel` will use UTC time zone by default
since that is the default expected time zone `ITimeRule` provides
- Adding regression test
2019-11-04 15:34:57 -03:00
Jared
e0f0a04f0f Update LiquidETFUniverse.cs 2019-11-01 20:48:55 -07:00
Jared
c239f8d718 Merge pull request #3797 from AlexCatarino/master
Adds Liquid ETF Universe Selection Model
2019-11-01 20:41:49 -07:00
Jared
e8d388ef37 Update LiquidETFUniverse.cs 2019-11-01 20:41:33 -07:00
Jared
9a3ab283aa Update LiquidETFUniverse.cs 2019-11-01 20:41:21 -07:00
AlexCatarino
74d1f7b79c Adds Liquid ETF Universe Selection Model 2019-11-02 03:36:21 +00:00
Martin-Molinero
d91c3e4499 Merge pull request #3789 from RobSchut/bug-3788-AlgoSeekFuturesConverter-GetFilesInRawFolder
Fix AlgoSeekFuturesConverter.cs (GetFilesInRawFolder)
2019-11-01 19:13:47 -03:00
Martin Molinero
118c1e49cc Add data channel provider
- Adding `IDataChannelProvider` that will be used to determine if
streaming should be used
- Adding `data-channel-provider` for `config.json`
- Adding unit tests
2019-11-01 14:53:56 -03:00
Rob Schut
a8477d597e dir replaced by cmd.exe with dir as argument 2019-10-31 15:48:23 +01:00
Stefano Raggi
8ee0892de2 Update TiingoNews.GetSource for live mode 2019-10-31 11:12:23 +01:00
Stefano Raggi
6cf0fd6a08 Fix LiveTradingDataFeed failing tests 2019-10-31 11:12:23 +01:00
Stefano Raggi
0e6d5d98d2 Add streaming custom data support to LiveTradingDataFeed 2019-10-31 11:12:22 +01:00
Martin Molinero
62753b5425 Adding Security.NullLeverage
- Adding `Security.NullLeverage` value to determine when the
`SecurityInitializer` leverage should be used or not
- Adding regression algorithm which reproduces the issue
2019-10-30 20:03:37 -03:00
Martin-Molinero
aaf81ef467 Merge pull request #3768 from QuantConnect/bug-3763-margin-remaining
Fix maintenance margin calculation
2019-10-30 13:04:24 -03:00
Jared
5d1b48f2d7 Merge pull request #3778 from QuantConnect/feature-3776-updates-alpha-streams-brokerage-model-leverage
Updates AlphaStreamsBrokerageModel Leverage
2019-10-28 17:20:58 -07:00
AlexCatarino
17c767f2e0 Updates AlphaStreamsBrokerageModel Leverage
Increases to 1.1 from 1.
2019-10-28 22:50:28 +00:00
Jared
ccbb2093da Merge pull request #3770 from QuantConnect/bug-3519-data-emitted-before-first-date
Fix data emitted before first date
2019-10-28 11:21:38 -07:00
Jared
61d07dd907 Merge pull request #3774 from AlexCatarino/feature-3773-adds-train-feature-examples
Adds Examples for Train Feature
2019-10-28 11:21:28 -07:00
AlexCatarino
49701657fb Use Train Helper Method Instead of Schedule.TrainingNow 2019-10-28 18:13:59 +00:00
AlexCatarino
5bb28b44a8 Adds Examples for Train Feature
- Adds Python version of `TrainingInitializeRegressionAlgorithm`;
- Adds C# version of `TrainingExampleAlgorithm`;
- Removes `TrainingScheduledRegressionAlgorithm`.
2019-10-28 17:49:53 +00:00
Martin Molinero
0783a50dcc Fix data emitted before first date
- `SubscriptionDataReader` will check map file first data and adjust
start date based on it
- Adding unit test
- Reducing code duplication
- Setting up `HistoryProvider` event handling
2019-10-25 14:09:02 -03:00
Jared
bad69c584c Merge pull request #3767 from StefanoRaggi/bug-3766-composer-loader-exceptions
Handle ReflectionTypeLoadException in Composer.GetExportedValues
2019-10-25 07:18:09 -07:00
Martin Molinero
6719109ed1 Fix maintenance margin calculation
- Maintenance Margin will be calculated using current securities Value
and not acquisition price.
- Adding unit and regression tests
2019-10-24 20:52:28 -03:00
Stefano Raggi
39c1b22f8b Handle ReflectionTypeLoadException in Composer.GetExportedValues 2019-10-24 12:31:30 +02:00
Jared
ee07baa0c8 Merge pull request #3758 from AlexCatarino/feature-3757-ewpcm-refresh
Extends EWPCM Rebalancing Options
2019-10-23 17:45:22 -07:00
AlexCatarino
725889198c Adds EWPCM Usage Examples in BasicTemplateFrameworkAlgorithm 2019-10-24 01:19:35 +01:00
Jared
19fa8664bd Merge pull request #3748 from QuantConnect/bug-3745-fix-history-request-for-cboe
Fixes failing CBOE History request by removing duplicate property
2019-10-23 17:04:00 -07:00
Jared
8070c81b1e Merge pull request #3764 from QuantConnect/bug-3760-renkobar-consolidator-forex-tick
Fix SubscriptionManager consolidator check for Tick resolution
2019-10-23 17:03:30 -07:00
Jared
dca8f361d7 Merge pull request #3765 from gsalaz98/feature-fred-convert-properties-add-example
Convert FRED properties to fields
2019-10-23 17:03:05 -07:00
Gerardo Salazar
3aadf5635b Convert FRED properties to fields
* Add example FRED usage
2019-10-23 16:59:37 -07:00
AlexCatarino
f02b39940b Addresses Peer-Reviews
See #3758
2019-10-23 22:14:22 +01:00
Jared
36c87f0ef4 Merge pull request #3750 from QuantConnect/feature-FRED-custom-data
Feature fred custom data
2019-10-23 13:20:38 -07:00
Jared
281d5266f1 Merge pull request #3762 from QuantConnect/bug-3759-excessive-portfolio-rebalance
Adding FreePortfolioValue
2019-10-23 13:14:19 -07:00
Stefano Raggi
9c257a46c5 Fix SubscriptionManager consolidator check for Tick resolution 2019-10-23 21:08:50 +02:00
Martin Molinero
0e7c035329 Adding FreePortfolioValue
- Adding `FreePortfolioValue` to be set after algorithm initialize based
on the `TotalPortfolioValue` and the `FreePortfolioValuePercentage`
- Updating regression tests
- Adding new regression test
- Adding check for minimum order value at `BuyingPowerModel`
2019-10-23 13:56:35 -03:00
AlexCatarino
98a25910f1 Extends EWPCM Rebalancing Options
Adds constructor overloads to `EqualWeightingPortfolioConstructionModel` (`EWPCM`) to allow different rebalancing definitions.

It is possible to define rebalancing period with `Resolution`, `TimeSpan` (`timedelta` for Python) or a `Func<DateTime, DateTime>` (`lambda x: x+timedelta(y)`). The last option lets the model use `Expiry` helper class with the members such as `EndOfWeek` and `EndOfMonth`.
2019-10-22 21:07:54 +01:00
Jared
fec278a229 Merge pull request #3746 from QuantConnect/performance-3739-securitycache
Performance improvements v3
2019-10-22 11:12:00 -07:00
Martin Molinero
b00a599e16 Address reviews
- Address reviews and rebase
2019-10-22 13:47:45 -03:00
Martin Molinero
a5dc1774a7 Add SecurityCacheProvider
- Adding `SecurityCacheProvider` this class allows for two different
`Security` to share the same data type cache through different instance
of `SecurityCache`. This is used to directly access custom data types
through their underlying in a peformant maner
- Some small improvements
2019-10-22 13:46:57 -03:00
Martin Molinero
b2706b427c SecurityCache performace improvements
- `DynamicSecurityData` will be a view into the `SecurityCache` instance
- Custom data which has an underlying will use the underlying
`SecurityCache` data type cache instance
- Refactors for `Security` and `SecurityCache` to avoid storing twice
the same data points in the data type cache
2019-10-22 13:46:56 -03:00
Juan José D'Ambrosio
461e77d31a Move FRED source page to remarks 2019-10-22 14:36:36 +00:00
Jared
811aae81f9 Merge pull request #3753 from QuantConnect/bug-3721-custom-data-on-securities-changed-events
Filter custom securities from SecurityChanges
2019-10-22 07:33:01 -07:00
AlexCatarino
b97d11d37a Addresses Reviews
- Covers another level on inheritance of Market Data by using `Type.IsAssignableFrom`
- Caches the list of `MethodInfo` for custom data types to avoid redefining that list.
2019-10-22 15:14:04 +01:00
AlexCatarino
0cca6869f7 Fixes Support for Custom Data
When custom data classes inherited from market data classes such as `TradeBar`, it created duplicate entries. Therefore, we need to exclude the common properties in the private field `PandasData._members`.
2019-10-22 15:14:04 +01:00
Gerardo Salazar
2f323076bf Fixes failing CBOE History request by removing duplicate property 2019-10-22 15:14:04 +01:00
Juan José D'Ambrosio
ed02072425 Renaming classes to match current patterns 2019-10-22 13:29:08 +00:00
Juan José D'Ambrosio
a30445e3c9 Address reviews 2019-10-22 12:46:17 +00:00
Jared
7452667f8d Merge pull request #3743 from mchandschuh/feature-3319-add-training-scheduled-events
Adds support for extending algo time loop for long-running scheduled events
2019-10-22 05:42:55 -07:00
Martin Molinero
891f94fbeb Address reviews
- Set `CanRunLocally => false` for training regression algorithms
- Reverting sorting changes at `BacktestingRealTimeHandler` due to
performance degradation of current scheduled event benchmark algorithm
2019-10-21 21:18:06 -03:00
Jared
a9c99cd1b8 Merge pull request #3752 from QuantConnect/feature-3725-probabilistic-sharpe-ratio
Add ProbabilisticSharpeRatio
2019-10-21 17:08:35 -07:00
Martin Molinero
4439a070fa Address reviews
- Will use a deannualized sharpe ratio of 1 as benchmark
2019-10-21 20:21:26 -03:00
Martin Molinero
8966a3884f Filter custom securities from SecurityChanges
- Will filter out custom securities from `SecurityChanges` for user
code, note that by default it will not filter
- Adding unit tests
2019-10-21 18:03:13 -03:00
Martin Molinero
324556db62 Add ProbabilisticSharpeRatio
- Add `ProbabilisticSharpeRatio` to `PortfolioStatistics`
- `Probabilistic Sharpe Ratio` will be added to the `RunTimeStatistics`
sent by the `ResultHandlers`
- Making `TradeBuilder.ClosedTrades` thread safe since its accessed by
the `ResultHandlers`
- Removing `:` from live runtime statistics
- Adding unit tests
2019-10-21 15:54:42 -03:00
Michael Handschuh
b371847a19 Usings cleanup, doc, unused parms, etc
Per review comments provided in #3743 regarding the
training/long-running scheduled events and the leaky
bucket algorithm. See the PR for more information.
2019-10-19 14:52:34 -04:00
Michael Handschuh
eec60db0c7 Fix additional minutes message
Deducts the standard time step limit from the additional minutes.
We start counting minutes immediately, even before the standard limit
has been exceeded.
This change ensures  that we're not confusing the user with the message
2019-10-19 14:52:34 -04:00
AlexCatarino
c37b450a2e Adds Python Support
- Adds PyObject overload to `ScheduleManager.TrainingNow` and `ScheduleManager.Training`
- Adds `QCAlgorithm.Train` helper method
- Adds Python algorithm showing how to use the helper method.
2019-10-19 14:52:34 -04:00
Michael Handschuh
28be3bbe3d Refactors scheduled events to execute on main thread
In order to continue to provide debugging support in the QC cloud, the
scheduled events were moved from inside of a task to the algorithm's
main execution thread. This necesitated a different methodology for
managing timeouts. Instead of raising an exception when attempting to
request additional time when none is remaining, we're now simply allowing
the isolator's limit to be reached by virtue of not incrementing the
additional minutes in the time manager. This uncovered a bug in LEAN
engine where if the isolator terminates an algorithm, then the status
of the algorithm (on the algorithm manager instance) isn't properly
updated to indicate RuntimeError. This is in direct conflict with the
status update that is provided to the api, which is RuntimeError, so
this change remedies that issue as well. One of the regression algorithms
depends on this status value being properly flipped to RuntimeError in
the event that the isolator limit is reached.

See #3319
2019-10-19 14:52:34 -04:00
Michael Handschuh
22d56e5ffb Properly handle events raised in ScheduledEvents
Adds logic to intercept exceptions raised by user code in the
task used to wrap the scheduled event execution.
2019-10-19 14:52:34 -04:00
Michael Handschuh
09cc78599a Add mechanism for scheduled events to use 'additional time'
We restrict each algorithm time loop to a pre-determined amount of time.
Exceeding this limit will cause the algorithm to immediately terminate.
This quickly becomes an issue when considering users running trainable
models that have a long initialization period that exceeds the time loop
maximum.

This change provides a mechanism through which a long-running scheduled
event is permitted to keep running and is permitted to avoid the time loop
permitted by requesting additional time. Requests for additional time are
limited according to a leaky bucket implementation whose parameters are
set via the job's controls structure. The fundamental time unit for the
algorithm is a single minute.

Here's how it works. If a scheduled event takes longer than one full wall
clock second then a request is made to the leaky bucket for one more minute.
If the scheduled event continues to take more time, it will continue to
request additional minutes. Each requested minute will prevent the algorithm's
time loop check from terminating the algorithm. When the bucket is empty and
no more minutes are available to be requested, a TimeoutException is thrown
causing a cascade that ends in the algorithm's termination and status being
flipped to RuntimeError.

Additionally, this applies equally to ALL scheduled events. While some helpers
were added with the naming of Train and TrainNow to the ScheduleManager, these
methods don't do anything special and the infrastructure doesn't otherwise
flag them as different, so this feature becomes part of the core Scheduled
Event feature set.

Further, the live scheduled events were not touched and are still pending
further discussion regarding the value added by enforcing a time restriction
when simulation time and wall clock time are equivalent.

Fixes #3319
2019-10-19 14:52:34 -04:00
Juan José D'Ambrosio
2c55937f1a Add test for FredApi 2019-10-19 09:15:59 -03:00
Michael Handschuh
053a8ae55d Fix typo, move ScheduledEventException to its own file 2019-10-19 01:52:07 -04:00
Michael Handschuh
5db332a118 Add DateRules Today,Tomorrow and TimeRules Now, Midnight, Noon
These are simple, easy to use convenience properties for creating short-term
scheduled events and produces a cleaner, easier reading syntax than using the
other various methods to produce the same result, for example:
Schedule.On(DateRules.Tomorrow, TimeRules.Noon, MyScheduledEventMethod);

Also fixes typo in FuncDateRule constructor parameter.
2019-10-19 01:52:07 -04:00
Michael Handschuh
70048738d3 Don't skip ScheduledEvent at current time
When adding a new ScheduledEvent with exactly one event time set
to the algorithm's current time, the SkipEventsUntil function would
skip the only event. It appears that this bug was 'fixed' via commit:
33a4db4559

This 'fix' is more of a bandaid and I'm forgoing undoing the bandaid
applied in ScheduleManager and ScheduledEventBuilder where we start
calculating the event schedule a full day before the algorithm's
current time in an effort to reduce additional potential risks from
creeping into this PR focused on adding support for long-running
training functions.
2019-10-19 01:52:07 -04:00
Michael Handschuh
1a0947aa59 Defines ITokenBucket and a LeakyBucket implementation
The inspiration for this implementation design comes directly from:
https://github.com/mxplusb/TokenBucket

Minor modifications were made, including a prominent behavior change
that prevents the Refill method from executing the initial refill
before any time has passed.

We'll use the leaky bucket algorithm to track consumption of CPU
resources by the soon-to-be-implemented training feature.
2019-10-19 01:52:07 -04:00
Michael Handschuh
0c862c5652 Move ITimeProvider and RealTimeProvider to Common
These are fairly generic and useful types that have zero dependencies.
We'll reuse the the ITimeProvider for the leaky bucket implementation
to permit for better unit testing as well as potentially alternate modes
of managing the time that the leaky bucket sees, such as simulation time.
2019-10-19 01:52:07 -04:00
Michael Handschuh
75f89e03f2 Refactor algo mgr time loop isolator limit
Extracting this behavior into it's own class. We'll later extend
the functionality of the implementation to enable a training event
a mechanism for extending the current time loop maximum and/or for
flat out disabling it while the training is runnig and the leaky
bucket has capacity.
2019-10-19 01:52:07 -04:00
Juan José D'Ambrosio
2c161002b9 Follow name convention and tidy code 2019-10-18 22:06:00 +00:00
Juan José D'Ambrosio
bca78a2b2e Implement base data for FRED 2019-10-18 21:53:44 +00:00
Martin-Molinero
d95967e350 Merge pull request #3718 from AlexCatarino/feature-3672-confidence-weighted-pcm
Implements ConfidenceWeightedPortfolioConstructionModel
2019-10-18 17:14:14 -03:00
AlexCatarino
1e2cec3da6 Removes Unused Imports 2019-10-18 20:47:06 +01:00
AlexCatarino
a18bd953ac Implements ConfidenceWeightedPortfolioConstructionModel
- Adding new `ConfidenceWeightedPortfolioConstructionModel` (C# / Py) that will
generate percent `Targets` based on the latest active `Insight` `Confidence` per
`Symbol`.
   - Will ignore `Insights` that have no `Confidence`.(unit tested)
   - If the sum of all the last active `Insight` per `Symbol` is bigger than 1, it
will factor down each target percent holdings proportionally so the sum is 1. (unit tested)
   - Adding unit tests
   - Adding a new regression test framework algorithm (C#/Py)
   -**Note**: `ConfidenceWeightedPortfolioConstructionModel` inherits from the `InsightWeightingPortfolioConstructionModel`. Protect method `GetValue` was implemented in `IWPCM` to enable the choice of `Insight` member.
2019-10-18 20:47:06 +01:00
Martin-Molinero
36ce55e284 Merge pull request #3749 from QuantConnect/bug-3728-exclude-expired-options-from-ib-holdings
Exclude expired options from IB GetAccountHoldings
2019-10-18 15:59:55 -03:00
Jared
73c2ef930a Merge pull request #3714 from QuantConnect/performance-3696-dynamicsecuritydata-improvements
Performance improvements v2
2019-10-18 11:34:54 -07:00
Stefano Raggi
8eab224ad7 Add user warning for expired option holding 2019-10-18 20:10:49 +02:00
Juan José D'Ambrosio
e3ff35b5d4 Implement Central Bank and LIBOR helper class 2019-10-18 16:45:21 +00:00
Juan José D'Ambrosio
0989d28c7a Implement Wilshire helper class 2019-10-18 16:45:21 +00:00
Juan José D'Ambrosio
e68178db3b Implement Commercial Papers helpers 2019-10-18 16:45:21 +00:00
Juan José D'Ambrosio
319edfafca Add OECD recession indicators helper classes 2019-10-18 16:45:21 +00:00
Juan José D'Ambrosio
de00505316 Make FRED helper class partial 2019-10-18 16:45:21 +00:00
Juan José D'Ambrosio
07f6ab3b27 Implment FRED helper class. 2019-10-18 16:45:21 +00:00
Stefano Raggi
e4bbddc509 Exclude expired options from IB GetAccountHoldings 2019-10-18 18:28:07 +02:00
Jared
979577eb30 Merge pull request #3747 from QuantConnect/bug-3744-do-not-emit-insights-during-warmup
Ignore insights emitted during warmup
2019-10-18 08:16:32 -07:00
Jared
b5bed43f6c Merge pull request #3742 from StefanoRaggi/feature-3728-ib-better-logging-info
Add symbol value to log messages in IB error handler
2019-10-18 06:35:33 -07:00
Martin Molinero
298d751866 Ignore insight emitted during warmup 2019-10-17 21:22:37 -03:00
Martin Molinero
2433105c46 Address review
- SecurityCache: replace `ToList` with `ToHashSet` that provides O(1) contains lookup
2019-10-17 10:26:37 -03:00
Martin Molinero
3828a7804e Stop running threads in unit tests 2019-10-17 10:26:37 -03:00
Martin Molinero
9ec1a41235 Performance improvements
- `PortfolioTargetCollection` avoid calling `Count` on
ConcurrentDictionary directly -> has to take all locks
- `SecurityChanges` change Union for Concat since constructor will call
HashSet
- Make `DynamicSecurityData` hold lazy data objects
- `RegisteredSecurityDataTypesProvider` avoid looping over all
registered types, adding `TryGetType`
- `Security.Update()` will no call group by on data since this data is
already grouped by type. Adding `ContainsFillForwardData` will allows to
be lazy and not re loop through the data unless necessary
- `DefaultAlphaHandler` will use the `static`
`Enumerable.Empty<Insight>` instance when possible
- `SubscriptionSynchronizer` will be lazy to construct the
`universeData` dictionary which is not used in most of the times. Will
use `Count` vs `Any` -> `Count` is known by the dictionary
- For python algorithms `JobQueue` will respect `AlgorithmLocation`, was
using unexisting `"algorithm-path-python"`
2019-10-17 10:26:37 -03:00
Stefano Raggi
7905b2989b Add symbol to log messages in IB error handler 2019-10-17 11:47:17 +02:00
Jared
7ac11ae47d Merge pull request #3736 from gsalaz98/feature-add-history-requests-to-demo-altdata-algorithms
Implement History request in demo AltData algorithms
2019-10-16 15:11:27 -07:00
Jared
70875a345e Merge pull request #3720 from Martin-Molinero/performance-3715-smartinsider-benchmark-algorithms
Add SmartInsider performance benchmark
2019-10-16 14:53:43 -07:00
Jared
3c5940ea0d Merge pull request #3726 from gsalaz98/feature-us-energy-cached-custom-data
Implement U.S. Energy (EIA) cached data source
2019-10-16 14:48:31 -07:00
Jared
4030ee3f9f Merge pull request #3738 from QuantConnect/bug-3737-onframeworkdata-pythonslice
Wraps Slice Object with PythonSlice for Python Framework Algorithms
2019-10-16 14:47:03 -07:00
AlexCatarino
7865516a7a Refactors AlgorithmPythonWrapper.OnFrameworkData 2019-10-16 22:36:34 +01:00
AlexCatarino
d55eaae231 Uses the same instance wthether there is custom data or not. 2019-10-16 22:25:27 +01:00
AlexCatarino
24d0ba392d Wraps Slice Object with PythonSlice for Python Framework Algorithms
Wraps `Slice` object with `PythonSlice` for Python framework algorithms when alternative/custom data is present.
2019-10-16 20:13:50 +01:00
Jared
86cf6b52ca Merge pull request #3699 from QuantConnect/bug-ib-data-queue-handler-ticks
Fix tick emit logic bugs in IB DataQueueHandler
2019-10-16 11:09:19 -07:00
Jared
a426bc1708 Merge pull request #3708 from Martin-Molinero/bug-3707-fillforward-enumerator-history-loop
Fix inifite loop FillForwardEnumerator
2019-10-16 11:07:42 -07:00
Jared
a6ad56b314 Merge pull request #3733 from Martin-Molinero/bug-3732-python-onmargincall
Check if Python OnMarginCall is defined
2019-10-16 10:56:08 -07:00
Jared
c011ebb964 Merge pull request #3712 from randomthought/bug-3711-docker-builder-errors
Fixed the build issues from nuget and msbuild.
2019-10-16 10:54:33 -07:00
Gerardo Salazar
0aadd2b9ae Implement history requests in demo AltData algorithms 2019-10-16 10:16:17 -07:00
Gerardo Salazar
d43ef3e68e Address review: remove link to cache for CBOE in CachedAlternativeDataAlgorithm 2019-10-16 10:02:21 -07:00
Gerardo Salazar
7232693a71 Address review: Include ticker definitions in partial USEnergy class instead of USEnergyCategory 2019-10-16 09:36:19 -07:00
Martin Molinero
cce87c992d Address review
- Increase time lenght of SmartInsider benchmarks. Adding history
requests
2019-10-16 13:35:05 -03:00
Martin Molinero
0d171a2e70 Add SmartInsider performance benchmark
- Adjust Sec performance benchmark algorithm
2019-10-16 12:15:00 -03:00
Martin Molinero
27ce9489a4 Check if Python OnMarginCall is defined
- Will check if python OnMarginCall is defined and throw is returns null
or empty list
- Adding unit tests
2019-10-16 11:49:12 -03:00
Jared
d3de36cc2d Merge pull request #3729 from QuantConnect/bug-3719-fix-python-smartinsider-transaction-history-request
Fix Failing Python History Request in SmartInsiderTransaction
2019-10-15 18:01:35 -07:00
Gerardo Salazar
07d6f41f9b Implement U.S. Energy (EIA) cached data source
* Rename USEnergyInformation to USEnergyAPI
2019-10-15 16:06:37 -07:00
Jared
7160be5974 Merge pull request #3723 from QuantConnect/bug-3722-python-applysplit-call
Python ApplySplit - PythonNet update
2019-10-15 15:23:11 -07:00
Stefano Raggi
7754ef37f9 Address review
- normalize negative quantity to zero in HandleTickSize
2019-10-16 00:06:47 +02:00
Martin Molinero
b35bc31f51 Version bump 1.0.5.26 2019-10-15 18:43:33 -03:00
Martin Molinero
3e3bfd83d5 Try to convert to managed type
- Will try to convert IBrokerage from PyObject to managed type
- Adding unit tests
2019-10-15 17:34:36 -03:00
Stefano Raggi
e284b78c1d Address review
- Add private SubscriptionEntry class to remove extra dictionary access on each tick
- Remove duplicate check for negative price
2019-10-15 15:55:55 +02:00
Stefano Raggi
a64f1119c3 Fix tick emit logic bugs in IB DataQueueHandler
1. Only emit quote ticks when both the price and size messages have been received
Market data for trades and quotes is received by the IB API callbacks as separate messages and price is always received before the size. Previously we were emitting ticks on both price and size messages.

2. Do not emit half-quotes
Even in a very liquid instruments, we were previously sending quote ticks with e.g. only bid price and size but zero ask price and size. For consistency with other IDataQueueHandler implementations we now always emit complete quote ticks (for cases where there is no bid price available such as far OTM options, we'll emit the half-quote with zero for bid price and size).

3. The tick Quantity field is now set only for Trade ticks
Previously it was also being set for Quote ticks.
2019-10-15 15:49:45 +02:00
Jared
de19f7e7d8 Merge pull request #3710 from gsalaz98/feature-cboe-vix-basedata
Implement CBOE BaseData class
2019-10-14 18:18:14 -07:00
Gerardo Salazar
4b6c44c48a Address review: Return default values instead of null when CBOE data is empty 2019-10-14 15:23:09 -07:00
Gerardo Salazar
e5052b067e Fix History request by renaming SmartInsiderTransaction field from Price to ExecutionPrice
* Adds Symbol, Value, Time to properties cloned in SmartInsiderIntention
2019-10-14 15:10:14 -07:00
Jared
aa28c6fa3a Merge pull request #3717 from QuantConnect/performance-3715-sec-benchmark-algorithms
Add SecReport performance branchmarks
2019-10-14 13:20:15 -07:00
Martin Molinero
3fe7838f09 Add Sec report perf branchmark
- Add Sec report performance benchmarks C# and Py
- Add missing `using(Py.Gil)`
2019-10-14 16:53:53 -03:00
Martin Molinero
404533eb39 Address reviews - Use TimeZoneOffsetProvider 2019-10-14 14:39:26 -03:00
Gerardo Salazar
7880cdf456 Address review: Make CBOE implementation more consistent with BaseData
* Adds new TryParse methods to the Parse class
2019-10-14 09:36:14 -07:00
Malcolm Mulong
1326a49ff5 Fixed the build issues from nuget and msbuild. 2019-10-12 01:22:31 -07:00
Gerardo Salazar
8797a47e3f Fixes failing Reader for other CBOE data sources 2019-10-11 12:17:59 -07:00
Gerardo Salazar
e6f0135943 Address reviews - add python algorithm and rename algorithm to
CachedAlterantiveDataAlgorithm
2019-10-11 12:01:45 -07:00
Gerardo Salazar
0c31ff91b6 Implement CBOE BaseData class 2019-10-11 10:53:08 -07:00
Jared
fb8bd124b1 Merge pull request #3703 from AlexCatarino/feature-3576-adds-python-packages
Adds New Python Packages
2019-10-11 06:00:39 -07:00
Stefano Raggi
961157ed59 Update CoinApiDataQueueHandler to use CoinApi's NuGet package (#3645) 2019-10-10 17:05:01 -07:00
Martin Molinero
0c37e62733 Fix inifite loop FillForwardEnumerator
- Adding check for `FillForwardEnumerator` not to emit twice the same
end time. Adding unit tests
- Fix issue with `FileLogHandlerTests` conflicting with existing logging
instance, started by `QuantBook`
2019-10-10 19:28:33 -03:00
Gerardo Salazar
e38e553d1c Add new fields to Smart Insider enums (EventType, ExecutionHolding) (#3706)
* Add new fields to Smart Insider enums (EventType, ExecutionHolding)

* Reroutes Error variant to SatisfyStockVesting in ExecutionHolding
* Adds additional documentation clarifying unknown fields
* Adds unit tests for Intentions and Transactions
* Enables SEC test that was disabled

* Self review - Fix typo in SmartInsiderEventType

* Self-review: Add additional documentation to missing SmartInsiderEvent fields
2019-10-10 13:29:53 -07:00
Jared
2920ad148f Merge pull request #3705 from simonsonjack/bug-Update-AlphaStreamsSlippageModel
Bug update alpha streams slippage model
2019-10-10 13:20:29 -07:00
Jack Simonson
775251cc9c Update SlippageModelsTests.cs 2019-10-10 11:51:22 -07:00
Jack Simonson
44a6fd08d4 Update SlippageModelsTests.cs 2019-10-10 11:44:08 -07:00
Jack Simonson
a8c81714a1 Fee Model bug fix
Fixed a bug in the fee model and added slippage test for hard-coded slippage values
2019-10-10 11:34:24 -07:00
Jack Simonson
d87fce19a0 Update AlphaStreamsFeeModel.cs
Small tidying up of code, no performance fixes
2019-10-10 11:03:21 -07:00
Jack Simonson
9b62b50c2f Update AlphaStreamsSlippageModel.cs
Fix bug to return slippage value for hard-coded symbols rather than return as a percent.
2019-10-10 10:59:49 -07:00
Jack Simonson
af57933c2c Update unit tests
Update fee and slippage unit tests to use IB Fee unit tests and new AS slippage
2019-10-10 09:14:00 -07:00
Jack Simonson
f63f3992ab Update AlphaStreamsSlippageModel.cs
Change slippage to 1 basis point
2019-10-10 09:08:08 -07:00
Jack Simonson
187503bfa1 Update AlphaStreamsFeeModel.cs
Use IB fee model for Alpha Streams Fee Model. Change some syntax to use switch statement for all security types
2019-10-10 09:05:59 -07:00
Jack Simonson
1374409b29 Update AlphaStreamsSlippageModel.cs
Hard-code slippage values for low-liquidity ETFs. Switch to 5bp slippage model for any other equity as 10bp was seen as too-high of a penatly.
2019-10-10 08:18:36 -07:00
AlexCatarino
5a85fd1b8e Uses Self-Hosted Packages 2019-10-10 15:35:29 +01:00
Jared
fb296e28d9 Merge pull request #3704 from QuantConnect/research-improvements
QuantBook improvements
2019-10-09 17:32:36 -07:00
Martin Molinero
4010c0b815 QuantBook improvements
- Initialize API
- Set log handler from config
- Add default backtest id
2019-10-09 20:37:10 -03:00
AlexCatarino
63cc139aef Adds New Python Packages
- creme: https://github.com/creme-ml/creme
- scikit-multiflow: https://scikit-multiflow.github.io/scikit-multiflow/index.html
- PuLP: https://pypi.org/project/PuLP/
- PyMC3: https://docs.pymc.io
- PyPortfolioOpt: https://pypi.org/project/pyportfolioopt/
- gensim: https://radimrehurek.com/gensim/
- Fasttext: https://fasttext.cc/

- Upgrades Numpy and Wrapt
- Changes installation order to  facilitate package dependency solving
- We get the latest odo package from Blaze due to a incompatibility with pandas 0.23.4
2019-10-10 00:01:14 +01:00
Laur Aliste
2b60bec586 Dockerfile-foundation: install hmmlearn globally
Fixes #3684
2019-10-09 23:51:31 +01:00
Jared
b2e4cdb09b Merge pull request #3702 from QuantConnect/bug-update-regression-algorithms
Update regression test after new crypto lot size
2019-10-09 15:33:07 -07:00
Jared
631fe9f5bd Merge pull request #3700 from Martin-Molinero/performance-3696-dynamicsecuritydata
Performance improvements
2019-10-09 15:32:26 -07:00
Jared
ee4bae8339 Merge pull request #3701 from goenchan/feature-notebook-logo-update
Update logo src to image with transparent background and default margins
2019-10-09 15:26:23 -07:00
Juan José D'Ambrosio
135f426ddb Update regression test after new crypto lot size 2019-10-09 17:31:29 +00:00
Ethan Lee
d565e37d92 Update logo src to image with transparent background and default margins 2019-10-09 09:42:27 -07:00
Martin Molinero
0f595efa1f Performance improvements
- Only define `DEBUG` is `SelectedOptimization` is not defined
- `DynamicSecurityData` will Keep a cache of the generic types
- Avoid using so much linq at `Security.Update()`
- `Slice` will also keep a cache of the generic types
2019-10-09 11:46:21 -03:00
Jared
49960c416e Merge pull request #3698 from randomthought/bug-3697-docker-master-build-fix
Ensure docker build is not failing due to not finding the extracted d…
2019-10-09 07:28:35 -07:00
Malcolm Mulong
de88a13555 Commenting out steps 1. 2019-10-09 00:26:05 -07:00
Malcolm Mulong
a8c07013db Proper tab alignment 2019-10-09 00:24:49 -07:00
Malcolm Mulong
0ea12fa74f Ensure docker build is not failing due to not finding the extracted directory. 2019-10-09 00:06:29 -07:00
Jared
93a7eec38d Merge pull request #3693 from gsalaz98/bug-3692-smartinsider-use-enum-values
Change Smart Insider transactions/intentions classes to use enums
2019-10-08 16:40:07 -07:00
Jared
acb946b2df Merge pull request #3695 from Martin-Molinero/bug-3694-csharp-research-enviroment
Update CSharp research template and loading script
2019-10-08 16:39:56 -07:00
Gerardo Salazar
b37b299312 Self-review: updates Smart Insider intention variable name
* Updates typo in documentation
2019-10-08 15:48:15 -07:00
Martin Molinero
2b1c93ff7c Update CSharp research
- Update `.csx` assembly loader
- Fix for template notebook
2019-10-08 19:36:04 -03:00
Gerardo Salazar
f5999f794e Change Smart Insider transactions/intentions classes to use enums
* Adds and removes various fields from enums to represent data accurately
* Renames various variables
* Changes algorithms to work with new changes
* SmartInsider transaction/intention docs updated
* Added new enum values to represent pieces of data
2019-10-08 15:14:27 -07:00
Jared
2e9cdef97c Merge pull request #3690 from QuantConnect/bug-3689-option-bid-ask-prices-override
Allow Option BidPrice or AskPrice to have zero value
2019-10-08 14:49:35 -07:00
Jared
d08f893658 Merge pull request #3686 from QuantConnect/issue-3360-au200aud-and-sg30sgd-issue-in-mhdb
Update SG30SGD Exchange time zone
2019-10-08 13:50:36 -07:00
Jared
d2c4dbd7c9 Merge pull request #3646 from Martin-Molinero/bug-3608-alternative-securitytype
Match 'alternative' data paths to SecurityType.Base
2019-10-08 13:40:19 -07:00
Stefano Raggi
7a7319e108 Allow Option BidPrice or AskPrice to have zero value 2019-10-08 21:32:40 +02:00
Martin Molinero
5b85d1edbf Address review
- Add `alternative` LeanData unit tests
- Fix implementation so new unit tests pass
2019-10-08 16:00:08 -03:00
Juan José D'Ambrosio
39296d331e Update SG30SGD Exchange time zone 2019-10-08 15:42:42 +00:00
Martin Molinero
a063eb2a5f Match alternative to SecurityType.Base
- 'alternative' is used in Lean data paths and should be matched to
SecurityType.Base
- Adding unit tests
2019-10-08 11:51:22 -03:00
Jared
cc336c18c1 Merge pull request #3677 from QuantConnect/bug-3676-backtestingfuturechainprovider-contract-list-resolution
BacktestingFutureChainProvider contract list resolution
2019-10-07 16:10:24 -07:00
Jared
dbb74ddee3 Merge pull request #3683 from gsalaz98/bug-update-sec-smartinsider-demo-algorithms-remove-universe-liquidate
Updates SEC and Smart Insider AltData demo algorithms
2019-10-07 16:06:28 -07:00
Gerardo Salazar
5ecc8d4696 Updates SEC and Smart Insider demo AltData algorithms to remove custom data from universe
* Updates Smart Insider demo algorithm end date for presentation
purposes of the equity curve

* Adds liquidation logic to SEC and Smart Insider demo algorithms
2019-10-07 15:05:21 -07:00
Jared
470874a68c Merge pull request #3681 from gsalaz98/feature-add-sec-demonstration-algorithm
Add SEC demonstration algorithms (C# and Python)
2019-10-07 14:35:30 -07:00
Jared
e2e796f736 Merge branch 'master' into feature-add-sec-demonstration-algorithm 2019-10-07 14:32:48 -07:00
Jared
20f9b57a94 Merge pull request #3680 from gsalaz98/feature-add-smartinsider-demonstration-algorithm
Adds Smart Insider demonstration algorithms (C# and Python)
2019-10-07 14:32:02 -07:00
Jared
38fef12717 Merge branch 'master' into feature-add-smartinsider-demonstration-algorithm 2019-10-07 13:39:30 -07:00
Jared
4832ef8ee0 Merge pull request #3679 from gsalaz98/feature-add-us-treasury-yield-curve-demonstration-algorithm
Adds demonstration algorithms for USTreasuryYieldCurveRate (C# and Py)
2019-10-07 13:38:48 -07:00
Martin Molinero
6e92e56b78 Allow intraday QuantBook history requests 2019-10-07 17:12:40 -03:00
Martin Molinero
d8e41c67ee Add support for Contract History requests
- Improve usage of `QuantBook.GetOptionHistory()` and
`GetFutureHistory()` allowing to send in specific contracts
2019-10-07 16:10:00 -03:00
Gerardo Salazar
5d62c03a0f Add SEC demonstration algorithms (C# and Python) 2019-10-07 11:02:21 -07:00
Martin Molinero
e6a7ab9c97 BacktestingFutureChainProvider contract list resolution
- The `BacktestingFutureChainProvider` will check Quote files and
OpenInterest files are not present, some futures are missing these
files.
2019-10-07 13:49:28 -03:00
Jared
5a04c5a9de Merge pull request #3673 from QuantConnect/bug-3671-back-comp-py-custom-indicator
Implements Backward Compatibility for Python Custom Indicator
2019-10-06 16:41:10 -07:00
Gerardo Salazar
77ea64bf97 Adds demonstration algorithms for USTreasuryYieldCurveRate (C# and Py) 2019-10-04 17:28:52 -07:00
Gerardo Salazar
7f267ed55b Adds Smart Insider demonstration algorithms (C# and Python) 2019-10-04 17:10:01 -07:00
AlexCatarino
eb571937b2 Implements Backward Compatibility for Python Custom Indicator 2019-10-04 19:12:11 +01:00
Jared
fbd88b20b0 Merge pull request #3670 from QuantConnect/bug-3668-fix-sparse-data-source-outputting-log
Fixes custom data logging missing file error even when marked as sparse
2019-10-03 16:52:31 -07:00
Jared
def14b9a1f Merge pull request #3669 from QuantConnect/feature-3650-etf-basket-modules
Improves ETF Basket Universe Selection Models
2019-10-03 16:06:18 -07:00
Gerardo Salazar
7f3ebffc62 Check if data source is sparse before logging missing file error 2019-10-03 15:45:28 -07:00
AlexCatarino
ff00e9e776 Adds Regression Algorithms for InceptionDateUniverseSelectionModel
Adds Regression Algorithms to show `CustomUniverseSelectionModel` and `InceptionDateUniverseSelectionModel` in action.
2019-10-03 23:32:16 +01:00
AlexCatarino
ee7e71e63c Improves ETF Basket Universe Selection Models
- Creates `CustomUniverseSelectionModel` that mimics `QCAlgorithm.AddUniverse(String, Func<DateTime, IEnumerable<string>>)`
- Replaces `BaseETFUniverse` for `InceptionDateUniverseSelectionModel` that inherits from `CustomUniverseSelectionModel`
- ETF Basket USMs inherits from `InceptionDateUniverseSelectionModel`
2019-10-03 23:26:43 +01:00
Jared
db020b8ecf Merge pull request #3667 from gsalaz98/feature-add-psychsignal-demonstration-algorithms
Adds PsychSignal demonstration algorithms
2019-10-03 15:23:56 -07:00
Jared
efa6f3cf22 Remove unused variable 2019-10-03 15:23:26 -07:00
Jared
f7c97d66d8 Removed unused variable 2019-10-03 15:22:43 -07:00
Gerardo Salazar
48f6372a6a Adds PsychSignal demonstration algorithms 2019-10-03 14:59:14 -07:00
Jared
6277abd731 Merge pull request #3649 from QuantConnect/issue-3610-update-symbol-properties-database-with-new-crypto-symbols
Add new crypto pairs for both exchanges
2019-10-03 13:26:53 -07:00
Jared
38bdc8aed9 Merge pull request #3660 from gsalaz98/bug-3659-tradingeconomics-calendar-downloader-failing-2019-10-01
Fixes Failing Trading Economics Processing For 2019-10-01
2019-10-03 13:24:02 -07:00
Jared
da05468a6d Merge pull request #3664 from simonsonjack/bug-Remove-Volatility-Ticker
Update VolatilityETFUniverse.cs
2019-10-03 13:23:32 -07:00
Jared
8f07b1bd52 Merge pull request #3666 from gsalaz98/feature-add-tradingeconomics-data-demo-algorithms
Adds Trading Economics Demonstration Algorithms
2019-10-03 13:23:10 -07:00
Jared
d5050ff6d5 Merge branch 'master' into feature-add-tradingeconomics-data-demo-algorithms 2019-10-03 13:22:14 -07:00
Jared
ddabbdf47a Merge pull request #3665 from gsalaz98/feature-add-tiingo-news-data-demo-algorithms
Adds Demonstration Tiingo NLP Algorithms
2019-10-03 13:21:24 -07:00
Gerardo Salazar
ba21d1e1bb Adds Trading Economics demonstration algorithms 2019-10-03 13:20:07 -07:00
Gerardo Salazar
db3f0df01b Self review: Rename Tiingo algorithms from TiingoNLPDemonstrationAlgorithm to
TiingoNewsAlgorithm
2019-10-03 12:06:04 -07:00
Gerardo Salazar
b61377cd37 Adds demonstration Tiingo NLP Algorithms
* Adds `AltData` folder to Algorithm.CSharp|Python
2019-10-03 11:35:56 -07:00
Jack Simonson
fc52d9e730 Update VolatilityETFUniverse.cs
Removes DUST, which is an ETF tracking gold mining activity.
2019-10-03 11:04:09 -07:00
Gerardo Salazar
7f2d9fa411 Cleanup Trading Economics Calendar Downloader code
* Check for invalid values in ParseDecimal to prevent crashes
2019-10-03 10:55:16 -07:00
Jared
22264ab128 Merge pull request #3663 from gsalaz98/feature-psychsignal-data-rename
Renames PsychSignalSentimentData to PsychSignalSentiment
2019-10-03 10:14:29 -07:00
Gerardo Salazar
c608514aea Renames PsychSignalSentimentData to PsychSignalSentiment
Fixes Python PsychSignal algorithm

Fixes regression algorithm statistics
2019-10-03 09:47:25 -07:00
Jared
5f5a14c6f3 Merge pull request #3661 from QuantConnect/feature-3658-dynamic-security-data-python-accessors
Dynamic security data python accessors
2019-10-03 07:48:58 -07:00
Martin Molinero
5fdbc04888 DynamicSecurity python accessors
- Add DynamicSecurity python accessors
- Adding unit tests
2019-10-02 23:42:45 -03:00
Jared Broad
5a3766e438 Scaffolding for python friendly accessors 2019-10-02 23:42:45 -03:00
Martin Molinero
0b9862a7a7 Fix for PythonSlice 2019-10-02 23:22:52 -03:00
Jared
638af4186f Fix incorrect ticker 2019-10-02 17:52:31 -07:00
Gerardo Salazar
7a453200a2 Fixes failing Trading Economics processing for 2019-10-01 2019-10-02 17:02:42 -07:00
Martin Molinero
57a0934e78 Reduce dynamic usage 2019-10-02 20:03:44 -03:00
Martin Molinero
ec203be632 Self review - improvement 2019-10-02 18:25:20 -03:00
Martin Molinero
a349f619a0 Add Slice.Get(Type) for python
- Adding `Slice.Get(Type)` and `Slice.Get(Type, Symbol)` for python use case
- Adding unit tests
2019-10-02 18:19:44 -03:00
Jared
43e4b8d6b3 Merge pull request #3643 from simonsonjack/bug-update-AlphaStreamsBrokerageModel
Update AlphaStreamsFeeModelTests.cs
2019-10-02 10:53:44 -07:00
Juan José D'Ambrosio
e20e461a02 Update failing tests
As our previous lot sizes values were much smaller than the one in the exchanges, many test failed because of rounding.
2019-10-02 16:57:46 +00:00
Jared
baeb8741fc Merge pull request #3654 from Martin-Molinero/bug-3652-tiingo-news-backtesting-time
Add TiingoNews.HistoricalCrawlOffset
2019-10-02 09:50:14 -07:00
Jared
8e1a547540 Merge pull request #3655 from simonsonjack/bug-Remove-duplicate-US-treasury-ticker
Update USTreasuriesETFUniverse.cs
2019-10-02 09:48:37 -07:00
Jack Simonson
3cf8a3c95f Update USTreasuriesETFUniverse.cs
Remove duplicate ticker from the universe.
2019-10-02 09:46:32 -07:00
Martin Molinero
a9f3993e32 Address reviews 2019-10-02 13:33:36 -03:00
Martin Molinero
d1abefc1fe Add TiingoNews.HistoricalCrawlOffset - Rename
- Add `TiingoNews.HistoricalCrawlOffset`, timespan to add for
backtesting
- Rename:  remove `Data` from `TiingoNewsData` and rename `TiingoDailyData` to `TiingoPrice`
2019-10-02 13:11:31 -03:00
Jared
a68553bf73 Merge pull request #3653 from QuantConnect/feature-3650-etf-basket-modules
Adds ETF Basket Universe Selection Models
2019-10-02 08:14:46 -07:00
AlexCatarino
163fddcf75 Adds ETF Basket Universe Selection Models
Adds `BaseETFUniverseSelectionModel` that handles the common universe selection logic for all ETF Basket.
Adds the following ETF Baskets:
- Energy
- Precious Metals
- S&P500 Sectors
- Technology
- US Treasuries
- Volatility
2019-10-02 14:53:58 +01:00
Jared
0b3381b9d3 Merge pull request #3642 from Martin-Molinero/bug-3572-benchmark-equity-custom-ticker-colission
SetBenchmark will check SymbolCache for ticker
2019-10-01 15:35:53 -07:00
Jared
9621d1f890 Update readme.md 2019-10-01 15:35:33 -07:00
Jared
42e3b34ea7 Merge pull request #3648 from QuantConnect/feature-3547-symbol-pandas-data-frame-key
Add support for Symbol as key for Pandas dataframe
2019-10-01 14:54:50 -07:00
Martin Molinero
1cb4856557 Add support for Symbol as key for Pandas dataframe
- Improve user experience allowing users to use `Symbol` instance as key
for pandas data frame
2019-10-01 18:43:38 -03:00
Juan José D'Ambrosio
75b360411e Add new crypto pairs for both exchanges
Changes in this PR were made based in data from CoinApi, and data from exchanges API.
2019-10-01 21:39:34 +00:00
Jack Simonson
4811fc3aec Update AlphaStreamsFeeModel.cs
Includes forgotten AS Fee Model changes
2019-10-01 11:15:57 -07:00
Jack Simonson
277543dc91 Update AlphaStreamsFeeModelTests.cs
Update AS Fee Model tests to use proper Crypto and CFD constructors.
2019-10-01 11:02:35 -07:00
Martin Molinero
73eaa60785 SetBenchmark will check SymbolCache for ticker 2019-10-01 14:15:58 -03:00
Jared
fa6509dd5e Merge pull request #3630 from StefanoRaggi/gdax-symbol-properties-fix
Fix GDAX entries in symbol properties database
2019-10-01 10:00:50 -07:00
Jared
16eb0c3196 Merge pull request #3624 from QuantConnect/bug-1436-market-hours-db-late-opens
Add support for Late Opens in market hours database
2019-10-01 09:27:26 -07:00
Jared
b946de2110 Merge pull request #3636 from QuantConnect/bug-3633-update-travis-mono-version
Update Travis mono version
2019-10-01 09:21:28 -07:00
Jared
4c17b30391 Merge pull request #3638 from QuantConnect/feature-3626-tiingo-news-data-converter
Tiingo news data
2019-10-01 09:17:33 -07:00
Jared
16a474fd58 Merge pull request #3640 from StefanoRaggi/bug-3639-add-missing-invariant-usages
Add missing Invariant usages in alpha models and unit tests
2019-10-01 07:49:32 -07:00
Stefano Raggi
d3f5e115e0 Add missing Invariant usages in alpha models and unit tests 2019-10-01 11:00:04 +02:00
Jared
9de637d761 Merge pull request #3637 from Martin-Molinero/feature-3634-lean-custom-data-types-timezones
Adding BaseData.DataTimeZone()
2019-09-30 21:15:37 -07:00
Martin Molinero
de9b28b654 Adding processing date parameter - UTC timezone
- Setting UTC timezone for TiingoNewsData
- Adding processing data parameter
2019-10-01 00:26:37 -03:00
Martin Molinero
b7f5abc43e Address reviews and improvements
- Adding new `TemporaryPathProvider`. Helper class that will provide and
clean temporary paths
- Some code clean up
2019-10-01 00:26:36 -03:00
Martin Molinero
65737297c7 Adding Tiingo new data converter 2019-10-01 00:26:36 -03:00
Martin Molinero
c9a189ae3d Add Tiingo news data
- Add Tiingo news data
- Add `IndexSubscriptionDataSourceReader` that will handle data source
which use and index file
- Add `BaseSubscriptionDataSourceReader` to avoid code duplication
- Adjustments at `LiveCustomDataSubscriptionEnumeratorFactory` so that
custom data in a collection format does not emit old data
- Adding `TiingoNewsJsonConverter`
- Adding unit tests
2019-10-01 00:26:36 -03:00
Martin Molinero
276ae796bf Adding BaseData.DataTimeZone()
- Adding `BaseData.DataTimeZone()` with the objective of allowing custom
data types to determine their data time zone.
2019-10-01 00:25:26 -03:00
Martin Molinero
af6cc80b48 Adding BaseData.DataTimeZone()
- Adding `BaseData.DataTimeZone()` with the objective of allowing custom
data types to determine their data time zone.
2019-09-30 23:59:36 -03:00
Jared
d8da446065 Merge pull request #3631 from mchandschuh/feature-3620-cache-custom-deriv-data-in-underlying
Add DynamicSecurityData and cache derivative custom data in underlying
2019-09-30 17:23:58 -07:00
Michael Handschuh
f20fab2e39 Use ConcurrentDictionary in DynamicSecurityData
This is a safety precaution to avoid any potential shenanigans w/
multi-threaded access.
2019-09-30 20:19:29 -04:00
Michael Handschuh
362826988f Improve DynamicSecurityData usability
Adds IRegisteredSecurityDataTypesProvider to track all the data types
registered in the algorithm. Using this data, we can detect if it's
possible that we'll eventually have a property of a certain type name.
For example, consider I wish to use security.Data.TradeBar but we haven't
received any trade bars yet. Before this change a KeyNotFoundException
would be raised, but since we can determine that we expect to have trade
bars, we can detect this and return an empty list when we haven't received
any data yet. This also removes the need to constantly do a HasData<T>()
check before accessing the dynamic members.

Closes #3620
2019-09-30 19:06:21 -04:00
Jared
bfd6a60b02 Merge pull request #3632 from simonsonjack/feature-AlphaStreamsSlippageModel
Feature alpha streams slippage model
2019-09-30 15:15:42 -07:00
Jared
b33941e431 Update AlphaStreamsFeeModel.cs 2019-09-30 15:14:40 -07:00
Martin Molinero
32739df398 Update Travis mono version 2019-09-30 18:39:01 -03:00
Jack Simonson
b7cbab7ab1 Changes to ensure successful build 2019-09-30 13:57:46 -07:00
Jack Simonson
65bfc0966a Update brokerage model to handle more security types
Revert some Brokerage Model changes to ensure that security types other than equities are handled. Deleted unnecessary files and sub-directory in the Lean/Brokerages directory.
2019-09-30 13:40:06 -07:00
Jack Simonson
2285b51656 Update AlphaStreamsSlippageModel.cs
Further cleaning
2019-09-30 11:57:18 -07:00
Jack Simonson
2055625c6d Update AlphaStreamsSlippageModel.cs
Simplify conditional statements
2019-09-30 11:54:24 -07:00
Jack Simonson
fee88bf8b8 Update AlphaStreamsSlippageModel.cs
Modification to handle Tick types for Equities
2019-09-30 11:51:21 -07:00
Jack Simonson
307224ec9a Create new AlphaStreams Brokerage model
Implements basic AS brokerage model, slippage model, and updates the fee model to be sufficient for the competition and provide a skeleton for future additions.
2019-09-30 11:33:36 -07:00
Michael Handschuh
8c1867193b Add Security.Data => DynamicSecurityData
Provides dynamic access to cached security data keyed by the type's name.
For example, `security.Data.GetAll<Tick>()` would yield a list of ticks.
Likewise, using the dynamic accessors, `((dynamic)security.Data).Tick`
would return the same list. In C# you'll need to cast security.Data to
a dynamic. In python, all C# objects are viewed as dynamic, so python can
simply access `security.Data.Tick` directly.

See #3620
2019-09-30 13:31:56 -04:00
Michael Handschuh
1f02e1f3b3 Extract GetSetPropertyDynamicMetaObject from DynamicData
We'll reuse this meta object implementation for the new SecurityData dynamic
type.
2019-09-30 13:31:55 -04:00
Michael Handschuh
aa03f0739d Update SecurityCache to hold list and save custom derivatives
Custom derivative data is now being saved into the underlying security's
cache. This makes the custom derivative data available via the underlying's
security object via underlying.Cache.Get<T> where T is the custom data type.
2019-09-30 13:31:55 -04:00
Michael Handschuh
fbc0a22355 Provide detailed regression algorithm portfolio logging
I noticed some deltas in regression statistics after a change. Before this
change, we log all orders into an {AlgorithmName}.{Language}.orders.log.
This information turned out to be insufficient to identify the regression.
This change also adds daily logging of portfolio value and each security's
holding quantity/value, as well as the full cash book. This should help to
more quickly identify the root cause behind system regression test failures.
2019-09-30 12:30:26 -04:00
Michael Handschuh
e01cf07368 Remove unnecessary cast to double
RoundToSignificantDigits is implemented both for doubles and decimal
types, so there's no need to cast this to a double here and can only
introduce rounding errors. Now, it's unlikely that those rounding
errors would show themselves in the first 7 digits, unless of course
it's a serial case such as 0.1 which is notoriously non-representable
as a binary floating point number.
2019-09-30 12:30:26 -04:00
Michael Handschuh
033c1d3eab Remove double Invariant
Looks like some copy/pasta when initially implementing invariant culture
enforcement. This change simply removes an extra Invariant(...) call
since the one line has them doubled up.
2019-09-30 12:30:26 -04:00
Michael Handschuh
e5c71d8011 Add ToString impl for common data types
All of these types were relying on BaseData.ToString() and therefore
were only providing minimal amounts of data. I'm using these to improve
our ability to diff regression runs to help identify why regression
statistics may have changed.
2019-09-30 12:30:26 -04:00
Jared
fd9c4a4911 Merge pull request #3629 from QuantConnect/bug-3628-last-data-point-being-discarded
Fix subscription last data point being discarded in some cases
2019-09-30 09:19:47 -07:00
Jared
be2fe87c08 Merge pull request #3530 from IlshatGaripov/bitfinex-brokerage-get-history-improve-the-loop
**
2019-09-30 09:05:33 -07:00
Jared
1cfe7d0075 Merge branch 'master' into bitfinex-brokerage-get-history-improve-the-loop 2019-09-30 09:05:16 -07:00
Stefano Raggi
9341ea2a47 Fix Oanda forex market hours
- Fixed early closes time zone (must be exchange time zone)
- Added late opens for Christmas and New Year (2018-2019)
2019-09-30 16:28:36 +02:00
Stefano Raggi
db2f4eb624 Fix GDAX entries in symbol properties database 2019-09-30 14:42:31 +02:00
Martin Molinero
2f4929e685 Update regression algorithms 2019-09-29 21:50:44 -03:00
Martin Molinero
cc71c9fa5b Perform late OnSubscriptionFinished
- `SubscriptionSynchronizer` will call `OnSubscriptionFinished` for
subscriptions that added a data point to the packet after creating the
`TimeSlice` to avoid dropping the last data point.
2019-09-29 21:48:44 -03:00
Jack Simonson
86843ff05f Create AlphaStreamsSlippageModel.cs
Rudimentary implementation of AS slippage model. Will likely need expanded on, but provides framework for Equity slippage for the competition.
2019-09-27 17:48:52 -07:00
Jared
a1fcd9ea9c Merge pull request #3627 from mchandschuh/bug-3618-fix-exception
Fixes bug introduced by #3618
2019-09-27 14:50:40 -07:00
Michael Handschuh
2df4ef45f3 Fixes bug introduced by #3618 2019-09-27 17:45:58 -04:00
Jared
6ca47e010d Merge pull request #3623 from mchandschuh/feature-3618-add-sparse-data-flag
Feature 3618 add sparse data flag
2019-09-27 12:55:45 -07:00
Michael Handschuh
f79e40f0a3 Raise InvalidSource when reader is empty
Updates CollectionSubscriptionDataSourceReader to raise InvalidSource event
when a created reader is empty. The most common case for this to happen is
when the file is not found.

See #3618
2019-09-27 15:26:36 -04:00
Stefano Raggi
4d3923e47c Add support for Late Opens in market hours database 2019-09-27 20:43:40 +02:00
Michael Handschuh
757c37f6db Add equity AAPL underlying to EstimizeDataAlgorithm
See #3618
2019-09-27 14:28:47 -04:00
Michael Handschuh
f3611019e1 Log file not found only for dense data sets
Moves the FNF logging out of the DefaultDataProvider and into the
CreateStreamReaderError event handler. This move was required since
we don't have the required data in scope to perform this conditional
logging.

See #3618
2019-09-27 14:28:47 -04:00
Michael Handschuh
f7034aa9d7 Add SubscriptionDataConfig GetBaseDataInstance extension method
Updates usages of GetBaseDataInstance that have a config in scope to use this
new method. This method properly assigns the symbol to the newly created base
data instance. This enables some of the new flag methods to work as expected.
Updated other poor usages where we weren't setting the symbol property.

See #3618
2019-09-27 14:27:08 -04:00
Michael Handschuh
7807ae7af6 Add BaseData.IsSparseData
Flags a particular data type as having a sparse data set, meaning,
we don't expect it to have data for every single day. We'll use
this to prevent spamming log messages
2019-09-27 14:24:08 -04:00
Michael Handschuh
c1ee66e26d Use auto-properties in BaseData
See #3618
2019-09-27 14:24:08 -04:00
Jared
6b2b802e57 Merge pull request #3596 from gsalaz98/feature-3595-normalize-tradingeconomics-calendar-data
Implement Data Normalization/Parsing for Trading Economics Calendar Data
2019-09-27 06:14:44 -07:00
Jared
dd7796b156 Merge pull request #3534 from olegsheyner/feature-3533-improve-extensibility-framework-fillmodel
Feature 3533 improve extensibility framework fillmodel
2019-09-26 17:40:37 -07:00
Jared
78facffb77 Merge pull request #3605 from mchandschuh/bug-3603-thread-safe-consolidator-collection
Use thread safe consolidator collection in SubscriptionDataConfig
2019-09-26 14:25:27 -07:00
Martin-Molinero
ad30e62607 Merge pull request #3614 from gsalaz98/bug-3613-smartinsider-add-processed-files-directory
Fixes issue in SmartInsider where we could not choose where the final processed directory is
2019-09-26 13:48:05 -03:00
Gerardo Salazar
5e43ef4967 Address review - update log message 2019-09-26 09:27:37 -07:00
Gerardo Salazar
4fc81956d1 Address review and changes documentation 2019-09-26 08:34:23 -07:00
Gerardo Salazar
288aaf8ac8 Address review - Update outdated documentation 2019-09-25 16:45:43 -07:00
Jared
45ffbb393f Merge pull request #3600 from QuantConnect/issue-3599-add-christmas-and-new-year-eve-to-oanda-forex-mhdb
Update market-hours-database.json
2019-09-25 15:15:49 -07:00
Gerardo Salazar
1e10cf7f7e Fixes issue in SmartInsider where we could not choose where the final processed directory is. 2019-09-25 15:06:25 -07:00
Juan José D'Ambrosio
a2d8cc74e0 Fix holidays and Early closes
All changes in this commit were based on the actual data. 
For early closes,  check the previous date last available data to define the close time. Also checked for boxing day for years were the New year eve was on weekend days.
For holidays dates, I checked the raw data and our processed data for observations. And in the cases I found ticks, I consider it was *not* a holiday. Worth noticing that in many cases the ticks start later.

It is somehow expected in FX markets, givens its global market hours. E.g., Sydney opens its markets 20xx-01-20 at 9:30 in a good part of the world it is still January 1st.
2019-09-25 17:50:00 +00:00
Michael Handschuh
32077c0ddf Use ConcurrentSet<T> for SubscriptionDataConfig.Consolidators
Fixes #3603
2019-09-25 02:28:20 -04:00
Michael Handschuh
0564d1e327 Add ConcurrentSet<T>
See: # 3603
2019-09-25 02:28:20 -04:00
Gerardo Salazar
ad784a2633 Fix wrong start date in Trading Economics
Add designator to parse values as percentages

Add new unit test cases
2019-09-24 17:42:06 -07:00
Gerardo Salazar
14214ab164 Add missing file 2019-09-24 15:52:38 -07:00
Gerardo Salazar
46d9546f56 Address reviews 2019-09-24 15:42:35 -07:00
Martin-Molinero
d52a05fd9a Merge pull request #3601 from StefanoRaggi/build-fsharp-missing-reference
Add missing reference in Algorithm.FSharp
2019-09-24 17:45:30 -03:00
Juan José D'Ambrosio
0cbf149ddc Add early closes before New year 2019-09-24 20:12:44 +00:00
Juan José D'Ambrosio
cef91ebab3 Update market-hours-database.json
Update market-hours-database.json
Update market-hours-database.json
2019-09-24 20:05:16 +00:00
Stefano Raggi
8d2904fb20 Add missing reference in Algorithm.FSharp
Although the Algorithm.FSharp project is excluded from the default Lean build, the reference to StringInterpolationBridgeStrong is required to build the project.
2019-09-24 21:13:17 +02:00
Martin-Molinero
d6eb72fa45 Merge pull request #3588 from QuantConnect/feature-adddata-symbol-ticker-underlying-linking
Mapped Alt Data Support w/SID Collision Avoidance
2019-09-24 11:59:48 -03:00
Martin Molinero
851d02c527 Update PythonNet version - Revert work around 2019-09-24 11:18:46 -03:00
Gerardo Salazar
7e2b69db98 Update regression tests statistics and trades placed 2019-09-24 10:34:35 -03:00
Martin Molinero
e887c9f6b4 Normalize wrapt version being used 2019-09-24 10:34:35 -03:00
Gerardo Salazar
ba424cd5b6 Fix failing regression algorithm tests - associated issue is #3597 2019-09-24 10:34:35 -03:00
Gerardo Salazar
56462f0283 Address reviews from Mike and Martin
* Added better documentation for AddData methods
* Added new regression algorithms for adding in OnSecuritiesChanged
* Changed regression algorithms to add data that exists
* Styling and logging fixes
2019-09-24 10:34:35 -03:00
Gerardo Salazar
e785f95eee Address Martin and Mike's review from PR 3580 2019-09-24 10:34:35 -03:00
Gerardo Salazar
4b0ed03b4f Added new regression algorithms
* Deleted regression algorithms because they tested behavior similar to
other existing regression algorithms
* Fixed new bug in regression algorithm due to AddData changes
* Added unit tests for wrapt version and package existence

* Fix issue where data would be set to raw normalization mode
2019-09-24 10:34:35 -03:00
Gerardo Salazar
9265bfe065 Implement C# AddData Symbol method equivalents
* Implement method precedence hack on two additional python methods
* Changed behavior of SymbolCache loading with a ticker
	- Previously, we would search the cache with ticker for types that did not
	require mapping.
* Added new documentation
* Code cleanup
* Change first date to be SID.DefaultDate if SecurityType isn't expected
* Modified AddData tests to meet expectations. AddData unit tests are passing
2019-09-24 10:34:35 -03:00
Gerardo Salazar
9d052afcf3 Work in progress commit
* Added new method for Symbol to allow creation with underlying
* Added new unit tests
* Alter SecurityIdentifier method signature for BaseData
* AddData changes to accept underlying Symbol
* Added AddDataImpl
2019-09-24 10:34:35 -03:00
Gerardo Salazar
48e4d3660a Add unit tests for AddData for changes 2019-09-24 10:34:35 -03:00
Martin Molinero
787c8bd149 Revert collission work around 2019-09-24 10:34:35 -03:00
Martin Molinero
6fabe30317 Add backwards compatibility index.levels[0]
- Add backwards compatibility shim for the `df.index.levels[0]` use
case. Reverting broken use cases and adding unit tests.
2019-09-24 10:34:35 -03:00
Martin Molinero
b6b7720a1e Add more backwards compatible cases
- Moving mapper from C# to Python since some cases did not work when
implemented in C#
- Small changes to `PandasDataFrameHistoryAlgorithm` which runs till the
end with no errors
- Adding more backwards compatible unit tests
2019-09-24 10:34:35 -03:00
AlexCatarino
35d32ed9f4 More Tests for PR#3484 2019-09-24 10:34:35 -03:00
Martin-Molinero
4ab813d1a3 Address review fix typo 2019-09-24 10:34:35 -03:00
Martin Molinero
6a2f5b09f2 Improvements
- Add new dependency to documentation, docker files, python setup readme
- Adding backwards compatibility pandas DataFrame unit tests
- Adding missing cases for backwards compatility shim
2019-09-24 10:34:35 -03:00
Martin Molinero
8dbbbb618f Pandas and CustomData mapping fixes
- Add Pandas backwards compatibility shim
- Adding `MappingExtensions` which will remove data type from the
`Symbol.ID.Symbol` value to resolve the `MapFile`
- `SecurityIdentifier.TryParse()` will throw when given an invalid
`SecurityType`
2019-09-24 10:34:35 -03:00
Martin Molinero
50d9188c16 Fix rebase 2019-09-24 10:34:35 -03:00
Michael Handschuh
6362d101c1 Append type to custom data symbol
This is being done in an effort to prevent symbol collisions within the
custom data (SecurityType.Base) namespace. The custom data type's name,
is used for disambiguation. As written, this change will break several
user algorithms that still rely on using the implicit string -> Symbol
lift. Providing this type information is optional an currently only being
used by AddData<T> methods. Other consumers of SecurityType.Base symbols
arn't at risk for collision, such as the UserDefinedUniverse, ScheduledUniverse
and others that are LEAN controlled. In order to maintain backwards compatibility,
the SymbolCache was updated to do a hard search when the requested ticker was
not found, looking for the prefix ('ticker.').

Fixes #3332
2019-09-24 10:34:35 -03:00
Michael Handschuh
e65f718577 Enforce consistency in AddData<T> C#/Python
See #3332 - initial pre-factoring/clean-up
2019-09-24 10:34:34 -03:00
Michael Handschuh
821090c237 Refactor SecurityIdentifier's usage of IMapFileProvider
Moves the map file provider instance to a static readonly Lazy to ensure
single initialization and guarantee thread-safety without requiring an
additional locking mechanism. This change also simplifies the resolution
of the first ticker/date into it's own function vs embedding the logic
in the existing GenerateWithFirstDate method.
2019-09-24 10:34:34 -03:00
Martin Molinero
e7ca829a0d PythonNet bump 1.0.5.25 2019-09-23 19:45:46 -03:00
Gerardo Salazar
248929eb25 Implement data normalization for Trading Economics calendar data 2019-09-23 14:52:44 -07:00
Oleg Sheyner
f18ab156f7 #3533 Make IsExchangeOpen available to subclasses of QCAlgorithm 2019-09-20 16:11:23 -04:00
Jared
b84263840b Merge pull request #3582 from IlshatGaripov/unit-test-round-to-significant-digits
Provides a test for RoundToSignificantDigits Extension method.
2019-09-19 16:57:32 -07:00
Jared
5812a083c4 Merge pull request #3586 from mchandschuh/bug-3584-preserve-convert-null-to-default-value-behavior
Preserve converting null to default values in ConvertInvariant
2019-09-18 18:30:23 -07:00
Jared
c023257495 Merge pull request #3569 from Martin-Molinero/refactor-3532-rename-live-result-handler-new-json
Rename LiveTradingResultHandler json
2019-09-18 18:24:22 -07:00
Jared
36f20828bc Fix JSON file name
The L- is included in the job id, no need to add additionally.
2019-09-18 18:22:18 -07:00
Jared
1aefd2d005 Merge pull request #3570 from QuantConnect/bug-3556-coinapi-symbol-list-duplicated-symbol-breaks-converter
Fix error when CoinApi symbol list has duplicates
2019-09-18 18:20:29 -07:00
Jared
1aef17809f Merge pull request #3585 from AlexCatarino/bug-3583-remove-round-zero-message
Silences Order Quantity Rounding to Zero Message
2019-09-18 17:13:24 -07:00
Michael Handschuh
cd97f511ab Preserve converting null to default values in ConvertInvariant
Many places in the code were updated from using Convert.ToXXX to ConvertInvariant<T>.
The existing ConvertInvariant<T> implementation would throw an error when attempting
to convert a null value into a value type, such as null -> decimal. This change
preserves the null conversion behavior by delegating to the appropriate Convert.ToXXX
method under the hood.

Fixes #3584
2019-09-18 16:44:28 -04:00
AlexCatarino
5bc0572884 Silences Order Quantity Rounding to Zero Message
Sets `GetMaximumOrderQuantityForTargetValueResult.IsError` to false to silence the logging for order quantity rounding to zero in `BuyingPowerModel.GetMaximumOrderQuantityForTargetValue`.
2019-09-18 21:24:54 +01:00
IlshatGaripov
88c94da355 Provides a test for RoundToSignificantDigits Extension method. 2019-09-18 22:35:16 +03:00
IlshatGaripov
ae8f5495bf Fixes bitfinex history request last bar issue:
1) Additional warning on end time not a full round of history request resolution
2) Logic to drop the last candle that start at end TimeKeeper
3) Test now time is rounded to resolution
4) minute resolution test case period reduced to 1 min.
2019-09-18 15:49:12 +03:00
Martin-Molinero
301e676aad Merge pull request #3442 from mchandschuh/bug-3045-enforce-ca1304-ca1305-IFormatProvider-CultureInfo
Enforce usage of IFormatProvider/CultureInfo.InvariantCulture
2019-09-17 13:57:23 -03:00
Michael Handschuh
b21bfe1731 Remove trailing space from SecurityTypesPacket.cs filename
See #3045
2019-09-12 15:30:46 -04:00
Michael Handschuh
df5846569f Enforce CA1304 and CA1305 as build errors
This will cause the build to fail if overloads are available that accept
an IFormatProvider/CultureInfo that are not used. In most cases, simply
invoking the appropriate method in `StringExtensions` will do the trick.
For parsing, such `Parse<Type>Invariant` and associated methods.
For ToString-ing, use `ToStringInvariant` and `ToStringInvariant(format)`
Other culture-specific string methods are also provided, including
`StartsWithInvariant`, `EndsWithInvariant` and `IndexOfInvariant`. We
can continue to add methods to `StringExtensions` as new cases arise.

See #3045
2019-09-12 15:30:46 -04:00
Michael Handschuh
35dcec2dc4 Update Tests to respect CA1304 and CA1305
Updates all occurrences of parsing/ToString-ing to go through the new
StringExtensions methods that use CultureInfo.InvariantCulture

See #3045
2019-09-12 15:30:46 -04:00
Michael Handschuh
d21d620457 Update ToolBox to respect CA1304 and CA1305
Updates all occurrences of parsing/ToString-ing to go through the new
StringExtensions methods that use CultureInfo.InvariantCulture

See #3045
2019-09-12 15:30:45 -04:00
Michael Handschuh
e4d1005c4a Update Lean.Engine to respect CA1304 and CA1305
Updates all occurrences of parsing/ToString-ing to go through the new
StringExtensions methods that use CultureInfo.InvariantCulture

See #3045
2019-09-12 15:30:45 -04:00
Michael Handschuh
49af364055 Update Algorithm.CSharp to respect CA1304 and CA1305
Updates all occurrences of parsing/ToString-ing to go through the new
StringExtensions methods that use CultureInfo.InvariantCulture

See #3045
2019-09-12 15:30:45 -04:00
Michael Handschuh
4155f0e567 Update Brokerages to respect CA1304 and CA1305
Updates all occurrences of parsing/ToString-ing to go through the new
StringExtensions methods that use CultureInfo.InvariantCulture

See #3045
2019-09-12 15:30:44 -04:00
Michael Handschuh
30c8772a7e Update Compression/Jupyter/Launcher/Queues/UserInterface to respect CA1304 and CA1305
Updates all occurrences of parsing/ToString-ing to go through the new
StringExtensions methods that use CultureInfo.InvariantCulture

See #3045
2019-09-12 15:30:44 -04:00
Michael Handschuh
bcd358001f Update Api to respect CA1304 and CA1305
Updates all occurrences of parsing/ToString-ing to go through the new
StringExtensions methods that use CultureInfo.InvariantCulture

See #3045
2019-09-12 15:30:44 -04:00
Michael Handschuh
d8db9f9fce Update Algorithm to respect CA1304 and CA1305
Updates all occurrences of parsing/ToString-ing to go through the new
StringExtensions methods that use CultureInfo.InvariantCulture

See #3045
2019-09-12 15:30:44 -04:00
Michael Handschuh
06831afd0a Update Indicators to respect CA1304 and CA1305
Updates all occurrences of parsing/ToString-ing to go through the new
StringExtensions methods that use CultureInfo.InvariantCulture

See #3045
2019-09-12 15:30:44 -04:00
Michael Handschuh
0d4a3f3e9a Update Logging to respect CA1304 and CA1305
Updates all occurrences of parsing/ToString-ing to use CultureInfo if
possible. This project can not reference QuantConnect.Common, so it's
unable to use the new StringExtensions.

See #3045
2019-09-12 15:30:44 -04:00
Michael Handschuh
f9ddb316e6 Update Configuration to respect CA1304 and CA1305
Updates all occurrences of parsing/ToString-ing to use CultureInfo if
possible. This project can not reference QuantConnect.Common, so it's
unable to use the new StringExtensions.

See #3045
2019-09-12 15:30:44 -04:00
Michael Handschuh
d709d1c4e0 Update Common to respect CA1304 and CA1305
Updates all occurrences of parsing/ToString-ing to go through the new
StringExtensions methods that use CultureInfo.InvariantCulture

See #3045
2019-09-12 14:13:24 -04:00
Juan José D'Ambrosio
df053a4ca1 Address reviews 2019-09-12 15:12:35 +00:00
Juan José D'Ambrosio
d0a46d4d15 Put back the throws in SymbolMapper 2019-09-11 20:07:07 +00:00
Juan José D'Ambrosio
db0d0e641f Fix error when CoinApi symbol list has duplicates
We assumed CoinAPi symbol list has no duplicates, but they those cases are expected, as we can read in their docs https://docs.coinapi.io/#list-all-symbols

>  In the unlikely event when the "symbol_id" for more than one market is the same. We will append the additional term (prefixed with the "_") at the end of the duplicated identifiers to differentiate them.
Ignore files if they have the extra suffix

After asking CoinApi support,  they inform us that symbols with the extra suffix are for edge cases.
> There could be corner-cases for other data types like FUTURES or OPTIONS, e.g., exchange lists same option but one with American and other with European execution-style
2019-09-11 18:25:10 +00:00
Martin Molinero
9213852d30 Rename LiveTradingResultHandler json 2019-09-11 12:01:27 -03:00
Jared
bdf80f6f9f Merge pull request #3540 from QuantConnect/refactor-3532-live-result-handler-new-json
Adding new LiveTradingResultHandler json
2019-09-10 15:57:49 -07:00
Jared
65d5c6337d Merge pull request #3568 from QuantConnect/bug-cloud-505-py-initialization-hang
Python initialization hang - PythonNet to 1.0.5.24
2019-09-10 13:44:17 -07:00
Martin Molinero
cd9cd943f4 Empty commit 2019-09-10 14:32:00 -03:00
Martin Molinero
f96cb2a0cf Bump PythonNet to 1.0.5.24 2019-09-10 12:11:42 -03:00
Jared
c4552704cd Merge pull request #3566 from KamuelaFranco/patch-1
Update macOS instructions to include exact working version of Python@3.6.6
2019-09-09 14:00:30 -07:00
Jared
350525f3c0 Update readme.md 2019-09-09 14:00:20 -07:00
Kamuela Franco
78a9fb01a5 Update readme.md 2019-09-08 19:57:51 +01:00
Jared
a08c366fe2 Merge pull request #3563 from QuantConnect/bug-2402-python-jupiter
Python Jupyter lab improvements
2019-09-06 11:42:54 -07:00
Martin Molinero
210fc47d46 Update DockerfileJupyter 2019-09-05 23:55:30 -03:00
Martin Molinero
e396c3ef10 Bump PythonNet to 1.0.5.23 2019-09-05 23:55:30 -03:00
AlexCatarino
45c81371a3 Implements ConvertToSymbolEnumerable Extension Method
Following the convert python objects patter, it replaces `QCAlgorithm.GetSymbolsFromPyObject`.
Add unit tests.
2019-09-05 23:55:30 -03:00
Martin Molinero
d658a6ea95 Add Jupyter missing clr.pyd dependency 2019-09-05 23:55:26 -03:00
Jared
d5c5d9a86c Merge pull request #3503 from gsalaz98/bug-3499-fix-randomly-failing-rategate
Fix Randomly Failing RateGate and Add Unit Tests
2019-09-05 11:18:32 -07:00
Jared
a2ea64d20f Merge pull request #3558 from QuantConnect/bug-3557-bitfinex-brokerage-model
Allows Custom Data With BitfinexBrokerageModel
2019-09-05 11:18:06 -07:00
Jared
e0d89c20ae Merge pull request #3561 from KamuelaFranco/patch-1
Fix small typographical error
2019-09-05 11:17:43 -07:00
Kamuela Franco
cf055a7ccb Fix small typographical error 2019-09-04 23:46:22 +01:00
Gerardo Salazar
c7d4b62a4c Disable problematic RateGate test 2019-09-04 14:52:52 -07:00
AlexCatarino
70a979f7f4 Allows Custom Data With BitfinexBrokerageModel
Changes `BitfinexBrokerageModel.GetLeverage(Security)` to not throw exception for custom data types (`SecurityType.Base`).
2019-09-04 15:11:07 +01:00
Jared
cf47e88413 Merge pull request #3550 from QuantConnect/bug-3549-compression-unziptofolder
Fix Compression.UnzipToFolder
2019-09-03 17:59:22 -07:00
Martin Molinero
f00049f709 Bump PythonNet to 1.0.5.22 2019-09-03 16:05:12 -03:00
Gerardo Salazar
8eb55d136f Update RateGate test names and enable ignored test after changes 2019-09-03 08:56:21 -07:00
Gerardo Salazar
81068967dd Address review 2019-09-03 08:56:08 -07:00
Gerardo Salazar
b1f50292ad Fix randomly failing RateGate and add unit tests 2019-09-03 08:56:00 -07:00
IlshatGaripov
5d798e9bf5 In response to requested changes.
+ little enhancement for BitfinexBrokerageHistoryProviderTests
2019-09-02 16:44:04 +03:00
Martin Molinero
357b045a13 Fix Compression.UnzipToFolder 2019-08-29 19:06:02 -03:00
Jared
f6ce8a6ad8 Merge pull request #3547 from gsalaz98/feature-add-more-tradingeconomics-symbols
Extending Prewritten Helpers for Trading Economics
2019-08-29 12:09:14 -07:00
Gerardo Salazar
5f535fee99 Extending Prewritten Helpers for Trading Economics 2019-08-28 14:50:21 -07:00
Jared
35f1467268 Merge pull request #3506 from gsalaz98/bug-3504-tradingeconomics-calendar-missing-symbol
Fixes TradingEconomicsCalendar Empty Symbol In Algorithms and Non-Deterministic Crashes
2019-08-28 14:19:41 -07:00
Jared
1fd8563488 Merge pull request #3546 from QuantConnect/feature-3545-mute-python-warning-logging
Mute Python Library Warning Logging
2019-08-28 14:18:42 -07:00
Gerardo Salazar
8e93569e35 Address review - invert condition in TradingEconomicsCalendar 2019-08-28 08:44:14 -07:00
AlexCatarino
c7804423f7 Mute Python Library Warning Logging
Adds `logging.captureWarnings(True)`
2019-08-27 20:39:20 +01:00
Martin Molinero
dfe6bd28c7 Add LiveTradingResult complete json
- Adding new LiveTradingResult complete daily json file, which will be
updated at 1am UTC, after Daily Peformance gets sampled.
2019-08-26 15:49:40 -03:00
Jared
a07e580d64 Merge pull request #3536 from mortensorensen/master
Fix invalid JSON in market-hours-database.json
2019-08-26 11:46:03 -07:00
Jared
ef1b5ab414 Merge pull request #3535 from Martin-Molinero/refactor-3532-result-handler-clean-up
Move StatisticsResults into BaseResultHandler
2019-08-26 11:42:44 -07:00
Morten Sorensen
dcf53a49fa Fix invalid JSON in market-hours-database.json 2019-08-25 12:00:43 +08:00
Martin Molinero
194bed88ec Add Base.GetNetReturn method 2019-08-23 21:16:15 -03:00
Martin Molinero
573ea6ebea Address review - RuntimeStatistics 2019-08-23 20:54:22 -03:00
Martin Molinero
b1f7a40b4c Move StatisticsResults into ResultHandler 2019-08-23 19:38:00 -03:00
Oleg Sheyner
b6b8e008ee #3533 Make private methods accessible to sub-classes (QCAlgorithm, FillModel) 2019-08-23 13:58:50 -04:00
Oleg Sheyner
80611d08fa Merge branch 'master' of https://github.com/QuantConnect/Lean 2019-08-23 13:21:17 -04:00
Jared
4f752973d7 Merge pull request #3526 from Martin-Molinero/bug-3516-handle-coarse-data-unit-test
Fix enumerator Dispose chain
2019-08-22 14:34:39 -07:00
Martin Molinero
0938e9f984 Fix Dispose enumerator chain
- Adding new `SubscriptionDataEnumerator` to fix broken enumerator Dipose chain
- Adding `Dispose` calls on enumerators in unit tests
- Fix unit test HandlesCoarseFundamentalData
2019-08-22 17:25:02 -03:00
IlshatGaripov
fd22101b90 Fixes BitfinexBrokerage GetHistory() data iterator for do-while loop.
Plus, other minor fixes, including verifying 'candles' returned from exchange are not an empty set.
2019-08-22 17:36:48 +03:00
IlshatGaripov
9ad8c94d1d Adds Api keys storage fields in BitfinexBrokerageTests
Fixes Ignore attribute's message
2019-08-22 17:36:48 +03:00
Martin Molinero
36bca1d4c9 Address review 2019-08-22 11:04:57 -03:00
Jared
5accca2197 Merge pull request #3521 from QuantConnect/feature-3296-add-support-for-custom-data-mapping-v2
Add support for custom data mapping v2
2019-08-21 14:01:04 -07:00
Martin Molinero
24527e0cc2 Address reviews - Renaming 2019-08-21 16:30:03 -03:00
Jared
f9b2ab8e7f Merge pull request #3514 from Martin-Molinero/engine-code-clean-up
Engine code clean up
2019-08-21 12:12:36 -07:00
Jared
e2883f72c5 Merge pull request #3523 from Martin-Molinero/bug-2381-2260-benchmark-symbol-not-added-to-cache
Benchmark Symbol will not be added to cache
2019-08-21 12:11:15 -07:00
Jared
553453490d Merge pull request #3515 from QuantConnect/websocket-updates
Improve WebSocketWrapper diagnostics
2019-08-21 12:09:26 -07:00
Jared
47ec8dd924 Merge pull request #3525 from xinweimetrics/bug-3524-quandlfutures-remove-token
Remove Hard-Coded Token from QuandlImporterAlgorithm
2019-08-21 11:57:20 -07:00
Martin Molinero
cdcef9638e Fix unit test 2019-08-21 12:56:30 -03:00
Stefano Raggi
7a832c3006 Address review
- replaced concatenation with string interpolation in log output
- added clarifying comment for the stack frame number used
2019-08-21 09:55:48 +02:00
Martin Molinero
c5a8174d49 Address review 2019-08-20 20:55:42 -03:00
Xin Wei
baf2062667 Remove Hard-Coded Token from QuandlImporterAlgorithm
Remove Hard-Coded Token from QuandlImporterAlgorithm
2019-08-20 16:21:35 -07:00
Martin Molinero
6b00a97b0d Address review 2019-08-20 19:22:18 -03:00
Martin Molinero
7cd1c18887 Benchmark Symbol will not be added to cache 2019-08-20 18:42:31 -03:00
Martin Molinero
73d780daae Moving UsesMapFiles to DataType
- Custom data types will know whether or not Lean should use map files
- Updating regression test with sample custom data using map files,
which can run locally
- Adding unit tests for the `SubscriptionDataReaderHistoryProvider`,
checking it mappes equities and options correctly
2019-08-20 17:33:41 -03:00
Gerardo Salazar
c25bdc6a07 Address self review and mchandschuh's review 2019-08-20 16:56:02 -03:00
Gerardo Salazar
1494603cf8 Add missing checks to python regression test 2019-08-20 16:56:02 -03:00
Gerardo Salazar
e6a510d803 Add Mapfile support for custom data sources 2019-08-20 16:56:02 -03:00
Jared
2637695f9d Merge pull request #3518 from QuantConnect/issue-3517-tickers-traded-as-warrants-in-universe-selection
Add warrants to excluded tickers for Coarse Generator
2019-08-19 17:25:01 -07:00
Juan José D'Ambrosio
6552cac843 Add PSTVZ to excluded list 2019-08-19 18:13:05 +00:00
Juan José D'Ambrosio
b1875a8253 Add warrants to excluded tickers for Coarse Generator 2019-08-19 18:06:36 +00:00
Stefano Raggi
1fef996ef8 Improve WebSocketWrapper diagnostics
- added config setting for detailed WebSocketSharp logging
- added caller method name in WebSocketSharp log output
- added additional information in WebSocket Close events
2019-08-19 16:28:49 +02:00
Martin Molinero
eb9fe73ebc Engine code clean up 2019-08-16 19:09:45 -03:00
Jared
62b6659481 Merge pull request #3485 from mchandschuh/bug-3045-add-fxcop-analyzers-and-invariant-culture-helpers
Add FxCop analyzers and invariant culture helpers
2019-08-16 15:05:34 -07:00
Jared
cd59e4082a Merge pull request #3448 from Martin-Molinero/bug-3444-subscriptionfrontiertimeprovider-skips-time-step
SubscriptionFrontierTimeProvider will advance new subscriptions
2019-08-16 14:23:23 -07:00
Martin Molinero
ef445c75c2 Fix rebase 2019-08-16 18:08:59 -03:00
Michael Handschuh
c7df4e9fb3 Add StringExtensions and Parse utilizing CultureInfo.InvariantCulture
Adds static methods of the form Parse.<TypeName>(string str) that use
CultureInfo.InvariantCulture. These are to be used when parsing strings.
It's still safe (from the CA1304/CA1305 perspective) to use the ToDecimal
extension method for decimals.

Adds string extension methods for common operations that will now require
CultureInfo.InvariantCulture. These are to be used when converting values
to strings, such as ToStringInvariant()/ToStringInvariant(format), but also
useful for searching within strings, StartsWithInvariant, EndsWithInvariant
 and IndexOfInvariant.
2019-08-16 18:08:28 -03:00
Michael Handschuh
703f915182 Configure QuantConnect.ruleset in all projects
The initial ruleset is specifically aimed at addressing #3045. When we'd like
to start addressing other issues available via the FxCopAnalyzers, we can update
the action in QuantConnect.ruleset. A nice way to do it is to first set it to
warning, then go through the solution, project-by-project, fixing each warning.
At the end you can flip it to error and ensure it still builds. Moving forward,
any changes will fail if they violate the rule.

In support of #3045, we'll be configuring the following rules:
> CA1304: https://docs.microsoft.com/en-us/visualstudio/code-quality/ca1304-specify-cultureinfo?view=vs-2017
> CA1305: https://docs.microsoft.com/en-us/visualstudio/code-quality/ca1305-specify-iformatprovider?view=vs-2017
2019-08-16 18:08:18 -03:00
Michael Handschuh
c42057809d Add Microsoft.CodeAnalysis.FxCopAnalyzers to all projects
FxCop has various rulesets for enforcing things within our codebase.
For this particular issue, we'll be enforcing CA1304 and CA1305 to
ensure we're always using an IFormatProvider or a CultureInfo where
applicable.

Linked Issue: #3045
2019-08-16 18:08:05 -03:00
Michael Handschuh
3e93158713 Use proper exception types
The `NullReferenceException` type is intended to only be thrown by the CLR.
In most cases, it should be converted to an `ArgumentException` or an
`InvalidOperationException`, depending on if the null value is a parameter
to the current method or not.

The `Exception` type should never really be thrown as it doesn't provide any
additional information or hints as to the issue. It also forces users that
would like to handle expected exceptions to catch all exceptions. These are
converted to an exception type that more accurately describes the reason for
raising the exception: `KeyNotFoundException`, `InvalidOperationException`
2019-08-16 18:07:30 -03:00
Michael Handschuh
141eaa1fee Add missing license banner 2019-08-16 18:07:30 -03:00
Jared
2753d2c7be Merge pull request #3513 from gsalaz98/bug-3509-sec-downloader-robustness
Makes SEC Downloader Check Actual File Size For Robustness
2019-08-16 13:50:08 -07:00
Gerardo Salazar
8a7b72f0c5 Make SEC downloader check actual file size for robustness 2019-08-15 16:59:48 -07:00
Jared
d4bd99987a Merge pull request #3510 from AlexCatarino/bug-xxxx-remove-qc-views
Removes QuantConnect.Views project
2019-08-15 13:26:11 -07:00
Martin-Molinero
92cc56e2d9 Merge pull request #3376 from IlshatGaripov/loader-type-load-catch-improvement
ReflectionTypeLoadException exception handling improvement.
2019-08-15 17:09:56 -03:00
Martin Molinero
180f902053 Fix visual studio plugin resources 2019-08-15 16:13:11 -03:00
Jared
48fab43550 Merge pull request #3491 from AlexCatarino/bug-3462-auto-filter-hasfundamental
Do Not Include Securities Without Fundamental Data When Performing Fine Fundamental Selection
2019-08-15 12:00:08 -07:00
Jared
f2ea39170d Merge pull request #3486 from QuantConnect/live-trading-data-feed-new-unit-tests
Add new LiveTradingDataFeed unit tests
2019-08-15 11:58:50 -07:00
Martin Molinero
4b1cb2c283 SubscriptionFrontierTimeProvider will advance new subscriptions
- `SubscriptionFrontierTimeProvider` will advance new subscriptions to find the current emit time of the enumerator. This will make enumeration more deterministic, since we will not skip any time step of the new enumerators.
- Adding a just in case flag to the backtesting `Synchronizer` to retry creating a new time slice when the time has not advanced but there is data in the slice, this could happen with subscriptions added after initialize using algorithm.AddSecurity() API, where the subscription start time is the current time loop (but should just happen once)
2019-08-15 15:46:07 -03:00
Stefano Raggi
cfcccf7a45 Fix HandlesCoarseFundamentalData occasionally failing in Travis 2019-08-15 18:07:22 +02:00
Stefano Raggi
c092c11d28 Address review
- speed up minute resolution tests
- code clean up
2019-08-15 16:13:34 +02:00
Stefano Raggi
35d07c2010 Fix failing tick resolution tests 2019-08-15 13:47:34 +02:00
Stefano Raggi
b8200bb543 Update tests for timeSlice.IsTimePulse 2019-08-15 13:47:34 +02:00
Stefano Raggi
a2b1450c14 Update new LiveTradingDataFeed unit tests 2019-08-15 13:47:34 +02:00
Stefano Raggi
9a110633a1 Add new LiveTradingDataFeed unit tests 2019-08-15 13:47:34 +02:00
AlexCatarino
0fcceb7998 Improves Message
Raise to user-level via `IAlgorithm.Debug` and separate "warning" from "fix" message concepts.
2019-08-15 00:18:28 +01:00
Jared
73a1a319fa Merge pull request #3379 from AlexCatarino/pr3368
While-lists Python Libraries
2019-08-14 16:05:11 -07:00
Jared
fc1b5bda61 Merge pull request #3507 from IlshatGaripov/base-setup-handler-remove-always-false-cond
Removes always false condition checking in BaseSetupHandler
2019-08-14 15:53:29 -07:00
AlexCatarino
a751556779 Removes QuantConnect.Views project
This UX has been deprecated and now removed.
2019-08-14 21:23:58 +01:00
Jared
3ddfcb06a6 Merge pull request #3495 from QuantConnect/feature-lean-debugging
Enable Python and CSharp debugging
2019-08-14 12:05:41 -07:00
IlshatGaripov
5ff0d60697 Cleans always false conditions checking ? 2019-08-14 14:01:13 +03:00
Jared
6387fb92dc Merge pull request #3501 from QuantConnect/issue-3500-sort-coinapi-ticks-before-write-them
Sort CoinApi raw ticks before write them
2019-08-13 17:24:56 -07:00
Jared
a4da50100f Merge pull request #3497 from QuantConnect/issue-3496-multiperiodfield-throws-error-if-updated-with-null
Fix issue updating  MultiPeriodField
2019-08-13 17:24:14 -07:00
Jared
3f65f6d7dd Merge pull request #3505 from goenchan/bug-report-overflow
Fix bug in function for processing dictionary to image blocks
2019-08-13 15:52:57 -07:00
Gerardo Salazar
5198540205 Fix issue in TradingEconomics where symbol was empty in algorithms
Fixes non-deterministic crash when using TE indicator data
2019-08-13 15:21:29 -07:00
Ethan Lee
8bda8340e2 Refactor and fix bugs in function for processing dictionary to image blocks 2019-08-13 14:58:38 -07:00
Martin Molinero
f5fa12203c Add Timeout in Controls 2019-08-13 18:25:31 -03:00
Juan José D'Ambrosio
6479af1a11 Sort CoinApi raw ticks before write them 2019-08-13 21:04:26 +00:00
Juan José D'Ambrosio
910c330950 Fix issue updating MultiPeriodField 2019-08-13 18:08:38 +00:00
Martin Molinero
f887c42638 Enable python and CSharp debugging
- Adding `DebuggerHelper` class, handles debugging initialization
- Setting the "PYTHONPATH" will be handled by the `JobQueue`
2019-08-12 22:03:13 -03:00
Jared
a80e96f4bb Merge pull request #3490 from AlexCatarino/bug-3330-statistics-packet-error
Verify Whether There is Recorded Portfolio Equity Before Computing Performace
2019-08-12 09:16:02 -07:00
Jared
2227cf3da0 Merge pull request #3481 from gsalaz98/feature-3480-add-smartinsider-custom-data
Implements Smart Insider Alternative Data Source
2019-08-12 09:14:53 -07:00
AlexCatarino
6b28fc5f04 Do Not Include Securities Without Fundamental Data When Performing Fine Fundamental Selection
The engine will no longer try to look for fine fundamental files that does not exist.
Notifies the user that the algorithm should be handle the fine fundamental data filtering.
2019-08-09 23:31:47 +01:00
AlexCatarino
6defc92a60 Verify Whether There is Recorded Portfolio Equity Before Computing Performace
When there is no recorded portfolio equity for a given period, we don't need to compute the algorithm performance (it is all zeroes). This procedure prevents the unrepresented `DateTime` error in `CreateBenchmarkDifferences`.
2019-08-09 01:56:52 +01:00
AlexCatarino
046fa38200 Removes White Space 2019-08-09 01:46:57 +01:00
Jared
90ab859d47 Merge pull request #3489 from QuantConnect/fix-max-orders
Move order count control to job packet
2019-08-08 11:24:42 -07:00
Martin-Molinero
658b9e61ba Merge pull request #3488 from QuantConnect/bug-3487-live-warmup-null-ref
Fix NullReferenceException during warmup in live mode
2019-08-08 08:55:41 -03:00
Martin Molinero
892e2d9b20 Adjust fix position
- Adjusting fix position to just affect live algorithms which perform a
warmup
2019-08-08 08:53:23 -03:00
Stefano Raggi
a08c093d91 Fix NullReferenceException during warmup in live mode 2019-08-08 11:41:00 +02:00
Jared Broad
6e5a73dc67 Move order controls to job packet 2019-08-07 17:50:45 -07:00
Gerardo Salazar
2efa168b44 Address Michael's review
Fix issue where CurrencyValue fields would be too large for int32

Rename Smart Insider base class methods

Change source extension to TSV
2019-08-07 16:29:16 -07:00
Jared
6571b69d75 Merge pull request #3452 from Martin-Molinero/bug-3410-3409-selection-algorithm-time-v2
Universe selection time fixes - v2
2019-08-07 14:52:53 -07:00
Martin Molinero
093335bb2a Address review - update documentation 2019-08-07 16:25:44 -03:00
Martin Molinero
10fd48417b Adding new TimeSlice TimePulse
- `SubscriptionSynchronizer` will emit a `TimeSlice.TimePulse` before
performing any universe selection on each time loop. This will advance
`Algorithm.Time` which will allow universe selection data time and
`Algorithm.Time` to be aligned.
- Updating Regression algorithms that were using `algorithm.Time` in the
selection method.
- Coarse selection will start from the algorithms start date (not in the
next day)
- Adding regression algorithm
2019-08-07 14:45:39 -03:00
Jared
411c6456f5 Merge pull request #3431 from Martin-Molinero/bug-2381-2260-benchmark-security
SPY default benchmark security
2019-08-07 09:45:58 -07:00
Martin Molinero
cb4c574eeb Adjust algorithms statistics 2019-08-06 21:35:25 -03:00
Martin Molinero
0d6d66cd09 SPY default security benchmark
- Setting SPY as the default security benchmark
- The security benchmark subscription will be added at `UniverseSelection`
as an internal subscription. Using its own dedicated Security instance
which doesn't live in the algorithms.Securities collection.
- Reducing algorithms exposure to internal subscriptions
- `TimeSliceFactory` will prioritize higher resolution bars, when same
symbol is present twice (for non-internal subscriptionst)
- Adding regression test `CustomUniverseWithBenchmarkRegressionAlgorithm`
2019-08-06 21:15:33 -03:00
Jared
a5724976e2 Merge pull request #3479 from AlexCatarino/feature-3478-mute-python-library-logging
Mute Python Library Logging
2019-08-05 17:25:23 -07:00
Jared
45bc62f94d Merge pull request #3483 from AlexCatarino/bug-3482-remove-unnecessary-price-rounding-warning
Prevents Warning of Price Rounding When Increment is Non-Positive
2019-08-05 15:16:22 -07:00
AlexCatarino
1ab8d84ee7 Prevents Warning of Price Rounding When Increment is Non-Positive
Moves the logic of sending warning message of price rounding inside the if-condition of valid increment value.
2019-08-05 22:33:23 +01:00
Gerardo Salazar
436a72f435 Implements SmartInsider custom data source
Implements Smart Insider data converter ToolBox application

Includes example algorithms demonstrating use of data
2019-08-05 13:42:08 -07:00
Jared
4aa15eda6f Merge pull request #3472 from QuantConnect/performance-3471-finefundamental-memory-footprint-reduction
FineFundamental memory footprint improvements
2019-08-05 09:34:44 -07:00
AlexCatarino
0f114df756 Mute Python Library Logging
Redirects Python standard output (`sys.stdout`) to `devull`
2019-08-05 17:32:03 +01:00
Jared
7e75bfc961 Merge pull request #3473 from QuantConnect/performance-3403-finefundamental-backtesting-rebased
Improve FineFundamental backtesting performance - static cache
2019-08-05 09:22:41 -07:00
Jared
692dc97810 Merge pull request #3477 from Martin-Molinero/bug-3476-adding-logs-python-initialization
Adding some logs to Python initialization
2019-08-05 09:21:02 -07:00
Martin Molinero
d6b89a6d0d Adding some logs to Python initialization 2019-08-05 13:14:52 -03:00
Jared
3e3fcfe40a Merge pull request #3474 from QuantConnect/performance-memory-adjust-coarse-data-count-loading
Adjust the data count Coarse limits
2019-08-05 08:46:00 -07:00
Martin Molinero
1461a4698c Adjust the data count Coarse limits
- Reducing the filesystem upper limit data count for coarse file to 1GB
of ram. Currently in master as is, for long backtests, will load all
data, which is roughly 9GB of ram
2019-08-02 20:16:28 -03:00
Martin Molinero
4b125bd43a Improve FineFundamental backtesting performance
- For backtesting, adding new private static fine cache that will hold the available dates
for which there is a fine file, reducing the amount of times we
enumerate the files in the directory. Updating unit tests.
2019-08-02 17:16:37 -03:00
Martin Molinero
6bcbd726a9 Fine memory footprint improvementes
- Will use an array as store, the most efficient collection memory wise.
Holding a custom internal `struct PeriodField`
- Will store period as a byte number, not a string
- By default the collection will be null and created on demand
- Adding more unit tests
2019-08-02 13:16:54 -03:00
Jared
7902d62dac Merge pull request #3450 from QuantConnect/support-equity-quotes-processing
Equity trades and quotes processing support
2019-08-02 07:55:34 -07:00
Jared
df1a11f734 Merge pull request #3465 from StefanoRaggi/bug-ib-automater-windows-no-output
Fix Console.OutputEncoding in LEAN Launcher (Windows only)
2019-08-02 07:32:16 -07:00
Jared
e2d9dd73d3 Merge pull request #3454 from QuantConnect/bug-3453-equity-price-variation-fix
Fix order price rounding in BrokerageTransactionHandler and EquityPriceVariationModel
2019-08-02 07:31:50 -07:00
Jared
836cc872f4 Merge pull request #3464 from RohanTalip/RT/remove-print
Removed a print statement from FundamentalUniverseSelectionModel.py
2019-08-01 16:25:28 -07:00
Jared
afc3f01ba6 Merge pull request #3463 from goenchan/bug-report-style
Fix exported report pdf style errors
2019-08-01 16:24:50 -07:00
Jared
a0e0c49618 Merge pull request #3467 from gsalaz98/bug-3466-estimize-symbol-not-set
Fix Issue In Estimize Where Symbol Would Not Be Set In Reader
2019-08-01 16:24:27 -07:00
Stefano Raggi
bf3aeb96de Add GetMinimumPriceVariationParameters 2019-08-01 21:52:08 +02:00
Gerardo Salazar
f49b7b9f7d Fix issue in Estimize where symbol would not be set in Reader 2019-08-01 10:33:44 -07:00
Stefano Raggi
f44c202d76 Fix Console.OutputEncoding in LEAN Launcher (Windows only)
The current setting of Encoding.Unicode was preventing LEAN from receiving IBAutomater output and error events when running local LEAN under Windows.
Changing to Encoding.UTF8 solves the issue.
2019-08-01 17:04:26 +02:00
Rohan Talip
d046befcb7 Removed a print statement from FundamentalUniverseSelectionModel.py 2019-08-01 05:23:34 -07:00
Stefano Raggi
bce36fd9de Revert public RoundOrderPrices 2019-08-01 10:19:41 +02:00
Ethan Lee
6d13aa4bd4 Merge branch 'master' of https://github.com/QuantConnect/Lean into feature-report-style 2019-07-31 17:19:06 -07:00
Ethan Lee
f83f3e99df Edit font style, import Open Sans, and modify page ratio 2019-07-31 17:18:46 -07:00
Jared
88c5777adb Merge pull request #3405 from gsalaz98/feature-3404-improve-estimize-downloaders
Improves Estimize Downloaders
2019-07-31 14:05:08 -07:00
Juan José D'Ambrosio
5ef4597010 Revert Tick aggregator and consolidators to previous state 2019-07-31 20:34:34 +00:00
Jared
a4a7632716 Merge pull request #3458 from simonsonjack/feature-LeanReportCreator-updates
Update LeanOutputReader.py asset allocation plots
2019-07-31 13:28:59 -07:00
Jared
dcff0ee20c Merge pull request #3459 from QuantConnect/bug-3455-python-universe-selection-unchanged
Allow Python universe selection to return unchanged
2019-07-31 13:28:12 -07:00
Juan José D'Ambrosio
c274ca92a3 Fix bug in quotes lines generation 2019-07-31 19:45:50 +00:00
Jack Simonson
d152fcc474 Remove condition imposing 5% minimum on labels
This restriction is no longer necessary as we are plotting 7 slices maximum no matter what value they are.
2019-07-31 11:59:47 -07:00
Jack Simonson
dacf27a329 Update LeanOutputReader.py asset allocation plots
Discrepencies were being noted between the plotted asset holdings and the actual holdings weights. Additionally, the plot was changing between HTML renderings using the same backtest data.
2019-07-31 11:40:25 -07:00
Martin Molinero
1983f36792 Allow Python selection to return unchanged
- We will now check if python selection method returned `Universe.Unchanged`
- Removing `ToList()` call on fine and coarse data before sending it to
the python algorithm
- Adding regression algorithms
2019-07-31 15:36:07 -03:00
Jared
fc9a646e7a Merge pull request #3456 from simonsonjack/feature-LeanReportCreator-updates
Update LeanOutputReader plot formatting
2019-07-31 11:30:26 -07:00
Jack Simonson
ff41cf3cf0 Update LeanOutputReader plot formatting
Updated the monthly returns matrix text labeling. Force the top row of labels to align bottom and the bottom row of labels to align top. As originally done, the local report created was fine but the report in the cloud still have overlapping label/axis issues. This fixes that problem.
2019-07-31 10:05:32 -07:00
Stefano Raggi
422af0610a Fix order price rounding in EquityPriceVariationModel 2019-07-31 15:48:14 +02:00
Jared
084ac67cce Merge pull request #3451 from simonsonjack/feature-LeanReportCreator-updates
Update LeanOutputReader.py
2019-07-30 16:25:28 -07:00
Jack Simonson
f557b5128e Update LeanOutputReader.py
Add try-except controls to ensure successful report creation when backtest result is incomplete. Prevents issues popping up with None types for Total Performance and Portfolio Statistics.
2019-07-30 16:02:49 -07:00
Juan José D'Ambrosio
f85d0edfa7 Fix bug in ticks aggregators 2019-07-30 21:53:48 +00:00
Gerardo Salazar
c5d3d050b4 Add error handling for potential RateGate failure 2019-07-30 14:29:44 -07:00
Juan José D'Ambrosio
bb295d5ceb Equity trades and quotes processing support 2019-07-30 21:29:34 +00:00
Ethan Lee
5a03bfad6c Add page-break-avoid css to fix the page collapsing bug when exported as pdf 2019-07-30 13:49:26 -07:00
Jared
bfbdace989 Merge pull request #3427 from gsalaz98/feature-3426-yield-curve-alternative-data
Implement U.S. Treasury Yield Curve Alternative Data Source
2019-07-30 13:19:37 -07:00
Gerardo Salazar
26bc0f9b0b Add symbol to USTreasuryYieldCurveRate so that we can index inside algos
Update USTreasuryYieldCurveRate python algorithm
2019-07-30 10:53:33 -07:00
Gerardo Salazar
e3e3fc710a Add python example algorithm
Address reviews
2019-07-30 10:13:31 -07:00
Jared
c46bdd0f86 Merge pull request #3420 from QuantConnect/bug-3137-returns-symbol-data
Prevents ReturnsSymbolData.Add from Adding Repeated RateOfChange
2019-07-30 09:41:54 -07:00
Jared
2e561266a0 Merge pull request #3445 from QuantConnect/bug-3395-ib-cash-sync-fix
Update IB cash sync to not be performed during server reset times
2019-07-30 09:38:20 -07:00
Jared
d61a693371 Update readme.md 2019-07-30 09:06:49 -07:00
Jared
806da03724 Merge pull request #3447 from StefanoRaggi/bug-3428-gdax-brokerage-invalid-signature
Fix invalid signature error in GDAX brokerage
2019-07-30 09:00:40 -07:00
Stefano Raggi
8e4e741c58 Fix invalid signature error in GDAX brokerage
The invalid signature error was only partially fixed in #3429, this PR completes the updates to the GDAX brokerage implementation required after #3407
2019-07-30 16:51:50 +02:00
Jared
4f95719018 Merge pull request #3388 from Adalyat/feature-3387-unify-orderbook
Unify brokerage orderbook class
2019-07-30 07:34:43 -07:00
Jared
b30395ef7c Merge pull request #3432 from AlexCatarino/bug-3423-py-custom-indicator-updated
Refactors PythonIndicator
2019-07-30 07:34:02 -07:00
Jared
a85a3094f4 Merge pull request #3446 from Martin-Molinero/bug-3443-insight-context-zero-initial-price
ConstantAlphaModel will check Security.Price is not zero
2019-07-30 07:30:44 -07:00
Martin Molinero
e322381dfa ConstantAlphaModel check Security.Price 2019-07-29 22:41:14 -03:00
Jared
df8a69bee1 Merge pull request #3439 from QuantConnect/feature-3394-add-kelly-criterion-estimate
Add Kelly Criterion values
2019-07-29 16:49:22 -07:00
Gerardo Salazar
0fb996acc1 Update Estimize data to include seconds
Fix bug where we would call SaveContentToFile more than once
2019-07-29 10:07:42 -07:00
Stefano Raggi
7bfe12d379 Invert order of checks in IB ShouldPerformCashSync
This avoids the logging in IsWithinScheduledServerResetTimes every time ShouldPerformCashSync is called.
2019-07-29 18:01:55 +02:00
Stefano Raggi
34152bbbcc Update IB cash sync to not be performed during server reset times
A new IBrokerageCashSynchronizer interface has been added to allow brokerage implementations to handle the cash sync process. Most of the cash sync logic has been moved from the BrokerageTransactionHandler to the base Brokerage class.
The IB brokerage will not attempt to perform cash sync during server reset times, respecting the different regional schedules (see also #3413).
2019-07-29 18:01:54 +02:00
Martin Molinero
2db7e06f0e Address review 2019-07-29 11:35:34 -03:00
AlexCatarino
618ecd76b7 Adds DuplicateKeyPortfolioConstructionModelTests
Adds `DuplicateKeyPortfolioConstructionModelTests` to evaluate duplicate keys exception on `ReturnsSymbolData.FormReturnsMatrix` method.
Removes `DuplicateKeyExceptionAlgorithm` as it is replaced by the unit test.
2019-07-29 15:10:34 +01:00
AlexCatarino
22723204ff Fixes VolumeWeightedAveragePriceExecutionModel.IntradayVwap
`VolumeWeightedAveragePriceExecutionModel.IntradayVwap.Update` did not return a boolean.
2019-07-29 11:28:06 +01:00
Jared
992d721d08 Revert "Reduce python load time 30% (#3440)" (#3441)
Reverts test commit 70017f0e05.
2019-07-28 18:37:34 -07:00
Jared
70017f0e05 Reduce python load time 30% (#3440)
Optimize python load times
2019-07-28 17:20:52 -07:00
Gerardo Salazar
11879119c1 Make downloaders use map files for historical ticker resolution
Fix issue in Consensus downloader where attempt to select non-duplicates would cause a chunk
of data to be dropped and never processed

Update output path to be CSV files instead of JSON, non-zipped

Fix documentation

Fix bug where we would not properly output files
2019-07-26 17:32:47 -07:00
Martin Molinero
a4dfa708c5 Address reviews 2019-07-26 20:19:38 -03:00
AlexCatarino
74df37bf09 Adds DuplicateKeyExceptionAlgorithm
`DuplicateKeyExceptionAlgorithm` demonstrates the issue.
2019-07-26 23:49:24 +01:00
Martin Molinero
a79cc16b03 Add Kelly Criterion values
- New `KellyCriterionManager` will be used by the
`StatisticsInsightManagerExtension` to calculate and update the
`AlphaRuntimeStatistics` with the new Kelly Criterion values, on a daily
basis.
2019-07-26 19:16:36 -03:00
AlexCatarino
3f2f4683de Prevents ReturnsSymbolData.Add from adding repetead RateOfChange 2019-07-26 22:55:01 +01:00
Adalyat Nazirov
f3e73b1907 sync best bid/ask properties 2019-07-26 18:53:58 +03:00
Adalyat Nazirov
a9d28f2380 precludes use from needing to access the dictionary twice 2019-07-26 18:53:58 +03:00
Adalyat Nazirov
ace826e3a7 [Requested changes]
- access to ask/bid dictionaries is synchronized
2019-07-26 18:53:58 +03:00
Adalyat Nazirov
048c53585e [Requested changes]
- rename protected fields to follow coding style
- rename iterface IOrderBook -> IOrderBookUpdater
2019-07-26 18:53:58 +03:00
Adalyat Nazirov
6387e751ce Unify brokerage orderbook class 2019-07-26 18:53:58 +03:00
AlexCatarino
0b0a1b31ff Refactors PythonIndicator
In order to provide full Lean Indicator functionality to python custom indicators, they need to inherit from a C# class. `PythonIndicator` will serve for this purpose.
Algorithms can use the former version (no inheritance).
2019-07-26 00:35:57 +01:00
Gerardo Salazar
d394251ac9 Implement U.S. Treasury yield curve alternative data source 2019-07-24 16:48:55 -07:00
Gerardo Salazar
b1434bfef4 Add completion tracking in Estimize downloaders (excluding consensus)
Add better logging to estimize downloaders

Speed up estimize consensus downloader by checking for duplicates

Move duplicated code to single method
2019-07-18 17:03:23 -07:00
IlshatGaripov
79a4e6a8df Uses LoaderExceptions.Length to count null entries. 2019-07-15 16:42:21 +00:00
IlshatGaripov
191f097492 Adds log for count of the null entries 2019-07-15 16:14:39 +00:00
Oleg Sheyner
4032de1dd3 #3386 Trade Builder creates incorrect trades: finalize fixes + add regression tests 2019-07-11 12:36:54 -04:00
Oleg Sheyner
519ca88052 Fix #3386 2019-07-11 12:36:54 -04:00
AlexCatarino
ee957f6a53 Fix Python Packages Versions 2019-07-10 12:05:00 +01:00
AlexCatarino
cdca13a6f6 Creates Unit Tests for Python Packages
Verify whether python packages can ne imported and used with unit test instead of algorithm
2019-07-09 23:33:33 +01:00
AlexCatarino
1e19ac4572 Whilelists Python Libraries
- copulas, hmm and pomegranate (closes #2832)
- tsfresh (closes #3084)
- LightGBM (closes #3173)
- BeautifulSoup (closes #3178)
- Facebook/Prophet (closes #3199)
- fastai (closes #3233)
- Pyramid ARIMA (closes #3234)
- punkt for nltk (closes #3367)
- Stable Baselines (closes #3369)

- Updates:
  - Miniconda to 4.5.12 (Foundation and travis)
  - Python to 3.6.8
  - numpy to 1.16.1

- Revert changes to Dockerfile
2019-07-09 23:33:33 +01:00
Frank Norman
d18851b230 Fixes for issue 3334 2019-07-09 23:33:33 +01:00
IlshatGaripov
24c3efed36 ReflectionTypeLoadException exception handling improvement.
Removing always false if statement.
2019-07-09 10:49:20 +00:00
2728 changed files with 273690 additions and 97879 deletions

View File

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

4
.github/funding.yml vendored Normal file
View File

@@ -0,0 +1,4 @@
# These are supported funding model platforms
github: quantconnect
#custom: ['https://github.com/sponsors/QuantConnect']

View File

@@ -24,6 +24,8 @@
#### Types of changes
<!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: -->
- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] Refactor (non-breaking change which improves implementation)
- [ ] Performance (non-breaking change which improves performance. Please add associated performance test and results)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to change)
- [ ] Non-functional change (xml comments/documentation/etc)
@@ -37,4 +39,4 @@
- [ ] All new and existing tests passed.
- [ ] My branch follows the naming convention `bug-<issue#>-<description>` or `feature-<issue#>-<description>`
<!--- Template inspired by https://www.talater.com/open-source-templates/#/page/99 -->
<!--- Template inspired by https://www.talater.com/open-source-templates/#/page/99 -->

9
.gitignore vendored
View File

@@ -34,6 +34,9 @@
# QC Cloud Setup Bash Files
*.sh
# Include docker launch scripts for Mac/Linux
!run_docker.sh
!research/run_docker_notebook.sh
# QC Config Files:
# config.json
@@ -166,6 +169,9 @@ AutoTest.Net/
# Installshield output folder
[Ee]xpress/
# JetBrains Rider
.idea/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
@@ -262,3 +268,6 @@ Launcher/Plugins/*
/ApiPython/quantconnect.egg-info/*
QuantConnect.Lean.sln.DotSettings*
#User notebook files
Research/Notebooks

18
.idea/Lean.iml generated Normal file
View File

@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/Algorithm.Python" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/Algorithm.Python/stubs" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="PyDocumentationSettings">
<option name="format" value="PLAIN" />
<option name="myDocStringFormat" value="Plain" />
</component>
<component name="TestRunnerService">
<option name="PROJECT_TEST_RUNNER" value="pytest" />
</component>
</module>

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="5678" />
<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="5678" />
<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,21 +1,26 @@
sudo: required
language: csharp
mono:
- 5.8.0
- 5.12.0
solution: QuantConnect.Lean.sln
before_install:
- export PATH="$HOME/miniconda3/bin:$PATH"
- wget https://cdn.quantconnect.com/miniconda/Miniconda3-4.3.31-Linux-x86_64.sh
- bash Miniconda3-4.3.31-Linux-x86_64.sh -b
- rm -rf Miniconda3-4.3.31-Linux-x86_64.sh
- wget 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
- conda update -y python conda pip
- conda install -y cython pandas scipy
- conda install -y python=3.6.8
- conda install -y numpy=1.18.1
- conda install -y pandas=0.25.3
- conda install -y cython=0.29.15
- conda install -y scipy=1.4.1
- conda install -y wrapt=1.12.1
install:
- nuget restore QuantConnect.Lean.sln
- nuget install NUnit.Runners -Version 2.6.4 -OutputDirectory testrunner
- 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.Runners.2.6.4/tools/nunit-console.exe ./Tests/bin/Release/QuantConnect.Tests.dll --exclude:TravisExclude --labels
after_success:
- coveralls
- mono ./testrunner/NUnit.ConsoleRunner.3.11.1/tools/nunit3-console.exe ./Tests/bin/Release/QuantConnect.Tests.dll --where "cat != TravisExclude" --labels=Off
- chmod +x ci_build_stubs.sh
- sudo -E ./ci_build_stubs.sh -ipy -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}"
}]
}
]
}

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

@@ -0,0 +1,197 @@
<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](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
<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",
<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 arguements are:
"image=quantconnect/lean:latest",
"config_file=${workspaceFolder}/Launcher/config.json",
"data_dir=${workspaceFolder}/Data",
"results_dir=${workspaceFolder}/",
"debugging=Y",
"python_location=${workspaceFolder}/Algorithm.Python"
As defaults these are all great! Feel free to change them as needed for your setup.
<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: _~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>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!
* Error messages about build in VSCode points 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.

5
.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,5 @@
{
"python.autoComplete.extraPaths": [
"Algorithm.Python/stubs"
]
}

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

@@ -0,0 +1,111 @@
{
/*
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": "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}/",
"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

@@ -0,0 +1,119 @@
/*
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using System.Collections.Generic;
using QuantConnect.Algorithm.Framework.Alphas;
using QuantConnect.Algorithm.Framework.Execution;
using QuantConnect.Algorithm.Framework.Portfolio;
using QuantConnect.Algorithm.Framework.Selection;
using QuantConnect.Interfaces;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Test algorithm using <see cref="AccumulativeInsightPortfolioConstructionModel"/> and <see cref="ConstantAlphaModel"/>
/// generating a constant <see cref="Insight"/> with a 0.25 confidence
/// </summary>
public class AccumulativeInsightPortfolioRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
{
/// <summary>
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
/// </summary>
public override void Initialize()
{
// Set requested data resolution
UniverseSettings.Resolution = Resolution.Minute;
SetStartDate(2013, 10, 07); //Set Start Date
SetEndDate(2013, 10, 11); //Set End Date
SetCash(100000); //Set Strategy Cash
// set algorithm framework models
SetUniverseSelection(new ManualUniverseSelectionModel(QuantConnect.Symbol.Create("SPY", SecurityType.Equity, Market.USA)));
SetAlpha(new ConstantAlphaModel(InsightType.Price, InsightDirection.Up, TimeSpan.FromMinutes(20), 0.025, 0.25));
SetPortfolioConstruction(new AccumulativeInsightPortfolioConstructionModel());
SetExecution(new ImmediateExecutionModel());
}
public override void OnEndOfAlgorithm()
{
if (// holdings value should be 0.03 - to avoid price fluctuation issue we compare with 0.06 and 0.01
Portfolio.TotalHoldingsValue > Portfolio.TotalPortfolioValue * 0.06m
||
Portfolio.TotalHoldingsValue < Portfolio.TotalPortfolioValue * 0.01m)
{
throw new Exception($"Unexpected Total Holdings Value: {Portfolio.TotalHoldingsValue}");
}
}
/// <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", "199"},
{"Average Win", "0.00%"},
{"Average Loss", "0.00%"},
{"Compounding Annual Return", "-12.472%"},
{"Drawdown", "0.200%"},
{"Expectancy", "-0.586"},
{"Net Profit", "-0.170%"},
{"Sharpe Ratio", "-9.693"},
{"Probabilistic Sharpe Ratio", "12.704%"},
{"Loss Rate", "79%"},
{"Win Rate", "21%"},
{"Profit-Loss Ratio", "0.95"},
{"Alpha", "-0.149"},
{"Beta", "0.037"},
{"Annual Standard Deviation", "0.008"},
{"Annual Variance", "0"},
{"Information Ratio", "-9.471"},
{"Tracking Error", "0.212"},
{"Treynor Ratio", "-2.13"},
{"Total Fees", "$199.00"},
{"Fitness Score", "0.002"},
{"Kelly Criterion Estimate", "38.64"},
{"Kelly Criterion Probability Value", "0.229"},
{"Sortino Ratio", "-21.545"},
{"Return Over Maximum Drawdown", "-77.972"},
{"Portfolio Turnover", "1.135"},
{"Total Insights Generated", "100"},
{"Total Insights Closed", "99"},
{"Total Insights Analysis Completed", "99"},
{"Long Insight Count", "100"},
{"Short Insight Count", "0"},
{"Long/Short Ratio", "100%"},
{"Estimated Monthly Alpha Value", "$126657.6305"},
{"Total Accumulated Estimated Alpha Value", "$20405.9516"},
{"Mean Population Estimated Insight Value", "$206.1207"},
{"Mean Population Direction", "54.5455%"},
{"Mean Population Magnitude", "54.5455%"},
{"Rolling Averaged Population Direction", "59.8056%"},
{"Rolling Averaged Population Magnitude", "59.8056%"},
{"OrderListHash", "1256341962"}
};
}
}

View File

@@ -1,4 +1,4 @@
/*
/*
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
*
@@ -110,38 +110,46 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "6"},
{"Average Win", "0.91%"},
{"Average Loss", "-0.23%"},
{"Compounding Annual Return", "214.278%"},
{"Drawdown", "1.600%"},
{"Expectancy", "2.248"},
{"Net Profit", "1.581%"},
{"Sharpe Ratio", "2.803"},
{"Total Trades", "9"},
{"Average Win", "0.89%"},
{"Average Loss", "-0.27%"},
{"Compounding Annual Return", "196.104%"},
{"Drawdown", "1.700%"},
{"Expectancy", "1.853"},
{"Net Profit", "1.498%"},
{"Sharpe Ratio", "4.275"},
{"Probabilistic Sharpe Ratio", "60.462%"},
{"Loss Rate", "33%"},
{"Win Rate", "67%"},
{"Profit-Loss Ratio", "3.87"},
{"Alpha", "0"},
{"Beta", "59.491"},
{"Annual Standard Deviation", "0.244"},
{"Annual Variance", "0.06"},
{"Information Ratio", "2.756"},
{"Tracking Error", "0.244"},
{"Treynor Ratio", "0.012"},
{"Total Fees", "$10.88"},
{"Profit-Loss Ratio", "3.28"},
{"Alpha", "1.574"},
{"Beta", "-0.289"},
{"Annual Standard Deviation", "0.276"},
{"Annual Variance", "0.076"},
{"Information Ratio", "-0.495"},
{"Tracking Error", "0.367"},
{"Treynor Ratio", "-4.079"},
{"Total Fees", "$14.33"},
{"Fitness Score", "0.408"},
{"Kelly Criterion Estimate", "16.447"},
{"Kelly Criterion Probability Value", "0.315"},
{"Sortino Ratio", "13.611"},
{"Return Over Maximum Drawdown", "117.635"},
{"Portfolio Turnover", "0.411"},
{"Total Insights Generated", "3"},
{"Total Insights Closed", "3"},
{"Total Insights Analysis Completed", "3"},
{"Long Insight Count", "0"},
{"Short Insight Count", "3"},
{"Long/Short Ratio", "0%"},
{"Estimated Monthly Alpha Value", "$13262182.1037"},
{"Total Accumulated Estimated Alpha Value", "$2284042.4734"},
{"Mean Population Estimated Insight Value", "$761347.4911"},
{"Estimated Monthly Alpha Value", "$19868365.6628"},
{"Total Accumulated Estimated Alpha Value", "$3421774.0864"},
{"Mean Population Estimated Insight Value", "$1140591.3621"},
{"Mean Population Direction", "100%"},
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "100%"},
{"Rolling Averaged Population Magnitude", "0%"}
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "-887015098"}
};
}
}

View File

@@ -0,0 +1,164 @@
/*
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using System.Linq;
using QuantConnect.Data;
using QuantConnect.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.023"},
{"Beta", "0.005"},
{"Annual Standard Deviation", "0.006"},
{"Annual Variance", "0"},
{"Information Ratio", "-3.424"},
{"Tracking Error", "0.057"},
{"Treynor Ratio", "-4.775"},
{"Total Fees", "$2.00"},
{"Fitness Score", "0"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "-43.418"},
{"Return Over Maximum Drawdown", "-14.274"},
{"Portfolio Turnover", "0.007"},
{"Total Insights Generated", "0"},
{"Total Insights Closed", "0"},
{"Total Insights Analysis Completed", "0"},
{"Long Insight Count", "0"},
{"Short Insight Count", "0"},
{"Long/Short Ratio", "100%"},
{"Estimated Monthly Alpha Value", "$0"},
{"Total Accumulated Estimated Alpha Value", "$0"},
{"Mean Population Estimated Insight Value", "$0"},
{"Mean Population Direction", "0%"},
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "-1185639451"}
};
}
}

View File

@@ -0,0 +1,216 @@
/*
* 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"},
{"Fitness Score", "0"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "-19.883"},
{"Return Over Maximum Drawdown", "-67.224"},
{"Portfolio Turnover", "0.014"},
{"Total Insights Generated", "0"},
{"Total Insights Closed", "0"},
{"Total Insights Analysis Completed", "0"},
{"Long Insight Count", "0"},
{"Short Insight Count", "0"},
{"Long/Short Ratio", "100%"},
{"Estimated Monthly Alpha Value", "$0"},
{"Total Accumulated Estimated Alpha Value", "$0"},
{"Mean Population Estimated Insight Value", "$0"},
{"Mean Population Direction", "0%"},
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "721476625"}
};
}
}

View File

@@ -40,8 +40,8 @@ namespace QuantConnect.Algorithm.CSharp
private int _expectedContractIndex;
private readonly List<Symbol> _expectedContracts = new List<Symbol>
{
SymbolRepresentation.ParseOptionTickerOSI("GOOG 151224P00747500"),
SymbolRepresentation.ParseOptionTickerOSI("GOOG 151224P00750000"),
SymbolRepresentation.ParseOptionTickerOSI("GOOG 151224P00747500"),
SymbolRepresentation.ParseOptionTickerOSI("GOOG 151224P00752500")
};
@@ -212,13 +212,14 @@ namespace QuantConnect.Algorithm.CSharp
{
{"Total Trades", "6"},
{"Average Win", "0%"},
{"Average Loss", "-0.21%"},
{"Compounding Annual Return", "-98.595%"},
{"Drawdown", "0.600%"},
{"Expectancy", "-1"},
{"Net Profit", "-0.631%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "0%"},
{"Drawdown", "0%"},
{"Expectancy", "0"},
{"Net Profit", "0%"},
{"Sharpe Ratio", "0"},
{"Loss Rate", "100%"},
{"Probabilistic Sharpe Ratio", "0%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "0"},
@@ -228,7 +229,27 @@ namespace QuantConnect.Algorithm.CSharp
{"Information Ratio", "0"},
{"Tracking Error", "0"},
{"Treynor Ratio", "0"},
{"Total Fees", "$6.00"}
{"Total Fees", "$6.00"},
{"Fitness Score", "0"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "0"},
{"Return Over Maximum Drawdown", "0"},
{"Portfolio Turnover", "0"},
{"Total Insights Generated", "0"},
{"Total Insights Closed", "0"},
{"Total Insights Analysis Completed", "0"},
{"Long Insight Count", "0"},
{"Short Insight Count", "0"},
{"Long/Short Ratio", "100%"},
{"Estimated Monthly Alpha Value", "$0"},
{"Total Accumulated Estimated Alpha Value", "$0"},
{"Mean Population Estimated Insight Value", "$0"},
{"Mean Population Direction", "0%"},
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "731140098"}
};
}
}

View File

@@ -74,8 +74,8 @@ namespace QuantConnect.Algorithm.CSharp
}
else if (Time.DayOfWeek == DayOfWeek.Thursday)
{
RemoveSecurity(_bac);
RemoveSecurity(_aig);
RemoveSecurity(_bac);
lastAction = Time;
}
}
@@ -112,24 +112,45 @@ namespace QuantConnect.Algorithm.CSharp
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "5"},
{"Average Win", "0.49%"},
{"Average Win", "0.47%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "305.340%"},
{"Compounding Annual Return", "293.067%"},
{"Drawdown", "1.400%"},
{"Expectancy", "0"},
{"Net Profit", "1.805%"},
{"Sharpe Ratio", "6.475"},
{"Net Profit", "1.765%"},
{"Sharpe Ratio", "13.11"},
{"Probabilistic Sharpe Ratio", "80.231%"},
{"Loss Rate", "0%"},
{"Win Rate", "100%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "0.003"},
{"Beta", "82.247"},
{"Annual Standard Deviation", "0.141"},
{"Annual Variance", "0.02"},
{"Information Ratio", "6.401"},
{"Tracking Error", "0.141"},
{"Treynor Ratio", "0.011"},
{"Total Fees", "$26.40"}
{"Alpha", "0.705"},
{"Beta", "0.7"},
{"Annual Standard Deviation", "0.157"},
{"Annual Variance", "0.025"},
{"Information Ratio", "1.76"},
{"Tracking Error", "0.072"},
{"Treynor Ratio", "2.933"},
{"Total Fees", "$26.39"},
{"Fitness Score", "0.374"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "79228162514264337593543950335"},
{"Return Over Maximum Drawdown", "373.973"},
{"Portfolio Turnover", "0.374"},
{"Total Insights Generated", "0"},
{"Total Insights Closed", "0"},
{"Total Insights Analysis Completed", "0"},
{"Long Insight Count", "0"},
{"Short Insight Count", "0"},
{"Long/Short Ratio", "100%"},
{"Estimated Monthly Alpha Value", "$0"},
{"Total Accumulated Estimated Alpha Value", "$0"},
{"Mean Population Estimated Insight Value", "$0"},
{"Mean Population Direction", "0%"},
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "1779055144"}
};
}
}

View File

@@ -1,4 +1,4 @@
/*
/*
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
*
@@ -67,35 +67,43 @@ namespace QuantConnect.Algorithm.CSharp
{"Total Trades", "3"},
{"Average Win", "1.02%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "289.117%"},
{"Compounding Annual Return", "289.119%"},
{"Drawdown", "2.200%"},
{"Expectancy", "0"},
{"Net Profit", "1.752%"},
{"Sharpe Ratio", "4.52"},
{"Sharpe Ratio", "9.235"},
{"Probabilistic Sharpe Ratio", "68.013%"},
{"Loss Rate", "0%"},
{"Win Rate", "100%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "0.007"},
{"Beta", "80.237"},
{"Annual Standard Deviation", "0.197"},
{"Annual Variance", "0.039"},
{"Information Ratio", "4.466"},
{"Tracking Error", "0.197"},
{"Treynor Ratio", "0.011"},
{"Alpha", "0.105"},
{"Beta", "1.022"},
{"Annual Standard Deviation", "0.224"},
{"Annual Variance", "0.05"},
{"Information Ratio", "24.59"},
{"Tracking Error", "0.006"},
{"Treynor Ratio", "2.029"},
{"Total Fees", "$9.77"},
{"Fitness Score", "0.747"},
{"Kelly Criterion Estimate", "38.64"},
{"Kelly Criterion Probability Value", "0.229"},
{"Sortino Ratio", "79228162514264337593543950335"},
{"Return Over Maximum Drawdown", "107.109"},
{"Portfolio Turnover", "0.747"},
{"Total Insights Generated", "100"},
{"Total Insights Closed", "99"},
{"Total Insights Analysis Completed", "99"},
{"Long Insight Count", "100"},
{"Short Insight Count", "0"},
{"Long/Short Ratio", "100%"},
{"Estimated Monthly Alpha Value", "$158418.3850"},
{"Total Accumulated Estimated Alpha Value", "$25522.9620"},
{"Mean Population Estimated Insight Value", "$257.8077"},
{"Estimated Monthly Alpha Value", "$126657.6305"},
{"Total Accumulated Estimated Alpha Value", "$20405.9516"},
{"Mean Population Estimated Insight Value", "$206.1207"},
{"Mean Population Direction", "54.5455%"},
{"Mean Population Magnitude", "54.5455%"},
{"Rolling Averaged Population Direction", "59.8056%"},
{"Rolling Averaged Population Magnitude", "59.8056%"}
{"Rolling Averaged Population Magnitude", "59.8056%"},
{"OrderListHash", "-887190565"}
};
}
}

View File

@@ -1,4 +1,4 @@
/*
/*
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
*
@@ -86,35 +86,43 @@ namespace QuantConnect.Algorithm.CSharp
{"Total Trades", "10"},
{"Average Win", "0%"},
{"Average Loss", "-0.01%"},
{"Compounding Annual Return", "-14.943%"},
{"Compounding Annual Return", "-14.333%"},
{"Drawdown", "3.300%"},
{"Expectancy", "-1"},
{"Net Profit", "-0.177%"},
{"Sharpe Ratio", "-0.136"},
{"Net Profit", "-0.169%"},
{"Sharpe Ratio", "-0.131"},
{"Probabilistic Sharpe Ratio", "45.057%"},
{"Loss Rate", "100%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "0"},
{"Beta", "-4.084"},
{"Annual Standard Deviation", "0.332"},
{"Annual Variance", "0.11"},
{"Information Ratio", "-0.169"},
{"Tracking Error", "0.332"},
{"Treynor Ratio", "0.011"},
{"Alpha", "-3.068"},
{"Beta", "0.595"},
{"Annual Standard Deviation", "0.382"},
{"Annual Variance", "0.146"},
{"Information Ratio", "-13.618"},
{"Tracking Error", "0.376"},
{"Treynor Ratio", "-0.084"},
{"Total Fees", "$13.98"},
{"Fitness Score", "0.146"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "1"},
{"Sortino Ratio", "79228162514264337593543950335"},
{"Return Over Maximum Drawdown", "-4.398"},
{"Portfolio Turnover", "0.268"},
{"Total Insights Generated", "15"},
{"Total Insights Closed", "12"},
{"Total Insights Analysis Completed", "12"},
{"Long Insight Count", "15"},
{"Short Insight Count", "0"},
{"Long/Short Ratio", "100%"},
{"Estimated Monthly Alpha Value", "$33015795.7342"},
{"Total Accumulated Estimated Alpha Value", "$4585527.1853"},
{"Mean Population Estimated Insight Value", "$382127.2654"},
{"Mean Population Direction", "66.6667%"},
{"Mean Population Magnitude", "66.6667%"},
{"Rolling Averaged Population Direction", "34.3681%"},
{"Rolling Averaged Population Magnitude", "34.3681%"}
{"Estimated Monthly Alpha Value", "$0"},
{"Total Accumulated Estimated Alpha Value", "$0"},
{"Mean Population Estimated Insight Value", "$0"},
{"Mean Population Direction", "0%"},
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "1917702312"}
};
}
}

View File

@@ -1,4 +1,4 @@
/*
/*
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
*
@@ -93,35 +93,43 @@ namespace QuantConnect.Algorithm.CSharp
{"Total Trades", "23"},
{"Average Win", "0.00%"},
{"Average Loss", "-0.01%"},
{"Compounding Annual Return", "-75.360%"},
{"Compounding Annual Return", "-75.307%"},
{"Drawdown", "5.800%"},
{"Expectancy", "-0.859"},
{"Net Profit", "-5.594%"},
{"Sharpe Ratio", "-5.582"},
{"Net Profit", "-5.586%"},
{"Sharpe Ratio", "-3.257"},
{"Probabilistic Sharpe Ratio", "5.931%"},
{"Loss Rate", "92%"},
{"Win Rate", "8%"},
{"Profit-Loss Ratio", "0.70"},
{"Alpha", "-1.454"},
{"Beta", "15.578"},
{"Annual Standard Deviation", "0.212"},
{"Annual Variance", "0.045"},
{"Information Ratio", "-5.664"},
{"Tracking Error", "0.212"},
{"Treynor Ratio", "-0.076"},
{"Alpha", "-0.593"},
{"Beta", "0.692"},
{"Annual Standard Deviation", "0.204"},
{"Annual Variance", "0.042"},
{"Information Ratio", "-2.884"},
{"Tracking Error", "0.194"},
{"Treynor Ratio", "-0.962"},
{"Total Fees", "$25.92"},
{"Fitness Score", "0.004"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "1"},
{"Sortino Ratio", "-4.462"},
{"Return Over Maximum Drawdown", "-13.032"},
{"Portfolio Turnover", "0.083"},
{"Total Insights Generated", "33"},
{"Total Insights Closed", "30"},
{"Total Insights Analysis Completed", "30"},
{"Long Insight Count", "33"},
{"Short Insight Count", "0"},
{"Long/Short Ratio", "100%"},
{"Estimated Monthly Alpha Value", "$-7788114"},
{"Total Accumulated Estimated Alpha Value", "$-3937325"},
{"Mean Population Estimated Insight Value", "$-131244.2"},
{"Mean Population Direction", "46.6667%"},
{"Mean Population Magnitude", "46.6667%"},
{"Rolling Averaged Population Direction", "61.4247%"},
{"Rolling Averaged Population Magnitude", "61.4247%"}
{"Estimated Monthly Alpha Value", "$0"},
{"Total Accumulated Estimated Alpha Value", "$0"},
{"Mean Population Estimated Insight Value", "$0"},
{"Mean Population Direction", "0%"},
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "-1674230481"}
};
}
}

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;
using System.Collections.Generic;
using System.Linq;
using QuantConnect.Data;
using QuantConnect.Data.Custom.Benzinga;
using QuantConnect.Data.UniverseSelection;
namespace QuantConnect.Algorithm.CSharp.AltData
{
/// <summary>
/// Benzinga is a provider of news data. Their news is made in-house
/// and covers stock related news such as corporate events.
/// </summary>
public class BenzingaNewsAlgorithm : QCAlgorithm
{
// Predefine a dictionary of words with scores to scan for in the description
// of the Benzinga news article
private readonly Dictionary<string, double> _words = new Dictionary<string, double>()
{
{"bad", -0.5}, {"good", 0.5},
{"negative", -0.5}, {"great", 0.5},
{"growth", 0.5}, {"fail", -0.5},
{"failed", -0.5}, {"success", 0.5},
{"nailed", 0.5}, {"beat", 0.5},
{"missed", -0.5}
};
// Trade only every 5 days
private DateTime _lastTrade = DateTime.MinValue;
/// <summary>
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
/// </summary>
public override void Initialize()
{
SetStartDate(2018, 6, 5);
SetEndDate(2018, 8, 4);
SetCash(100000);
var aapl = AddEquity("AAPL", Resolution.Hour).Symbol;
var ibm = AddEquity("IBM", Resolution.Hour).Symbol;
AddData<BenzingaNews>(aapl);
AddData<BenzingaNews>(ibm);
}
public override void OnData(Slice data)
{
if ((Time - _lastTrade) < TimeSpan.FromDays(5))
{
return;
}
// Get rid of our holdings after 5 days, and start fresh
Liquidate();
// Get all Benzinga data and loop over it
foreach (var article in data.Get<BenzingaNews>().Values)
{
// Select the same Symbol we're getting a data point for
// from the articles list so that we can get the sentiment of the article.
// We use the underlying Symbol because the Symbols included in the `Symbols` property
// are equity Symbols.
var selectedSymbol = article.Symbols.SingleOrDefault(s => s == article.Symbol.Underlying);
if (selectedSymbol == null)
{
throw new Exception($"Could not find current Symbol {article.Symbol.Underlying} even though it should exist");
}
// The intersection of the article contents and the pre-defined words are the words that are included in both collections
var intersection = article.Contents.ToLowerInvariant().Split(' ').Intersect(_words.Keys);
// Get the words, then get the aggregate sentiment
var sentimentSum = intersection.Select(x => _words[x]).Sum();
if (sentimentSum >= 0.5)
{
Log($"Longing {article.Symbol.Underlying} with sentiment score of {sentimentSum}");
SetHoldings(article.Symbol.Underlying, sentimentSum / 5);
_lastTrade = Time;
}
if (sentimentSum <= -0.5)
{
Log($"Shorting {article.Symbol.Underlying} with sentiment score of {sentimentSum}");
SetHoldings(article.Symbol.Underlying, sentimentSum / 5);
_lastTrade = Time;
}
}
}
public override void OnSecuritiesChanged(SecurityChanges changes)
{
foreach (var r in changes.RemovedSecurities)
{
// If removed from the universe, liquidate and remove the custom data from the algorithm
Liquidate(r.Symbol);
RemoveSecurity(QuantConnect.Symbol.CreateBase(typeof(BenzingaNews), r.Symbol, Market.USA));
}
}
}
}

View File

@@ -0,0 +1,66 @@
/*
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using QuantConnect.Data;
using QuantConnect.Data.Custom.CBOE;
using QuantConnect.Data.Custom.Fred;
using QuantConnect.Data.Custom.USEnergy;
namespace QuantConnect.Algorithm.CSharp.AltData
{
public class CachedAlternativeDataAlgorithm : QCAlgorithm
{
private Symbol _cboeVix;
private Symbol _usEnergy;
private Symbol _fredPeakToTrough;
public override void Initialize()
{
SetStartDate(2003, 1, 1);
SetEndDate(2019, 10, 11);
SetCash(100000);
// QuantConnect caches a small subset of alternative data for easy consumption for the community.
// You can use this in your algorithm as demonstrated below:
_cboeVix = AddData<CBOE>("VIX", Resolution.Daily).Symbol;
// United States EIA data: https://eia.gov/
_usEnergy = AddData<USEnergy>(USEnergy.Petroleum.UnitedStates.WeeklyGrossInputsIntoRefineries, Resolution.Daily).Symbol;
// FRED data
_fredPeakToTrough = AddData<Fred>(Fred.OECDRecessionIndicators.UnitedStatesFromPeakThroughTheTrough, Resolution.Daily).Symbol;
}
public override void OnData(Slice data)
{
if (data.ContainsKey(_cboeVix))
{
var vix = data.Get<CBOE>(_cboeVix);
Log($"VIX: {vix}");
}
if (data.ContainsKey(_usEnergy))
{
var inputIntoRefineries = data.Get<USEnergy>(_usEnergy);
Log($"U.S. Input Into Refineries: {Time}, {inputIntoRefineries.Value}");
}
if (data.ContainsKey(_fredPeakToTrough))
{
var peakToTrough = data.Get<Fred>(_fredPeakToTrough);
Log($"OECD based Recession Indicator for the United States from the Peak through the Trough: {peakToTrough}");
}
}
}
}

View File

@@ -0,0 +1,99 @@
/*
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System.Collections.Generic;
using System.Linq;
using QuantConnect.Algorithm.Framework.Selection;
using QuantConnect.Data;
using QuantConnect.Data.Custom.SEC;
using QuantConnect.Data.UniverseSelection;
namespace QuantConnect.Algorithm.CSharp
{
public class SECReport8KAlgorithm : QCAlgorithm
{
/// <summary>
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
/// </summary>
public override void Initialize()
{
SetStartDate(2019, 1, 1);
SetEndDate(2019, 8, 21);
SetCash(100000);
UniverseSettings.Resolution = Resolution.Minute;
AddUniverseSelection(new CoarseFundamentalUniverseSelectionModel(CoarseSelector));
// Request underlying equity data.
var ibm = AddEquity("IBM", Resolution.Minute).Symbol;
// Add SEC report 10-Q data for the underlying IBM asset
var earningsFiling = AddData<SECReport10Q>(ibm, Resolution.Daily).Symbol;
// Request 120 days of history with the SECReport10Q IBM custom data Symbol.
var history = History<SECReport10Q>(earningsFiling, 120, Resolution.Daily);
// Count the number of items we get from our history request
Debug($"We got {history.Count()} items from our history request");
}
public IEnumerable<Symbol> CoarseSelector(IEnumerable<CoarseFundamental> coarse)
{
// Add SEC data from the filtered coarse selection
var symbols = coarse.Where(x => x.HasFundamentalData && x.DollarVolume > 50000000)
.Select(x => x.Symbol)
.Take(10);
foreach (var symbol in symbols)
{
AddData<SECReport8K>(symbol);
}
return symbols;
}
public override void OnData(Slice data)
{
// Store the symbols we want to long in a list
// so that we can have an equal-weighted portfolio
var longEquitySymbols = new List<Symbol>();
// Get all SEC data and loop over it
foreach (var report in data.Get<SECReport8K>().Values)
{
// Get the length of all contents contained within the report
var reportTextLength = report.Report.Documents.Select(x => x.Text.Length).Sum();
if (reportTextLength > 20000)
{
longEquitySymbols.Add(report.Symbol.Underlying);
}
}
foreach (var equitySymbol in longEquitySymbols)
{
SetHoldings(equitySymbol, 1m / longEquitySymbols.Count);
}
}
public override void OnSecuritiesChanged(SecurityChanges changes)
{
foreach (var r in changes.RemovedSecurities)
{
// If removed from the universe, liquidate and remove the custom data from the algorithm
Liquidate(r.Symbol);
RemoveSecurity(QuantConnect.Symbol.CreateBase(typeof(SECReport8K), r.Symbol, Market.USA));
}
}
}
}

View File

@@ -0,0 +1,90 @@
/*
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System.Collections.Generic;
using System.Linq;
using QuantConnect.Algorithm.Framework.Selection;
using QuantConnect.Data;
using QuantConnect.Data.Custom.SmartInsider;
using QuantConnect.Data.UniverseSelection;
namespace QuantConnect.Algorithm.CSharp
{
public class SmartInsiderTransactionAlgorithm : QCAlgorithm
{
public override void Initialize()
{
SetStartDate(2019, 3, 1);
SetEndDate(2019, 7, 4);
SetCash(1000000);
AddUniverseSelection(new CoarseFundamentalUniverseSelectionModel(CoarseUniverse));
// Request underlying equity data.
var ibm = AddEquity("IBM", Resolution.Minute).Symbol;
// Add Smart Insider stock buyback transaction data for the underlying IBM asset
var si = AddData<SmartInsiderTransaction>(ibm).Symbol;
// Request 60 days of history with the SmartInsiderTransaction IBM Custom Data Symbol.
var history = History<SmartInsiderTransaction>(si, 60, Resolution.Daily);
// Count the number of items we get from our history request
Debug($"We got {history.Count()} items from our history request");
}
public IEnumerable<Symbol> CoarseUniverse(IEnumerable<CoarseFundamental> coarse)
{
var symbols = coarse.Where(x => x.HasFundamentalData && x.DollarVolume > 50000000)
.Select(x => x.Symbol)
.Take(10);
foreach (var symbol in symbols)
{
AddData<SmartInsiderTransaction>(symbol);
}
return symbols;
}
public override void OnData(Slice data)
{
// Get all SmartInsider data available
var transactions = data.Get<SmartInsiderTransaction>();
foreach (var transaction in transactions.Values)
{
if (transaction.VolumePercentage == null || transaction.EventType == null)
{
continue;
}
// Using the Smart Insider transaction information, buy when company does a stock buyback
if (transaction.EventType == SmartInsiderEventType.Transaction && transaction.VolumePercentage > 5)
{
SetHoldings(transaction.Symbol.Underlying, (decimal)transaction.VolumePercentage / 100);
}
}
}
public override void OnSecuritiesChanged(SecurityChanges changes)
{
foreach (var r in changes.RemovedSecurities)
{
// If removed from the universe, liquidate and remove the custom data from the algorithm
Liquidate(r.Symbol);
RemoveSecurity(QuantConnect.Symbol.CreateBase(typeof(SmartInsiderTransaction), r.Symbol, Market.USA));
}
}
}
}

View File

@@ -0,0 +1,85 @@
/*
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System.Collections.Generic;
using System.Linq;
using QuantConnect.Data;
using QuantConnect.Data.Custom.Tiingo;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Look for positive and negative words in the news article description
/// and trade based on the sum of the sentiment
/// </summary>
public class TiingoNewsAlgorithm : QCAlgorithm
{
private Symbol _tiingoSymbol;
// Predefine a dictionary of words with scores to scan for in the description
// of the Tiingo news article
private readonly Dictionary<string, double> _words = new Dictionary<string, double>()
{
{"bad", -0.5}, {"good", 0.5},
{ "negative", -0.5}, {"great", 0.5},
{"growth", 0.5}, {"fail", -0.5},
{"failed", -0.5}, {"success", 0.5},
{"nailed", 0.5}, {"beat", 0.5},
{"missed", -0.5}
};
public override void Initialize()
{
SetStartDate(2019, 6, 10);
SetEndDate(2019, 10, 3);
SetCash(100000);
var aapl = AddEquity("AAPL", Resolution.Hour).Symbol;
_tiingoSymbol = AddData<TiingoNews>(aapl).Symbol;
// Request underlying equity data
var ibm = AddEquity("IBM", Resolution.Minute).Symbol;
// Add news data for the underlying IBM asset
var news = AddData<TiingoNews>(ibm).Symbol;
// Request 60 days of history with the TiingoNews IBM Custom Data Symbol.
var history = History<TiingoNews>(news, 60, Resolution.Daily);
// Count the number of items we get from our history request
Debug($"We got {history.Count()} items from our history request");
}
public override void OnData(Slice data)
{
//Confirm that the data is in the collection
if (!data.ContainsKey(_tiingoSymbol)) return;
// Gets the first piece of data from the Slice
var article = data.Get<TiingoNews>(_tiingoSymbol);
// Article descriptions come in all caps. Lower and split by word
var descriptionWords = article.Description.ToLowerInvariant().Split(' ');
// Take the intersection of predefined words and the words in the
// description to get a list of matching words
var intersection = _words.Keys.Intersect(descriptionWords);
// Get the sum of the article's sentiment, and go long or short
// depending if it's a positive or negative description
var sentiment = intersection.Select(x => _words[x]).Sum();
SetHoldings(article.Symbol.Underlying, sentiment);
}
}
}

View File

@@ -0,0 +1,80 @@
/*
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System.Linq;
using QuantConnect.Data;
using QuantConnect.Data.Custom.TradingEconomics;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Trades on interest rate announcements from data provided by Trading Economics
/// </summary>
public class TradingEconomicsAlgorithm : QCAlgorithm
{
private Symbol _interestRate;
public override void Initialize()
{
SetStartDate(2013, 11, 1);
SetEndDate(2019, 10, 3);
SetCash(100000);
AddEquity("AGG", Resolution.Hour);
AddEquity("SPY", Resolution.Hour);
_interestRate = AddData<TradingEconomicsCalendar>(TradingEconomics.Calendar.UnitedStates.InterestRate).Symbol;
// Request 365 days of interest rate history with the TradingEconomicsCalendar custom data Symbol.
// We should expect no historical data because 2013-11-01 is before the absolute first point of data
var history = History<TradingEconomicsCalendar>(_interestRate, 365, Resolution.Daily);
// Count the number of items we get from our history request (should be zero)
Debug($"We got {history.Count()} items from our history request");
}
public override void OnData(Slice data)
{
// Make sure we have an interest rate calendar event
if (!data.ContainsKey(_interestRate))
{
return;
}
var announcement = data.Get<TradingEconomicsCalendar>(_interestRate);
// Confirm it's a FED Rate Decision
if (announcement.Event != TradingEconomics.Event.UnitedStates.FedInterestRateDecision)
{
return;
}
// In the event of a rate increase, rebalance 50% to Bonds.
var interestRateDecreased = announcement.Actual <= announcement.Previous;
if (interestRateDecreased)
{
SetHoldings("SPY", 1);
SetHoldings("AGG", 0);
}
else
{
SetHoldings("SPY", 0.5);
SetHoldings("AGG", 0.5);
}
}
}
}

View File

@@ -0,0 +1,87 @@
/*
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using System.Linq;
using QuantConnect.Data;
using QuantConnect.Data.Custom.USTreasury;
namespace QuantConnect.Algorithm.CSharp
{
public class USTreasuryYieldCurveRateAlgorithm : QCAlgorithm
{
private Symbol _yieldCurve;
private Symbol _spy;
private DateTime _lastInversion = DateTime.MinValue;
public override void Initialize()
{
SetStartDate(2000, 3, 1);
SetEndDate(2019, 9, 15);
SetCash(100000);
_spy = AddEquity("SPY", Resolution.Hour).Symbol;
_yieldCurve = AddData<USTreasuryYieldCurveRate>("USTYCR", Resolution.Daily).Symbol;
// Request 60 days of history with the USTreasuryYieldCurveRate custom data Symbol.
var history = History<USTreasuryYieldCurveRate>(_yieldCurve, 60, Resolution.Daily);
// Count the number of items we get from our history request
Debug($"We got {history.Count()} items from our history request");
}
public override void OnData(Slice data)
{
if (!data.ContainsKey(_yieldCurve))
{
return;
}
// Preserve null values by getting the data with `slice.Get<T>`
// Accessing the data using `data[_yieldCurve]` results in null
// values becoming `default(decimal)` which is equal to 0
var rates = data.Get<USTreasuryYieldCurveRate>().Values.First();
// Check for null before using the values
if (!rates.TenYear.HasValue || !rates.TwoYear.HasValue)
{
return;
}
// Only advance if a year has gone by
if (Time - _lastInversion < TimeSpan.FromDays(365))
{
return;
}
// if there is a yield curve inversion after not having one for a year, short SPY for two years
if (!Portfolio.Invested && rates.TwoYear > rates.TenYear)
{
Debug($"{Time} - Yield curve inversion! Shorting the market for two years");
SetHoldings(_spy, -0.5);
_lastInversion = Time;
return;
}
// If two years have passed, liquidate our position in SPY
if (Time - _lastInversion >= TimeSpan.FromDays(365 * 2))
{
Liquidate(_spy);
}
}
}
}

View File

@@ -0,0 +1,193 @@
/*
* 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.Indicators;
using QuantConnect.Interfaces;
using QuantConnect.Securities;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Algorithm which tests indicator warm up using different data types, related to GH issue 4205
/// </summary>
public class AutomaticIndicatorWarmupDataTypeRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
{
private Symbol _symbol;
public override void Initialize()
{
UniverseSettings.DataNormalizationMode = DataNormalizationMode.Raw;
EnableAutomaticIndicatorWarmUp = true;
SetStartDate(2013, 10, 08);
SetEndDate(2013, 10, 09);
var SP500 = QuantConnect.Symbol.Create(Futures.Indices.SP500EMini, SecurityType.Future, Market.CME);
_symbol = FutureChainProvider.GetFutureContractList(SP500, StartDate).First();
// Test case: custom IndicatorBase<QuoteBar> indicator using Future unsubscribed symbol
var indicator1 = new CustomIndicator();
AssertIndicatorState(indicator1, isReady: false);
WarmUpIndicator(_symbol, indicator1);
AssertIndicatorState(indicator1, isReady: true);
// Test case: SimpleMovingAverage<IndicatorDataPoint> using Future unsubscribed symbol (should use TradeBar)
var sma1 = new SimpleMovingAverage(10);
AssertIndicatorState(sma1, isReady: false);
WarmUpIndicator(_symbol, sma1);
AssertIndicatorState(sma1, isReady: true);
// Test case: SimpleMovingAverage<IndicatorDataPoint> using Equity unsubscribed symbol
var spy = QuantConnect.Symbol.Create("SPY", SecurityType.Equity, Market.USA);
var sma = new SimpleMovingAverage(10);
AssertIndicatorState(sma, isReady: false);
WarmUpIndicator(spy, sma);
AssertIndicatorState(sma, isReady: true);
// We add the symbol
AddFutureContract(_symbol);
AddEquity("SPY");
// force spy for use Raw data mode so that it matches the used when unsubscribed which uses the universe settings
SubscriptionManager.SubscriptionDataConfigService.GetSubscriptionDataConfigs(spy).SetDataNormalizationMode(DataNormalizationMode.Raw);
// Test case: custom IndicatorBase<QuoteBar> indicator using Future subscribed symbol
var indicator = new CustomIndicator();
var consolidator = CreateConsolidator(TimeSpan.FromMinutes(1), typeof(QuoteBar));
RegisterIndicator(_symbol, indicator, consolidator);
AssertIndicatorState(indicator, isReady: false);
WarmUpIndicator(_symbol, indicator);
AssertIndicatorState(indicator, isReady: true);
// Test case: SimpleMovingAverage<IndicatorDataPoint> using Future Subscribed symbol (should use TradeBar)
var sma11 = new SimpleMovingAverage(10);
AssertIndicatorState(sma11, isReady: false);
WarmUpIndicator(_symbol, sma11);
AssertIndicatorState(sma11, isReady: true);
if (!sma11.Current.Equals(sma1.Current))
{
throw new Exception("Expected SMAs warmed up before and after adding the Future to the algorithm to have the same current value. " +
"The result of 'WarmUpIndicator' shouldn't change if the symbol is or isn't subscribed");
}
// Test case: SimpleMovingAverage<IndicatorDataPoint> using Equity unsubscribed symbol
var smaSpy = new SimpleMovingAverage(10);
AssertIndicatorState(smaSpy, isReady: false);
WarmUpIndicator(spy, smaSpy);
AssertIndicatorState(smaSpy, isReady: true);
if (!smaSpy.Current.Equals(sma.Current))
{
throw new Exception("Expected SMAs warmed up before and after adding the Equity to the algorithm to have the same current value. " +
"The result of 'WarmUpIndicator' shouldn't change if the symbol is or isn't subscribed");
}
}
private void AssertIndicatorState(IIndicator indicator, bool isReady)
{
if (indicator.IsReady != isReady)
{
throw new Exception($"Expected indicator state, expected {isReady} but was {indicator.IsReady}");
}
}
/// <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 (!Portfolio.Invested)
{
SetHoldings(_symbol, 0.5);
}
}
private class CustomIndicator : IndicatorBase<QuoteBar>, IIndicatorWarmUpPeriodProvider
{
private bool _isReady;
public int WarmUpPeriod => 1;
public override bool IsReady => _isReady;
public CustomIndicator() : base("Pepe")
{ }
protected override decimal ComputeNextValue(QuoteBar input)
{
_isReady = true;
return input.Ask.High;
}
}
/// <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", "1"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "-99.999%"},
{"Drawdown", "16.100%"},
{"Expectancy", "0"},
{"Net Profit", "-6.366%"},
{"Sharpe Ratio", "1.194"},
{"Probabilistic Sharpe Ratio", "0%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "5.579"},
{"Beta", "-63.972"},
{"Annual Standard Deviation", "0.434"},
{"Annual Variance", "0.188"},
{"Information Ratio", "0.996"},
{"Tracking Error", "0.441"},
{"Treynor Ratio", "-0.008"},
{"Total Fees", "$20.35"},
{"Fitness Score", "0.138"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "-1.727"},
{"Return Over Maximum Drawdown", "-12.061"},
{"Portfolio Turnover", "4.916"},
{"Total Insights Generated", "0"},
{"Total Insights Closed", "0"},
{"Total Insights Analysis Completed", "0"},
{"Long Insight Count", "0"},
{"Short Insight Count", "0"},
{"Long/Short Ratio", "100%"},
{"Estimated Monthly Alpha Value", "$0"},
{"Total Accumulated Estimated Alpha Value", "$0"},
{"Mean Population Estimated Insight Value", "$0"},
{"Mean Population Direction", "0%"},
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "-1453269600"}
};
}
}

View File

@@ -0,0 +1,155 @@
/*
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using QuantConnect.Data;
using QuantConnect.Indicators;
using QuantConnect.Interfaces;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Algorithm which reproduces GH issue 3861, where in some cases 2 consolidators were added when
/// using the automatic indicator warmup feature
/// </summary>
public class AutomaticIndicatorWarmupRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
{
private Symbol _spy;
public override void Initialize()
{
SetStartDate(2013, 10, 07);
SetEndDate(2013, 10, 11);
EnableAutomaticIndicatorWarmUp = true;
// Test case 1
_spy = AddEquity("SPY").Symbol;
var sma = SMA(_spy, 10);
if (!sma.IsReady)
{
throw new Exception("Expected SMA to be warmed up");
}
// Test case 2
var indicator = new CustomIndicator(10);
RegisterIndicator(_spy, indicator, Resolution.Minute, (Func<IBaseData, decimal>) null);
if (indicator.IsReady)
{
throw new Exception("Expected CustomIndicator Not to be warmed up");
}
WarmUpIndicator(_spy, indicator);
if (!indicator.IsReady)
{
throw new Exception("Expected CustomIndicator to be warmed up");
}
}
/// <summary>
/// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
/// </summary>
/// <param name="data">Slice object keyed by symbol containing the stock data</param>
public override void OnData(Slice data)
{
if (!Portfolio.Invested)
{
var subscription = SubscriptionManager.SubscriptionDataConfigService.GetSubscriptionDataConfigs(_spy).First(config => config.TickType == TickType.Trade);
// we expect 1 consolidator per indicator
if (subscription.Consolidators.Count != 2)
{
throw new Exception($"Unexpected consolidator count for subscription: {subscription.Consolidators.Count}");
}
SetHoldings(_spy, 1);
}
}
private class CustomIndicator : SimpleMovingAverage
{
private IndicatorDataPoint _previous;
public CustomIndicator(int period) : base(period)
{
}
protected override decimal ComputeNextValue(IReadOnlyWindow<IndicatorDataPoint> window, IndicatorDataPoint input)
{
if (_previous != null && input.EndTime == _previous.EndTime)
{
throw new Exception($"Unexpected indicator double data point call: {_previous}");
}
_previous = input;
return base.ComputeNextValue(window, input);
}
}
/// <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", "1"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "264.819%"},
{"Drawdown", "2.200%"},
{"Expectancy", "0"},
{"Net Profit", "1.668%"},
{"Sharpe Ratio", "8.749"},
{"Probabilistic Sharpe Ratio", "67.311%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "-0.005"},
{"Beta", "0.996"},
{"Annual Standard Deviation", "0.219"},
{"Annual Variance", "0.048"},
{"Information Ratio", "-14.189"},
{"Tracking Error", "0.001"},
{"Treynor Ratio", "1.922"},
{"Total Fees", "$3.26"},
{"Fitness Score", "0.248"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "79228162514264337593543950335"},
{"Return Over Maximum Drawdown", "93.761"},
{"Portfolio Turnover", "0.248"},
{"Total Insights Generated", "0"},
{"Total Insights Closed", "0"},
{"Total Insights Analysis Completed", "0"},
{"Long Insight Count", "0"},
{"Short Insight Count", "0"},
{"Long/Short Ratio", "100%"},
{"Estimated Monthly Alpha Value", "$0"},
{"Total Accumulated Estimated Alpha Value", "$0"},
{"Mean Population Estimated Insight Value", "$0"},
{"Mean Population Direction", "0%"},
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "491919591"}
};
}
}

View File

@@ -0,0 +1,323 @@
/*
* 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", "-0.888"},
{"Probabilistic Sharpe Ratio", "0%"},
{"Loss Rate", "100%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "0.035"},
{"Beta", "0.183"},
{"Annual Standard Deviation", "0.004"},
{"Annual Variance", "0"},
{"Information Ratio", "12.058"},
{"Tracking Error", "0.017"},
{"Treynor Ratio", "-0.018"},
{"Total Fees", "$2.00"},
{"Fitness Score", "0.213"},
{"OrderListHash", "904167951"}
};
}
}

View File

@@ -1,4 +1,4 @@
/*
/*
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
*
@@ -71,22 +71,43 @@ namespace QuantConnect.Algorithm.CSharp
{"Total Trades", "1"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "-100.000%"},
{"Drawdown", "11.000%"},
{"Compounding Annual Return", "0%"},
{"Drawdown", "0%"},
{"Expectancy", "0"},
{"Net Profit", "-7.328%"},
{"Sharpe Ratio", "-12.15"},
{"Net Profit", "0%"},
{"Sharpe Ratio", "0"},
{"Probabilistic Sharpe Ratio", "0%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "-17.811"},
{"Beta", "1239.638"},
{"Annual Standard Deviation", "0.762"},
{"Annual Variance", "0.581"},
{"Information Ratio", "-12.169"},
{"Tracking Error", "0.761"},
{"Treynor Ratio", "-0.007"},
{"Total Fees", "$0.00"}
{"Alpha", "0"},
{"Beta", "0"},
{"Annual Standard Deviation", "0"},
{"Annual Variance", "0"},
{"Information Ratio", "0"},
{"Tracking Error", "0"},
{"Treynor Ratio", "0"},
{"Total Fees", "$0.00"},
{"Fitness Score", "0.506"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "79228162514264337593543950335"},
{"Return Over Maximum Drawdown", "-14.148"},
{"Portfolio Turnover", "1.073"},
{"Total Insights Generated", "0"},
{"Total Insights Closed", "0"},
{"Total Insights Analysis Completed", "0"},
{"Long Insight Count", "0"},
{"Short Insight Count", "0"},
{"Long/Short Ratio", "100%"},
{"Estimated Monthly Alpha Value", "€0"},
{"Total Accumulated Estimated Alpha Value", "€0"},
{"Mean Population Estimated Insight Value", "€0"},
{"Mean Population Direction", "0%"},
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "498372354"}
};
}
}

View File

@@ -80,22 +80,43 @@ namespace QuantConnect.Algorithm.CSharp
{"Total Trades", "1"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "263.153%"},
{"Compounding Annual Return", "264.819%"},
{"Drawdown", "2.200%"},
{"Expectancy", "0"},
{"Net Profit", "1.663%"},
{"Sharpe Ratio", "4.41"},
{"Net Profit", "1.668%"},
{"Sharpe Ratio", "8.749"},
{"Probabilistic Sharpe Ratio", "67.311%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "0.007"},
{"Beta", "76.118"},
{"Annual Standard Deviation", "0.192"},
{"Annual Variance", "0.037"},
{"Information Ratio", "4.354"},
{"Tracking Error", "0.192"},
{"Treynor Ratio", "0.011"},
{"Total Fees", "$3.26"}
{"Alpha", "-0.005"},
{"Beta", "0.996"},
{"Annual Standard Deviation", "0.219"},
{"Annual Variance", "0.048"},
{"Information Ratio", "-14.189"},
{"Tracking Error", "0.001"},
{"Treynor Ratio", "1.922"},
{"Total Fees", "$3.26"},
{"Fitness Score", "0.248"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "79228162514264337593543950335"},
{"Return Over Maximum Drawdown", "93.761"},
{"Portfolio Turnover", "0.248"},
{"Total Insights Generated", "0"},
{"Total Insights Closed", "0"},
{"Total Insights Analysis Completed", "0"},
{"Long Insight Count", "0"},
{"Short Insight Count", "0"},
{"Long/Short Ratio", "100%"},
{"Estimated Monthly Alpha Value", "$0"},
{"Total Accumulated Estimated Alpha Value", "$0"},
{"Mean Population Estimated Insight Value", "$0"},
{"Mean Population Direction", "0%"},
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "491919591"}
};
}
}
}

View File

@@ -0,0 +1,53 @@
/*
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using QuantConnect.Algorithm.Framework.Alphas;
using QuantConnect.Algorithm.Framework.Execution;
using QuantConnect.Algorithm.Framework.Portfolio;
using QuantConnect.Data.UniverseSelection;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Basic template algorithm which showcases <see cref="ConstituentsUniverse"/> simple use case
/// </summary>
public class BasicTemplateConstituentUniverseAlgorithm : QCAlgorithm
{
/// <summary>
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
/// </summary>
public override void Initialize()
{
SetStartDate(2013, 10, 07);
SetEndDate(2013, 10, 11);
// by default will use algorithms UniverseSettings
AddUniverse(Universe.Constituent.Steel());
// we specify the UniverseSettings it should use
AddUniverse(Universe.Constituent.AggressiveGrowth(
new UniverseSettings(Resolution.Hour,
2,
false,
false,
UniverseSettings.MinimumTimeInUniverse)));
SetAlpha(new ConstantAlphaModel(InsightType.Price, InsightDirection.Up, TimeSpan.FromDays(1)));
SetExecution(new ImmediateExecutionModel());
SetPortfolioConstruction(new EqualWeightingPortfolioConstructionModel());
}
}
}

View File

@@ -205,23 +205,44 @@ namespace QuantConnect.Algorithm.CSharp
{
{"Total Trades", "10"},
{"Average Win", "0%"},
{"Average Loss", "-0.13%"},
{"Compounding Annual Return", "-99.979%"},
{"Drawdown", "3.500%"},
{"Expectancy", "-1"},
{"Net Profit", "-2.288%"},
{"Sharpe Ratio", "-11.335"},
{"Loss Rate", "100%"},
{"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", "-5.739"},
{"Beta", "413.859"},
{"Annual Standard Deviation", "0.254"},
{"Annual Variance", "0.065"},
{"Information Ratio", "-11.39"},
{"Tracking Error", "0.254"},
{"Treynor Ratio", "-0.007"},
{"Total Fees", "$85.34"}
{"Alpha", "0"},
{"Beta", "0"},
{"Annual Standard Deviation", "0"},
{"Annual Variance", "0"},
{"Information Ratio", "0"},
{"Tracking Error", "0"},
{"Treynor Ratio", "0"},
{"Total Fees", "$85.33"},
{"Fitness Score", "0.5"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "79228162514264337593543950335"},
{"Return Over Maximum Drawdown", "-43.937"},
{"Portfolio Turnover", "1.028"},
{"Total Insights Generated", "0"},
{"Total Insights Closed", "0"},
{"Total Insights Analysis Completed", "0"},
{"Long Insight Count", "0"},
{"Short Insight Count", "0"},
{"Long/Short Ratio", "100%"},
{"Estimated Monthly Alpha Value", "$0"},
{"Total Accumulated Estimated Alpha Value", "$0"},
{"Mean Population Estimated Insight Value", "$0"},
{"Mean Population Direction", "0%"},
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "415415696"}
};
}
}

View File

@@ -75,18 +75,39 @@ namespace QuantConnect.Algorithm.CSharp
{"Drawdown", "1.100%"},
{"Expectancy", "0"},
{"Net Profit", "3.459%"},
{"Sharpe Ratio", "6.033"},
{"Sharpe Ratio", "10.11"},
{"Probabilistic Sharpe Ratio", "83.150%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "0.696"},
{"Beta", "17.597"},
{"Alpha", "1.935"},
{"Beta", "-0.119"},
{"Annual Standard Deviation", "0.16"},
{"Annual Variance", "0.026"},
{"Information Ratio", "5.939"},
{"Tracking Error", "0.16"},
{"Treynor Ratio", "0.055"},
{"Total Fees", "$3.26"}
{"Information Ratio", "-4.556"},
{"Tracking Error", "0.221"},
{"Treynor Ratio", "-13.568"},
{"Total Fees", "$3.26"},
{"Fitness Score", "0.111"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "52.533"},
{"Return Over Maximum Drawdown", "214.75"},
{"Portfolio Turnover", "0.111"},
{"Total Insights Generated", "0"},
{"Total Insights Closed", "0"},
{"Total Insights Analysis Completed", "0"},
{"Long Insight Count", "0"},
{"Short Insight Count", "0"},
{"Long/Short Ratio", "100%"},
{"Estimated Monthly Alpha Value", "$0"},
{"Total Accumulated Estimated Alpha Value", "$0"},
{"Mean Population Estimated Insight Value", "$0"},
{"Mean Population Direction", "0%"},
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "1268340653"}
};
}
}

View File

@@ -53,7 +53,15 @@ namespace QuantConnect.Algorithm.CSharp
// set algorithm framework models
SetUniverseSelection(new ManualUniverseSelectionModel(QuantConnect.Symbol.Create("SPY", SecurityType.Equity, Market.USA)));
SetAlpha(new ConstantAlphaModel(InsightType.Price, InsightDirection.Up, TimeSpan.FromMinutes(20), 0.025, null));
SetPortfolioConstruction(new EqualWeightingPortfolioConstructionModel());
// We can define who often the EWPCM will rebalance if no new insight is submitted using:
// Resolution Enum:
SetPortfolioConstruction(new EqualWeightingPortfolioConstructionModel(Resolution.Daily));
// TimeSpan
// SetPortfolioConstruction(new EqualWeightingPortfolioConstructionModel(TimeSpan.FromDays(2)));
// A Func<DateTime, DateTime>. In this case, we can use the pre-defined func at Expiry helper class
// SetPortfolioConstruction(new EqualWeightingPortfolioConstructionModel(Expiry.EndOfWeek));
SetExecution(new ImmediateExecutionModel());
SetRiskManagement(new MaximumDrawdownPercentPerSecurity(0.01m));
}
@@ -83,37 +91,44 @@ namespace QuantConnect.Algorithm.CSharp
{
{"Total Trades", "3"},
{"Average Win", "0%"},
{"Average Loss", "-1.03%"},
{"Compounding Annual Return", "245.167%"},
{"Drawdown", "2.300%"},
{"Average Loss", "-1.01%"},
{"Compounding Annual Return", "254.782%"},
{"Drawdown", "2.200%"},
{"Expectancy", "-1"},
{"Net Profit", "1.597%"},
{"Sharpe Ratio", "4.169"},
{"Net Profit", "1.632%"},
{"Sharpe Ratio", "8.371"},
{"Probabilistic Sharpe Ratio", "66.555%"},
{"Loss Rate", "100%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "0.007"},
{"Beta", "73.191"},
{"Annual Standard Deviation", "0.195"},
{"Annual Variance", "0.038"},
{"Information Ratio", "4.113"},
{"Tracking Error", "0.195"},
{"Treynor Ratio", "0.011"},
{"Alpha", "-0.088"},
{"Beta", "1.006"},
{"Annual Standard Deviation", "0.221"},
{"Annual Variance", "0.049"},
{"Information Ratio", "-32.586"},
{"Tracking Error", "0.002"},
{"Treynor Ratio", "1.839"},
{"Total Fees", "$9.77"},
{"Fitness Score", "0.747"},
{"Kelly Criterion Estimate", "38.64"},
{"Kelly Criterion Probability Value", "0.229"},
{"Sortino Ratio", "79228162514264337593543950335"},
{"Return Over Maximum Drawdown", "85.209"},
{"Portfolio Turnover", "0.747"},
{"Total Insights Generated", "100"},
{"Total Insights Closed", "99"},
{"Total Insights Analysis Completed", "99"},
{"Long Insight Count", "100"},
{"Short Insight Count", "0"},
{"Long/Short Ratio", "100%"},
{"Estimated Monthly Alpha Value", "$158418.3850"},
{"Total Accumulated Estimated Alpha Value", "$25522.9620"},
{"Mean Population Estimated Insight Value", "$257.8077"},
{"Estimated Monthly Alpha Value", "$126657.6305"},
{"Total Accumulated Estimated Alpha Value", "$20405.9516"},
{"Mean Population Estimated Insight Value", "$206.1207"},
{"Mean Population Direction", "54.5455%"},
{"Mean Population Magnitude", "54.5455%"},
{"Rolling Averaged Population Direction", "59.8056%"},
{"Rolling Averaged Population Magnitude", "59.8056%"}
{"Rolling Averaged Population Magnitude", "59.8056%"},
{"OrderListHash", "951346025"}
};
}
}

View File

@@ -1,4 +1,4 @@
/*
/*
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
*
@@ -20,6 +20,7 @@ using System.Linq;
using QuantConnect.Data;
using QuantConnect.Interfaces;
using QuantConnect.Securities;
using QuantConnect.Securities.Future;
namespace QuantConnect.Algorithm.CSharp
{
@@ -33,13 +34,15 @@ namespace QuantConnect.Algorithm.CSharp
/// <meta name="tag" content="futures" />
public class BasicTemplateFuturesAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
{
private Symbol _contractSymbol;
// S&P 500 EMini futures
private const string RootSP500 = Futures.Indices.SP500EMini;
public Symbol SP500 = QuantConnect.Symbol.Create(RootSP500, SecurityType.Future, Market.USA);
public Symbol SP500 = QuantConnect.Symbol.Create(RootSP500, SecurityType.Future, Market.CME);
// Gold futures
private const string RootGold = Futures.Metals.Gold;
public Symbol Gold = QuantConnect.Symbol.Create(RootGold, SecurityType.Future, Market.USA);
public Symbol Gold = QuantConnect.Symbol.Create(RootGold, SecurityType.Future, Market.COMEX);
/// <summary>
/// Initialize your algorithm and add desired assets.
@@ -54,8 +57,10 @@ namespace QuantConnect.Algorithm.CSharp
var futureGold = AddFuture(RootGold);
// set our expiry filter for this futures chain
// SetFilter method accepts TimeSpan objects or integer for days.
// The following statements yield the same filtering criteria
futureSP500.SetFilter(TimeSpan.Zero, TimeSpan.FromDays(182));
futureGold.SetFilter(TimeSpan.Zero, TimeSpan.FromDays(182));
futureGold.SetFilter(0, 182);
var benchmark = AddEquity("SPY");
SetBenchmark(benchmark.Symbol);
@@ -81,7 +86,8 @@ namespace QuantConnect.Algorithm.CSharp
// if found, trade it
if (contract != null)
{
MarketOrder(contract.Symbol, 1);
_contractSymbol = contract.Symbol;
MarketOrder(_contractSymbol, 1);
}
}
}
@@ -91,6 +97,21 @@ namespace QuantConnect.Algorithm.CSharp
}
}
public override void OnEndOfAlgorithm()
{
// Get the margin requirements
var buyingPowerModel = Securities[_contractSymbol].BuyingPowerModel;
var futureMarginModel = buyingPowerModel as FutureMarginModel;
if (buyingPowerModel == null)
{
throw new Exception($"Invalid buying power model. Found: {buyingPowerModel.GetType().Name}. Expected: {nameof(FutureMarginModel)}");
}
var initialOvernight = futureMarginModel.InitialOvernightMarginRequirement;
var maintenanceOvernight = futureMarginModel.MaintenanceOvernightMarginRequirement;
var initialIntraday = futureMarginModel.InitialIntradayMarginRequirement;
var maintenanceIntraday = futureMarginModel.MaintenanceIntradayMarginRequirement;
}
/// <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>
@@ -113,19 +134,39 @@ namespace QuantConnect.Algorithm.CSharp
{"Drawdown", "13.500%"},
{"Expectancy", "-0.818"},
{"Net Profit", "-13.517%"},
{"Sharpe Ratio", "-29.354"},
{"Sharpe Ratio", "-2.678"},
{"Probabilistic Sharpe Ratio", "0%"},
{"Loss Rate", "89%"},
{"Win Rate", "11%"},
{"Profit-Loss Ratio", "0.69"},
{"Alpha", "-7.746"},
{"Beta", "-0.859"},
{"Annual Standard Deviation", "0.305"},
{"Annual Variance", "0.093"},
{"Information Ratio", "-24.985"},
{"Tracking Error", "0.414"},
{"Treynor Ratio", "10.413"},
{"Alpha", "4.398"},
{"Beta", "-0.989"},
{"Annual Standard Deviation", "0.373"},
{"Annual Variance", "0.139"},
{"Information Ratio", "-12.816"},
{"Tracking Error", "0.504"},
{"Treynor Ratio", "1.011"},
{"Total Fees", "$15207.00"},
{"Fitness Score", "0.033"}
{"Fitness Score", "0.033"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "-8.62"},
{"Return Over Maximum Drawdown", "-7.81"},
{"Portfolio Turnover", "302.321"},
{"Total Insights Generated", "0"},
{"Total Insights Closed", "0"},
{"Total Insights Analysis Completed", "0"},
{"Long Insight Count", "0"},
{"Short Insight Count", "0"},
{"Long/Short Ratio", "100%"},
{"Estimated Monthly Alpha Value", "$0"},
{"Total Accumulated Estimated Alpha Value", "$0"},
{"Mean Population Estimated Insight Value", "$0"},
{"Mean Population Direction", "0%"},
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "-1197265007"}
};
}
}

View File

@@ -33,7 +33,7 @@ namespace QuantConnect.Algorithm.CSharp
public class BasicTemplateFuturesConsolidationAlgorithm : QCAlgorithm
{
private const string RootSP500 = Futures.Indices.SP500EMini;
public Symbol SP500 = QuantConnect.Symbol.Create(RootSP500, SecurityType.Future, Market.USA);
public Symbol SP500 = QuantConnect.Symbol.Create(RootSP500, SecurityType.Future, Market.CME);
private HashSet<Symbol> _futureContracts = new HashSet<Symbol>();
public override void Initialize()
@@ -43,7 +43,11 @@ namespace QuantConnect.Algorithm.CSharp
SetCash(1000000);
var futureSP500 = AddFuture(RootSP500);
futureSP500.SetFilter(TimeSpan.Zero, TimeSpan.FromDays(182));
// set our expiry filter for this future chain
// SetFilter method accepts TimeSpan objects or integer for days.
// The following statements yield the same filtering criteria
futureSP500.SetFilter(0, 182);
// futureSP500.SetFilter(TimeSpan.Zero, TimeSpan.FromDays(182));
SetBenchmark(x => 0);
}

View File

@@ -53,12 +53,12 @@ namespace QuantConnect.Algorithm.CSharp
var newYorkTime = utcTime.ConvertFromUtc(TimeZones.NewYork);
if (newYorkTime.Date < new DateTime(2013, 10, 09))
{
yield return QuantConnect.Symbol.Create(Futures.Indices.SP500EMini, SecurityType.Future, Market.USA);
yield return QuantConnect.Symbol.Create(Futures.Indices.SP500EMini, SecurityType.Future, Market.CME);
}
if (newYorkTime.Date >= new DateTime(2013, 10, 09))
{
yield return QuantConnect.Symbol.Create(Futures.Metals.Gold, SecurityType.Future, Market.USA);
yield return QuantConnect.Symbol.Create(Futures.Metals.Gold, SecurityType.Future, Market.COMEX);
}
}
@@ -142,18 +142,25 @@ namespace QuantConnect.Algorithm.CSharp
{"Drawdown", "5.000%"},
{"Expectancy", "0"},
{"Net Profit", "-3.312%"},
{"Sharpe Ratio", "-16.986"},
{"Sharpe Ratio", "-7.795"},
{"Probabilistic Sharpe Ratio", "0.164%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "-0.828"},
{"Beta", "-77.873"},
{"Annual Standard Deviation", "0.099"},
{"Annual Variance", "0.01"},
{"Information Ratio", "-17.076"},
{"Tracking Error", "0.099"},
{"Treynor Ratio", "0.022"},
{"Alpha", "-1.347"},
{"Beta", "0.257"},
{"Annual Standard Deviation", "0.109"},
{"Annual Variance", "0.012"},
{"Information Ratio", "-14.763"},
{"Tracking Error", "0.188"},
{"Treynor Ratio", "-3.318"},
{"Total Fees", "$3.70"},
{"Fitness Score", "0.009"},
{"Kelly Criterion Estimate", "-112.972"},
{"Kelly Criterion Probability Value", "0.671"},
{"Sortino Ratio", "-8.425"},
{"Return Over Maximum Drawdown", "-35.219"},
{"Portfolio Turnover", "0.548"},
{"Total Insights Generated", "6"},
{"Total Insights Closed", "5"},
{"Total Insights Analysis Completed", "5"},
@@ -166,7 +173,8 @@ namespace QuantConnect.Algorithm.CSharp
{"Mean Population Direction", "0%"},
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"}
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "-1624258832"}
};
}
}

View File

@@ -20,6 +20,8 @@ using QuantConnect.Data;
using QuantConnect.Orders;
using QuantConnect.Securities;
using QuantConnect.Data.UniverseSelection;
using QuantConnect.Interfaces;
using System.Collections.Generic;
namespace QuantConnect.Algorithm.CSharp
{
@@ -32,7 +34,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <meta name="tag" content="history and warm up" />
/// <meta name="tag" content="history" />
/// <meta name="tag" content="futures" />
public class BasicTemplateFuturesHistoryAlgorithm : QCAlgorithm
public class BasicTemplateFuturesHistoryAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
{
// S&P 500 EMini futures
private string [] roots = new []
@@ -41,6 +43,8 @@ namespace QuantConnect.Algorithm.CSharp
Futures.Metals.Gold,
};
private int _successCount = 0;
public override void Initialize()
{
SetStartDate(2013, 10, 8);
@@ -54,6 +58,26 @@ namespace QuantConnect.Algorithm.CSharp
}
SetBenchmark(d => 1000000);
Schedule.On(DateRules.EveryDay(), TimeRules.Every(TimeSpan.FromHours(1)), MakeHistoryCall);
}
private void MakeHistoryCall()
{
var history = History(10, Resolution.Minute);
if (history.Count() < 10)
{
throw new Exception($"Empty history at {Time}");
}
_successCount++;
}
public override void OnEndOfAlgorithm()
{
if (_successCount < 49)
{
throw new Exception($"Scheduled Event did not assert history call as many times as expected: {_successCount}/49");
}
}
/// <summary>
@@ -68,12 +92,12 @@ namespace QuantConnect.Algorithm.CSharp
{
foreach (var contract in chain.Value)
{
Log(String.Format("{0},Bid={1} Ask={2} Last={3} OI={4}",
contract.Symbol.Value,
contract.BidPrice,
contract.AskPrice,
contract.LastPrice,
contract.OpenInterest));
Log($"{contract.Symbol.Value}," +
$"Bid={contract.BidPrice.ToStringInvariant()} " +
$"Ask={contract.AskPrice.ToStringInvariant()} " +
$"Last={contract.LastPrice.ToStringInvariant()} " +
$"OI={contract.OpenInterest.ToStringInvariant()}"
);
}
}
}
@@ -100,5 +124,62 @@ 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", "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"},
{"Fitness Score", "0"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "79228162514264337593543950335"},
{"Return Over Maximum Drawdown", "79228162514264337593543950335"},
{"Portfolio Turnover", "0"},
{"Total Insights Generated", "0"},
{"Total Insights Closed", "0"},
{"Total Insights Analysis Completed", "0"},
{"Long Insight Count", "0"},
{"Short Insight Count", "0"},
{"Long/Short Ratio", "100%"},
{"Estimated Monthly Alpha Value", "$0"},
{"Total Accumulated Estimated Alpha Value", "$0"},
{"Mean Population Estimated Insight Value", "$0"},
{"Mean Population Direction", "0%"},
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "371857150"}
};
}
}

View File

@@ -56,9 +56,12 @@ namespace QuantConnect.Algorithm.CSharp
// setting up S&P 500 EMini futures
var futureSP500 = AddFuture(Futures.Indices.SP500EMini);
_futureSymbol = futureSP500.Symbol;
// set our expiry filter for this futures chain
futureSP500.SetFilter(TimeSpan.FromDays(10), TimeSpan.FromDays(182));
// SetFilter method accepts TimeSpan objects or integer for days.
// The following statements yield the same filtering criteria
futureSP500.SetFilter(10, 182);
// futureSP500.SetFilter(TimeSpan.FromDays(10), TimeSpan.FromDays(182));
// setting up Dow Jones ETF Options
var option = AddOption("DIA");
@@ -66,8 +69,11 @@ namespace QuantConnect.Algorithm.CSharp
option.PriceModel = OptionPriceModels.BinomialCoxRossRubinstein();
// option.EnableGreekApproximation = true;
// set our expiry filter for this option chain
option.SetFilter(-2, +2, TimeSpan.Zero, TimeSpan.FromDays(180));
// set our strike/expiry filter for this option chain
// SetFilter method accepts TimeSpan objects or integer for days.
// The following statements yield the same filtering criteria
option.SetFilter(-2, +2, 0, 180);
// option.SetFilter(-2, +2, TimeSpan.Zero, TimeSpan.FromDays(180));
// specifying zero benchmark
SetBenchmark(date => 0m);
@@ -131,26 +137,26 @@ namespace QuantConnect.Algorithm.CSharp
if (_barCount % 20 == 1)
{
Log(String.Format("P/L:{0:0.00}, Fees:{1:0.00}, Profit:{2:0.00}, Eq:{3:0.00}, Holdings:{4:0.00}, Vol: {5:0.00}, Margin: {6:0.00}",
Portfolio.TotalUnrealisedProfit,
Portfolio.TotalFees,
Portfolio.TotalProfit,
Portfolio.TotalPortfolioValue,
Portfolio.TotalHoldingsValue,
Portfolio.TotalSaleVolume,
Portfolio.TotalMarginUsed));
Log($"P/L:{Portfolio.TotalUnrealisedProfit.ToStringInvariant("0.00")}, " +
$"Fees:{Portfolio.TotalFees.ToStringInvariant("0.00")}, " +
$"Profit:{Portfolio.TotalProfit.ToStringInvariant("0.00")}, " +
$"Eq:{Portfolio.TotalPortfolioValue.ToStringInvariant("0.00")}, " +
$"Holdings:{Portfolio.TotalHoldingsValue.ToStringInvariant("0.00")}, " +
$"Vol: {Portfolio.TotalSaleVolume.ToStringInvariant("0.00")}, " +
$"Margin: {Portfolio.TotalMarginUsed.ToStringInvariant("0.00")}"
);
foreach (var holding in Securities.Values.OrderByDescending(x => x.Holdings.AbsoluteQuantity))
{
Log(String.Format(" - {0}, Avg Prc:{1:0.00}, Qty:{2:0.00}, Mkt Prc:{3:0.00}, Mkt Val:{4:0.00}, Unreal P/L: {5:0.00}, Fees: {6:0.00}, Vol: {7:0.00}",
holding.Symbol.Value,
holding.Holdings.AveragePrice,
holding.Holdings.Quantity,
holding.Holdings.Price,
holding.Holdings.HoldingsValue,
holding.Holdings.UnrealizedProfit,
holding.Holdings.TotalFees,
holding.Holdings.TotalSaleVolume));
Log($" - {holding.Symbol.Value}, " +
$"Avg Prc:{holding.Holdings.AveragePrice.ToStringInvariant("0.00")}, " +
$"Qty:{holding.Holdings.Quantity.ToStringInvariant("0.00")}, " +
$"Mkt Prc:{holding.Holdings.Price.ToStringInvariant("0.00")}, " +
$"Mkt Val:{holding.Holdings.HoldingsValue.ToStringInvariant("0.00")}, " +
$"Unreal P/L: {holding.Holdings.UnrealizedProfit.ToStringInvariant("0.00")}, " +
$"Fees: {holding.Holdings.TotalFees.ToStringInvariant("0.00")}, " +
$"Vol: {holding.Holdings.TotalSaleVolume.ToStringInvariant("0.00")}"
);
}
}
@@ -161,21 +167,20 @@ namespace QuantConnect.Algorithm.CSharp
var underlying = Securities[chain.Key.Underlying];
foreach (var contract in chain.Value)
{
Log(String.Format(@"{0} {1},B={2} A={3} L={4} OI={5} σ={6:0.00} NPV={7:0.00} Δ={8:0.00} Γ={9:0.00} ν={10:0.00} ρ={11:0.00} Θ={12:0.00} IV={13:0.00}",
Time.ToString(),
contract.Symbol.Value,
contract.BidPrice,
contract.AskPrice,
contract.LastPrice,
contract.OpenInterest,
underlying.VolatilityModel.Volatility,
contract.TheoreticalPrice,
contract.Greeks.Delta,
contract.Greeks.Gamma,
contract.Greeks.Vega,
contract.Greeks.Rho,
contract.Greeks.Theta / 365.0m,
contract.ImpliedVolatility));
Log($"{Time.ToStringInvariant()} {contract.Symbol.Value}," +
$"B={contract.BidPrice.ToStringInvariant()} " +
$"A={contract.AskPrice.ToStringInvariant()} " +
$"L={contract.LastPrice.ToStringInvariant()} " +
$"OI={contract.OpenInterest.ToStringInvariant()} " +
$"σ={underlying.VolatilityModel.Volatility:0.00} " +
$"NPV={contract.TheoreticalPrice.ToStringInvariant("0.00")} " +
$"Δ={contract.Greeks.Delta.ToStringInvariant("0.00")} " +
$"Γ={contract.Greeks.Gamma.ToStringInvariant("0.00")} " +
$"ν={contract.Greeks.Vega.ToStringInvariant("0.00")} " +
$"ρ={contract.Greeks.Rho.ToStringInvariant("0.00")} " +
$"Θ={(contract.Greeks.Theta / 365.0m).ToStringInvariant("0.00")} " +
$"IV={contract.ImpliedVolatility.ToStringInvariant("0.00")}"
);
}
}
@@ -183,13 +188,12 @@ namespace QuantConnect.Algorithm.CSharp
{
foreach (var contract in chain.Value)
{
Log(String.Format("{0}, {1}, B={2} A={3} L={4} OI={5}",
contract.Symbol.Value,
Time,
contract.BidPrice,
contract.AskPrice,
contract.LastPrice,
contract.OpenInterest));
Log($"{contract.Symbol.Value}, {Time}, " +
$"B={contract.BidPrice} " +
$"A={contract.AskPrice} " +
$"L={contract.LastPrice} " +
$"OI={contract.OpenInterest}"
);
}
}
}
@@ -201,7 +205,7 @@ namespace QuantConnect.Algorithm.CSharp
foreach (var kpv in slice.Bars)
{
Log($"---> Bar: {Time}, {kpv.Key.Value}, {kpv.Value.Close:0.0000}");
Log($"---> Bar: {Time}, {kpv.Key.Value}, {kpv.Value.Close.ToStringInvariant("0.0000")}");
}
}

View File

@@ -1,4 +1,4 @@
/*
/*
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
*
@@ -48,7 +48,10 @@ namespace QuantConnect.Algorithm.CSharp
_optionSymbol = option.Symbol;
// set our strike/expiry filter for this option chain
option.SetFilter(-2, +2, TimeSpan.Zero, TimeSpan.FromDays(180));
// SetFilter method accepts TimeSpan objects or integer for days.
// The following statements yield the same filtering criteria
option.SetFilter(-2, +2, 0, 180);
// option.SetFilter(-2, +2, TimeSpan.Zero, TimeSpan.FromDays(180));
// Adding this to reproduce GH issue #2314
SetWarmup(TimeSpan.FromMinutes(1));
@@ -113,13 +116,14 @@ namespace QuantConnect.Algorithm.CSharp
{
{"Total Trades", "778"},
{"Average Win", "0%"},
{"Average Loss", "-0.02%"},
{"Compounding Annual Return", "-100%"},
{"Drawdown", "6.900%"},
{"Expectancy", "-1"},
{"Net Profit", "-6.860%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "0%"},
{"Drawdown", "0%"},
{"Expectancy", "0"},
{"Net Profit", "0%"},
{"Sharpe Ratio", "0"},
{"Loss Rate", "100%"},
{"Probabilistic Sharpe Ratio", "0%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "0"},
@@ -129,7 +133,27 @@ namespace QuantConnect.Algorithm.CSharp
{"Information Ratio", "0"},
{"Tracking Error", "0"},
{"Treynor Ratio", "0"},
{"Total Fees", "$778.00"}
{"Total Fees", "$778.00"},
{"Fitness Score", "0"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "0"},
{"Return Over Maximum Drawdown", "0"},
{"Portfolio Turnover", "0"},
{"Total Insights Generated", "0"},
{"Total Insights Closed", "0"},
{"Total Insights Analysis Completed", "0"},
{"Long Insight Count", "0"},
{"Short Insight Count", "0"},
{"Long/Short Ratio", "100%"},
{"Estimated Monthly Alpha Value", "$0"},
{"Total Accumulated Estimated Alpha Value", "$0"},
{"Mean Population Estimated Insight Value", "$0"},
{"Mean Population Direction", "0%"},
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "-702975961"}
};
}
}

View File

@@ -41,7 +41,10 @@ namespace QuantConnect.Algorithm.CSharp
_optionSymbol = option.Symbol;
// set our strike/expiry filter for this option chain
option.SetFilter(-2, +2, TimeSpan.Zero, TimeSpan.FromDays(10));
// SetFilter method accepts TimeSpan objects or integer for days.
// The following statements yields the same filtering criteria
option.SetFilter(-2, +2, 0, 10);
// option.SetFilter(-2, +2, TimeSpan.Zero, TimeSpan.FromDays(10));
// use the underlying equity as the benchmark
SetBenchmark("GOOG");

View File

@@ -35,8 +35,7 @@ namespace QuantConnect.Algorithm.CSharp
public class BasicTemplateOptionsAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
{
private const string UnderlyingTicker = "GOOG";
public readonly Symbol Underlying = QuantConnect.Symbol.Create(UnderlyingTicker, SecurityType.Equity, Market.USA);
public readonly Symbol OptionSymbol = QuantConnect.Symbol.Create(UnderlyingTicker, SecurityType.Option, Market.USA);
public Symbol OptionSymbol;
public override void Initialize()
{
@@ -46,10 +45,14 @@ namespace QuantConnect.Algorithm.CSharp
var equity = AddEquity(UnderlyingTicker);
var option = AddOption(UnderlyingTicker);
OptionSymbol = option.Symbol;
// set our strike/expiry filter for this option chain
option.SetFilter(u => u.Strikes(-2, +2)
.Expiration(TimeSpan.Zero, TimeSpan.FromDays(180)));
// Expiration method accepts TimeSpan objects or integer for days.
// The following statements yield the same filtering criteria
.Expiration(0, 180));
// .Expiration(TimeSpan.Zero, TimeSpan.FromDays(180)));
// use the underlying equity as the benchmark
SetBenchmark(equity.Symbol);
@@ -110,13 +113,14 @@ namespace QuantConnect.Algorithm.CSharp
{
{"Total Trades", "2"},
{"Average Win", "0%"},
{"Average Loss", "-0.28%"},
{"Compounding Annual Return", "-78.282%"},
{"Drawdown", "0.300%"},
{"Expectancy", "-1"},
{"Net Profit", "-0.282%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "0%"},
{"Drawdown", "0%"},
{"Expectancy", "0"},
{"Net Profit", "0%"},
{"Sharpe Ratio", "0"},
{"Loss Rate", "100%"},
{"Probabilistic Sharpe Ratio", "0%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "0"},
@@ -126,7 +130,27 @@ namespace QuantConnect.Algorithm.CSharp
{"Information Ratio", "0"},
{"Tracking Error", "0"},
{"Treynor Ratio", "0"},
{"Total Fees", "$2.00"}
{"Total Fees", "$2.00"},
{"Fitness Score", "0"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "0"},
{"Return Over Maximum Drawdown", "0"},
{"Portfolio Turnover", "0"},
{"Total Insights Generated", "0"},
{"Total Insights Closed", "0"},
{"Total Insights Analysis Completed", "0"},
{"Long Insight Count", "0"},
{"Short Insight Count", "0"},
{"Long/Short Ratio", "100%"},
{"Estimated Monthly Alpha Value", "$0"},
{"Total Accumulated Estimated Alpha Value", "$0"},
{"Mean Population Estimated Insight Value", "$0"},
{"Mean Population Direction", "0%"},
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "1130102123"}
};
}
}

View File

@@ -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,27 +33,26 @@ 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 readonly Symbol Underlying = QuantConnect.Symbol.Create(UnderlyingTicker, SecurityType.Equity, Market.USA);
public readonly Symbol OptionSymbol = QuantConnect.Symbol.Create(UnderlyingTicker, SecurityType.Option, Market.USA);
public Symbol OptionSymbol;
public override void Initialize()
{
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(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
@@ -65,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)
{
@@ -86,5 +86,62 @@ 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", "1"},
{"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"},
{"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", "687310345"}
};
}
}

View File

@@ -80,7 +80,10 @@ namespace QuantConnect.Algorithm.CSharp
{
return filter
.Strikes(+1, +1)
.Expiration(TimeSpan.Zero, TimeSpan.FromDays(7))
// Expiration method accepts TimeSpan objects or integer for days.
// The following statements yield the same filtering criteria
.Expiration(0, 7)
//.Expiration(TimeSpan.Zero, TimeSpan.FromDays(7))
.WeeklysOnly()
.PutsOnly()
.OnlyApplyFilterAtMarketOpen();
@@ -139,37 +142,45 @@ namespace QuantConnect.Algorithm.CSharp
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "4"},
{"Average Win", "0.14%"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "71.396%"},
{"Drawdown", "0.700%"},
{"Compounding Annual Return", "0%"},
{"Drawdown", "0%"},
{"Expectancy", "0"},
{"Net Profit", "0.271%"},
{"Sharpe Ratio", "9.165"},
{"Net Profit", "0%"},
{"Sharpe Ratio", "0"},
{"Probabilistic Sharpe Ratio", "0%"},
{"Loss Rate", "0%"},
{"Win Rate", "100%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "0"},
{"Beta", "24.746"},
{"Annual Standard Deviation", "0.025"},
{"Annual Variance", "0.001"},
{"Information Ratio", "8.883"},
{"Tracking Error", "0.025"},
{"Treynor Ratio", "0.009"},
{"Beta", "0"},
{"Annual Standard Deviation", "0"},
{"Annual Variance", "0"},
{"Information Ratio", "0"},
{"Tracking Error", "0"},
{"Treynor Ratio", "0"},
{"Total Fees", "$4.00"},
{"Fitness Score", "0"},
{"Kelly Criterion Estimate", "0.327"},
{"Kelly Criterion Probability Value", "1"},
{"Sortino Ratio", "79228162514264337593543950335"},
{"Return Over Maximum Drawdown", "79228162514264337593543950335"},
{"Portfolio Turnover", "0"},
{"Total Insights Generated", "26"},
{"Total Insights Closed", "24"},
{"Total Insights Analysis Completed", "24"},
{"Long Insight Count", "26"},
{"Short Insight Count", "0"},
{"Long/Short Ratio", "100%"},
{"Estimated Monthly Alpha Value", "$28.43325"},
{"Estimated Monthly Alpha Value", "$31.01809"},
{"Total Accumulated Estimated Alpha Value", "$1.89555"},
{"Mean Population Estimated Insight Value", "$0.07898125"},
{"Mean Population Direction", "50%"},
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "50.0482%"},
{"Rolling Averaged Population Magnitude", "0%"}
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "352959406"}
};
}
}

View File

@@ -39,8 +39,11 @@ namespace QuantConnect.Algorithm.CSharp
SetCash(1000000);
var option = AddOption("GOOG");
// add the initial contract filter
option.SetFilter(-2, +2, TimeSpan.Zero, TimeSpan.FromDays(180));
// add the initial contract filter
// SetFilter method accepts TimeSpan objects or integer for days.
// The following statements yield the same filtering criteria
option.SetFilter(-2, +2, 0, 180);
// option.SetFilter(-2, +2, TimeSpan.Zero, TimeSpan.FromDays(180));
// set the pricing model for Greeks and volatility
// find more pricing models https://www.quantconnect.com/lean/documentation/topic27704.html
@@ -65,20 +68,20 @@ namespace QuantConnect.Algorithm.CSharp
var underlying = Securities[chain.Key.Underlying];
foreach (var contract in chain.Value)
{
Log(String.Format(@"{0},Bid={1} Ask={2} Last={3} OI={4} σ={5:0.000} NPV={6:0.000} Δ={7:0.000} Γ={8:0.000} ν={9:0.000} ρ={10:0.00} Θ={11:0.00} IV={12:0.000}",
contract.Symbol.Value,
contract.BidPrice,
contract.AskPrice,
contract.LastPrice,
contract.OpenInterest,
underlying.VolatilityModel.Volatility,
contract.TheoreticalPrice,
contract.Greeks.Delta,
contract.Greeks.Gamma,
contract.Greeks.Vega,
contract.Greeks.Rho,
contract.Greeks.Theta / 365.0m,
contract.ImpliedVolatility));
Log($"{contract.Symbol.Value}," +
$"Bid={contract.BidPrice.ToStringInvariant()} " +
$"Ask={contract.AskPrice.ToStringInvariant()} " +
$"Last={contract.LastPrice.ToStringInvariant()} " +
$"OI={contract.OpenInterest.ToStringInvariant()} " +
$"σ={underlying.VolatilityModel.Volatility.ToStringInvariant("0.000")} " +
$"NPV={contract.TheoreticalPrice.ToStringInvariant("0.000")} " +
$"Δ={contract.Greeks.Delta.ToStringInvariant("0.000")} " +
$"Γ={contract.Greeks.Gamma.ToStringInvariant("0.000")} " +
$"ν={contract.Greeks.Vega.ToStringInvariant("0.000")} " +
$"ρ={contract.Greeks.Rho.ToStringInvariant("0.00")} " +
$"Θ={(contract.Greeks.Theta / 365.0m).ToStringInvariant("0.00")} " +
$"IV={contract.ImpliedVolatility.ToStringInvariant("0.000")}"
);
}
}
}

View File

@@ -0,0 +1,63 @@
/*
* 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.Data.Custom.SEC;
using QuantConnect.Securities;
namespace QuantConnect.Algorithm.CSharp.Benchmarks
{
public class SECReportBenchmarkAlgorithm : QCAlgorithm
{
private List<Security> _securities;
/// <summary>
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
/// </summary>
public override void Initialize()
{
SetStartDate(2018, 1, 1);
SetEndDate(2019, 1, 1);
var tickers = new List<string> {"AAPL", "AMZN", "MSFT", "IBM", "FB", "QQQ",
"IWM", "BAC", "BNO", "AIG", "UW", "WM" };
_securities = new List<Security>();
foreach (var ticker in tickers)
{
var equity = AddEquity(ticker);
_securities.Add(equity);
AddData<SECReport8K>(equity.Symbol, Resolution.Daily);
AddData<SECReport10K>(equity.Symbol, Resolution.Daily);
}
}
public override void OnData(Slice data)
{
foreach (var security in _securities)
{
SECReport8K report8K = security.Data.Get<SECReport8K>();
SECReport10K report10K = security.Data.Get<SECReport10K>();
if (!security.HoldStock && report8K != null && report10K != null)
{
SetHoldings(security.Symbol, 1d / _securities.Count);
}
}
}
}
}

View File

@@ -0,0 +1,81 @@
/*
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
using System;
using System.Collections.Generic;
using QuantConnect.Data;
using QuantConnect.Data.Custom.SmartInsider;
using QuantConnect.Securities;
namespace QuantConnect.Algorithm.CSharp.Benchmarks
{
public class SmartInsiderEventBenchmarkAlgorithm : QCAlgorithm
{
private List<Security> _securities;
private List<Symbol> _customSymbols;
private int _historySymbolCount;
/// <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(2010, 1, 1);
SetEndDate(2019, 1, 1);
var tickers = new List<string> {"AAPL", "AMZN", "MSFT", "IBM", "FB", "QQQ",
"IWM", "BAC", "BNO", "AIG", "UW", "WM" };
_securities = new List<Security>();
_customSymbols = new List<Symbol>();
foreach (var ticker in tickers)
{
var equity = AddEquity(ticker, Resolution.Hour);
_securities.Add(equity);
_customSymbols.Add(
AddData<SmartInsiderIntention>(equity.Symbol, Resolution.Daily).Symbol);
_customSymbols.Add(
AddData<SmartInsiderTransaction>(equity.Symbol, Resolution.Daily).Symbol);
}
Schedule.On(DateRules.EveryDay(), TimeRules.At(16, 0), () =>
{
foreach (var slice in History(_customSymbols, TimeSpan.FromDays(5)))
{
_historySymbolCount += slice.Count;
}
foreach (var security in _securities)
{
SmartInsiderIntention intention = security.Data.Get<SmartInsiderIntention>();
SmartInsiderTransaction transaction = security.Data.Get<SmartInsiderTransaction>();
if (!security.HoldStock && intention != null && transaction != null)
{
SetHoldings(security.Symbol, 1d / _securities.Count);
}
}
});
}
public override void OnData(Slice data)
{
var intentions = data.Get<SmartInsiderIntention>();
var transactions = data.Get<SmartInsiderTransaction>();
}
}
}

View File

@@ -74,38 +74,46 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "21"},
{"Total Trades", "18"},
{"Average Win", "0%"},
{"Average Loss", "-0.38%"},
{"Compounding Annual Return", "-82.823%"},
{"Drawdown", "4.300%"},
{"Average Loss", "-0.16%"},
{"Compounding Annual Return", "72.164%"},
{"Drawdown", "1.100%"},
{"Expectancy", "-1"},
{"Net Profit", "-2.384%"},
{"Sharpe Ratio", "-6.465"},
{"Net Profit", "0.747%"},
{"Sharpe Ratio", "4.086"},
{"Probabilistic Sharpe Ratio", "61.091%"},
{"Loss Rate", "100%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "0"},
{"Beta", "-87.084"},
{"Annual Standard Deviation", "0.155"},
{"Annual Variance", "0.024"},
{"Information Ratio", "-6.536"},
{"Tracking Error", "0.155"},
{"Treynor Ratio", "0.011"},
{"Total Fees", "$72.41"},
{"Total Insights Generated", "14"},
{"Total Insights Closed", "11"},
{"Total Insights Analysis Completed", "11"},
{"Alpha", "-0.305"},
{"Beta", "0.564"},
{"Annual Standard Deviation", "0.113"},
{"Annual Variance", "0.013"},
{"Information Ratio", "-10.007"},
{"Tracking Error", "0.09"},
{"Treynor Ratio", "0.82"},
{"Total Fees", "$41.70"},
{"Fitness Score", "0.634"},
{"Kelly Criterion Estimate", "13.656"},
{"Kelly Criterion Probability Value", "0.228"},
{"Sortino Ratio", "79228162514264337593543950335"},
{"Return Over Maximum Drawdown", "80.05"},
{"Portfolio Turnover", "0.634"},
{"Total Insights Generated", "17"},
{"Total Insights Closed", "14"},
{"Total Insights Analysis Completed", "14"},
{"Long Insight Count", "6"},
{"Short Insight Count", "4"},
{"Long/Short Ratio", "150.0%"},
{"Estimated Monthly Alpha Value", "$-85612.32"},
{"Total Accumulated Estimated Alpha Value", "$-14744.34"},
{"Mean Population Estimated Insight Value", "$-1340.395"},
{"Mean Population Direction", "27.2727%"},
{"Mean Population Magnitude", "27.2727%"},
{"Rolling Averaged Population Direction", "5.8237%"},
{"Rolling Averaged Population Magnitude", "5.8237%"}
{"Short Insight Count", "7"},
{"Long/Short Ratio", "85.71%"},
{"Estimated Monthly Alpha Value", "$72447.6813"},
{"Total Accumulated Estimated Alpha Value", "$12477.1007"},
{"Mean Population Estimated Insight Value", "$891.2215"},
{"Mean Population Direction", "50%"},
{"Mean Population Magnitude", "50%"},
{"Rolling Averaged Population Direction", "12.6429%"},
{"Rolling Averaged Population Magnitude", "12.6429%"},
{"OrderListHash", "-2004493274"}
};
}
}

View File

@@ -108,8 +108,9 @@ namespace QuantConnect.Algorithm.CSharp
{
// return a message describing why we're not allowing this order
message = new BrokerageMessageEvent(BrokerageMessageType.Warning, "InsufficientRemainingCapital",
string.Format("Account must maintain a minimum of ${0} USD at all times. Order ID: {1}", _minimumAccountBalance, order.Id)
);
$"Account must maintain a minimum of ${_minimumAccountBalance.ToStringInvariant()} USD at all times. " +
$"Order ID: {order.Id.ToStringInvariant()}"
);
return false;
}
return true;

View File

@@ -130,22 +130,43 @@ namespace QuantConnect.Algorithm.CSharp
{"Total Trades", "2"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "-100.000%"},
{"Drawdown", "5.600%"},
{"Compounding Annual Return", "0%"},
{"Drawdown", "0%"},
{"Expectancy", "0"},
{"Net Profit", "-4.431%"},
{"Sharpe Ratio", "-23.129"},
{"Net Profit", "0%"},
{"Sharpe Ratio", "0"},
{"Probabilistic Sharpe Ratio", "0%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "-8.364"},
{"Beta", "395.811"},
{"Annual Standard Deviation", "0.243"},
{"Annual Variance", "0.059"},
{"Information Ratio", "-23.216"},
{"Tracking Error", "0.243"},
{"Treynor Ratio", "-0.014"},
{"Total Fees", "$0.00"}
{"Alpha", "0"},
{"Beta", "0"},
{"Annual Standard Deviation", "0"},
{"Annual Variance", "0"},
{"Information Ratio", "0"},
{"Tracking Error", "0"},
{"Treynor Ratio", "0"},
{"Total Fees", "$0.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"},
{"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", "737971736"}
};
}
}

View File

@@ -76,24 +76,45 @@ namespace QuantConnect.Algorithm.CSharp
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "167"},
{"Average Win", "0.01%"},
{"Average Loss", "-0.01%"},
{"Compounding Annual Return", "-16.316%"},
{"Drawdown", "0.100%"},
{"Expectancy", "-0.121"},
{"Net Profit", "-0.081%"},
{"Sharpe Ratio", "-87.066"},
{"Loss Rate", "49%"},
{"Win Rate", "51%"},
{"Profit-Loss Ratio", "0.74"},
{"Alpha", "-0.116"},
{"Beta", "-0.092"},
{"Annual Standard Deviation", "0.001"},
{"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", "2.962"},
{"Tracking Error", "0.014"},
{"Treynor Ratio", "1.116"},
{"Total Fees", "$0.00"}
{"Information Ratio", "0"},
{"Tracking Error", "0"},
{"Treynor Ratio", "0"},
{"Total Fees", "$0.00"},
{"Fitness Score", "0.5"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "79228162514264337593543950335"},
{"Return Over Maximum Drawdown", "-325.922"},
{"Portfolio Turnover", "9.561"},
{"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", "1456907343"}
};
}
}

View File

@@ -74,14 +74,14 @@ namespace QuantConnect.Algorithm.CSharp
};
}
// sort the data by P/E ratio and take the top 'NumberOfSymbolsFine'
// sort the data by market capitalization and take the top 'NumberOfSymbolsFine'
public IEnumerable<Symbol> FineSelectionFunction(IEnumerable<FineFundamental> fine)
{
// sort descending by P/E ratio
var sortedByPeRatio = fine.OrderByDescending(x => x.ValuationRatios.PERatio);
// sort descending by market capitalization
var sortedByMarketCap = fine.OrderByDescending(x => x.MarketCap);
// take the top entries from our sorted collection
var topFine = sortedByPeRatio.Take(NumberOfSymbolsFine);
var topFine = sortedByMarketCap.Take(NumberOfSymbolsFine);
// we need to return only the symbol objects
return topFine.Select(x => x.Symbol);
@@ -162,24 +162,45 @@ namespace QuantConnect.Algorithm.CSharp
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "2"},
{"Average Win", "1.39%"},
{"Average Win", "1.16%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "40.038%"},
{"Compounding Annual Return", "32.515%"},
{"Drawdown", "1.400%"},
{"Expectancy", "0"},
{"Net Profit", "1.394%"},
{"Sharpe Ratio", "3.081"},
{"Net Profit", "1.164%"},
{"Sharpe Ratio", "2.857"},
{"Probabilistic Sharpe Ratio", "64.822%"},
{"Loss Rate", "0%"},
{"Win Rate", "100%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "-0.033"},
{"Beta", "19.023"},
{"Annual Standard Deviation", "0.096"},
{"Annual Variance", "0.009"},
{"Information Ratio", "2.904"},
{"Tracking Error", "0.096"},
{"Treynor Ratio", "0.016"},
{"Total Fees", "$2.00"}
{"Alpha", "0.237"},
{"Beta", "-0.182"},
{"Annual Standard Deviation", "0.09"},
{"Annual Variance", "0.008"},
{"Information Ratio", "2.425"},
{"Tracking Error", "0.149"},
{"Treynor Ratio", "-1.405"},
{"Total Fees", "$2.00"},
{"Fitness Score", "0.076"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "27.329"},
{"Return Over Maximum Drawdown", "24.003"},
{"Portfolio Turnover", "0.076"},
{"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", "-1465929889"}
};
}
}

View File

@@ -0,0 +1,189 @@
/*
* 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"},
{"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", "1630141557"}
};
}
}

View File

@@ -119,22 +119,43 @@ namespace QuantConnect.Algorithm.CSharp
{"Total Trades", "11"},
{"Average Win", "0.51%"},
{"Average Loss", "-0.33%"},
{"Compounding Annual Return", "-31.051%"},
{"Compounding Annual Return", "-31.082%"},
{"Drawdown", "2.700%"},
{"Expectancy", "0.263"},
{"Net Profit", "-1.516%"},
{"Sharpe Ratio", "-2.526"},
{"Net Profit", "-1.518%"},
{"Sharpe Ratio", "-2.118"},
{"Probabilistic Sharpe Ratio", "23.259%"},
{"Loss Rate", "50%"},
{"Win Rate", "50%"},
{"Profit-Loss Ratio", "1.53"},
{"Alpha", "-0.556"},
{"Beta", "14.058"},
{"Annual Standard Deviation", "0.124"},
{"Annual Variance", "0.015"},
{"Information Ratio", "-2.666"},
{"Tracking Error", "0.124"},
{"Treynor Ratio", "-0.022"},
{"Total Fees", "$11.63"}
{"Alpha", "-0.208"},
{"Beta", "0.415"},
{"Annual Standard Deviation", "0.119"},
{"Annual Variance", "0.014"},
{"Information Ratio", "-1.167"},
{"Tracking Error", "0.126"},
{"Treynor Ratio", "-0.607"},
{"Total Fees", "$11.63"},
{"Fitness Score", "0.013"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "-5.1"},
{"Return Over Maximum Drawdown", "-11.717"},
{"Portfolio Turnover", "0.282"},
{"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", "-1623759093"}
};
}
}

View File

@@ -102,6 +102,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Expectancy", "0"},
{"Net Profit", "0%"},
{"Sharpe Ratio", "0"},
{"Probabilistic Sharpe Ratio", "0%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
@@ -109,10 +110,30 @@ namespace QuantConnect.Algorithm.CSharp
{"Beta", "0"},
{"Annual Standard Deviation", "0"},
{"Annual Variance", "0"},
{"Information Ratio", "0"},
{"Tracking Error", "0"},
{"Information Ratio", "-1.383"},
{"Tracking Error", "0.096"},
{"Treynor Ratio", "0"},
{"Total Fees", "$0.00"}
{"Total Fees", "$0.00"},
{"Fitness Score", "0"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "79228162514264337593543950335"},
{"Return Over Maximum Drawdown", "79228162514264337593543950335"},
{"Portfolio Turnover", "0"},
{"Total Insights Generated", "0"},
{"Total Insights Closed", "0"},
{"Total Insights Analysis Completed", "0"},
{"Long Insight Count", "0"},
{"Short Insight Count", "0"},
{"Long/Short Ratio", "100%"},
{"Estimated Monthly Alpha Value", "$0"},
{"Total Accumulated Estimated Alpha Value", "$0"},
{"Mean Population Estimated Insight Value", "$0"},
{"Mean Population Direction", "0%"},
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "371857150"}
};
}
}

View File

@@ -0,0 +1,145 @@
/*
* 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>
/// Test algorithm that reproduces GH issues 3410 and 3409.
/// Coarse universe selection should start from the algorithm start date.
/// Data returned by history requests performed from the selection method should be up to date.
/// </summary>
public class CoarseSelectionTimeRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
{
private Symbol _spy;
private decimal _historyCoarseSpyPrice;
/// <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(2014, 03, 25);
SetEndDate(2014, 04, 01);
_spy = AddEquity("SPY", Resolution.Daily).Symbol;
UniverseSettings.Resolution = Resolution.Daily;
AddUniverse(CoarseSelectionFunction);
}
public IEnumerable<Symbol> CoarseSelectionFunction(IEnumerable<CoarseFundamental> coarse)
{
var sortedByDollarVolume = coarse.OrderByDescending(x => x.DollarVolume);
var top = sortedByDollarVolume
.Where(fundamental => fundamental.Symbol != _spy) // ignore spy
.Take(1);
_historyCoarseSpyPrice = History(_spy, 1).First().Close;
return top.Select(x => x.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 (data.Count != 2)
{
throw new Exception($"Unexpected data count: {data.Count}");
}
if (ActiveSecurities.Count != 2)
{
throw new Exception($"Unexpected ActiveSecurities count: {ActiveSecurities.Count}");
}
// the price obtained by the previous coarse selection should be the same as the current price
if (_historyCoarseSpyPrice != 0 && _historyCoarseSpyPrice != Securities[_spy].Price)
{
throw new Exception($"Unexpected SPY price: {_historyCoarseSpyPrice}");
}
_historyCoarseSpyPrice = 0;
if (!Portfolio.Invested)
{
SetHoldings(_spy, 1);
Debug("Purchased Stock");
}
}
/// <summary>
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
/// </summary>
public bool CanRunLocally { get; } = true;
/// <summary>
/// This is used by the regression test system to indicate which languages this algorithm is written in.
/// </summary>
public 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", "58.336%"},
{"Drawdown", "0.900%"},
{"Expectancy", "0"},
{"Net Profit", "1.012%"},
{"Sharpe Ratio", "5.09"},
{"Probabilistic Sharpe Ratio", "68.472%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "0.322"},
{"Beta", "0.265"},
{"Annual Standard Deviation", "0.087"},
{"Annual Variance", "0.008"},
{"Information Ratio", "-0.088"},
{"Tracking Error", "0.105"},
{"Treynor Ratio", "1.667"},
{"Total Fees", "$2.91"},
{"Fitness Score", "0.141"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "9.731"},
{"Return Over Maximum Drawdown", "61.515"},
{"Portfolio Turnover", "0.143"},
{"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", "-1959413055"}
};
}
}

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

@@ -73,23 +73,30 @@ namespace QuantConnect.Algorithm.CSharp
{
{"Total Trades", "7"},
{"Average Win", "0.01%"},
{"Average Loss", "-0.38%"},
{"Compounding Annual Return", "1192.794%"},
{"Drawdown", "1.700%"},
{"Expectancy", "-0.323"},
{"Net Profit", "3.326%"},
{"Sharpe Ratio", "6.635"},
{"Average Loss", "-0.40%"},
{"Compounding Annual Return", "1114.772%"},
{"Drawdown", "1.800%"},
{"Expectancy", "-0.319"},
{"Net Profit", "3.244%"},
{"Sharpe Ratio", "23.478"},
{"Probabilistic Sharpe Ratio", "80.383%"},
{"Loss Rate", "33%"},
{"Win Rate", "67%"},
{"Profit-Loss Ratio", "0.01"},
{"Alpha", "0"},
{"Beta", "152.178"},
{"Annual Standard Deviation", "0.253"},
{"Annual Variance", "0.064"},
{"Information Ratio", "6.594"},
{"Tracking Error", "0.253"},
{"Treynor Ratio", "0.011"},
{"Profit-Loss Ratio", "0.02"},
{"Alpha", "4.314"},
{"Beta", "1.239"},
{"Annual Standard Deviation", "0.285"},
{"Annual Variance", "0.081"},
{"Information Ratio", "47.452"},
{"Tracking Error", "0.101"},
{"Treynor Ratio", "5.409"},
{"Total Fees", "$67.00"},
{"Fitness Score", "0.501"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "148.636"},
{"Return Over Maximum Drawdown", "1502.912"},
{"Portfolio Turnover", "0.501"},
{"Total Insights Generated", "2"},
{"Total Insights Closed", "0"},
{"Total Insights Analysis Completed", "0"},
@@ -102,7 +109,8 @@ namespace QuantConnect.Algorithm.CSharp
{"Mean Population Direction", "0%"},
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"}
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "-28636839"}
};
}
}

View File

@@ -66,37 +66,45 @@ namespace QuantConnect.Algorithm.CSharp
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "7"},
{"Average Win", "1.00%"},
{"Average Loss", "-1.03%"},
{"Compounding Annual Return", "190.425%"},
{"Drawdown", "2.300%"},
{"Expectancy", "0.314"},
{"Net Profit", "1.372%"},
{"Sharpe Ratio", "3.771"},
{"Average Win", "1.02%"},
{"Average Loss", "-1.01%"},
{"Compounding Annual Return", "205.606%"},
{"Drawdown", "2.200%"},
{"Expectancy", "0.339"},
{"Net Profit", "1.439%"},
{"Sharpe Ratio", "7.166"},
{"Probabilistic Sharpe Ratio", "64.794%"},
{"Loss Rate", "33%"},
{"Win Rate", "67%"},
{"Profit-Loss Ratio", "0.97"},
{"Alpha", "0.007"},
{"Beta", "62.953"},
{"Annual Standard Deviation", "0.186"},
{"Annual Variance", "0.035"},
{"Information Ratio", "3.713"},
{"Tracking Error", "0.186"},
{"Treynor Ratio", "0.011"},
{"Profit-Loss Ratio", "1.01"},
{"Alpha", "-0.341"},
{"Beta", "0.968"},
{"Annual Standard Deviation", "0.213"},
{"Annual Variance", "0.045"},
{"Information Ratio", "-46.719"},
{"Tracking Error", "0.009"},
{"Treynor Ratio", "1.575"},
{"Total Fees", "$22.77"},
{"Fitness Score", "0.999"},
{"Kelly Criterion Estimate", "38.64"},
{"Kelly Criterion Probability Value", "0.229"},
{"Sortino Ratio", "79228162514264337593543950335"},
{"Return Over Maximum Drawdown", "69.159"},
{"Portfolio Turnover", "1.242"},
{"Total Insights Generated", "100"},
{"Total Insights Closed", "99"},
{"Total Insights Analysis Completed", "99"},
{"Long Insight Count", "100"},
{"Short Insight Count", "0"},
{"Long/Short Ratio", "100%"},
{"Estimated Monthly Alpha Value", "$158418.3850"},
{"Total Accumulated Estimated Alpha Value", "$25522.9620"},
{"Mean Population Estimated Insight Value", "$257.8077"},
{"Estimated Monthly Alpha Value", "$126657.6305"},
{"Total Accumulated Estimated Alpha Value", "$20405.9516"},
{"Mean Population Estimated Insight Value", "$206.1207"},
{"Mean Population Direction", "54.5455%"},
{"Mean Population Magnitude", "54.5455%"},
{"Rolling Averaged Population Direction", "59.8056%"},
{"Rolling Averaged Population Magnitude", "59.8056%"}
{"Rolling Averaged Population Magnitude", "59.8056%"},
{"OrderListHash", "-1225025518"}
};
}
}

View File

@@ -0,0 +1,119 @@
/*
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using System.Collections.Generic;
using QuantConnect.Algorithm.Framework.Alphas;
using QuantConnect.Algorithm.Framework.Execution;
using QuantConnect.Algorithm.Framework.Portfolio;
using QuantConnect.Algorithm.Framework.Selection;
using QuantConnect.Interfaces;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Test algorithm using <see cref="ConfidenceWeightedPortfolioConstructionModel"/> and <see cref="ConstantAlphaModel"/>
/// generating a constant <see cref="Insight"/> with a 0.25 confidence
/// </summary>
public class ConfidenceWeightedFrameworkAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
{
/// <summary>
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
/// </summary>
public override void Initialize()
{
// Set requested data resolution
UniverseSettings.Resolution = Resolution.Minute;
SetStartDate(2013, 10, 07); //Set Start Date
SetEndDate(2013, 10, 11); //Set End Date
SetCash(100000); //Set Strategy Cash
// set algorithm framework models
SetUniverseSelection(new ManualUniverseSelectionModel(QuantConnect.Symbol.Create("SPY", SecurityType.Equity, Market.USA)));
SetAlpha(new ConstantAlphaModel(InsightType.Price, InsightDirection.Up, TimeSpan.FromMinutes(20), 0.025, 0.25));
SetPortfolioConstruction(new ConfidenceWeightedPortfolioConstructionModel());
SetExecution(new ImmediateExecutionModel());
}
public override void OnEndOfAlgorithm()
{
if (// holdings value should be 0.25 - to avoid price fluctuation issue we compare with 0.28 and 0.23
Portfolio.TotalHoldingsValue > Portfolio.TotalPortfolioValue * 0.28m
||
Portfolio.TotalHoldingsValue < Portfolio.TotalPortfolioValue * 0.23m)
{
throw new Exception($"Unexpected Total Holdings Value: {Portfolio.TotalHoldingsValue}");
}
}
/// <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", "6"},
{"Average Win", "0.00%"},
{"Average Loss", "0.00%"},
{"Compounding Annual Return", "38.059%"},
{"Drawdown", "0.600%"},
{"Expectancy", "-0.502"},
{"Net Profit", "0.413%"},
{"Sharpe Ratio", "5.518"},
{"Probabilistic Sharpe Ratio", "66.933%"},
{"Loss Rate", "67%"},
{"Win Rate", "33%"},
{"Profit-Loss Ratio", "0.50"},
{"Alpha", "-0.178"},
{"Beta", "0.249"},
{"Annual Standard Deviation", "0.055"},
{"Annual Variance", "0.003"},
{"Information Ratio", "-9.844"},
{"Tracking Error", "0.165"},
{"Treynor Ratio", "1.212"},
{"Total Fees", "$6.00"},
{"Fitness Score", "0.063"},
{"Kelly Criterion Estimate", "38.64"},
{"Kelly Criterion Probability Value", "0.229"},
{"Sortino Ratio", "79228162514264337593543950335"},
{"Return Over Maximum Drawdown", "70.188"},
{"Portfolio Turnover", "0.063"},
{"Total Insights Generated", "100"},
{"Total Insights Closed", "99"},
{"Total Insights Analysis Completed", "99"},
{"Long Insight Count", "100"},
{"Short Insight Count", "0"},
{"Long/Short Ratio", "100%"},
{"Estimated Monthly Alpha Value", "$126657.6305"},
{"Total Accumulated Estimated Alpha Value", "$20405.9516"},
{"Mean Population Estimated Insight Value", "$206.1207"},
{"Mean Population Direction", "54.5455%"},
{"Mean Population Magnitude", "54.5455%"},
{"Rolling Averaged Population Direction", "59.8056%"},
{"Rolling Averaged Population Magnitude", "59.8056%"},
{"OrderListHash", "501060991"}
};
}
}

View File

@@ -0,0 +1,189 @@
/*
* 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.Consolidators;
using QuantConnect.Data.Market;
using QuantConnect.Indicators;
using QuantConnect.Interfaces;
using QuantConnect.Securities;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Regression algorithm reproducing data type bugs in the Consolidate API. Related to GH 4205.
/// </summary>
public class ConsolidateRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
{
private List<int> _consolidationCount;
private int _customDataConsolidator;
private Symbol _symbol;
/// <summary>
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
/// </summary>
public override void Initialize()
{
SetStartDate(2013, 10, 08);
SetEndDate(2013, 10, 09);
var SP500 = QuantConnect.Symbol.Create(Futures.Indices.SP500EMini, SecurityType.Future, Market.CME);
_symbol = FutureChainProvider.GetFutureContractList(SP500, StartDate).First();
AddFutureContract(_symbol);
_consolidationCount = new List<int> { 0, 0, 0, 0, 0, 0, 0, 0 };
var sma = new SimpleMovingAverage(10);
Consolidate<QuoteBar>(_symbol, time => new CalendarInfo(time.RoundDown(TimeSpan.FromDays(1)), TimeSpan.FromDays(1)),
bar => UpdateQuoteBar(sma, bar, 0));
var sma2 = new SimpleMovingAverage(10);
Consolidate<QuoteBar>(_symbol, TimeSpan.FromDays(1), bar => UpdateQuoteBar(sma2, bar, 1));
var sma3 = new SimpleMovingAverage(10);
Consolidate(_symbol, Resolution.Daily, TickType.Quote, (Action<QuoteBar>)(bar => UpdateQuoteBar(sma3, bar, 2)));
var sma4 = new SimpleMovingAverage(10);
Consolidate(_symbol, TimeSpan.FromDays(1), bar => UpdateTradeBar(sma4, bar, 3));
var sma5 = new SimpleMovingAverage(10);
Consolidate<TradeBar>(_symbol, TimeSpan.FromDays(1), bar => UpdateTradeBar(sma5, bar, 4));
// custom data
var sma6 = new SimpleMovingAverage(10);
var symbol = AddData<CustomDataRegressionAlgorithm.Bitcoin>("BTC", Resolution.Minute).Symbol;
Consolidate<TradeBar>(symbol, TimeSpan.FromDays(1), bar => _customDataConsolidator++);
try
{
Consolidate<QuoteBar>(symbol, TimeSpan.FromDays(1), bar => { UpdateQuoteBar(sma6, bar, -1); });
throw new Exception($"Expected {nameof(ArgumentException)} to be thrown");
}
catch (ArgumentException)
{
// will try to use BaseDataConsolidator for which input is TradeBars not QuoteBars
}
// Test using abstract T types, through defining a 'BaseData' handler
var sma7 = new SimpleMovingAverage(10);
Consolidate(_symbol, Resolution.Daily, null, (Action<BaseData>)(bar => UpdateBar(sma7, bar, 5)));
var sma8 = new SimpleMovingAverage(10);
Consolidate(_symbol, TimeSpan.FromDays(1), null, (Action<BaseData>)(bar => UpdateBar(sma8, bar, 6)));
var sma9 = new SimpleMovingAverage(10);
Consolidate(_symbol, TimeSpan.FromDays(1), (Action<BaseData>)(bar => UpdateBar(sma9, bar, 7)));
}
private void UpdateBar(SimpleMovingAverage sma, BaseData tradeBar, int position)
{
if (!(tradeBar is TradeBar))
{
throw new Exception("Expected a TradeBar");
}
_consolidationCount[position]++;
sma.Update(tradeBar.EndTime, tradeBar.Value);
}
private void UpdateTradeBar(SimpleMovingAverage sma, TradeBar tradeBar, int position)
{
_consolidationCount[position]++;
sma.Update(tradeBar.EndTime, tradeBar.High);
}
private void UpdateQuoteBar(SimpleMovingAverage sma, QuoteBar quoteBar, int position)
{
_consolidationCount[position]++;
sma.Update(quoteBar.EndTime, quoteBar.High);
}
public override void OnEndOfAlgorithm()
{
if (_consolidationCount.Any(i => i != 3) || _customDataConsolidator == 0)
{
throw new Exception("Unexpected consolidation count");
}
}
/// <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 (!Portfolio.Invested)
{
SetHoldings(_symbol, 0.5);
}
}
/// <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", "-99.999%"},
{"Drawdown", "16.100%"},
{"Expectancy", "0"},
{"Net Profit", "-6.366%"},
{"Sharpe Ratio", "1.194"},
{"Probabilistic Sharpe Ratio", "0%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "5.579"},
{"Beta", "-63.972"},
{"Annual Standard Deviation", "0.434"},
{"Annual Variance", "0.188"},
{"Information Ratio", "0.996"},
{"Tracking Error", "0.441"},
{"Treynor Ratio", "-0.008"},
{"Total Fees", "$20.35"},
{"Fitness Score", "0.138"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "-1.727"},
{"Return Over Maximum Drawdown", "-12.061"},
{"Portfolio Turnover", "4.916"},
{"Total Insights Generated", "0"},
{"Total Insights Closed", "0"},
{"Total Insights Analysis Completed", "0"},
{"Long Insight Count", "0"},
{"Short Insight Count", "0"},
{"Long/Short Ratio", "100%"},
{"Estimated Monthly Alpha Value", "$0"},
{"Total Accumulated Estimated Alpha Value", "$0"},
{"Mean Population Estimated Insight Value", "$0"},
{"Mean Population Direction", "0%"},
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "-1453269600"}
};
}
}

View File

@@ -13,14 +13,12 @@
* limitations under the License.
*/
using QuantConnect.Data.UniverseSelection;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Demonstration of how to estimate constituents of QC500 index based on the company fundamentals
/// The algorithm creates a default tradable and liquid universe containing 500 US equities
/// which are chosen at the first trading day of each month.
/// The algorithm creates a default tradable and liquid universe containing 500 US equities
/// which are chosen at the first trading day of each month.
/// </summary>
/// <meta name="tag" content="using data" />
/// <meta name="tag" content="universes" />

View File

@@ -0,0 +1,161 @@
/*
* 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 System.Linq;
using QuantConnect.Data.UniverseSelection;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Algorithm used to generate daily data on disk for the different <see cref="ConstituentsUniverse"/>.
/// How to use me? search for 'CHANGE ME'
/// 1- change the universe name
/// 2- change the desired start and end date to generate
/// 3- define the universe selection to use
/// Data will be generated in:
/// 'Globals.DataFolder\SecurityType\Market\universes\Resolution\{UniverseName}\{dates:yyyyMMdd}.csv'
/// </summary>
/// <remarks>The data produced by this algorithm is the one used by the
/// <see cref="ConstituentsUniverseRegressionAlgorithm"/></remarks>
/// <remarks>In the cloud, users can implement their own <see cref="ConstituentsUniverseData"/>
/// (not using <see cref="SubscriptionTransportMedium.LocalFile"/>) that can fetch the files
/// generated from this algorithm</remarks>
public class ConstituentsUniverseDataGeneratorAlgorithm : QCAlgorithm
{
private readonly HashSet<Symbol> _currentSelection = new HashSet<Symbol>();
private DateTime _currentDateTime = DateTime.MinValue;
private readonly string _rootDataPath = Globals.DataFolder;
private string _dataPath;
private bool _skippedFirst;
// Configuration properties: Only these are supported for now (Don't change me)
private readonly SecurityType _securityType = SecurityType.Equity;
private readonly string _market = Market.USA;
private readonly Resolution _resolution = Resolution.Daily;
// CHANGE ME
private readonly string _universeName = "qctest";
public override void Initialize()
{
// CHANGE ME
SetStartDate(2013, 10, 07); // Set Start Date
SetEndDate(2013, 10, 11); // Set End Date
SetCash(100000); // Set Strategy Cash
UniverseSettings.Resolution = Resolution.Daily;
_dataPath = Path.Combine(_rootDataPath,
_securityType.SecurityTypeToLower(),
_market,
"universes",
_resolution.ResolutionToLower(),
_universeName);
Directory.CreateDirectory(_dataPath);
// CHANGE ME
int step = 0;
AddUniverse(coarse =>
{
step++;
switch (step)
{
case 1:
case 2:
return new[]
{
QuantConnect.Symbol.Create("QQQ", SecurityType.Equity, Market.USA),
QuantConnect.Symbol.Create("AAPL", SecurityType.Equity, Market.USA)
};
case 3:
return Enumerable.Empty<Symbol>();
case 4:
case 5:
return new[]
{
QuantConnect.Symbol.Create("SPY", SecurityType.Equity, Market.USA),
QuantConnect.Symbol.Create("FB", SecurityType.Equity, Market.USA)
};
default:
throw new Exception("Unexpected step count");
}
});
Schedule.On(DateRules.EveryDay(), TimeRules.At(23, 0), SaveConstituentsUniverseDataToDisk);
}
private void SaveConstituentsUniverseDataToDisk()
{
if (_skippedFirst && Time > _currentDateTime)
{
if (Time.DayOfWeek == DayOfWeek.Sunday
|| Time.DayOfWeek == DayOfWeek.Monday)
{
// we generate files from Tue to Saturday using current selected securities
return;
}
// files are for Mon to Friday
_currentDateTime = Time.Date.AddDays(-1);
var path = Path.Combine(_dataPath, $"{_currentDateTime:yyyyMMdd}.csv");
File.Delete(path);
if (_currentSelection.Count == 0)
{
using (StreamWriter constituentsUniverseFile = new StreamWriter(path, append:true))
{
constituentsUniverseFile.WriteLine(
$"{QuantConnect.Symbol.None.Value},{QuantConnect.Symbol.None.ID.ToString()}");
}
}
else
{
foreach (var symbol in _currentSelection)
{
using (StreamWriter constituentsUniverseFile = new StreamWriter(path, append: true))
{
constituentsUniverseFile.WriteLine($"{symbol.Value},{symbol.ID.ToString()}");
}
}
}
}
_skippedFirst = true;
}
public override void OnSecuritiesChanged(SecurityChanges changes)
{
foreach (var added in changes.AddedSecurities)
{
Log($"AddedSecurities {added}");
if (_currentSelection.Contains(added.Symbol))
{
throw new Exception("Added symbol already selected");
}
_currentSelection.Add(added.Symbol);
}
foreach (var removed in changes.RemovedSecurities)
{
Log($"RemovedSecurities {removed}");
if (!_currentSelection.Contains(removed.Symbol))
{
throw new Exception("Removing symbol already deselected");
}
_currentSelection.Remove(removed.Symbol);
}
}
}
}

View File

@@ -0,0 +1,215 @@
/*
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using System.Collections.Generic;
using QuantConnect.Data;
using QuantConnect.Data.UniverseSelection;
using QuantConnect.Interfaces;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Test algorithm using a <see cref="ConstituentsUniverse"/> with test data
/// </summary>
public class ConstituentsUniverseRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
{
private readonly Symbol _appl = QuantConnect.Symbol.Create("AAPL", SecurityType.Equity, Market.USA);
private readonly Symbol _spy = QuantConnect.Symbol.Create("SPY", SecurityType.Equity, Market.USA);
private readonly Symbol _qqq = QuantConnect.Symbol.Create("QQQ", SecurityType.Equity, Market.USA);
private readonly Symbol _fb = QuantConnect.Symbol.Create("FB", SecurityType.Equity, Market.USA);
private int _step;
/// <summary>
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
/// </summary>
public override void Initialize()
{
SetStartDate(2013, 10, 07); //Set Start Date
SetEndDate(2013, 10, 11); //Set End Date
SetCash(100000); //Set Strategy Cash
UniverseSettings.Resolution = Resolution.Daily;
var customUniverseSymbol = new Symbol(SecurityIdentifier.GenerateConstituentIdentifier(
"constituents-universe-qctest",
SecurityType.Equity,
Market.USA),
"constituents-universe-qctest");
AddUniverse(new ConstituentsUniverse(customUniverseSymbol, UniverseSettings));
}
/// <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)
{
_step++;
if (_step == 1)
{
if (!data.ContainsKey(_qqq)
|| !data.ContainsKey(_appl))
{
throw new Exception($"Unexpected symbols found, step: {_step}");
}
if (data.Count != 2)
{
throw new Exception($"Unexpected data count, step: {_step}");
}
// AAPL will be deselected by the ConstituentsUniverse
// but it shouldn't be removed since we hold it
SetHoldings(_appl, 0.5);
}
else if (_step == 2)
{
if (!data.ContainsKey(_appl))
{
throw new Exception($"Unexpected symbols found, step: {_step}");
}
if (data.Count != 1)
{
throw new Exception($"Unexpected data count, step: {_step}");
}
// AAPL should now be released
// note: takes one extra loop because the order is executed on market open
Liquidate();
}
else if (_step == 3)
{
if (!data.ContainsKey(_fb)
|| !data.ContainsKey(_spy)
|| !data.ContainsKey(_appl))
{
throw new Exception($"Unexpected symbols found, step: {_step}");
}
if (data.Count != 3)
{
throw new Exception($"Unexpected data count, step: {_step}");
}
}
else if (_step == 4)
{
if (!data.ContainsKey(_fb)
|| !data.ContainsKey(_spy))
{
throw new Exception($"Unexpected symbols found, step: {_step}");
}
if (data.Count != 2)
{
throw new Exception($"Unexpected data count, step: {_step}");
}
}
else if (_step == 5)
{
if (!data.ContainsKey(_fb)
|| !data.ContainsKey(_spy))
{
throw new Exception($"Unexpected symbols found, step: {_step}");
}
if (data.Count != 2)
{
throw new Exception($"Unexpected data count, step: {_step}");
}
}
}
public override void OnEndOfAlgorithm()
{
if (_step != 5)
{
throw new Exception($"Unexpected step count: {_step}");
}
}
public override void OnSecuritiesChanged(SecurityChanges changes)
{
foreach (var added in changes.AddedSecurities)
{
Log($"AddedSecurities {added}");
}
foreach (var removed in changes.RemovedSecurities)
{
Log($"RemovedSecurities {removed} {_step}");
// we are currently notifying the removal of AAPl twice,
// when deselected and when finally removed (since it stayed pending)
if (removed.Symbol == _appl && _step != 1 && _step != 2
|| removed.Symbol == _qqq && _step != 1)
{
throw new Exception($"Unexpected removal step count: {_step}");
}
}
}
/// <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.52%"},
{"Compounding Annual Return", "-31.636%"},
{"Drawdown", "0.900%"},
{"Expectancy", "-1"},
{"Net Profit", "-0.520%"},
{"Sharpe Ratio", "-3.097"},
{"Probabilistic Sharpe Ratio", "24.675%"},
{"Loss Rate", "100%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "-0.443"},
{"Beta", "0.157"},
{"Annual Standard Deviation", "0.074"},
{"Annual Variance", "0.005"},
{"Information Ratio", "-9.046"},
{"Tracking Error", "0.176"},
{"Treynor Ratio", "-1.46"},
{"Total Fees", "$7.82"},
{"Fitness Score", "0.1"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "79228162514264337593543950335"},
{"Return Over Maximum Drawdown", "-35.683"},
{"Portfolio Turnover", "0.2"},
{"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", "-611289773"}
};
}
}

View File

@@ -129,35 +129,43 @@ namespace QuantConnect.Algorithm.CSharp
{"Total Trades", "85"},
{"Average Win", "4.85%"},
{"Average Loss", "-4.21%"},
{"Compounding Annual Return", "-3.105%"},
{"Compounding Annual Return", "-3.100%"},
{"Drawdown", "52.900%"},
{"Expectancy", "-0.053"},
{"Net Profit", "-29.335%"},
{"Sharpe Ratio", "-0.084"},
{"Expectancy", "-0.052"},
{"Net Profit", "-29.298%"},
{"Sharpe Ratio", "-0.076"},
{"Probabilistic Sharpe Ratio", "0.004%"},
{"Loss Rate", "56%"},
{"Win Rate", "44%"},
{"Profit-Loss Ratio", "1.15"},
{"Alpha", "0.046"},
{"Beta", "-3.04"},
{"Annual Standard Deviation", "0.181"},
{"Annual Variance", "0.033"},
{"Information Ratio", "-0.194"},
{"Tracking Error", "0.181"},
{"Treynor Ratio", "0.005"},
{"Total Fees", "$755.20"},
{"Alpha", "-0.013"},
{"Beta", "0.009"},
{"Annual Standard Deviation", "0.164"},
{"Annual Variance", "0.027"},
{"Information Ratio", "-0.391"},
{"Tracking Error", "0.239"},
{"Treynor Ratio", "-1.416"},
{"Total Fees", "$755.29"},
{"Fitness Score", "0.024"},
{"Kelly Criterion Estimate", "-0.84"},
{"Kelly Criterion Probability Value", "0.53"},
{"Sortino Ratio", "-0.224"},
{"Return Over Maximum Drawdown", "-0.058"},
{"Portfolio Turnover", "0.05"},
{"Total Insights Generated", "85"},
{"Total Insights Closed", "85"},
{"Total Insights Analysis Completed", "85"},
{"Long Insight Count", "42"},
{"Short Insight Count", "43"},
{"Long/Short Ratio", "97.67%"},
{"Estimated Monthly Alpha Value", "$-607698.1"},
{"Total Accumulated Estimated Alpha Value", "$-81395260"},
{"Mean Population Estimated Insight Value", "$-957591.3"},
{"Mean Population Direction", "50.5882%"},
{"Estimated Monthly Alpha Value", "$-617339.2"},
{"Total Accumulated Estimated Alpha Value", "$-82686580"},
{"Mean Population Estimated Insight Value", "$-972783.3"},
{"Mean Population Direction", "51.7647%"},
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "46.5677%"},
{"Rolling Averaged Population Magnitude", "0%"}
{"Rolling Averaged Population Direction", "48.2217%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "1370210213"}
};
}
}

View File

@@ -1,4 +1,4 @@
/*
/*
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
*
@@ -13,7 +13,10 @@
* limitations under the License.
*/
using System;
using System.Collections.Generic;
using QuantConnect.Data;
using QuantConnect.Interfaces;
namespace QuantConnect.Algorithm.CSharp
{
@@ -22,7 +25,7 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
/// <meta name="tag" content="using data" />
/// <meta name="tag" content="benchmarks" />
public class CustomBenchmarkAlgorithm : QCAlgorithm
public class CustomBenchmarkAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
{
/// <summary>
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
@@ -35,7 +38,7 @@ namespace QuantConnect.Algorithm.CSharp
// Find more symbols here: http://quantconnect.com/data
AddSecurity(SecurityType.Equity, "SPY", Resolution.Second);
SetBenchmark("SPY");
SetBenchmark("AAPL");
}
/// <summary>
@@ -49,6 +52,69 @@ namespace QuantConnect.Algorithm.CSharp
SetHoldings("SPY", 1);
Debug("Purchased Stock");
}
Symbol symbol;
if (SymbolCache.TryGetSymbol("AAPL", out symbol))
{
throw new Exception("Benchmark Symbol is not expected to be added to the Symbol cache");
}
}
/// <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", "264.819%"},
{"Drawdown", "2.200%"},
{"Expectancy", "0"},
{"Net Profit", "1.668%"},
{"Sharpe Ratio", "8.749"},
{"Probabilistic Sharpe Ratio", "67.311%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "1.119"},
{"Beta", "0.805"},
{"Annual Standard Deviation", "0.219"},
{"Annual Variance", "0.048"},
{"Information Ratio", "5.494"},
{"Tracking Error", "0.168"},
{"Treynor Ratio", "2.38"},
{"Total Fees", "$3.26"},
{"Fitness Score", "0.245"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "9.606"},
{"Return Over Maximum Drawdown", "105.85"},
{"Portfolio Turnover", "0.249"},
{"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", "2069976135"}
};
}
}
}

View File

@@ -0,0 +1,121 @@
/*
* 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>
/// Reproduces Lean GH issue 3572: benchmark _would_ use custom data versus equity
/// when both were present
/// </summary>
public class CustomBenchmarkRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
{
/// <summary>
/// Algorithm initialization
/// </summary>
public override void Initialize()
{
SetStartDate(2013, 10, 07);
SetEndDate(2013, 10, 11);
AddEquity("AAPL", Resolution.Hour);
AddData<DummyCustomData>("AAPL");
// set benchmark will use equity AAPL as benchmark
SetBenchmark("AAPL");
}
/// <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 (!Portfolio.Invested)
{
SetHoldings("AAPL", 1);
Debug("Purchased Stock");
}
}
private class DummyCustomData : BaseData
{
public override SubscriptionDataSource GetSource(SubscriptionDataConfig config, DateTime date, bool isLiveMode)
{
return new SubscriptionDataSource("NonExistingFile", SubscriptionTransportMedium.LocalFile);
}
}
/// <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", "1"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "37.355%"},
{"Drawdown", "2.300%"},
{"Expectancy", "0"},
{"Net Profit", "0.407%"},
{"Sharpe Ratio", "5.521"},
{"Probabilistic Sharpe Ratio", "60.177%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "-0.001"},
{"Beta", "0.997"},
{"Annual Standard Deviation", "0.179"},
{"Annual Variance", "0.032"},
{"Information Ratio", "-7.662"},
{"Tracking Error", "0"},
{"Treynor Ratio", "0.988"},
{"Total Fees", "$7.78"},
{"Fitness Score", "0.031"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "-2.145"},
{"Return Over Maximum Drawdown", "-8.479"},
{"Portfolio Turnover", "0.25"},
{"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", "519536519"}
};
}
}

View File

@@ -61,7 +61,7 @@ namespace QuantConnect.Algorithm.CSharp
/// <param name="message">Message object</param>
public void Handle(BrokerageMessageEvent message)
{
var toLog = _algo.Time.ToString("o") + " Event: " + message.Message;
var toLog = $"{_algo.Time.ToStringInvariant("o")} Event: {message.Message}";
_algo.Debug(toLog);
_algo.Log(toLog);
}

View File

@@ -0,0 +1,138 @@
/*
* 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"},
{"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", "639761089"}
};
}
}

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 QuantConnect.Algorithm.Framework.Selection;
using QuantConnect.Data;
using QuantConnect.Data.Custom.SEC;
using QuantConnect.Data.UniverseSelection;
using QuantConnect.Interfaces;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Regression algorithm ensures that data added via coarse selection (underlying) is present in ActiveSecurities
/// </summary>
/// <meta name="tag" content="using data" />
/// <meta name="tag" content="custom data" />
/// <meta name="tag" content="regression test" />d
public class CustomDataAddDataCoarseSelectionRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
{
private List<Symbol> _customSymbols = new List<Symbol>();
public override void Initialize()
{
SetStartDate(2014, 3, 24);
SetEndDate(2014, 4, 7);
SetCash(100000);
UniverseSettings.Resolution = Resolution.Daily;
AddUniverseSelection(new CoarseFundamentalUniverseSelectionModel(CoarseSelector));
}
public IEnumerable<Symbol> CoarseSelector(IEnumerable<CoarseFundamental> coarse)
{
var symbols = new[]
{
QuantConnect.Symbol.Create("AAPL", SecurityType.Equity, Market.USA),
QuantConnect.Symbol.Create("BAC", SecurityType.Equity, Market.USA),
QuantConnect.Symbol.Create("FB", SecurityType.Equity, Market.USA),
QuantConnect.Symbol.Create("GOOGL", SecurityType.Equity, Market.USA),
QuantConnect.Symbol.Create("GOOG", SecurityType.Equity, Market.USA),
QuantConnect.Symbol.Create("IBM", SecurityType.Equity, Market.USA),
};
_customSymbols.Clear();
foreach (var symbol in symbols)
{
_customSymbols.Add(AddData<SECReport8K>(symbol, Resolution.Daily).Symbol);
}
return symbols;
}
public override void OnData(Slice data)
{
if (!Portfolio.Invested && Transactions.GetOpenOrders().Count == 0)
{
var aapl = QuantConnect.Symbol.Create("AAPL", SecurityType.Equity, Market.USA);
SetHoldings(aapl, 0.5);
}
foreach (var customSymbol in _customSymbols)
{
if (!ActiveSecurities.ContainsKey(customSymbol.Underlying))
{
throw new Exception($"Custom data underlying ({customSymbol.Underlying}) Symbol was not found in active securities");
}
}
}
/// <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", "-33.612%"},
{"Drawdown", "2.000%"},
{"Expectancy", "0"},
{"Net Profit", "-1.669%"},
{"Sharpe Ratio", "-4.888"},
{"Probabilistic Sharpe Ratio", "5.495%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "-0.273"},
{"Beta", "0.045"},
{"Annual Standard Deviation", "0.057"},
{"Annual Variance", "0.003"},
{"Information Ratio", "-1.537"},
{"Tracking Error", "0.112"},
{"Treynor Ratio", "-6.121"},
{"Total Fees", "$3.50"},
{"Fitness Score", "0"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "-7.289"},
{"Return Over Maximum Drawdown", "-16.95"},
{"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", "559673838"}
};
}
}

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 System.Collections.Generic;
using QuantConnect.Algorithm.Framework.Selection;
using QuantConnect.Data;
using QuantConnect.Data.Custom.SEC;
using QuantConnect.Data.UniverseSelection;
using QuantConnect.Interfaces;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Regression algorithm ensures that data added via OnSecuritiesChanged (underlying) is present in ActiveSecurities
/// </summary>
/// <meta name="tag" content="using data" />
/// <meta name="tag" content="custom data" />
/// <meta name="tag" content="regression test" />
public class CustomDataAddDataOnSecuritiesChangedRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
{
private List<Symbol> _customSymbols = new List<Symbol>();
public override void Initialize()
{
SetStartDate(2014, 3, 24);
SetEndDate(2014, 4, 7);
SetCash(100000);
UniverseSettings.Resolution = Resolution.Daily;
AddUniverseSelection(new CoarseFundamentalUniverseSelectionModel(CoarseSelector));
}
public IEnumerable<Symbol> CoarseSelector(IEnumerable<CoarseFundamental> coarse)
{
return new[]
{
QuantConnect.Symbol.Create("AAPL", SecurityType.Equity, Market.USA),
QuantConnect.Symbol.Create("BAC", SecurityType.Equity, Market.USA),
QuantConnect.Symbol.Create("FB", SecurityType.Equity, Market.USA),
QuantConnect.Symbol.Create("GOOGL", SecurityType.Equity, Market.USA),
QuantConnect.Symbol.Create("GOOG", SecurityType.Equity, Market.USA),
QuantConnect.Symbol.Create("IBM", SecurityType.Equity, Market.USA),
};
}
public override void OnData(Slice data)
{
if (!Portfolio.Invested && Transactions.GetOpenOrders().Count == 0)
{
var aapl = QuantConnect.Symbol.Create("AAPL", SecurityType.Equity, Market.USA);
SetHoldings(aapl, 0.5);
}
foreach (var customSymbol in _customSymbols)
{
if (!ActiveSecurities.ContainsKey(customSymbol.Underlying))
{
throw new Exception($"Custom data underlying ({customSymbol.Underlying}) Symbol was not found in active securities");
}
}
}
public override void OnSecuritiesChanged(SecurityChanges changes)
{
bool iterated = false;
foreach (var added in changes.AddedSecurities)
{
if (!iterated)
{
_customSymbols.Clear();
iterated = true;
}
_customSymbols.Add(AddData<SECReport8K>(added.Symbol, Resolution.Daily).Symbol);
}
}
/// <summary>
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
/// </summary>
public bool CanRunLocally { get; } = true;
/// <summary>
/// This is used by the regression test system to indicate which languages this algorithm is written in.
/// </summary>
public 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", "-33.612%"},
{"Drawdown", "2.000%"},
{"Expectancy", "0"},
{"Net Profit", "-1.669%"},
{"Sharpe Ratio", "-4.888"},
{"Probabilistic Sharpe Ratio", "5.495%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "-0.273"},
{"Beta", "0.045"},
{"Annual Standard Deviation", "0.057"},
{"Annual Variance", "0.003"},
{"Information Ratio", "-1.537"},
{"Tracking Error", "0.112"},
{"Treynor Ratio", "-6.121"},
{"Total Fees", "$3.50"},
{"Fitness Score", "0"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "-7.289"},
{"Return Over Maximum Drawdown", "-16.95"},
{"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", "559673838"}
};
}
}

View File

@@ -0,0 +1,156 @@
/*
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
using System;
using System.Collections.Generic;
using System.Linq;
using QuantConnect.Data;
using QuantConnect.Data.Custom.SEC;
using QuantConnect.Data.Custom.USTreasury;
using QuantConnect.Interfaces;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Regression algorithm ensures that added data matches expectations
/// </summary>
public class CustomDataAddDataRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
{
private Symbol _googlEquity;
public override void Initialize()
{
SetStartDate(2013, 10, 7);
SetEndDate(2013, 10, 11);
SetCash(100000);
var twxEquity = AddEquity("TWX", Resolution.Daily).Symbol;
var customTwxSymbol = AddData<SECReport8K>(twxEquity, Resolution.Daily).Symbol;
_googlEquity = AddEquity("GOOGL", Resolution.Daily).Symbol;
var customGooglSymbol = AddData<SECReport10K>("GOOGL", Resolution.Daily).Symbol;
var usTreasury = AddData<USTreasuryYieldCurveRate>("GOOGL", Resolution.Daily).Symbol;
var usTreasuryUnderlyingEquity = QuantConnect.Symbol.Create("MSFT", SecurityType.Equity, Market.USA);
var usTreasuryUnderlying = AddData<USTreasuryYieldCurveRate>(usTreasuryUnderlyingEquity, Resolution.Daily).Symbol;
var optionSymbol = AddOption("TWX", Resolution.Minute).Symbol;
var customOptionSymbol = AddData<SECReport10K>(optionSymbol, Resolution.Daily).Symbol;
if (customTwxSymbol.Underlying != twxEquity)
{
throw new Exception($"Underlying symbol for {customTwxSymbol} is not equal to TWX equity. Expected {twxEquity} got {customTwxSymbol.Underlying}");
}
if (customGooglSymbol.Underlying != _googlEquity)
{
throw new Exception($"Underlying symbol for {customGooglSymbol} is not equal to GOOGL equity. Expected {_googlEquity} got {customGooglSymbol.Underlying}");
}
if (usTreasury.HasUnderlying)
{
throw new Exception($"US Treasury yield curve (no underlying) has underlying when it shouldn't. Found {usTreasury.Underlying}");
}
if (!usTreasuryUnderlying.HasUnderlying)
{
throw new Exception("US Treasury yield curve (with underlying) has no underlying Symbol even though we added with Symbol");
}
if (usTreasuryUnderlying.Underlying != usTreasuryUnderlyingEquity)
{
throw new Exception($"US Treasury yield curve underlying does not equal equity Symbol added. Expected {usTreasuryUnderlyingEquity} got {usTreasuryUnderlying.Underlying}");
}
if (customOptionSymbol.Underlying != optionSymbol)
{
throw new Exception("Option symbol not equal to custom underlying symbol. Expected {optionSymbol} got {customOptionSymbol.Underlying}");
}
try
{
var customDataNoCache = AddData<SECReport10Q>("AAPL", Resolution.Daily);
throw new Exception("AAPL was found in the SymbolCache, though it should be missing");
}
catch (InvalidOperationException)
{
// This is exactly what we wanted. AAPL shouldn't have been found in the SymbolCache, and because
// SECReport10Q is a mappable type, we threw
return;
}
}
public override void OnData(Slice data)
{
if (!Portfolio.Invested && !Transactions.GetOpenOrders().Any())
{
SetHoldings(_googlEquity, 0.5);
}
}
/// <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", "31.756%"},
{"Drawdown", "0.700%"},
{"Expectancy", "0"},
{"Net Profit", "0.378%"},
{"Sharpe Ratio", "2.708"},
{"Probabilistic Sharpe Ratio", "56.960%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "0.079"},
{"Beta", "0.099"},
{"Annual Standard Deviation", "0.079"},
{"Annual Variance", "0.006"},
{"Information Ratio", "-6.058"},
{"Tracking Error", "0.19"},
{"Treynor Ratio", "2.159"},
{"Total Fees", "$1.00"},
{"Fitness Score", "0.1"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "79228162514264337593543950335"},
{"Return Over Maximum Drawdown", "47.335"},
{"Portfolio Turnover", "0.1"},
{"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", "1531253381"}
};
}
}

View File

@@ -62,7 +62,7 @@ namespace QuantConnect.Algorithm.CSharp
}
Console.WriteLine("Buying BTC 'Shares': BTC: " + data.Close);
}
Console.WriteLine("Time: " + Time.ToLongDateString() + " " + Time.ToLongTimeString() + data.Close.ToString());
Console.WriteLine("Time: " + Time.ToStringInvariant("T") + " " + Time.ToStringInvariant("T") + data.Close.ToStringInvariant());
}
/// <summary>

View File

@@ -60,7 +60,8 @@ namespace QuantConnect.Algorithm.CSharp
//Bitcoin used as a tradable asset, like stocks, futures etc.
if (data.Close != 0)
{
Order("BTC", Portfolio.MarginRemaining / Math.Abs(data.Close + 1));
//Access custom data symbols using <ticker>.<custom-type>
Order("BTC.Bitcoin", Portfolio.MarginRemaining / Math.Abs(data.Close + 1));
}
}
}
@@ -83,22 +84,43 @@ namespace QuantConnect.Algorithm.CSharp
{"Total Trades", "1"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "155.365%"},
{"Compounding Annual Return", "155.262%"},
{"Drawdown", "84.800%"},
{"Expectancy", "0"},
{"Net Profit", "5123.170%"},
{"Sharpe Ratio", "1.2"},
{"Sharpe Ratio", "2.066"},
{"Probabilistic Sharpe Ratio", "68.832%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "-0.008"},
{"Beta", "73.725"},
{"Annual Standard Deviation", "0.84"},
{"Annual Variance", "0.706"},
{"Information Ratio", "1.183"},
{"Tracking Error", "0.84"},
{"Treynor Ratio", "0.014"},
{"Total Fees", "$0.00"}
{"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.996"},
{"Total Fees", "$0.00"},
{"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", "-541549381"}
};
/// <summary>

View File

@@ -128,7 +128,7 @@ namespace QuantConnect.Algorithm.CSharp
{
Time = DateTime.ParseExact(csv[0], "yyyyMMdd", null),
Symbol = Symbol.Create(csv[1], SecurityType.Equity, Market.USA),
TopGainersRank = int.Parse(csv[2])
TopGainersRank = Parse.Int(csv[2])
};
}

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.Market;
using QuantConnect.Interfaces;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Regression algorithm demonstrating use of map files with custom data
/// </summary>
/// <meta name="tag" content="using data" />
/// <meta name="tag" content="custom data" />
/// <meta name="tag" content="regression test" />
/// <meta name="tag" content="rename event" />
/// <meta name="tag" content="map" />
/// <meta name="tag" content="mapping" />
/// <meta name="tag" content="map files" />
public class CustomDataUsingMapFileRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
{
private Symbol _symbol;
private bool _initialMapping;
private bool _executionMapping;
/// <summary>
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
/// </summary>
public override void Initialize()
{
SetStartDate(2013, 06, 27);
SetEndDate(2013, 07, 02);
var foxa = QuantConnect.Symbol.Create("FOXA", SecurityType.Equity, Market.USA);
_symbol = AddData<CustomDataUsingMapping>(foxa).Symbol;
foreach (var config in SubscriptionManager.SubscriptionDataConfigService.GetSubscriptionDataConfigs(_symbol))
{
if (config.Resolution != Resolution.Minute)
{
throw new Exception("Expected resolution to be set to Minute");
}
}
}
/// <summary>
/// Checks to see if the stock has been renamed, and places an order once the symbol has changed
/// </summary>
public override void OnData(Slice slice)
{
if (slice.SymbolChangedEvents.ContainsKey(_symbol))
{
var mappingEvent = slice.SymbolChangedEvents.Single(x => x.Key.SecurityType == SecurityType.Base).Value;
Log($"{Time} - Ticker changed from: {mappingEvent.OldSymbol} to {mappingEvent.NewSymbol}");
if (Time.Date == new DateTime(2013, 06, 27))
{
// we should Not receive the initial mapping event
if (mappingEvent.NewSymbol != "NWSA"
|| mappingEvent.OldSymbol != "FOXA")
{
throw new Exception($"Unexpected mapping event {mappingEvent}");
}
_initialMapping = true;
}
else if (Time.Date == new DateTime(2013, 06, 29))
{
if (mappingEvent.NewSymbol != "FOXA"
|| mappingEvent.OldSymbol != "NWSA")
{
throw new Exception($"Unexpected mapping event {mappingEvent}");
}
_executionMapping = true;
SetHoldings(_symbol, 1);
}
}
}
/// <summary>
/// Final step of the algorithm
/// </summary>
public override void OnEndOfAlgorithm()
{
if (_initialMapping)
{
throw new Exception("The ticker generated the initial rename event");
}
if (!_executionMapping)
{
throw new Exception("The ticker did not rename throughout the course of its life even though it should have");
}
}
/// <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", "-99.920%"},
{"Drawdown", "11.100%"},
{"Expectancy", "0"},
{"Net Profit", "-10.486%"},
{"Sharpe Ratio", "-1.534"},
{"Probabilistic Sharpe Ratio", "0.001%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "-0.898"},
{"Beta", "-7.027"},
{"Annual Standard Deviation", "0.651"},
{"Annual Variance", "0.424"},
{"Information Ratio", "-1.396"},
{"Tracking Error", "0.726"},
{"Treynor Ratio", "0.142"},
{"Total Fees", "$0.00"},
{"Fitness Score", "0.127"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "79228162514264337593543950335"},
{"Return Over Maximum Drawdown", "-9.383"},
{"Portfolio Turnover", "0.249"},
{"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", "-1014157203"}
};
/// <summary>
/// Test example custom data showing how to enable the use of mapping.
/// Implemented as a wrapper of existing NWSA->FOXA equity
/// </summary>
private class CustomDataUsingMapping : TradeBar
{
/// <summary>
/// Indicates if there is support for mapping
/// </summary>
/// <returns>True indicates mapping should be done</returns>
public override bool RequiresMapping()
{
return true;
}
public override SubscriptionDataSource GetSource(SubscriptionDataConfig config, DateTime date, bool isLiveMode)
{
return base.GetSource(new SubscriptionDataConfig(config,
typeof(CustomDataUsingMapping),
// create a new symbol as equity so we find the existing data files
Symbol.Create(config.MappedSymbol, SecurityType.Equity, config.Market)),
date,
isLiveMode);
}
public override BaseData Reader(SubscriptionDataConfig config, string line, DateTime date, bool isLiveMode)
{
return ParseEquity(config, line, date);
}
/// <summary>
/// Gets the default resolution for this data and security type
/// </summary>
/// <remarks>This is a method and not a property so that python
/// custom data types can override it</remarks>
public override Resolution DefaultResolution()
{
return Resolution.Minute;
}
/// <summary>
/// Gets the supported resolution for this data and security type
/// </summary>
/// <remarks>This is a method and not a property so that python
/// custom data types can override it</remarks>
public override List<Resolution> SupportedResolutions()
{
return new List<Resolution> { Resolution.Minute };
}
}
}
}

View File

@@ -1,4 +1,4 @@
/*
/*
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
*
@@ -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>
@@ -171,24 +193,45 @@ namespace QuantConnect.Algorithm.CSharp
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "62"},
{"Average Win", "0.11%"},
{"Average Win", "0.10%"},
{"Average Loss", "-0.06%"},
{"Compounding Annual Return", "-7.582%"},
{"Compounding Annual Return", "-7.727%"},
{"Drawdown", "2.400%"},
{"Expectancy", "-0.193"},
{"Net Profit", "-0.660%"},
{"Sharpe Ratio", "-1.563"},
{"Expectancy", "-0.197"},
{"Net Profit", "-0.673%"},
{"Sharpe Ratio", "-1.565"},
{"Probabilistic Sharpe Ratio", "22.763%"},
{"Loss Rate", "70%"},
{"Win Rate", "30%"},
{"Profit-Loss Ratio", "1.71"},
{"Alpha", "-0.174"},
{"Beta", "5.695"},
{"Annual Standard Deviation", "0.046"},
{"Profit-Loss Ratio", "1.70"},
{"Alpha", "-0.14"},
{"Beta", "0.124"},
{"Annual Standard Deviation", "0.047"},
{"Annual Variance", "0.002"},
{"Information Ratio", "-1.959"},
{"Tracking Error", "0.046"},
{"Treynor Ratio", "-0.013"},
{"Total Fees", "$62.24"}
{"Information Ratio", "-5.163"},
{"Tracking Error", "0.118"},
{"Treynor Ratio", "-0.591"},
{"Total Fees", "$62.24"},
{"Fitness Score", "0.147"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "-2.792"},
{"Return Over Maximum Drawdown", "-3.569"},
{"Portfolio Turnover", "2.562"},
{"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", "852026186"}
};
}
}

View File

@@ -0,0 +1,108 @@
/*
* 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.Orders;
using QuantConnect.Orders.Fills;
using QuantConnect.Securities;
using System;
using System.Collections.Generic;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Basic template algorithm that implements a fill model with partial fills
/// </summary>
/// <meta name="tag" content="transaction fees and slippage" />
/// <meta name="tag" content="custom fill models" />
public class CustomPartialFillModelAlgorithm : QCAlgorithm
{
private Symbol _spy;
private SecurityHolding _holdings;
public override void Initialize()
{
SetStartDate(2019, 1, 1);
SetEndDate(2019, 3, 1);
var equity = AddEquity("SPY", Resolution.Hour);
_spy = equity.Symbol;
_holdings = equity.Holdings;
// Set the fill model
equity.SetFillModel(new CustomPartialFillModel(this));
}
public override void OnData(Slice data)
{
var openOrders = Transactions.GetOpenOrders(_spy);
if (openOrders.Count != 0) return;
if (Time.Day > 10 && _holdings.Quantity <= 0)
{
MarketOrder(_spy, 100, true);
}
else if (Time.Day > 20 && _holdings.Quantity >= 0)
{
MarketOrder(_spy, -100, true);
}
}
/// <summary>
/// Implements a custom fill model that inherit from FillModel. Override the MarketFill method to simulate partially fill orders
/// </summary>
internal class CustomPartialFillModel : FillModel
{
private readonly QCAlgorithm _algorithm;
private readonly Dictionary<int, decimal> _absoluteRemainingByOrderId;
public CustomPartialFillModel(QCAlgorithm algorithm)
: base()
{
_algorithm = algorithm;
_absoluteRemainingByOrderId = new Dictionary<int, decimal>();
}
public override OrderEvent MarketFill(Security asset, MarketOrder order)
{
decimal absoluteRemaining;
if (!_absoluteRemainingByOrderId.TryGetValue(order.Id, out absoluteRemaining))
{
absoluteRemaining = order.AbsoluteQuantity;
}
// Create the object
var fill = base.MarketFill(asset, order);
// Set this fill amount
fill.FillQuantity = Math.Sign(order.Quantity) * 10;
if (absoluteRemaining == fill.FillQuantity)
{
fill.Status = OrderStatus.Filled;
_absoluteRemainingByOrderId.Remove(order.Id);
}
else
{
fill.Status = OrderStatus.PartiallyFilled;
_absoluteRemainingByOrderId[order.Id] = absoluteRemaining - fill.FillQuantity;
var price = fill.FillPrice;
_algorithm.Debug($"{_algorithm.Time} - Partial Fill - Remaining {absoluteRemaining} Price - {price}");
}
return fill;
}
}
}
}

View File

@@ -0,0 +1,128 @@
/*
* 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;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Test algorithm that verifies that securities added through
/// <see cref="QCAlgorithm.AddEquity"/> API and universe selection
/// both start sending data at the same time
/// </summary>
public class CustomUniverseSelectionRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
{
/// <summary>
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
/// </summary>
public override void Initialize()
{
SetStartDate(2013, 10, 07);
SetEndDate(2013, 10, 11);
AddEquity("AAPL", Resolution.Daily);
UniverseSettings.Resolution = Resolution.Daily;
AddUniverse(SecurityType.Equity,
"SecondUniverse",
Resolution.Daily,
Market.USA,
UniverseSettings,
time => new[] { "SPY" });
}
/// <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 (data.Count != 2)
{
throw new Exception($"Unexpected data count: {data.Count}");
}
if (ActiveSecurities.Count != 2)
{
throw new Exception($"Unexpected ActiveSecurities count: {ActiveSecurities.Count}");
}
if (!Portfolio.Invested)
{
SetHoldings(Securities.Keys.First(symbol => symbol.Value == "SPY"), 1);
Debug("Purchased Stock");
}
}
/// <summary>
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
/// </summary>
public bool CanRunLocally { get; } = true;
/// <summary>
/// This is used by the regression test system to indicate which languages this algorithm is written in.
/// </summary>
public 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", "241.885%"},
{"Drawdown", "1.100%"},
{"Expectancy", "0"},
{"Net Profit", "1.698%"},
{"Sharpe Ratio", "7.17"},
{"Probabilistic Sharpe Ratio", "68.718%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "1.171"},
{"Beta", "0.147"},
{"Annual Standard Deviation", "0.191"},
{"Annual Variance", "0.037"},
{"Information Ratio", "0.035"},
{"Tracking Error", "0.251"},
{"Treynor Ratio", "9.323"},
{"Total Fees", "$3.26"},
{"Fitness Score", "0.201"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "79228162514264337593543950335"},
{"Return Over Maximum Drawdown", "211.158"},
{"Portfolio Turnover", "0.201"},
{"Total Insights Generated", "0"},
{"Total Insights Closed", "0"},
{"Total Insights Analysis Completed", "0"},
{"Long Insight Count", "0"},
{"Short Insight Count", "0"},
{"Long/Short Ratio", "100%"},
{"Estimated Monthly Alpha Value", "$0"},
{"Total Accumulated Estimated Alpha Value", "$0"},
{"Mean Population Estimated Insight Value", "$0"},
{"Mean Population Direction", "0%"},
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "1268340653"}
};
}
}

View File

@@ -0,0 +1,218 @@
/*
* 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;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Regression algorithm with a custom universe and benchmark, both using the same security.
/// </summary>
public class CustomUniverseWithBenchmarkRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
{
private const int ExpectedLeverage = 2;
private Symbol _spy;
private decimal _previousBenchmarkValue;
private DateTime _previousTime;
private decimal _previousSecurityValue;
private bool _universeSelected;
private bool _onDataWasCalled;
private int _benchmarkPriceDidNotChange;
/// <summary>
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
/// </summary>
public override void Initialize()
{
SetStartDate(2013, 10, 4);
SetEndDate(2013, 10, 11);
// Hour resolution
_spy = AddEquity("SPY", Resolution.Hour).Symbol;
// Minute resolution
AddUniverse("my-universe", x =>
{
if(x.Day % 2 == 0)
{
_universeSelected = true;
return new List<string> {"SPY"};
}
_universeSelected = false;
return Enumerable.Empty<string>();
}
);
// internal daily resolution
SetBenchmark("SPY");
Symbol symbol;
if (!SymbolCache.TryGetSymbol("SPY", out symbol)
|| !ReferenceEquals(_spy, symbol))
{
throw new Exception("We expected 'SPY' to be added to the Symbol cache," +
" since the algorithm is also using it");
}
}
/// <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)
{
var security = Securities[_spy];
_onDataWasCalled = true;
var bar = data.Bars.Values.Single();
if (_universeSelected)
{
if (bar.IsFillForward
|| bar.Period != TimeSpan.FromMinutes(1))
{
// bar should always be the Minute resolution one here
throw new Exception("Unexpected Bar error");
}
if (_previousTime.Date == data.Time.Date
&& (data.Time - _previousTime) != TimeSpan.FromMinutes(1))
{
throw new Exception("For the same date expected data updates every 1 minute");
}
}
else
{
if (data.Time.Minute == 0
&& _previousSecurityValue == security.Price)
{
throw new Exception($"Security Price error. Price should change every new hour");
}
if (data.Time.Minute != 0
&& _previousSecurityValue != security.Price)
{
throw new Exception($"Security Price error. Price should not change every minute");
}
}
_previousSecurityValue = security.Price;
// assert benchmark updates only on date change
var currentValue = Benchmark.Evaluate(data.Time);
if (_previousTime.Hour == data.Time.Hour)
{
if (currentValue != _previousBenchmarkValue)
{
throw new Exception($"Benchmark value error - expected: {_previousBenchmarkValue} {_previousTime}, actual: {currentValue} {data.Time}. " +
"Benchmark value should only change when there is a change in hours");
}
}
else
{
if (data.Time.Minute == 0)
{
if (currentValue == _previousBenchmarkValue)
{
_benchmarkPriceDidNotChange++;
// there are two consecutive equal data points so we give it some room
if (_benchmarkPriceDidNotChange > 1)
{
throw new Exception($"Benchmark value error - expected a new value, current {currentValue} {data.Time}" +
"Benchmark value should change when there is a change in hours");
}
}
else
{
_benchmarkPriceDidNotChange = 0;
}
}
}
_previousBenchmarkValue = currentValue;
_previousTime = data.Time;
// assert algorithm security is the correct one - not the internal one
if (security.Leverage != ExpectedLeverage)
{
throw new Exception($"Leverage error - expected: {ExpectedLeverage}, actual: {security.Leverage}");
}
}
public override void OnEndOfAlgorithm()
{
if (!_onDataWasCalled)
{
throw new Exception("OnData was not called");
}
}
/// <summary>
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
/// </summary>
public bool CanRunLocally { get; } = true;
/// <summary>
/// This is used by the regression test system to indicate which languages this algorithm is written in.
/// </summary>
public 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", "-2.53"},
{"Tracking Error", "0.211"},
{"Treynor Ratio", "0"},
{"Total Fees", "$0.00"},
{"Fitness Score", "0"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "79228162514264337593543950335"},
{"Return Over Maximum Drawdown", "79228162514264337593543950335"},
{"Portfolio Turnover", "0"},
{"Total Insights Generated", "0"},
{"Total Insights Closed", "0"},
{"Total Insights Analysis Completed", "0"},
{"Long Insight Count", "0"},
{"Short Insight Count", "0"},
{"Long/Short Ratio", "100%"},
{"Estimated Monthly Alpha Value", "$0"},
{"Total Accumulated Estimated Alpha Value", "$0"},
{"Mean Population Estimated Insight Value", "$0"},
{"Mean Population Direction", "0%"},
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "371857150"}
};
}
}

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;
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"},
{"Fitness Score", "0"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "79228162514264337593543950335"},
{"Return Over Maximum Drawdown", "79228162514264337593543950335"},
{"Portfolio Turnover", "0"},
{"Total Insights Generated", "0"},
{"Total Insights Closed", "0"},
{"Total Insights Analysis Completed", "0"},
{"Long Insight Count", "0"},
{"Short Insight Count", "0"},
{"Long/Short Ratio", "100%"},
{"Estimated Monthly Alpha Value", "$0"},
{"Total Accumulated Estimated Alpha Value", "$0"},
{"Mean Population Estimated Insight Value", "$0"},
{"Mean Population Direction", "0%"},
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "371857150"}
};
}
}

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;
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"},
{"Fitness Score", "0"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "79228162514264337593543950335"},
{"Return Over Maximum Drawdown", "79228162514264337593543950335"},
{"Portfolio Turnover", "0"},
{"Total Insights Generated", "0"},
{"Total Insights Closed", "0"},
{"Total Insights Analysis Completed", "0"},
{"Long Insight Count", "0"},
{"Short Insight Count", "0"},
{"Long/Short Ratio", "100%"},
{"Estimated Monthly Alpha Value", "$0"},
{"Total Accumulated Estimated Alpha Value", "$0"},
{"Mean Population Estimated Insight Value", "$0"},
{"Mean Population Direction", "0%"},
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "371857150"}
};
}
}

View File

@@ -96,12 +96,20 @@ namespace QuantConnect.Algorithm.CSharp
Consolidate("EURUSD", Resolution.Daily, DailyEurUsdBarHandler);
// API convenience method for easily receiving weekly-consolidated data
Consolidate("SPY", CalendarType.Weekly, CalendarTradeBarHandler);
Consolidate("EURUSD", CalendarType.Weekly, CalendarQuoteBarHandler);
Consolidate("SPY", Calendar.Weekly, CalendarTradeBarHandler);
Consolidate("EURUSD", Calendar.Weekly, CalendarQuoteBarHandler);
// API convenience method for easily receiving monthly-consolidated data
Consolidate("SPY", CalendarType.Monthly, CalendarTradeBarHandler);
Consolidate("EURUSD", CalendarType.Monthly, CalendarQuoteBarHandler);
Consolidate("SPY", Calendar.Monthly, CalendarTradeBarHandler);
Consolidate("EURUSD", Calendar.Monthly, CalendarQuoteBarHandler);
// API convenience method for easily receiving quarterly-consolidated data
Consolidate("SPY", Calendar.Quarterly, CalendarTradeBarHandler);
Consolidate("EURUSD", Calendar.Quarterly, CalendarQuoteBarHandler);
// API convenience method for easily receiving yearly-consolidated data
Consolidate("SPY", Calendar.Yearly, CalendarTradeBarHandler);
Consolidate("EURUSD", Calendar.Yearly, CalendarQuoteBarHandler);
// requires quote data subscription
//Consolidate<QuoteBar>("EURUSD", TimeSpan.FromMinutes(45), FortyFiveMinuteBarHandler);

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;
using System.Collections.Generic;
using System.Linq;
using NodaTime;
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];
var history = History<QuoteBar>(symbol, 10, Resolution.Daily);
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"},
{"Fitness Score", "0"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "79228162514264337593543950335"},
{"Return Over Maximum Drawdown", "79228162514264337593543950335"},
{"Portfolio Turnover", "0"},
{"Total Insights Generated", "0"},
{"Total Insights Closed", "0"},
{"Total Insights Analysis Completed", "0"},
{"Long Insight Count", "0"},
{"Short Insight Count", "0"},
{"Long/Short Ratio", "100%"},
{"Estimated Monthly Alpha Value", "$0"},
{"Total Accumulated Estimated Alpha Value", "$0"},
{"Mean Population Estimated Insight Value", "$0"},
{"Mean Population Direction", "0%"},
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "371857150"}
};
}
}

View File

@@ -0,0 +1,161 @@
/*
* 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.Custom;
using QuantConnect.Data.Custom.CBOE;
using QuantConnect.Data.Custom.Fred;
using QuantConnect.Data.Custom.SEC;
using QuantConnect.Data.Custom.Tiingo;
using QuantConnect.Data.Custom.USEnergy;
using QuantConnect.Data.Custom.USTreasury;
using QuantConnect.Interfaces;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// This regression algorithm tests the performance related GH issue 3772
/// </summary>
public class DefaultResolutionRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
{
public override void Initialize()
{
SetStartDate(2013, 10, 11);
SetEndDate(2013, 10, 12);
var spy = AddEquity("SPY").Symbol;
var types = new[]
{
typeof(SECReport8K),
typeof(SECReport10K),
typeof(SECReport10Q),
typeof(USTreasuryYieldCurveRate),
typeof(USEnergy),
typeof(CBOE),
typeof(TiingoPrice),
typeof(Fred)
};
foreach (var type in types)
{
var custom = AddData(type, spy);
if (SubscriptionManager.SubscriptionDataConfigService
.GetSubscriptionDataConfigs(custom.Symbol)
.Any(config => config.Resolution != Resolution.Daily))
{
throw new Exception("Was expecting resolution to be set to Daily");
}
try
{
AddData(type, spy, Resolution.Tick);
throw new Exception("Was expecting an ArgumentException to be thrown");
}
catch (ArgumentException)
{
// expected, these custom types don't support tick resolution
}
}
var security = AddData<USEnergyAPI>(spy);
if (SubscriptionManager.SubscriptionDataConfigService.GetSubscriptionDataConfigs(security.Symbol)
.Any(config => config.Resolution != Resolution.Hour))
{
throw new Exception("Was expecting resolution to be set to Hour");
}
try
{
AddOption("AAPL", Resolution.Daily);
throw new Exception("Was expecting an ArgumentException to be thrown");
}
catch (ArgumentException)
{
// expected, options only support minute resolution
}
var option = AddOption("AAPL");
if (SubscriptionManager.SubscriptionDataConfigService.GetSubscriptionDataConfigs(option.Symbol)
.Any(config => config.Resolution != Resolution.Minute))
{
throw new Exception("Was expecting resolution to be set to Minute");
}
Quit();
}
/// <summary>
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
/// </summary>
public bool CanRunLocally { get; } = true;
/// <summary>
/// This is used by the regression test system to indicate which languages this algorithm is written in.
/// </summary>
public 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"},
{"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", "371857150"}
};
}
}

View File

@@ -0,0 +1,138 @@
/*
* 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.476"},
{"Probabilistic Sharpe Ratio", "92.194%"},
{"Loss Rate", "0%"},
{"Win Rate", "100%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "0.006"},
{"Beta", "0.158"},
{"Annual Standard Deviation", "0.032"},
{"Annual Variance", "0.001"},
{"Information Ratio", "-4.89"},
{"Tracking Error", "0.08"},
{"Treynor Ratio", "0.509"},
{"Total Fees", "$3.70"},
{"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.022"},
{"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", "-1252326142"}
};
}
}

View File

@@ -66,7 +66,7 @@ namespace QuantConnect.Algorithm.CSharp
{
var symbol = kvp.Key;
var tradeBar = kvp.Value;
Debug($"OnData(Slice): {Time}: {symbol}: {tradeBar.Close.ToString("0.00")}");
Debug($"OnData(Slice): {Time}: {symbol}: {tradeBar.Close.ToStringInvariant("0.00")}");
}
// the slice can also contain delisting data: data.Delistings in a dictionary string->Delisting
@@ -80,11 +80,8 @@ namespace QuantConnect.Algorithm.CSharp
{
throw new Exception("Securities must be marked as tradable until they're delisted or removed from the universe");
}
}
public void OnData(Delistings data)
{
foreach (var kvp in data)
foreach (var kvp in data.Delistings)
{
var symbol = kvp.Key;
var delisting = kvp.Value;
@@ -143,25 +140,46 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "2"},
{"Total Trades", "3"},
{"Average Win", "0%"},
{"Average Loss", "-5.58%"},
{"Compounding Annual Return", "-87.694%"},
{"Drawdown", "5.600%"},
{"Average Loss", "-3.23%"},
{"Compounding Annual Return", "-79.990%"},
{"Drawdown", "4.300%"},
{"Expectancy", "-1"},
{"Net Profit", "-5.578%"},
{"Sharpe Ratio", "-10.227"},
{"Net Profit", "-4.312%"},
{"Sharpe Ratio", "-5.958"},
{"Probabilistic Sharpe Ratio", "0.000%"},
{"Loss Rate", "100%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "-1.953"},
{"Beta", "23.587"},
{"Annual Standard Deviation", "0.156"},
{"Annual Variance", "0.024"},
{"Information Ratio", "-10.33"},
{"Tracking Error", "0.156"},
{"Treynor Ratio", "-0.067"},
{"Total Fees", "$36.70"}
{"Alpha", "-0.685"},
{"Beta", "-0.445"},
{"Annual Standard Deviation", "0.119"},
{"Annual Variance", "0.014"},
{"Information Ratio", "-4.887"},
{"Tracking Error", "0.155"},
{"Treynor Ratio", "1.589"},
{"Total Fees", "$55.05"},
{"Fitness Score", "0.002"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "-15.687"},
{"Return Over Maximum Drawdown", "-18.549"},
{"Portfolio Turnover", "0.334"},
{"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", "-2022527947"}
};
}
}

View File

@@ -167,24 +167,45 @@ namespace QuantConnect.Algorithm.CSharp
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "7"},
{"Average Win", "19.15%"},
{"Average Win", "19.16%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "16.720%"},
{"Drawdown", "12.500%"},
{"Compounding Annual Return", "16.727%"},
{"Drawdown", "12.200%"},
{"Expectancy", "0"},
{"Net Profit", "152.966%"},
{"Sharpe Ratio", "1.275"},
{"Net Profit", "153.058%"},
{"Sharpe Ratio", "1.239"},
{"Probabilistic Sharpe Ratio", "66.414%"},
{"Loss Rate", "0%"},
{"Win Rate", "100%"},
{"Profit-Loss Ratio", "0"},
{"Alpha", "0.079"},
{"Beta", "4.194"},
{"Annual Standard Deviation", "0.128"},
{"Annual Variance", "0.016"},
{"Information Ratio", "1.119"},
{"Tracking Error", "0.128"},
{"Treynor Ratio", "0.039"},
{"Total Fees", "$46.73"}
{"Alpha", "0.146"},
{"Beta", "-0.018"},
{"Annual Standard Deviation", "0.116"},
{"Annual Variance", "0.013"},
{"Information Ratio", "-0.053"},
{"Tracking Error", "0.204"},
{"Treynor Ratio", "-8.165"},
{"Total Fees", "$46.75"},
{"Fitness Score", "0.002"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "1.607"},
{"Return Over Maximum Drawdown", "1.366"},
{"Portfolio Turnover", "0.003"},
{"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", "-807056289"}
};
}
}

View File

@@ -69,7 +69,10 @@ namespace QuantConnect.Algorithm.CSharp
public void OnData(Dividends data) // update this to Dividends dictionary
{
var dividend = data["MSFT"];
Debug(string.Format("{0} >> DIVIDEND >> {1} - {2} - {3} - {4}", dividend.Time.ToString("o"), dividend.Symbol, dividend.Distribution.ToString("C"), Portfolio.Cash, Portfolio["MSFT"].Price.ToString("C")));
Debug($"{dividend.Time.ToStringInvariant("o")} >> DIVIDEND >> {dividend.Symbol} - " +
$"{dividend.Distribution.ToStringInvariant("C")} - {Portfolio.Cash} - " +
$"{Portfolio["MSFT"].Price.ToStringInvariant("C")}"
);
}
/// <summary>
@@ -80,14 +83,18 @@ namespace QuantConnect.Algorithm.CSharp
{
Debug("MSFT: " + Securities["MSFT"].Price);
var split = data["MSFT"];
Debug(string.Format("{0} >> SPLIT >> {1} - {2} - {3} - {4}", split.Time.ToString("o"), split.Symbol, split.SplitFactor, Portfolio.Cash, Portfolio["MSFT"].Quantity));
Debug($"{split.Time.ToIso8601Invariant()} >> SPLIT >> {split.Symbol} - " +
$"{split.SplitFactor.ToStringInvariant()} - " +
$"{Portfolio.Cash.ToStringInvariant()} - " +
$"{Portfolio["MSFT"].Quantity.ToStringInvariant()}"
);
}
public override void OnOrderEvent(OrderEvent orderEvent)
{
// orders get adjusted based on split events to maintain order value
var order = Transactions.GetOrderById(orderEvent.OrderId);
Debug(string.Format("{0} >> ORDER >> " + order, Time));
Debug($"{Time.ToStringInvariant()} >> ORDER >> {order}");
}
}
}

View File

@@ -45,8 +45,8 @@ namespace QuantConnect.Algorithm.CSharp
{
UniverseSettings.Resolution = Resolution.Daily;
SetStartDate(2013, 01, 01);
SetEndDate(2013, 12, 31);
SetStartDate(2017, 07, 04);
SetEndDate(2018, 07, 04);
AddUniverse<StockDataSource>("my-stock-data-source", stockDataSource =>
{
@@ -102,8 +102,8 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
class StockDataSource : BaseData
{
private const string LiveUrl = @"https://www.dropbox.com/s/2az14r5xbx4w5j6/daily-stock-picker-live.csv?dl=1";
private const string BacktestUrl = @"https://www.dropbox.com/s/rmiiktz0ntpff3a/daily-stock-picker-backtest.csv?dl=1";
private const string LiveUrl = @"https://www.dropbox.com/s/2l73mu97gcehmh7/daily-stock-picker-live.csv?dl=1";
private const string BacktestUrl = @"https://www.dropbox.com/s/ae1couew5ir3z9y/daily-stock-picker-backtest.csv?dl=1";
/// <summary>
/// The symbols to be selected
@@ -184,25 +184,46 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "90"},
{"Average Win", "0.78%"},
{"Average Loss", "-0.39%"},
{"Compounding Annual Return", "18.547%"},
{"Drawdown", "4.700%"},
{"Expectancy", "1.068"},
{"Net Profit", "18.547%"},
{"Sharpe Ratio", "1.993"},
{"Loss Rate", "30%"},
{"Win Rate", "70%"},
{"Profit-Loss Ratio", "1.96"},
{"Alpha", "0.119"},
{"Beta", "2.617"},
{"Annual Standard Deviation", "0.086"},
{"Annual Variance", "0.007"},
{"Information Ratio", "1.764"},
{"Tracking Error", "0.086"},
{"Treynor Ratio", "0.065"},
{"Total Fees", "$251.12"}
{"Total Trades", "6441"},
{"Average Win", "0.07%"},
{"Average Loss", "-0.07%"},
{"Compounding Annual Return", "13.284%"},
{"Drawdown", "10.700%"},
{"Expectancy", "0.061"},
{"Net Profit", "13.284%"},
{"Sharpe Ratio", "0.96"},
{"Probabilistic Sharpe Ratio", "46.111%"},
{"Loss Rate", "46%"},
{"Win Rate", "54%"},
{"Profit-Loss Ratio", "0.97"},
{"Alpha", "0.124"},
{"Beta", "-0.066"},
{"Annual Standard Deviation", "0.121"},
{"Annual Variance", "0.015"},
{"Information Ratio", "0.004"},
{"Tracking Error", "0.171"},
{"Treynor Ratio", "-1.754"},
{"Total Fees", "$8669.33"},
{"Fitness Score", "0.675"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "1.124"},
{"Return Over Maximum Drawdown", "1.242"},
{"Portfolio Turnover", "1.64"},
{"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", "-1120327913"}
};
}
}

View File

@@ -50,8 +50,8 @@ namespace QuantConnect.Algorithm.CSharp
UniverseSettings.Resolution = Resolution.Daily;
// set our start and end for backtest mode
SetStartDate(2013, 01, 01);
SetEndDate(2013, 12, 31);
SetStartDate(2017, 07, 04);
SetEndDate(2018, 07, 04);
// define a new custom universe that will trigger each day at midnight
AddUniverse("my-dropbox-universe", Resolution.Daily, dateTime =>
@@ -60,7 +60,7 @@ namespace QuantConnect.Algorithm.CSharp
if (LiveMode)
{
// fetch the file from dropbox
var file = Download(@"https://www.dropbox.com/s/2az14r5xbx4w5j6/daily-stock-picker-live.csv?dl=1");
var file = Download(@"https://www.dropbox.com/s/2l73mu97gcehmh7/daily-stock-picker-live.csv?dl=1");
// if we have a file for today, break apart by commas and return symbols
if (file.Length > 0) return file.ToCsv();
// no symbol today, leave universe unchanged
@@ -78,7 +78,7 @@ namespace QuantConnect.Algorithm.CSharp
new KeyValuePair<string, string>("Authorization", $"Basic ({Convert.ToBase64String(byteKey)})")
};
var file = Download(@"https://www.dropbox.com/s/rmiiktz0ntpff3a/daily-stock-picker-backtest.csv?dl=1", headers);
var file = Download(@"https://www.dropbox.com/s/ae1couew5ir3z9y/daily-stock-picker-backtest.csv?dl=1", headers);
// split the file into lines and add to our cache
foreach (var line in file.Split(new[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries))
@@ -157,25 +157,46 @@ namespace QuantConnect.Algorithm.CSharp
/// </summary>
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
{
{"Total Trades", "66"},
{"Average Win", "1.06%"},
{"Average Loss", "-0.50%"},
{"Compounding Annual Return", "18.511%"},
{"Drawdown", "7.100%"},
{"Expectancy", "0.810"},
{"Net Profit", "18.511%"},
{"Sharpe Ratio", "1.439"},
{"Loss Rate", "42%"},
{"Win Rate", "58%"},
{"Profit-Loss Ratio", "2.12"},
{"Alpha", "0.308"},
{"Beta", "-10.065"},
{"Annual Standard Deviation", "0.1"},
{"Annual Variance", "0.01"},
{"Information Ratio", "1.275"},
{"Tracking Error", "0.1"},
{"Treynor Ratio", "-0.014"},
{"Total Fees", "$193.75"}
{"Total Trades", "5059"},
{"Average Win", "0.08%"},
{"Average Loss", "-0.08%"},
{"Compounding Annual Return", "14.901%"},
{"Drawdown", "10.600%"},
{"Expectancy", "0.075"},
{"Net Profit", "14.901%"},
{"Sharpe Ratio", "1.068"},
{"Probabilistic Sharpe Ratio", "50.201%"},
{"Loss Rate", "45%"},
{"Win Rate", "55%"},
{"Profit-Loss Ratio", "0.97"},
{"Alpha", "0.137"},
{"Beta", "-0.066"},
{"Annual Standard Deviation", "0.121"},
{"Annual Variance", "0.015"},
{"Information Ratio", "0.08"},
{"Tracking Error", "0.171"},
{"Treynor Ratio", "-1.963"},
{"Total Fees", "$6806.57"},
{"Fitness Score", "0.694"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "1.261"},
{"Return Over Maximum Drawdown", "1.404"},
{"Portfolio Turnover", "1.296"},
{"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", "974523768"}
};
}
}

View File

@@ -98,6 +98,7 @@ namespace QuantConnect.Algorithm.CSharp
{"Expectancy", "0"},
{"Net Profit", "0%"},
{"Sharpe Ratio", "0"},
{"Probabilistic Sharpe Ratio", "0%"},
{"Loss Rate", "0%"},
{"Win Rate", "0%"},
{"Profit-Loss Ratio", "0"},
@@ -105,10 +106,30 @@ namespace QuantConnect.Algorithm.CSharp
{"Beta", "0"},
{"Annual Standard Deviation", "0"},
{"Annual Variance", "0"},
{"Information Ratio", "0"},
{"Tracking Error", "0"},
{"Information Ratio", "-7.068"},
{"Tracking Error", "0.193"},
{"Treynor Ratio", "0"},
{"Total Fees", "$0.00"}
{"Total Fees", "$0.00"},
{"Fitness Score", "0"},
{"Kelly Criterion Estimate", "0"},
{"Kelly Criterion Probability Value", "0"},
{"Sortino Ratio", "79228162514264337593543950335"},
{"Return Over Maximum Drawdown", "79228162514264337593543950335"},
{"Portfolio Turnover", "0"},
{"Total Insights Generated", "0"},
{"Total Insights Closed", "0"},
{"Total Insights Analysis Completed", "0"},
{"Long Insight Count", "0"},
{"Short Insight Count", "0"},
{"Long/Short Ratio", "100%"},
{"Estimated Monthly Alpha Value", "$0"},
{"Total Accumulated Estimated Alpha Value", "$0"},
{"Mean Population Estimated Insight Value", "$0"},
{"Mean Population Direction", "0%"},
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "371857150"}
};
}
}

View File

@@ -0,0 +1,71 @@
/*
* 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.Data.Custom.SEC;
using QuantConnect.Securities;
namespace QuantConnect.Algorithm.CSharp
{
/// <summary>
/// Provides an example algorithm showcasing the <see cref="Security.Data"/> features
/// </summary>
public class DynamicSecurityDataAlgorithm : QCAlgorithm
{
private Security GOOGL;
private const string Ticker = "GOOGL";
public override void Initialize()
{
SetStartDate(2015, 10, 22);
SetEndDate(2015, 10, 30);
GOOGL = AddEquity(Ticker, Resolution.Daily);
AddData<SECReport8K>(Ticker, Resolution.Daily);
AddData<SECReport10K>(Ticker, Resolution.Daily);
AddData<SECReport10Q>(Ticker, Resolution.Daily);
}
public override void OnData(Slice slice)
{
// The Security object's Data property provides convenient access
// to the various types of data related to that security. You can
// access not only the security's price data, but also any custom
// data that is mapped to the security, such as our SEC reports.
// 1. Get the most recent data point of a particular type:
// 1.a Using the C# generic method, Get<T>:
SECReport8K googlSec8kReport = GOOGL.Data.Get<SECReport8K>();
SECReport10K googlSec10kReport = GOOGL.Data.Get<SECReport10K>();
Log($"{Time:o}: 8K: {googlSec8kReport}");
Log($"{Time:o}: 10K: {googlSec10kReport}");
// 2. Get the list of data points of a particular type for the most recent time step:
// 2.a Using the C# generic method, GetAll<T>:
List<SECReport8K> googlSec8kReports = GOOGL.Data.GetAll<SECReport8K>();
List<SECReport10K> googlSec10kReports = GOOGL.Data.GetAll<SECReport10K>();
Log($"{Time:o}: List: 8K: {googlSec8kReports.Count}");
Log($"{Time:o}: List: 10K: {googlSec10kReports.Count}");
if (!Portfolio.Invested)
{
Buy(GOOGL.Symbol, 10);
}
}
}
}

View File

@@ -105,7 +105,7 @@ namespace QuantConnect.Algorithm.CSharp
var orderedObjScores = _symbolData.OrderByDescending(x => x.ObjectiveScore).ToList();
foreach (var orderedObjScore in orderedObjScores)
{
Log(">>SCORE>>" + orderedObjScore.Symbol + ">>" + orderedObjScore.ObjectiveScore);
Log($">>SCORE>>{orderedObjScore.Symbol}>>{orderedObjScore.ObjectiveScore.ToStringInvariant()}");
}
var bestGrowth = orderedObjScores.First();
@@ -116,7 +116,7 @@ namespace QuantConnect.Algorithm.CSharp
Log("PREBUY>>LIQUIDATE>>");
Liquidate();
}
Log(">>BUY>>" + bestGrowth.Symbol + "@" + (100 * bestGrowth.OneMonthPerformance).ToString("00.00"));
Log($">>BUY>>{bestGrowth.Symbol}@{(100 * bestGrowth.OneMonthPerformance).ToStringInvariant("00.00")}");
var qty = Portfolio.MarginRemaining / Securities[bestGrowth.Symbol].Close;
MarketOrder(bestGrowth.Symbol, (int) qty);
}

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

@@ -1,4 +1,4 @@
/*
/*
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
*
@@ -74,22 +74,29 @@ namespace QuantConnect.Algorithm.CSharp
{"Total Trades", "1"},
{"Average Win", "0%"},
{"Average Loss", "0%"},
{"Compounding Annual Return", "-100.000%"},
{"Drawdown", "5.500%"},
{"Compounding Annual Return", "0%"},
{"Drawdown", "0%"},
{"Expectancy", "0"},
{"Net Profit", "-3.802%"},
{"Sharpe Ratio", "-12.079"},
{"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.397"},
{"Annual Variance", "0.158"},
{"Annual Standard Deviation", "0"},
{"Annual Variance", "0"},
{"Information Ratio", "0"},
{"Tracking Error", "0"},
{"Treynor Ratio", "0"},
{"Total Fees", "$14.92"},
{"Total Fees", "$14.91"},
{"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"},
{"Total Insights Generated", "1"},
{"Total Insights Closed", "1"},
{"Total Insights Analysis Completed", "1"},
@@ -102,7 +109,8 @@ namespace QuantConnect.Algorithm.CSharp
{"Mean Population Direction", "0%"},
{"Mean Population Magnitude", "0%"},
{"Rolling Averaged Population Direction", "0%"},
{"Rolling Averaged Population Magnitude", "0%"}
{"Rolling Averaged Population Magnitude", "0%"},
{"OrderListHash", "221046152"}
};
}
}

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