Commit Graph

103 Commits

Author SHA1 Message Date
Martin Molinero 7aafdef827 MapFile and FactorFile data feed resolution
- Moving `MapFile` and `FactorFile` resolution to the data feed stack so
that they do not add a performance overhead to the algorithm thread.
- Create logging string messaged only if required.
- Calculate `FactorFileRow.PriceScaleFactor` the least amount of times
2019-06-12 17:48:47 -03:00
Alexandre Catarino 3f00762bfd Adds Custom Data from US Energy Information Administration (eia.gov) (#3136)
New custom data class USEnergyInformation with new demonstration algorithms, the updated config file for users to set their EIA token.

Adds `CloseTime` to represent the time that the data period end. `EndTime` represents, in turn, the time the data is emitted. There is an offset between `CloseTime` and `EndTime` that is defined by the difference between the last bar as emitted and its time. 

In live mode, if the `USEnergyInformation.Reader` returns null, the `CollectionSubscriptionDataSourceReader.Read` method will pull for new data constantly. Therefore it should return an empty `BaseDataCollection` object.
2019-04-30 17:22:11 -07:00
Stefano Raggi 10329ed293 Fix time zone bugs in SubscriptionDataReader
In a few places SubscriptionDataReader was incorrectly assuming the TradeableDates were in ExchangeTimeZone instead of DataTimeZone.
This issue was found specifically with CFD assets which have the exchange time zone ahead of the data time zone.
2019-03-14 12:10:01 +01:00
Martin Molinero 8f6ad4e3c8 Cache raw data points
- `TextSubscriptionDataSourceReader` will now cache raw price mode data
points for each requested local source file, per data type.
Caching will be handled by the `MemoryCache` class.
- `GetLastKnownPrice()` will not `RoundDown` end time. This was causing
it to fail to fetch a data point in some cases.
2019-02-28 16:56:35 -03:00
Martin Molinero ed5f7ab58c Moving price scale factoring to new enumerator
- Adding new `PriceScaleFactorEnumerator` that will scale raw prices
based on a provided `SubscriptionDataConfig` and update the
`SubscriptionDataConfig.PriceScaleFactor`. Adding unit tests.
- `BaseData` factories (`TradeBar.cs`, `QuoteBar.cs`, `Tick.cs`) will
no longer scale factor prices, they will generate data points in raw
mode.
- `SubscriptionDataReader` will no longer update the
`SuscriptionDataConfig.PriceScaleFactor`
- Fix `BrokerageTransactionHandlerTests` unit test that was having a
race condition.
2019-02-27 15:11:34 -03:00
Martin Molinero dea0fe2674 Implementing composition over inheritance
- Mappings, splits, delisting and dividends will be
`ITradableDateEventProvider` that will be handled by
the `AuxiliaryDataEnumerator`.
2018-11-20 16:17:44 -03:00
Martin Molinero 6db7f13dca Addressing reviews
- Will now use the `SynchronizingEnumerator` and avoid the duplicated
synchronization logic.
- Slightly modified the `SynchronizingEnumerator` implementation to
avoid removing enumerators with current `null` returning `true`. Adding unit tests
- Adding unit tests for `DelistingEnumerator`
- Fixing issue where price was not correctly set. Adding new check for
`HourSplitRegressionAlgorithm`
2018-11-20 15:50:19 -03:00
Martin Molinero a746dd0137 Move corporate events to enumerators
- Moving `Splits`, `Dividends`, `Mappings`, `Delistings`, from the
`SubscriptionDataReader` into there own enumerator, inheriting from
new `CorporateEventBaseEnumerator`
- Adding new helper `static class CorporateEventEnumeratorFactory` to
create the new enumerators
- Adding unit tests for new `CorporateEventBaseEnumerator`
- Adding some extra checks to `HourSplitRegressionAlgorithm` and
`DelistingEventsAlgorithm`
2018-11-20 15:50:19 -03:00
Martin Molinero ed0544b075 Fix for split not correctly handled
- In some cases, for Resolution.Daily, application of splits were
up to one day behind the data. Causing the 'early' data to use a
wrong factor value
- Updating regression test affected by issue
- Adding new regression test
2018-11-01 17:45:24 -03:00
Stefano Raggi 289de60a7d Add Initialize checks in SubscriptionDataReader 2018-10-15 20:53:15 +02:00
Stefano Raggi dbaf109c78 Post-review updates
- Renamed events in SubscriptionDataReader and IHistoryProvider
- Added HistoryProvider base class with events and event invocators
2018-10-14 22:29:06 +02:00
Stefano Raggi 9fad26bc8f Add events to IHistoryProvider and SubscriptionDataReader
The SubscriptionDataReaderHistoryProvider was using StubResultHandler, so no error messages were being shown or logged. By adding events to IHistoryProvider and SubscriptionDataReader, the dependency on IResultHandler could be removed completely and error messages are now pushed up the stack.
2018-10-14 22:29:04 +02:00
Michael Handschuh 57affafdc2 Implement 'live' factor files
Adds reference price to dividend/split
Adds GetSplitsAndDividends to FactorFile
Adds Apply methods to FactorFile/FactorFileRow
Updates factor files to include reference prices
2018-08-14 17:58:44 -04:00
Juan José D'Ambrosio 84e0074350 Adding a control to avoid set the last trading date in a holiday
Move delisting date estimation to the constructor

Using `MarketHoursDatabase` for option delisting date estimation instead USHolidays
Adding file header.
Regression algorithm added.

Use of  `ExchangeHours.IsDateOpen` instead  `ExchangeHours.IsDateOpen.Holidays`.
Extract values from `symbol.ID` into a local variable.


Improved Regression test
2018-07-24 16:04:33 -03:00
Stefano Raggi ba1f5ae673 Add Tiingo daily data 2018-07-19 21:22:18 +02:00
Michael a39490edd0 Merge pull request #2250 from Martin-Molinero/bug-2197-delisted-symbol-data-being-sent
Fix for delisted subscription data being sent
2018-07-18 11:05:14 -04:00
Martin Molinero ff5e888313 Fix for delisted subscription data being sent 2018-07-18 09:45:13 -03:00
Martin Molinero f7dada5aae Adding default return value for GetMappedSymbol() 2018-07-13 18:51:06 -03:00
Martin Molinero ae048231b2 Performance fix for SubscriptionDataReader delisted symbols 2018-07-02 19:55:53 -03:00
Michael Handschuh ca747b3667 Add split warning events
This follows the pattern used by delisting events, where we send a warning event
before the start of trading on the trading day before the split will happen. This
change also adds a SplitType enum having a Warning and SplitOccurred values.
2018-01-22 22:06:30 -05:00
Stefano Raggi c2f9606149 Fix factor rescaling 2017-06-06 13:51:38 +02:00
Stefano Raggi bdd32d7634 Fix price adjusting on split dates with hourly resolution
In SubscriptionDataReader, the first hourly bar for a date with a split was emitted using the incorrect split factor.
2017-06-05 23:14:29 +02:00
jaredbroad 0f40b0df05 Merge remote-tracking branch 'origin/master' into pythonnet 2017-03-26 10:14:03 -04:00
Jared b347a900a9 Merge pull request #754 from QuantConnect/factor-file-inf-values
Handle factor files with INF values
2017-02-17 21:34:01 -05:00
Stefano Raggi 301b9e14fb Handle factor files with INF values
Before this PR, backtesting some symbols fails with an error when parsing the factor file.

Some factor files have INF split values, indicating that the stock has so many splits that prices can't be calculated with correct numerical precision.

To allow backtesting these symbols, we need to move the starting date forward when reading the data.

Known symbols: GBSN, JUNI, NEWL
2017-02-17 20:35:57 +01:00
Andrew 672e134939 Removed ApiDataProvider
Refactored IHistoryProvider interface order of parameters
2017-02-16 15:47:06 -05:00
Andrew b6171cc9d5 Renamed IDataFileProvider to IDataProvider using resharper
Refactored IDataProvider interface to return stream. The IDataProvider
Fetch method now only takes a key.  The IDataProvider
has been reshuffled to be at the bottom of the LeanDataStack.  It provides
data to the rest of the Lean stack. The default implementation of IDataProvider reads
data from disc.

All IDataCacheProviders now have constructors which take IDataProviders
and use them to find data on disc.

Renamed DataCacheProvider to ZipDataCacheProvider

Added comments to IDataProvider and it's implementations

Added comments to IDataCacheProvider and it's implementations
2017-02-15 12:16:50 -05:00
Andrew ed2107132e IHistoryProvider.Initialize() requires a DataCacheProvider
Fixed bug where DataCacheProvider was returning a stream without closing
the stream.  Also, ZipFiles returned from ZipFileCacheProvider are
effectively disposed.

Removed date field from IDataCacheProvider interface
2017-02-15 12:16:49 -05:00
Andrew 952e1d19e3 Added interface IDataCacheProvider that defines a mechanism for caching data
This interface was built around the existing implementation of the
DataCacheProvider.  It's purpose is to define a method for caching data
files.  Currently, most data files are either read from disc or retrieved
remotely. The IDataChceProvider returns returns a Stream and can handle
many types of data. The IDataFileCacheProvider is needed because keeping data in memory will improve performance and overcome certain File read/write limitations (such as sharing violations) currently experienced by Lean.

There are two implementations of this interface.  The first is the
SingleZipEntryDataCache.  This is the default implementation. It does not
cache and returns the first entry found within a ZipFile.  The second is
the ZipEntryCacheProvider.  This is a rework of the existing
DataCachePrivider.  It caches ZipFiles for up to 10 seconds.  It can
return specific entries for option and future ZipFiles.  Otherwise, it
returns the first entry in a ZipFile.

Added IDataFileCacheProvider as parameter to IHistoryProvider.Initialize()

The IDataFileCacheProvider is very useful for the IHistoryProvider in that it can eliminate the need for history request to touch disc.  This can greatly improve peerformance and eliminate disc bugs associated with disc read/writes. To minimize changes throughtout Lean, the default value for the IDataFileCacheProvider is null in the IHistoryProvider.Initialize method.

IDataCacheProviders are passed down the Lean stack. Each instance of a Subscription Enumerator factory decides what cache it
will use.  In other words, the IDataCacheProvider is not configurable from
config.json.  The IDataCacheProvider is passwed down the stack form the
Enumerator factory to the IStreamReader where it is used to retrieve data.

Added useful helper method to Unizp files into a Stream.
2017-02-15 12:16:49 -05:00
Stefano Raggi 689ac8a901 Remove SamplePerformance calls from SubscriptionDataReader.InvalidSource 2017-02-14 14:34:02 +01:00
AlexCatarino 9774af9adc Custom Data for Python Support 2017-02-09 17:48:50 -02:00
quant1729 c416df6241 Refactored option assignment/exercise:
1. Made sure we treat properly option expiration dates before Feb 2015 and after. Added tests.
2. Refactored expiration delisting, assignments/option exercise to happen in the end of the date, not MOC orders in the beginning of the day. Regression test.
3. Refactored option exercise model to generate proper fills on assignments/option. Those fills are reflected correctly in margins, in stats and correspond to IB model. Still need to run IB real-life live tests.
4. Refactored option symbol related functions into separate module (OptionSymbol.cs)
5. Made sure OnAssignmentEvent arrived to the user algo in regression test. Do we need OnExercise event? Not sure.
6. Tested end-to-end Ray's current code (covered call strat) to see short option legs expire worthless, and stats updated.
2017-02-02 19:35:37 +08:00
quant1729 ddbb7c902c Added support for light data file cache 2017-01-11 14:19:15 +08:00
quant1729 2a7d8d6b33 Revert "Refactored zip cache as discussed"
This reverts commit 61e92e18c0.
2017-01-11 11:27:16 +08:00
quant1729 61e92e18c0 Refactored zip cache as discussed 2017-01-10 17:02:44 +08:00
quant1729 3819561a82 Merge branch 'futures' into master-futures-merged
Conflicts:
	Common/QuantConnect.csproj
	Tests/RegressionTests.cs
2016-12-01 17:32:40 +01:00
quant1729 1141cd21e6 Merge branch 'futures' into master
Conflicts:
	Algorithm.CSharp/QuantConnect.Algorithm.CSharp.csproj
	Algorithm/QCAlgorithm.cs
	Brokerages/InteractiveBrokers/InteractiveBrokersBrokerage.cs
	Common/QuantConnect.csproj
	Common/Securities/Option/Option.cs
	Data/equity/usa/factor_files/aapl.csv
	Data/symbol-properties/symbol-properties-database.csv
	Engine/DataFeeds/Enumerators/Factories/BaseDataSubscriptionEnumeratorFactory.cs
	Engine/DataFeeds/Enumerators/Factories/OptionChainUniverseSubscriptionEnumeratorFactory.cs
	Engine/DataFeeds/SubscriptionDataReader.cs
	ToolBox/QuantConnect.ToolBox.csproj
2016-11-07 16:18:11 +01:00
Stefano Raggi 8660c0687a Enable FineFundamental to be used with AddData 2016-11-02 14:05:24 +01:00
quant1729 5803115548 Option splits and renames in backtesting. Added regression tests. 2016-10-26 21:20:03 +02:00
Andrew fdea52a933 Renamed XxxFileProvider to XxxDataFileProvider 2016-10-20 08:36:36 -04:00
Andrew bcd3cb6b10 FileProvider can now be configured in config.json
The DefaultFileProvider is now configured as by default as the file-provider in config.json and passed in the the engine through the leanAlgorithmHandlers object.

The FileProvider is now passed into the TextSubscriptionDataSourceReader and ZipEntryNameSubscriptionDataSourceReader.  Most of the changes in this commit are just getting the FileProvider to those two methods.
2016-10-17 15:52:11 -04:00
Stefano Raggi 350fd6afe2 Fixed missing delisting events 2016-08-30 12:58:21 -03:00
Stefano Raggi 600ee8b713 Reverts changes to ResolveMapFile calls 2016-06-14 21:03:54 +02:00
Jared b896ef087a Merge pull request #421 from QuantConnect/rename-subscription-factory
Rename subscription factory
2016-06-11 23:16:35 -04:00
Stefano Raggi 82062a5b7d Fixes map file resolution in SubscriptionDataReader
- tested with GOOG, GOOGL, SPXL
2016-06-09 17:39:44 +02:00
Stefano Raggi 7395d40e07 Fixes map file resolution bug in SubscriptionDataReader 2016-06-09 01:02:17 +02:00
Michael Handschuh 5e59f00d24 Renames ISubscriptionFactory to ISubscriptionDataSourceReader
This was always an unfortunate name since it doesn't actually produce subscription
instances. I'm beginning to clean up the data feeds to make them simpler and easier
to understand/work on... always start with low hanging fruit :)
2016-06-04 18:15:59 -04:00
jaredbroad 7c6713ebc2 Tidy SubscriptionDataReader time checking 2016-05-31 13:38:12 -04:00
jaredbroad ebbe704ac4 First commit; DailyFX with JSON Subscription factory 2016-05-27 23:22:18 -04:00
Michael Handschuh 05a2515380 Attach event handlers to subscription factory
Looks like these were incorrectly refactored and the event handlers were never re-applied. This led to us not getting error messages in the log about missing sources
2016-04-12 19:06:53 -04:00