Grab every 4th row in data
-
I want to grab every 4th row in data without resampling in backtrader as i have done in python here is code
ts = TimeSeries(key='av_api_key', output_format='pandas') data, meta_data = ts.get_intraday(symbol='MSFT', interval='60min', outputsize='full') # Convert the index to datetime. data.index = pd.to_datetime(data.index) data.columns = ['Open', 'High', 'Low', 'Close', 'Volume'] # Grabs every 4th row data = data.iloc[::4, :]
-
@mudassar031
if we have minutes of data and use resampling with compression=60 so backtrader give us data after averaging 60 mins actually i want to skip data in between and want to grab specific row as i have explained above example Thanks -
@mudassar031 said in Grab every 4th row in data:
I want to grab every 4th row in data
What does it mean to 'grab' every fourth row. What will you be doing with it? It might be easier to just have a counter in next and only consider every fourth row?
-
@run-out
can you please give me an code example to consider every fourth row in next function? -
Try this
def next(self): if len(self.data) % 4 != 0: return # operations you want to make on every 4th bar
-
@ab_trader
Thanks -
@ab_trader
i have minutes of data and i want to fetch 4 hours our data but it always executing one minutes on data i want only to display row after 240th rowif len(self.data) % 240 != 0: self.log( 'Open: %.2f ' 'High: %.2f ' 'Low: %.2f ' 'Close: %.2f ' % ( self.data.open[0], self.data.high[0], self.data.low[0], self.data.close[0] ))
-
@ab_trader
another question i am using 4 hours of resampledatadata0 = DataFactory( dataname=args.symbol or "MSFT", timeframe=bt.TimeFrame.TFrame("Minutes"), fromdate=pd.Timestamp('2020-07-27'), todate=pd.Timestamp('2020-07-29'), compression=1, historical=True) cerebro.adddata(data0) cerebro.resampledata(data0, timeframe=bt.TimeFrame.Minutes, compression=60 * 4)
and i am fetching 4 hours resample data in def init(self):
like thisself.data4h = self.datas[1] # 240 minute resampled data
its giving me error
File "4hresample.py", line 74, in __init__ self.data4h = self.datas[1] # 240 minute resampled data IndexError: list index out of range
-