My custom data is in a csv file, the data itself is in form of OHLCV with 1M timeframe.
Suppose I want to use TradeBar consolidator to produce 4H TradeBars, as the doc/community suggests, I need to somehow convert my custom data type to TradeBar type before feeding it to the TradeBar consolidator
According to the doc the custom data class inherits from PythonData class, in order to make it TradeBar compatible, should I modify it to inherit from TradeBar class like:
class MyCustomDataType(TradeBar):
def GetSource(self, config, date, isLiveMode):
source = "<directory>" + config.Symbol + ".csv"
return SubscriptionDataSource(
source,
SubscriptionTransportMedium.LocalFile,
FileFormat.csv)
def Reader(self, config, line, date, isLiveMode):
if not (line.strip() and line[0].isdigit()):
return None
idx = MyCustomDataType()
idx.Symbol = config.Symbol
idx.DataType = MarketDataType.TradeBar
try:
data = line.split(',')
currency.Time = datetime.strptime(data[0], "%Y-%m-%d")
currency.Value = decimal.Decimal(data[4])
currency.Open = float(data[1])
currency.High = float(data[2])
currency.Low = float(data[3])
currency.Close = float(data[4])
currency.Volume = float(data[5])
except ValueError:
return None
return idx
Any example in Python would be much appreciated!
Gurumeher Sawhney
The custom data class needs to inherit from PythonData because the PythonData class is where the GetSource and Reader methods get inherited from. The backtest shows a class NIFTY that is constructed and maintains OHLC data while reading through the .csv. To breakdown the backtest and what should be done, custom classes are made to handle the data and is then fed into the OnData handler, which will allows the OHLC data to be used. This data, in the format is <class 'converter.Data'>, can be consolidated with the method ResolveConsolidater method during the Initialize(). The data can be consolidated by a timespan and in the backtest the timespan is currently 30 days.
Thomas Cheng
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!