Skip to content

Commit

Permalink
Fix the Time Zone Convertion Target from DataTimeZone to ExchangeTime…
Browse files Browse the repository at this point in the history
…Zone
  • Loading branch information
AlexCatarino committed Apr 25, 2023
1 parent da26b8d commit 56a0513
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 12 deletions.
4 changes: 2 additions & 2 deletions BrainCompanyFilingLanguageMetricsUniverse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ public override BaseData Reader(SubscriptionDataConfig config, string line, Date
data.ManagementDiscussionAnalyasisOfFinancialConditionAndResultsOfOperations = BrainCompanyFilingLanguageMetrics.Parse(csv.Skip(24).Take(11).ToList());

data.Symbol = new Symbol(SecurityIdentifier.Parse(csv[0]), csv[1]);
// We need to convert the time since the date is in UTC, and AddUniverse sets the DateTimeZone to TimeZones.NewYork
// We need to convert the time since the date is in UTC, and AddUniverse sets the ExchangeTimeZone to TimeZones.NewYork
// Subtract 12 hours to match the BrainCompanyFilingLanguageMetricsBase EndTime
data.Time = date.ConvertFromUtc(config.DataTimeZone).AddHours(-12);
data.Time = date.ConvertFromUtc(config.ExchangeTimeZone).AddHours(-12);
data.Value = csv[4].IfNotNullOrEmpty(0m, s => decimal.Parse(s, NumberStyles.Any, CultureInfo.InvariantCulture));

return data;
Expand Down
4 changes: 2 additions & 2 deletions BrainSentimentIndicatorUniverse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ public override BaseData Reader(SubscriptionDataConfig config, string line, Date
SentimentalBuzzVolume30Days = csv[11].IfNotNullOrEmpty<decimal?>(s => decimal.Parse(s, NumberStyles.Any, CultureInfo.InvariantCulture)),

Symbol = new Symbol(SecurityIdentifier.Parse(csv[0]), csv[1]),
// We need to convert the time since the date is in UTC, and AddUniverse sets the DateTimeZone to TimeZones.NewYork
// We need to convert the time since the date is in UTC, and AddUniverse sets the ExchangeTimeZone to TimeZones.NewYork
// Subtract 12 hours to match the BrainSentimentIndicatorBase EndTime
Time = date.ConvertFromUtc(config.DataTimeZone).AddHours(-12),
Time = date.ConvertFromUtc(config.ExchangeTimeZone).AddHours(-12),
Value = sentiment7Days ?? 0m
};
}
Expand Down
4 changes: 2 additions & 2 deletions BrainStockRankingUniverse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ public override BaseData Reader(SubscriptionDataConfig config, string line, Date
Rank21Days = csv[6].IfNotNullOrEmpty<decimal?>(s => decimal.Parse(s, NumberStyles.Any, CultureInfo.InvariantCulture)),

Symbol = new Symbol(SecurityIdentifier.Parse(csv[0]), csv[1]),
// We need to convert the time since the date is in UTC, and AddUniverse sets the DateTimeZone to TimeZones.NewYork
// We need to convert the time since the date is in UTC, and AddUniverse sets the ExchangeTimeZone to TimeZones.NewYork
// Subtract 12 hours to match the BrainStockRankingBase EndTime
Time = date.ConvertFromUtc(config.DataTimeZone).AddHours(-12),
Time = date.ConvertFromUtc(config.ExchangeTimeZone).AddHours(-12),
Value = rank2Days ?? 0m
};
}
Expand Down
20 changes: 16 additions & 4 deletions tests/BrainSentimentIndicatorUniverseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ public void ReaderTest()
var factory = new BrainSentimentIndicatorUniverse();
var line = "AAPL R735QTJ8XC9X,AAPL,869,516,0.1196,,,5101,3176,0.0976,-0.169,0.0888";

var config = CreateSubscriptionDataConfig();
var date = new DateTime(2022, 04, 21);
var data = (BrainSentimentIndicatorUniverse)factory.Reader(null, line, date, false);
Assert.AreEqual(date.ConvertFromUtc(data.DataTimeZone()) + TimeSpan.FromHours(12), data.EndTime);
var data = (BrainSentimentIndicatorUniverse)factory.Reader(config, line, date, false);
Assert.AreEqual(date.ConvertFromUtc(config.ExchangeTimeZone) + TimeSpan.FromHours(12), data.EndTime);
Assert.AreEqual(0.1196, data.Sentiment7Days);
Assert.AreEqual(0.0976, data.Sentiment30Days);
Assert.AreEqual(516, data.SentimentalArticleMentions7Days);
Expand All @@ -56,9 +57,10 @@ public void ReaderNullSentiment7DaysTest()
var factory = new BrainSentimentIndicatorUniverse();
var line = "CNCE VO2R14MRA2XX,CNCE,,,,,,22,14,0.323100,-0.945800,-0.745700";

var config = CreateSubscriptionDataConfig();
var date = new DateTime(2022, 04, 21);
var data = (BrainSentimentIndicatorUniverse)factory.Reader(null, line, date, false);
Assert.AreEqual(date.ConvertFromUtc(data.DataTimeZone()) + TimeSpan.FromHours(12), data.EndTime);
var data = (BrainSentimentIndicatorUniverse)factory.Reader(config, line, date, false);
Assert.AreEqual(date.ConvertFromUtc(config.ExchangeTimeZone) + TimeSpan.FromHours(12), data.EndTime);
Assert.AreEqual("CNCE", data.Symbol.Value);

// Value is 0 because 7-day Sentiment is null
Expand Down Expand Up @@ -174,5 +176,15 @@ private IEnumerable<BrainSentimentIndicatorUniverse> CreateNewSelection()
}
};
}

private SubscriptionDataConfig CreateSubscriptionDataConfig() => new(
typeof(BrainSentimentIndicatorUniverse),
Symbol.None,
Resolution.Daily,
TimeZones.NewYork,
TimeZones.NewYork,
true,
true,
false);
}
}
15 changes: 13 additions & 2 deletions tests/BrainStockRankingUniverseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ public void ReaderTest(bool liveMode)
var factory = new BrainStockRankingUniverse();
var line = "AAPL R735QTJ8XC9X,AAPL,1,2,,,20";

var config = CreateSubscriptionDataConfig();
var now = new DateTime(2022, 04, 21);
var data = (BrainStockRankingUniverse)factory.Reader(null, line, now, liveMode);
Assert.AreEqual(now.ConvertFromUtc(data.DataTimeZone()) + TimeSpan.FromHours(12), data.EndTime);
var data = (BrainStockRankingUniverse)factory.Reader(config, line, now, liveMode);
Assert.AreEqual(now.ConvertFromUtc(config.ExchangeTimeZone) + TimeSpan.FromHours(12), data.EndTime);
Assert.AreEqual(1, data.Rank2Days);
Assert.AreEqual(2, data.Rank3Days);
Assert.AreEqual(null, data.Rank5Days);
Expand Down Expand Up @@ -129,5 +130,15 @@ private IEnumerable<BrainStockRankingUniverse> CreateNewSelection()
}
};
}

private SubscriptionDataConfig CreateSubscriptionDataConfig() => new(
typeof(BrainStockRankingUniverse),
Symbol.None,
Resolution.Daily,
TimeZones.NewYork,
TimeZones.NewYork,
true,
true,
false);
}
}

0 comments on commit 56a0513

Please sign in to comment.