Futures extended market hours not supported
Expected Behavior
Futures Market hours differs widely between securities.
- Some have only one regular open market segment, e.g. Live Cattle LE
- Others have multiple regular open market segments, e.g. Wheat ZW
- Finally, there are ones with extended and regular open market hours, e.g. VIX VX
Lean should be able to reproduce all cases.
Actual Behavior
All open market hours are considered regular. This means that cases like VX cannot be handled correctly.
Potential Solution
This requires two-step:
- Update the market hours database from
"monday": [{
"start": "00:00:00",
"end": "15:15:00",
"state": "market"
}, {
"start": "15:30:00",
"end": "1.00:00:00",
"state": "market"
}
]
To
"monday": [{
"start": "00:00:00",
"end": "8:30:00",
"state": "premarket"
}, {
"start": "8:30:00",
"end": "15:15:00",
"state": "market"
}, {
"start": "15:30:00",
"end": "16:00:00",
"state": "market"
}, {
"start": "16:00:00",
"end": "1.00:00:00",
"state": "postmarket"
}
]
- Modify the
QCAlgorithm. AddFuturemethod in order to change the hardcodedextendedMarketHours=falsein theSecurityManager.CreateSecuritymethod.
Reproducing the Problem
The attached algorithm was used to test the market hours.
But, after modifying market-hours-database.json and set in extendedMarketHours=true in SecurityManager.CreateSecurity method, the data in the premarket and postmarket segments is not pumped into OnData.
public class MarketHoursTester : QCAlgorithm
{
private bool _previousMarketStatus;
private Symbol _symbol;
public override void Initialize()
{
SetStartDate(year: 2018, month: 07, day: 01);
SetEndDate(year: 2018, month: 07, day: 10);
SetCash(startingCash: 100000);
var security = AddFuture("VX");
security.SetFilter(TimeSpan.Zero, TimeSpan.FromDays(value: 182));
_symbol = security.Symbol;
}
public override void OnData(Slice slice)
{
var marketStatus = Securities[_symbol].Exchange.ExchangeOpen;
if (marketStatus != _previousMarketStatus)
{
Log($"OnData - Market Status change at {Time.ConvertTo(TimeZone, Securities[_symbol].Exchange.TimeZone):f} ExchangeTimeZone - Is open? {marketStatus}");
_previousMarketStatus = marketStatus;
}
if (!marketStatus && Time.Minute == 0)
{
Log($"OnData {Time.ConvertTo(TimeZone, Securities[_symbol].Exchange.TimeZone):f} ExchangeTimeZone - Fired on extended hours");
}
}
}
System Information
Window 7.
Checklist
- [x] I have completely filled out this template
- [x] I have confirmed that this issue exists on the current
masterbranch - [x] I have confirmed that this is not a duplicate issue by searching issues
- [x] I have provided detailed steps to reproduce the issue
Related with:
This issue addresses issue #2449.
@Jay-Jay-D is this still an issue?
Yes, MHBD has no extended hours declared for futures, and the extended hour parameter is still hard coded to be false at security creation.