I'm just trying to do basic stuff: retrieve contracts in the first sixty days from a start date in the research environment but I'm getting unexpected results. I've read all the docs that I can find still don't understand the behavior.
1) Why is it returning 156 contracts? setFilter only spans 60 days!
2) Why do they start in 2011? I've tried both setting date in qb and passing it to GetFutureContractList(). Is there yet a third way to set the date?
I'm all out of ideas, help appreciated.
In:
# qb setup
qb = QuantBook()
qb.SetTimeZone(TimeZones.NewYork)
start_date = datetime(2022, 1, 1)
end_date = datetime(2022, 12, 31)
qb.SetStartDate(start_date) # What does this actually do? Some methods seems to need start/end dates passed as an argument (they ignore this)
qb.SetEndDate(end_date)
# Get futures contracts
res = Resolution.Daily
norm = DataNormalizationMode.BackwardsRatio
mapping = DataMappingMode.OpenInterest
# Get continuous Contract
vx = qb.AddFuture(Futures.Indices.VIX, res,
dataNormalizationMode = norm, dataMappingMode = mapping, contractDepthOffset = 0)
vx.SetFilter(0, 60)
# Print symbol and expiry of individual contracts
symbols = qb.FutureChainProvider.GetFutureContractList(vx.Symbol, start_date)
print('# of contracts: ', len(symbols))
for i in range(5):
c = qb.AddFutureContract(symbols[i], fillDataForward = False)
print(c.Symbol, c.Expiry)
Out:
# of contracts: 156
VX15M11 2011-06-15 13:00:00
VX16G11 2011-02-16 13:00:00
VX17Q11 2011-08-17 13:00:00
VX20J11 2011-04-20 13:00:00
VX18K11 2011-05-18 13:00:00
B9 Mike
You've probably already seen this, but I found this page helpful:
David E
GregasMaximus
I appreciate the responses, but I still can't see why it's returning 156 contracts after I call SetFilter(0,90). I have looked the documentation posted above…that's where I started. In the end, I gave up, got all 156 contracts and selected the correct ones in python. This was not a big deal, but I'm still curious why SetFilter(0,90) didn't work.
GregasMaximus
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!