For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

[SOLVED] Version: 1.9.73.123 - Still issues with resampling minutes to days?



  • Hey,

    I'm having an issue with resampling to days. Everything else, 15M, weeks and months works. Days wont...

    Im running a adjusted verison (to my datafeed) of the script posted here?

    The fix suggested last year seems to be implemented in resamplerfilter.py...

    Can anybody confirm this?

    Thx,
    Andreas

    Error:

    Traceback (most recent call last):
      File "test_resampling.py", line 62, in <module>
        runstrat()
      File "test_resampling.py", line 41, in runstrat
        cerebro.run()
      File "C:\Users\A\AppData\Local\Programs\Python\Python36\lib\site-packages\backtrader\cerebro.py", line 1127, in run
        runstrat = self.runstrategies(iterstrat)
      File "C:\Users\A\AppData\Local\Programs\Python\Python36\lib\site-packages\backtrader\cerebro.py", line 1298, in runstrategies
        self._runnext(runstrats)
      File "C:\Users\A\AppData\Local\Programs\Python\Python36\lib\site-packages\backtrader\cerebro.py", line 1557, in _runnext
        dt0 = min((d for i, d in enumerate(dts)
    ValueError: min() arg is an empty sequence
    

  • administrators

    Your message contains the following keywords:

    • Still?

      Were there?

    • Error:

      And the code is ... (you run your own "adjusted" version of something)

    • Data: None

    What are you expecting? Cellular Osmosis?



  • Ok, I solved it... Of course a user error (and I'm not expecting cellular osmosis, LOL).

    Short story (Fix):
    When u start dealing with Multiple timeframes and resampling, labeling the timeframe of your datafeed becomes important. It might be important before as well, I just didn't notice.

    data = bt.feeds.PandasData(dataname=df,timeframe=bt.TimeFrame.Minutes)
    

    Looong story (since I typed it up already and explains the story of identifying this issue):

    Where there?

    As in version 1.9.66.122

    1.9.67.122

    • Fix compression only scenarios when resampling and resampling after

      changes in 1.9.66.122

    • Final correction for rollover fix introduced in 1.9.66.122

    • Cover use case for mininum period calculation when all

      operations/indicators don't use the data feeds directly but lines of it

    Script I'm running:

    from __future__ import (absolute_import, division, print_function,
    						unicode_literals)
    
    import argparse
    
    import backtrader as bt
    import backtrader.feeds as btfeeds
    import numpy as np
    
    
    def runstrat():
    	args = parse_args()
    
    	# Create a cerebro entity
    	cerebro = bt.Cerebro(stdstats=False)
    
    	# Add a strategy
    	cerebro.addstrategy(bt.Strategy)
    	
    	# Handy dictionary for the argument timeframe conversion
    	tframes = dict(
    		minute=bt.TimeFrame.Minutes,
    		daily=bt.TimeFrame.Days,
    		weekly=bt.TimeFrame.Weeks,
    		monthly=bt.TimeFrame.Months)
    	
    	
    	# Load the Data
    	dataframe = np.load('dataframe_1S_min.npy').item()
    	
    	for symbol, df in dataframe.items():
    		print(df)
    		data = bt.feeds.PandasData(dataname=df)
    		# Add the Data Feed to Cerebro
    		cerebro.adddata(data)
    		cerebro.resampledata(data,
    						 timeframe=tframes[args.timeframe],
    						 compression=args.compression)
    
    	# Run over everything
    	cerebro.run()
    
    	# Plot the result
    	cerebro.plot(style='bar')
    
    
    def parse_args():
    	parser = argparse.ArgumentParser(
    		description='Pandas test script')
    
    	parser.add_argument('--timeframe', default='daily', required=False,
    						choices=['minute','daily', 'weekly', 'monhtly'],
    						help='Timeframe to resample to')
    
    	parser.add_argument('--compression', default=1, required=False, type=int,
    						help='Compress n bars into 1')
    
    	return parser.parse_args()
    
    
    if __name__ == '__main__':
    	runstrat()
    

    Data screen grab:

                                   open      high       low     close  volume  openinterest
    2019-05-02 09:30:00-04:00  184.5000  184.5700  184.5000  184.5100     752             1
    2019-05-02 09:31:00-04:00  184.3600  184.7000  183.5600  183.7500  174074             1
    2019-05-02 09:32:00-04:00  183.7500  183.8100  183.3800  183.5000   35592             1
    ...                             ...       ...       ...       ...     ...           ...
    2019-05-10 15:57:00-04:00  175.6800  175.7900  175.5400  175.7900   97358             1
    2019-05-10 15:58:00-04:00  175.7850  175.9800  175.6400  175.7400  111693             1
    2019-05-10 15:59:00-04:00  175.7600  176.0400  175.4700  175.8400  204595             1
    
    [2728 rows x 6 columns]
    

    Script instructions:

    python test_resampling.py --timeframe weekly --compression 1
    

    Result: Works
    0_1557686167864_02099056-49c6-47a9-96c3-1128a3669777-image.png

    Script instructions:

    python test_resampling.py --timeframe minute --compression 15
    

    Result: Works
    0_1557686410141_24b75c71-38fb-423d-ae7d-7bbca541c480-image.png

    Script instructions:

    python test_resampling.py --timeframe daily --compression 1
    

    Result: Error

    Traceback (most recent call last):
      File "test_resampling.py", line 62, in <module>
        runstrat()
      File "test_resampling.py", line 41, in runstrat
        cerebro.run()
      File "C:\Users\A\AppData\Local\Programs\Python\Python36\lib\site-packages\backtrader\cerebro.py", line 1127, in run
        runstrat = self.runstrategies(iterstrat)
      File "C:\Users\A\AppData\Local\Programs\Python\Python36\lib\site-packages\backtrader\cerebro.py", line 1298, in runstrategies
        self._runnext(runstrats)
      File "C:\Users\A\AppData\Local\Programs\Python\Python36\lib\site-packages\backtrader\cerebro.py", line 1557, in _runnext
        dt0 = min((d for i, d in enumerate(dts)
    ValueError: min() arg is an empty sequence
    

    The clue, which solved the problem:
    After looking at the plots again. It seems that the first data feed gets labeled as "Days" even though it's provided in minutes.


Log in to reply
 

});