Skip to content

Commit 5ff21ca

Browse files
Revert "Market-hours aware intraday consolidation (#9516)"
This reverts commit 9b89c16.
1 parent 90261c8 commit 5ff21ca

6 files changed

Lines changed: 1 addition & 386 deletions

File tree

Algorithm.CSharp/MarketHourAwareIntradayConsolidationRegressionAlgorithm.cs

Lines changed: 0 additions & 147 deletions
This file was deleted.

Algorithm.Python/MarketHourAwareIntradayConsolidationRegressionAlgorithm.py

Lines changed: 0 additions & 58 deletions
This file was deleted.

Common/AlgorithmImports.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@
6868
from QuantConnect.Securities.Equity import *
6969
from QuantConnect.Securities.Future import *
7070
from QuantConnect.Data.Consolidators import *
71-
from QuantConnect.Data.Common import *
7271
from QuantConnect.Orders.TimeInForces import *
7372
from QuantConnect.Algorithm.Framework import *
7473
from QuantConnect.Algorithm.Selection import *

Common/Data/Consolidators/MarketHourAwareConsolidator.cs

Lines changed: 1 addition & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -89,36 +89,6 @@ public MarketHourAwareConsolidator(bool dailyStrictEndTimeEnabled, Resolution re
8989
Consolidator.DataConsolidated += ForwardConsolidatedBar;
9090
}
9191

92-
/// <summary>
93-
/// Initializes a new instance of the <see cref="MarketHourAwareConsolidator"/> class for an arbitrary period.
94-
/// Intraday periods are anchored to the market open without extending past the close.
95-
/// </summary>
96-
/// <param name="dailyStrictEndTimeEnabled">True if daily strict end times should be enabled</param>
97-
/// <param name="period">The consolidation period</param>
98-
/// <param name="dataType">The target data type</param>
99-
/// <param name="tickType">The target tick type</param>
100-
/// <param name="extendedMarketHours">True if extended market hours should be consolidated</param>
101-
public MarketHourAwareConsolidator(bool dailyStrictEndTimeEnabled, TimeSpan period, Type dataType, TickType tickType, bool extendedMarketHours)
102-
{
103-
_dailyStrictEndTimeEnabled = dailyStrictEndTimeEnabled;
104-
Period = period;
105-
_extendedMarketHours = extendedMarketHours;
106-
107-
// when the period exactly matches a standard resolution, reuse the resolution based consolidation so its
108-
// well-tested behavior is preserved; only arbitrary periods need the market-open anchored intraday calendar
109-
var resolution = period.ToHigherResolutionEquivalent(false);
110-
if (resolution.ToTimeSpan() == period)
111-
{
112-
Consolidator = CreateConsolidator(resolution, dataType, tickType);
113-
}
114-
else
115-
{
116-
Func<DateTime, CalendarInfo> calendar = period < Time.OneDay ? IntradayCalendar : DailyStrictEndTime;
117-
Consolidator = CreateConsolidator(calendar, dataType, tickType);
118-
}
119-
Consolidator.DataConsolidated += ForwardConsolidatedBar;
120-
}
121-
12292
/// <summary>
12393
/// Creates the inner consolidator that produces the requested <paramref name="dataType"/> output.
12494
/// </summary>
@@ -151,28 +121,6 @@ protected virtual IDataConsolidator CreateConsolidator(Resolution resolution, Ty
151121
throw new ArgumentNullException(nameof(dataType), $"{dataType.Name} not supported");
152122
}
153123

