Futures with consolidator - No data

Back

I have troubles with futures using consolidator and indicators.

I don't get any data coming trough OnData and OnBar

Please help!

from System import *
from QuantConnect import *
from QuantConnect.Algorithm import *
from QuantConnect.Indicators import *

class Strategy(QCAlgorithm):

def Initialize(self):
self.SetStartDate(2020, 1, 1)
self.SetCash(100000)

self.symbols = ['ZW', "ZC", "ZS", "ZM", "ZL", "ZO"]

self.res_data = Resolution.Hour
self.res_bar = Resolution.Daily
self.res_cons = timedelta(hours=24)
self.SetTimeZone("America/New_York")

self.futures = {}
self.db = {}
self.ind = {}

self.p = AttrDict()
self.p.ema_period = 9
self.p.bb_period = 20
self.p.bb_std = 2
self.p.bb_ma = MovingAverageType.Simple

for s in self.symbols:
self.init_symbol(s)

warm_period = max([self.p.ema_period, self.p.bb_period]) + 1
self.SetWarmUp(timedelta(hours=warm_period))

def init_symbol(self, s):
self.futures[s] = self.AddFuture(s, self.res_data)
self.futures[s].SetFilter(timedelta(0), timedelta(182))

self.Consolidate(self.futures[s].Symbol, self.res_bar, self.OnBar)

self.ind[s] = {}
self.ind[s]['ema'] = ema = ExponentialMovingAverage(
self.p.ema_period)
self.ind[s]['bb'] = bb = BollingerBands(
self.p.bb_period, self.p.bb_std, self.p.bb_ma)
self.RegisterIndicator(self.futures[s].Symbol, ema, self.res_bar)
self.RegisterIndicator(self.futures[s].Symbol, bb, self.res_bar)

self.db[s] = {}
self.db[s]['history'] = RollingWindow[QuoteBar](
self.p.entry_valid)
self.db[s]['ema'] = RollingWindow[IndicatorDataPoint](
self.p.entry_valid)
self.db[s]['bb_top'] = RollingWindow[IndicatorDataPoint](
self.p.entry_valid)
self.db[s]['bb_mid'] = RollingWindow[IndicatorDataPoint](
self.p.entry_valid)
self.db[s]['bb_bot'] = RollingWindow[IndicatorDataPoint](
self.p.entry_valid)
self.db[s]['prices'] = []

def OnData(self, data):
self.Debug('OnData')

def OnBar(self, bar):
s = bar.Symbol.Value
self.Debug('OnBar %s' % s)


class AttrDict(dict):
def __init__(self, *args, **kwargs):
super(AttrDict, self).__init__(*args, **kwargs)
self.__dict__ = self

 

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.


After changing 
self.res_data = Resolution.Minute

OnData started working

OnBar for some reason still doesn't work

1

Hi Konstantin!

To consolidate futures data you will need to bind to the futures contract's data, not the root future symbol. You would do this in OnSecurityChanges by looking at the AddedSecurities to see the individual future contracts coming into your algorithm.

Currently, QuantConnect does not have support for continuous contracts.

Best

Jared

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.


Dear Jared,

What will happen when contract expire?
Will I need to unregister the consolidator?

Best Regards,
Konstantin

0

Correct. Please see this example algorithm for a demonstration

677_1586456746.jpg

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