Back

Open Interest of gold future data is always 0 on first day from 0:00 to 9:30

Hi, I am new to quantconnect, I have notice something strange when I am trying to get the the contract with the most open interested from the future chain just like how the boot camp demonstrated. On the start date of the algo from 0:00 to 9:00 the open interest is always zero while the volume is not, and the same thing did not happened on the second day. Here are some logging

2020-08-26 00:00:00 Contract No.: 0, Contract Symbol: GC XKR6JW5LEKKD, Underlying Symbol: None, Expiry: 2020-12-29 00:00:00, Open Interest: 0.0, Volume: 113

2020-08-26 09:30:00 Contract No.: 0, Contract Symbol: GC XKR6JW5LEKKD, Underlying Symbol: None, Expiry: 2020-12-29 00:00:00, Open Interest: 400382.0, Volume: 518

2020-08-27 00:00:00 Contract No.: 0, Contract Symbol: GC XKR6JW5LEKKD, Underlying Symbol: None, Expiry: 2020-12-29 00:00:00, Open Interest: 406586.0, Volume: 31

Is this the expected behaviour or am I missing something in the initialization process ?

Thanks in advance.

Update Backtest








0

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.


Hi Michael,

The problem is that the algorithm starts at midnight, however, the open interest for midnight today is from the previous day, so we can only start trading when the first open interest is emitted.  To address this, we first need to set a Security Initializer:

self.SetSecurityInitializer(self.OpenInterestSecurityInitializer)

Then, inside our Security Initialization function, we can warm up the futures' open interest with historical data:

def OpenInterestSecurityInitializer(self, security):
if security.Type == SecurityType.Future:
history = self.History([security.Symbol], timedelta(1))
if 'openinterest' in history:
oi = OpenInterest(self.Time, security.Symbol,
history.openinterest.dropna().iloc[-1])
security.SetMarketPrice(oi)

Please see the attached backtest for reference.

Best,
Shile Wen

1

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.


Update Backtest





0

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.


Loading...

This discussion is closed