Lean
Lean copied to clipboard
Security.Exchange.Hours.RegularMarketDuration Python Method for VX future
Hi, I would like to get the regular market duration for VX future, however when I called Security.Exchange.Hours.RegularMarketDuration, I got a wrong result.
Expected Behavior
It should be 6:45:00
Actual Behavior
The actual result is 23:45:00
Potential Solution
Reproducing the Problem
The following code could reproduce the problem.
import numpy as np
import decimal as d
class dataError(ValueError):
pass
class BasicTemplateAlgorithm(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2018,1, 7)
self.SetEndDate(2018,8,20)
self.SetCash(100000)
self.future_trading_class = "VX"
self.extendedMarketHours = False
self.vx_future = self.AddFuture(self.future_trading_class, Resolution.Minute, extendedMarketHours = self.extendedMarketHours)
self.vx_symbol = self.vx_future.Symbol.Value
self.counter = 0
def OnData(self, data):
self.counter += 1
if self.counter != 1:
try:
for ele in data.FuturesChains:
if ele.Key.Value == self.future_trading_class:
vx_futureschain = ele.Value
break
else:
raise dataError
vx_futureschain = list(filter(lambda x: x.Expiry > self.Time, vx_futureschain))
vx_futureschain = sorted(vx_futureschain, key = lambda x: x.Expiry, reverse = False)
front_month = vx_futureschain[0]
front_month_detail = self.Portfolio[front_month.Symbol].Security
if self.counter < 10:
self.Debug(str(self.Time)+ " Regular Market Duration: " + str(front_month_detail.Exchange.Hours.RegularMarketDuration))
except dataError:
pass
System Information
Checklist
- [ ] I have completely filled out this template
- [ ] I have confirmed that this issue exists on the current
masterbranch - [ ] I have confirmed that this is not a duplicate issue by searching issues
- [ ] I have provided detailed steps to reproduce the issue
Depends on https://github.com/QuantConnect/Lean/issues/2470
Sorry for the delay, this is solved already 👍. Based on CBOE specification regular market goes from 8:30 a.m. to 3:00 p.m. see https://www.cboe.com/tradable_products/vix/vix_futures/specifications/, lean returns 6:30 for RegularMarketDuration