Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    1. Home
    2. rsbowman
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
    R
    • Profile
    • Following 0
    • Followers 0
    • Topics 1
    • Posts 3
    • Best 0
    • Groups 0

    rsbowman

    @rsbowman

    0
    Reputation
    273
    Profile views
    3
    Posts
    0
    Followers
    0
    Following
    Joined Last Online

    rsbowman Unfollow Follow

    Latest posts made by rsbowman

    • RE: bug with resampling

      Ok, so in the case above the correct thing to do would be

      # ...
      data = bt.feeds.GenericCSVData(
          dataname="some-5m-data.csv",
          fromdate=datetime.datetime(2015, 1, 1),
          todate=datetime.datetime(2015, 12, 31),
          timeframe=bt.TimeFrame.Minutes,
          compression=5)
      cerebro.resampledata(data, 
          timeframe=bt.TimeFrame.Minutes,
          compression=60)
      

      This looks correct when I run it, thanks for your help!

      posted in General Code/Help
      R
      rsbowman
    • RE: bug with resampling

      Thank you both, and thank you for your patience. I think I have misunderstood the Cerebro.resampledata method. My example above was incorrect, here's the code I tried:

      import datetime
      # my backtrader __version__ = '1.9.58.122'
      import backtrader as bt
      
      if __name__ == '__main__':
          cerebro = bt.Cerebro()
          data = bt.feeds.GenericCSVData(
              dataname="some-5m-data.csv",
              fromdate=datetime.datetime(2015, 1, 1),
              todate=datetime.datetime(2015, 12, 31),
              openinterest=-1,
              timeframe=bt.TimeFrame.Ticks)
      
          cerebro.resampledata(d, timeframe=60*bt.TimeFrame.Minutes)
          #cerebro.resampledata(data, 
          #    timeframe=bt.TimeFrame.Ticks,
          #    compression=12)
          cerebro.run()
      

      I'd like to turn my 5m data into hourly data. Now I think that multiplying 60 times TimeFrame.Minutes is not meaningful and instead I should do the thing that's commented out above... Is this correct? Compress 12 5m bars into a single 60m bar?

      Thanks again!

      posted in General Code/Help
      R
      rsbowman
    • bug with resampling

      Hi,

      I have some 5m data I'm trying to resample to hourly using cerebro.resampledata(data, timeframe=bt.TimeFrame.Minutes) but I get the following error on running cerebro.run()

      Traceback (most recent call last):
        File "test.py", line 237, in <module>
          result = cerebro.run()
        File "/home/who/dev/py/trading/lib/python3.5/site-packages/backtrader/cerebro.py", line 1142, in run
          runstrat = self.runstrategies(iterstrat)
        File "/home/who/dev/py/trading/lib/python3.5/site-packages/backtrader/cerebro.py", line 1310, in runstrategies
          self._runnext(runstrats)
        File "/home/who/dev/py/trading/lib/python3.5/site-packages/backtrader/cerebro.py", line 1627, in _runnext
          self._check_timers(runstrats, dt0, cheat=True)
      UnboundLocalError: local variable 'dt0' referenced before assignment
      

      Indeed you can see at https://github.com/mementum/backtrader/blob/master/backtrader/cerebro.py#L1627 that the variable dt0 is not in scope, and again a few lines later. However, I'm not smart enough to know what the fix is -- when I changed dt0 to data0 I get a different error later....

      Thanks so much for this great software!

      posted in General Code/Help
      R
      rsbowman