Skip to content

Commit

Permalink
Minor fix for universe history (QuantConnect#7852)
Browse files Browse the repository at this point in the history
- Do not cache universe collection data. Adding unit test
  • Loading branch information
Martin-Molinero authored Mar 14, 2024
1 parent 934a8e0 commit a8280e1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
4 changes: 3 additions & 1 deletion Engine/DataFeeds/TextSubscriptionDataSourceReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ public TextSubscriptionDataSourceReader(IDataCacheProvider dataCacheProvider, Su
_date = date;
Config = config;
_shouldCacheDataPoints = !Config.IsCustomData && Config.Resolution >= Resolution.Hour
&& Config.Type != typeof(FineFundamental) && Config.Type != typeof(CoarseFundamental) && Config.Type != typeof(Fundamental) && Config.Type != typeof(FundamentalUniverse)
&& Config.Type != typeof(FineFundamental) && Config.Type != typeof(CoarseFundamental) && Config.Type != typeof(Fundamental)
// don't cache universe data, doesn't make much sense and we don't want to change the symbol of the clone
&& !Config.Type.IsAssignableTo(typeof(BaseDataCollection))
&& !DataCacheProvider.IsDataEphemeral;

_implementsStreamReader = Config.Type.ImplementsStreamReader();
Expand Down
24 changes: 15 additions & 9 deletions Tests/Engine/DataFeeds/BaseDataCollectionAggregatorReaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,17 @@ namespace QuantConnect.Tests.Engine.DataFeeds
[TestFixture, Parallelizable(ParallelScope.Fixtures)]
public class BaseDataCollectionAggregatorReaderTests
{
[TestCase(Resolution.Daily, 1, true)]
[TestCase( Resolution.Hour, 1, true)]
[TestCase(Resolution.Daily, 5849, false)]
[TestCase(Resolution.Hour, 40832, false)]
public void AggregatesDataPerTime(Resolution resolution, int expectedCount, bool singleDate)
[TestCase(Resolution.Daily, 1, true, true)]
[TestCase( Resolution.Hour, 1, true, true)]
[TestCase(Resolution.Daily, 5849, false, true)]
[TestCase(Resolution.Hour, 40832, false, true)]
[TestCase(Resolution.Daily, 1, true, false)]
[TestCase(Resolution.Hour, 1, true, false)]
[TestCase(Resolution.Daily, 5849, false, false)]
[TestCase(Resolution.Hour, 40832, false, false)]
public void AggregatesDataPerTime(Resolution resolution, int expectedCount, bool singleDate, bool isDataEphemeral)
{
var reader = Initialize(false, resolution, out var dataSource);
var reader = Initialize(false, resolution, isDataEphemeral, out var dataSource);
TestBaseDataCollection.SingleDate = singleDate;

var result = reader.Read(dataSource).ToList();
Expand All @@ -47,13 +51,13 @@ public void AggregatesDataPerTime(Resolution resolution, int expectedCount, bool
Assert.IsNotNull(collection);
Assert.GreaterOrEqual(collection.Data.Count, 5000);
Assert.AreEqual(expectedCount, collection.Data.DistinctBy(data => data.Time).Count());
Assert.IsTrue(collection.Data.All(x => x.Symbol == Symbols.AAPL));
}
}

private static ISubscriptionDataSourceReader Initialize(bool liveMode, Resolution resolution, out SubscriptionDataSource source)
private static ISubscriptionDataSourceReader Initialize(bool liveMode, Resolution resolution, bool isDataEphemeral, out SubscriptionDataSource source)
{
using var dataProvider = new DefaultDataProvider();
using var cache = new ZipDataCacheProvider(dataProvider);
using var cache = new ZipDataCacheProvider(TestGlobals.DataProvider, isDataEphemeral: isDataEphemeral);
var config = new SubscriptionDataConfig(typeof(TestBaseDataCollection),
Symbols.SPY,
resolution,
Expand All @@ -80,6 +84,8 @@ public override BaseData Reader(SubscriptionDataConfig config, string line, Date
// single day
dataPoint.Time = date;
}
// universe data collections can return data with a symbol different than the one in the configuration
dataPoint.Symbol = Symbols.AAPL;
return dataPoint;
}

Expand Down

0 comments on commit a8280e1

Please sign in to comment.