154-
/// <summary>
155-
/// Creates the underlying calendar based consolidator for the given data type, used for arbitrary periods
156-
/// </summary>
157-
protected virtual IDataConsolidator CreateConsolidator(Func<DateTime, CalendarInfo> calendar, Type dataType, TickType tickType)
158-
{
159-
if (dataType == typeof(Tick))
160-
{
161-
return tickType == TickType.Trade
162-
? new TickConsolidator(calendar)
163-
: new TickQuoteBarConsolidator(calendar);
164-
}
165-
if (dataType == typeof(TradeBar))
166-
{
167-
return new TradeBarConsolidator(calendar);
168-
}
169-
if (dataType == typeof(QuoteBar))
170-
{
171-
return new QuoteBarConsolidator(calendar);
172-
}
173-
throw new ArgumentNullException(nameof(dataType), $"{dataType.Name} not supported");
174-
}
175-
176124
/// <summary>
177125
/// Event handler that fires when a new piece of data is produced
178126
/// </summary>
@@ -247,27 +195,13 @@ protected void Initialize(IBaseData data)
247195
/// </summary>
248196
protected virtual CalendarInfo DailyStrictEndTime(DateTime dateTime)
249197
{
250-
// strict end times describe a single daily bar, so periods larger than a day fall back to standard period consolidation
251-
if (!_useStrictEndTime || Period > Time.OneDay)
198+
if (!_useStrictEndTime)
252199
{
253200
return new(Period > Time.OneDay ? dateTime : dateTime.RoundDown(Period), Period);
254201
}
255202
return LeanData.GetDailyCalendar(dateTime, ExchangeHours, _extendedMarketHours);
256203
}
257204

258-
/// <summary>
259-
/// Determines a bar start time and period for intraday consolidation, anchored to the market open
260-
/// without extending past the market close so a bar never spans across closed market hours
261-
/// </summary>
262-
protected virtual CalendarInfo IntradayCalendar(DateTime dateTime)
263-
{
264-
if (ExchangeHours == null || ExchangeHours.IsMarketAlwaysOpen)
265-
{
266-
return new(dateTime.RoundDown(Period), Period);
267-
}
268-
return LeanData.GetIntradayCalendar(dateTime, Period, ExchangeHours, _extendedMarketHours);
269-
}
270-
271205
/// <summary>
272206
/// Useful for testing
273207
/// </summary>

Common/Util/LeanData.cs

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1476,33 +1476,6 @@ public static CalendarInfo GetDailyCalendar(DateTime exchangeTimeZoneDate, Secur
14761476
return new CalendarInfo(startTime, period);
14771477
}
14781478

1479-
/// <summary>
1480-
/// Helper method to return the intraday bar start time and period, anchored to the market open, without extending past the close
1481-
/// </summary>
1482-
/// <param name="exchangeTimeZoneDate">The point in time we want to get the bar information about</param>
1483-
/// <param name="period">The intraday consolidation period</param>
1484-
/// <param name="exchangeHours">The associated exchange hours</param>
1485-
/// <param name="extendedMarketHours">True if extended market hours should be taken into consideration</param>
1486-
/// <returns>The calendar information that holds a start time and a period</returns>
1487-
public static CalendarInfo GetIntradayCalendar(DateTime exchangeTimeZoneDate, TimeSpan period, SecurityExchangeHours exchangeHours, bool extendedMarketHours)
1488-
{
1489-
var marketOpen = exchangeHours.IsOpen(exchangeTimeZoneDate, extendedMarketHours)
1490-
? exchangeHours.GetPreviousMarketOpen(exchangeTimeZoneDate.AddTicks(1), extendedMarketHours)
1491-
: exchangeHours.GetPreviousMarketOpen(exchangeTimeZoneDate, extendedMarketHours);
1492-
1493-
var intervalsPassed = (long)Math.Floor((exchangeTimeZoneDate - marketOpen).Ticks / (double)period.Ticks);
1494-
var startTime = marketOpen.AddTicks(intervalsPassed * period.Ticks);
1495-
1496-
// keep the last bar from extending past the market close
1497-
var endTime = startTime + period;
1498-
var marketClose = exchangeHours.GetNextMarketClose(marketOpen, extendedMarketHours);
1499-
if (endTime > marketClose)
1500-
{
1501-
endTime = marketClose;
1502-
}
1503-
return new CalendarInfo(startTime, endTime - startTime);
1504-
}
1505-
15061479
/// <summary>
15071480
/// Helper method to get the next daily end time, taking into account strict end times if appropriate
15081481
/// </summary>

0 commit comments

Comments
 (0)