Back

Creating Renko bars from futures security seems broken

Hey All, 

I'm trying to create some renko bars from S&P500Emini ticks. The renko consolidator seems broken? when I run the following backtest with an equity (SPY) the backtest logs some renko closes. when I run the same code with the ES it fails with 

During the algorithm initialization, the following exception has occurred: ArgumentException : Please subscribe to this symbol before adding a consolidator for it. Symbol:
at QuantConnect.Data.SubscriptionManager.AddConsolidator (QuantConnect.Symbol symbol, QuantConnect.Data.Consolidators.IDataConsolidator consolidator) [0x00047] in <796a9fb122d841fdaad855535a8219c0>:0
at (wrapper managed-to-native) System.Reflection.MonoMethod.InternalInvoke(System.Reflection.MonoMethod,object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00032] in :0
at Initialize in main.py:line 35
ArgumentException : Please subscribe to this symbol before adding a consolidator for it. Symbol:
at QuantConnect.Data.SubscriptionManager.AddConsolidator (QuantConnect.Symbol symbol, QuantConnect.Data.Consolidators.IDataConsolidator consolidator) [0x00047] in <796a9fb122d841fdaad855535a8219c0>:0
at (wrapper managed-to-native) System.Reflection.MonoMethod.InternalInvoke(System.Reflection.MonoMethod,object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00032] in :0

the code I'm running.

from clr import AddReference
AddReference("System")
AddReference("QuantConnect.Algorithm")
AddReference("QuantConnect.Common")

from System import *
from QuantConnect import *
from QuantConnect.Data import *
from QuantConnect.Data.Market import *
from QuantConnect.Algorithm import *
from QuantConnect.Indicators import *
from QuantConnect.Securities import *
from QuantConnect.Data.Consolidators import *
from datetime import timedelta


class TestFuturesAlgorithm(QCAlgorithm):

def Initialize(self):
self.SetStartDate(2013, 10, 7)
self.SetEndDate(2013, 10, 11)
self.SetCash(1000)

# spy_equity = self.AddSecurity(SecurityType.Equity, "SPY", Resolution.Tick).Symbol
es_future = self.AddFuture(Futures.Indices.SP500EMini, Resolution.Tick)
es_future.SetFilter(timedelta(0), timedelta(182))

renkoClose = RenkoConsolidator(0.5, RenkoType.Wicked)
renkoClose.DataConsolidated += self.HandleRenkoClose
self.SubscriptionManager.AddConsolidator(Futures.Indices.SP500EMini, renkoClose)
# self.SubscriptionManager.AddConsolidator(spy_equity, renkoClose)

def OnData(self,slice):
pass

def HandleRenkoClose(self, sender, data):
'''This function is called by our renkoClose consolidator defined in Initialize()
Args:
data: The new renko bar produced by the consolidator'''
if not self.Portfolio.Invested:
self.SetHoldings(data.Symbol, 1)

self.Log(f"CLOSE - {data.Time} - {data.Open} {data.Close}")

 

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 Keith - the key is in your commented out sections, where you used SPY's symbol when registering the consolidator. You need to use the actual Symbol of the future you've subscribed to in AddConsolidator.

self.SubscriptionManager.AddConsolidator(es_future.Symbol, renkoClose)

In general it's good practice to use symbols rather than strings (Futures.Indices.SP500EMini translates to a constant string). Even better practice is to store each security and call upon the security's specific symbol.

As for why the strategy still doesn't trade, I can't say for sure as I'm not too familiar with how Renko consolidators work with Futures data.

0

Thanks Douglas, 
ha, i did try using the symbol but thought I was doing something wrong, I apprecitiate the correction and best proactice tip. Any quantConnect folks know why Equites run in this scenario and Futures don't?

0


Hi Keith,

The problem that the strategy works for Equity but not Futures lies in the fact that the ways to retrieve data from Equity and Futures are different in QuantConnect. The data your strategy requires is contained in `FuturesContract` object, which is different from the output `es_future` of the `AddFuture` method. The output `es_future` contains a collection of individual future contracts.The futures contracts can be retrieved from `changes.AddedSecurities` under `OnSecuritiesChanged` event handler. Please refer to the backtest below for implementation details. Using `OnSecuritiesChanged` method ensures that every futures contract being added gets a consolidator, and also that the consolidators are removed when a contract drops out of the universe. 

Data Library - Futures doc section will be a useful resource for requesting and using Futures data in QuantConnect. Please let me know if you have further questions.

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.


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