Navigation

    Backtrader Community

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

    Drew Clayman

    @Drew Clayman

    4
    Reputation
    4
    Profile views
    8
    Posts
    0
    Followers
    0
    Following
    Joined Last Online

    Drew Clayman Unfollow Follow

    Best posts made by Drew Clayman

    • Date Changing But Time not Changing

      I think I've been following examples with very simple code, whatever I do I can't get the times to chage along with the dates while iterating, it keeps the time at 23:59:59. I can't figure out what I'm doing wrong. The code is as follows:

      class MyStrategy(bt.Strategy):
              def __init__(self):
                  self.dataclose = self.datas[0].close
          
              def next(self):
                  print(self.datas[0].datetime.date(0), self.datas[0].datetime.time(0))
      
      cerebro = bt.Cerebro()
      
      
      data = btfeeds.GenericCSVData(
          dataname='data.csv',
      
          dtformat=('%Y-%m-%d'),
          tmformat=('%H.%M.%S'),
          
          datetime=0,
          time=1,
          open=2,
          high=3,
          low=4,
          close=5,
          volume=6,
          openinterest=-1
      )
      
      cerebro.adddata(data)
      
      cerebro.addstrategy(MyStrategy)
      
      cerebro.run()
      

      The output from printing the date and time looks as follows:

      2010-03-22 23:59:59.999989
      2010-03-22 23:59:59.999989
      2010-03-22 23:59:59.999989
      2010-03-22 23:59:59.999989
      2010-03-22 23:59:59.999989
      2010-03-22 23:59:59.999989
      

      continuing all the way throughout. The csv file looks like this:

      ```
                date 	           time 	    open 	    high 	     low 	   close   ticks
      

      0 2010-03-01 00.24.00 0.89887 0.89887 0.89886 0.89886 2
      1 2010-03-01 00.25.00 0.89884 0.89888 0.89870 0.89881 20
      2 2010-03-01 00.26.00 0.89878 0.89883 0.89878 0.89883 7
      3 2010-03-01 00.27.00 0.89883 0.89883 0.89883 0.89883 1

      posted in General Code/Help
      Drew Clayman
      Drew Clayman
    • RE: Date Changing But Time not Changing

      Ah, thanks so much for that. Works perfectly

      posted in General Code/Help
      Drew Clayman
      Drew Clayman
    • drawdown value in 0.xx % meaning

      I just wanted a quick clarification on the meaning of having a drawdown of 0.xx %, based on the documentation. If i have a drawdown of 0.05, is this 5%, or 0.05%?

      posted in General Code/Help
      Drew Clayman
      Drew Clayman
    • RE: Commission Clarification

      I just found it in the documentation now. It would be 0.1%

      posted in General Code/Help
      Drew Clayman
      Drew Clayman

    Latest posts made by Drew Clayman

    • 'AutoInfoClass_OrderBase_Order_SellOrder' object has no attribute 'isclosed' (for trade.isclosed)

      I'm trying to log my trades like in this example:

      def log(self, txt, dt=None):
            ''' Logging function fot this strategy'''
            dt = dt or self.datas[0].datetime.date(0)
            print('%s, %s' % (dt.isoformat(), txt))
      
        def notify_trade(self, trade):
            if not trade.isclosed:
                return
      
            self.log('OPERATION PROFIT, GROSS %.2f, NET %.2f' %
                     (trade.pnl, trade.pnlcomm))
      

      The way I'm using these functions is like this:

      class MyStrategy(bt.Strategy):
          def __init__(self):
               self.order = None
      
          def log(self, txt, dt=None):
                  ''' Logging function fot this strategy'''
                  dt = dt or self.datas[0].datetime.date(0)
                  print('%s, %s' % (dt.isoformat(), txt))
          
          def notify_trade(self, trade):
              if not trade.isclosed:
                  return
          
              self.log('OPERATION PROFIT, GROSS %.2f, NET %.2f' %
                       (trade.pnl, trade.pnlcomm))
      
          def next(self):
              self.order = self.sell(size=lots)
              self.notify_trade(self.order)
      

      When I run it I get the error:

      'AutoInfoClass_OrderBase_Order_SellOrder' object has no attribute 'isclosed'
      

      When I just try to get the pnl it says the same thing, but about having no attribute 'pnl'.

      I'm guessing there's something wrong with the way I'm saving the trade. Any advice would be much appreciated, thanks.

      posted in General Code/Help
      Drew Clayman
      Drew Clayman
    • Backtest Going Beyond Dates of Available Data

      I'm finding that if I set the dates for the backtest past the dates that are actually available in my data it will eventually say index out of bounds, but before that it will continue for a couple months past the last available date. Along with the dates I'm printing some of the prices; sometimes the prices repeat and sometimes they don't. Some of the prices just aren't anywhere at my data. Has anyone come across this before or have any idea what might be happening?

      posted in General Code/Help
      Drew Clayman
      Drew Clayman
    • RE: Commission Clarification

      I just found it in the documentation now. It would be 0.1%

      posted in General Code/Help
      Drew Clayman
      Drew Clayman
    • Commission Clarification

      If I set the commission as 0.001, (with Margin=False), and each time I buy $100,000 worth of the asset, does that mean each time I'm paying 0.001%, or $100 each time? or is 0.1%

      posted in General Code/Help
      Drew Clayman
      Drew Clayman
    • drawdown value in 0.xx % meaning

      I just wanted a quick clarification on the meaning of having a drawdown of 0.xx %, based on the documentation. If i have a drawdown of 0.05, is this 5%, or 0.05%?

      posted in General Code/Help
      Drew Clayman
      Drew Clayman
    • RE: Date Changing But Time not Changing

      Ah, thanks so much for that. Works perfectly

      posted in General Code/Help
      Drew Clayman
      Drew Clayman
    • Time doesn't change but Date does

      I have been following examples, but whatever I do, the time won't change along with the date. My code looks as follows:

      class MyStrategy(bt.Strategy):
              def __init__(self):
                  self.dataclose = self.datas[0].close
          
              def next(self):
                  print(self.datas[0].datetime.date(0), self.datas[0].datetime.time(0))
      
      cerebro = bt.Cerebro()
      
      data = btfeeds.GenericCSVData(
          dataname='data.csv',
      
          dtformat=('%Y-%m-%d'),
          tmformat=('%H.%M.%S'),
          
          datetime=0,
          time=1,
          open=2,
          high=3,
          low=4,
          close=5,
          volume=6,
          openinterest=-1
      )
      

      cerebro.adddata(data)

      cerebro.addstrategy(MyStrategy)

      cerebro.run()

      The output looks as follows:

      2010-03-22 23:59:59.999989
      2010-03-22 23:59:59.999989
      2010-03-22 23:59:59.999989
      2010-03-22 23:59:59.999989
      2010-03-22 23:59:59.999989

      continuing like this all the way through. The csv file looks like this:

         date 	          time 	  open 	  high 	 low 	  close 	ticks
      

      0 2010-03-01 00.24.00 0.89887 0.89887 0.89886 0.89886 2
      1 2010-03-01 00.25.00 0.89884 0.89888 0.89870 0.89881 20
      2 2010-03-01 00.26.00 0.89878 0.89883 0.89878 0.89883 7

      posted in General Code/Help
      Drew Clayman
      Drew Clayman
    • Date Changing But Time not Changing

      I think I've been following examples with very simple code, whatever I do I can't get the times to chage along with the dates while iterating, it keeps the time at 23:59:59. I can't figure out what I'm doing wrong. The code is as follows:

      class MyStrategy(bt.Strategy):
              def __init__(self):
                  self.dataclose = self.datas[0].close
          
              def next(self):
                  print(self.datas[0].datetime.date(0), self.datas[0].datetime.time(0))
      
      cerebro = bt.Cerebro()
      
      
      data = btfeeds.GenericCSVData(
          dataname='data.csv',
      
          dtformat=('%Y-%m-%d'),
          tmformat=('%H.%M.%S'),
          
          datetime=0,
          time=1,
          open=2,
          high=3,
          low=4,
          close=5,
          volume=6,
          openinterest=-1
      )
      
      cerebro.adddata(data)
      
      cerebro.addstrategy(MyStrategy)
      
      cerebro.run()
      

      The output from printing the date and time looks as follows:

      2010-03-22 23:59:59.999989
      2010-03-22 23:59:59.999989
      2010-03-22 23:59:59.999989
      2010-03-22 23:59:59.999989
      2010-03-22 23:59:59.999989
      2010-03-22 23:59:59.999989
      

      continuing all the way throughout. The csv file looks like this:

      ```
                date 	           time 	    open 	    high 	     low 	   close   ticks
      

      0 2010-03-01 00.24.00 0.89887 0.89887 0.89886 0.89886 2
      1 2010-03-01 00.25.00 0.89884 0.89888 0.89870 0.89881 20
      2 2010-03-01 00.26.00 0.89878 0.89883 0.89878 0.89883 7
      3 2010-03-01 00.27.00 0.89883 0.89883 0.89883 0.89883 1

      posted in General Code/Help
      Drew Clayman
      Drew Clayman