Backtrader Community

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    1. Home
    2. RY 93
    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 4
    • Posts 10
    • Best 1
    • Controversial 0
    • Groups 0

    RY 93

    @RY 93

    1
    Reputation
    312
    Profile views
    10
    Posts
    0
    Followers
    0
    Following
    Joined Last Online

    RY 93 Unfollow Follow

    Best posts made by RY 93

    • RE: Optimization error when multiple data feed

      @yufeng-xin Thanks.
      But I got the actual problem(I am assuming it, may be I am wrong also). Actually I am using the second datafeed only for indicator calculation and thus it has not any observer(BuySell,CashValue etc.).So I am thinking that after the code completetion it is trying to fetch these values and thus giving this error.
      So when I put this for optimization:

      bt.Cerebro(maxcpus = 8, stdstats = False))
      

      it worked.

      posted in General Code/Help
      R
      RY 93

    Latest posts made by RY 93

    • Drop Variable Values(Buffer) Before Look-Back Period.

      @backtrader
      Can we drop the stored values of data,indicator values(Eg. self.line0, self.data0 etc.) before the look-back period(if there is no use of data for further analysis like plotting ,return calculation etc.), which will be essentially useful in memory(RAM) optimization.
      If yes, then Could you suggest the possible way ?

      posted in General Code/Help optimal free memory linebuffer
      R
      RY 93
    • RE: Cancel Repeated Order When Multiple DataFeed

      @backtrader Thanks.
      You are right @backtrader , multiple orders were coming for the same timeframe data. Actually I haven't added the session end time during dataread , so when any order created at the end-time of the trading day it gets created twice.

      posted in General Code/Help
      R
      RY 93
    • RE: Cancel Repeated Order When Multiple DataFeed

      @backtrader Is there any way that next method will only run for a particular timeframe, or more specifically can I create order only for a specific timeframe data.
      Actually I found this in the def that we can mention data in data=None option. But still it issues order for other timeframes as well.

      def buy(self, data=None,
                size=None, price=None, plimit=None,
                exectype=None, valid=None, tradeid=0, oco=None,
                trailamount=None, trailpercent=None,
                parent=None, transmit=True,
                **kwargs)
      
      posted in General Code/Help
      R
      RY 93
    • RE: Cancel Repeated Order When Multiple DataFeed

      @backtrader
      I am using this way to generate order:

                    def next(self):
                             if self.p.exectype == 'Market':
                                 self.buy(exectype=bt.Order.Market, valid=valid) 
                                 self.log('BUY CREATE, Market Order, Price: %.2f' % self.data0.close[0])
      
      posted in General Code/Help
      R
      RY 93
    • Cancel Repeated Order When Multiple DataFeed

      I am using two datafeed one of minute basis and one of daily basis. I am generating signals(buy-sell) using only minute data feed and daily data feed is for other analysis.
      So when my model generates signal at the starting time of day or at the closing time of day same signal gets generated twice with different Order Ref.(Because at the starting time or closing time of day it account the information of daily data as well and thus it generates same signal twice).
      I want to avoid this. How can I do it ?

      Example:
      I am using two data feeds like this:

                 data0 = bt.feeds.GenericCSVData(dataname=inFilePath0,
                                                 fromdate=self.startDate,
                                                 todate=self.endDate,
                                                 datetime=0,
                                                 open=1,
                                                 high=2,
                                                 low=3,
                                                 close=4,
                                                 volume=5,
                                                 openinterest=-1,
                                                 timeframe=bt.TimeFrame.Ticks,
                                                 dtformat="%m/%d/%Y %H:%M",  
                                                 tmformat='%H:%M'
                                                 )
      
                 # Resample the data
                 backtester.resampledata(
                     dataname=data0,
                     timeframe=timeFrameInfo.tframes[timeframe],
                     compression=compression)
      
                 # Add Daily Data
                 data1 = bt.feeds.GenericCSVData(dataname=inFilePath0,
                                                 fromdate=self.startDate,
                                                 todate=self.endDate,
                                                 datetime=0,
                                                 open=1,
                                                 high=2,
                                                 low=3,
                                                 close=4,
                                                 volume=5,
                                                 openinterest=-1,
                                                 timeframe=bt.TimeFrame.Ticks,
                                                 dtformat="%m/%d/%Y %H:%M",  
                                                 tmformat='%H:%M',
                                                 )
      
                 # Resample the data
                 backtester.resampledata(
                     dataname=data1,
                     timeframe=timeFrameInfo.tframes["daily"],
                     compression=1)
      

      After run i got this:

      Starting Portfolio Value: 100000000.00
      2010-03-16 - 15:30:00, BUY CREATE, Market Order, Price: 5210.00
      2010-03-16 - 15:30:00, BUY CREATE, Market Order, Price: 5210.00
      2010-03-17 - 09:10:00, REF : 1  PRICE : 5229.000  SIZE : 75.00  COMM : 187.50
      2010-03-17 - 09:10:00, REF : 2  PRICE : 5229.000  SIZE : 75.00  COMM : 187.50
      

      So same order is generating twice. But when I remove the daily data feed there is no problem
      @backtrader

      posted in General Code/Help
      R
      RY 93
    • RE: Optimization error when multiple data feed

      @yufeng-xin Thanks.
      But I got the actual problem(I am assuming it, may be I am wrong also). Actually I am using the second datafeed only for indicator calculation and thus it has not any observer(BuySell,CashValue etc.).So I am thinking that after the code completetion it is trying to fetch these values and thus giving this error.
      So when I put this for optimization:

      bt.Cerebro(maxcpus = 8, stdstats = False))
      

      it worked.

      posted in General Code/Help
      R
      RY 93
    • Optimization error when multiple data feed

      While carrying out optimization with multiple data feed I am getting threading(pickling) error.
      I have added multiple data feed in this way:

      backtester = bt.Cerebro(maxcpus = 6)
      data0 = bt.feeds.GenericCSVData(dataname=inFilePath0,
                                                  datetime=0,
                                                  open=1,
                                                  high=2,
                                                  low=3,
                                                  close=4,
                                                  volume=5,
                                                  openinterest=-1,
                                                  timeframe=bt.TimeFrame.Ticks,
                                                  dtformat="%m/%d/%Y %H:%M",
                                                  tmformat='%H:%M',
                                                  )
      
      backtester.resampledata(
                      dataname=data0,
                      timeframe=timeFrameInfo.tframes[timeframe],
                      compression=compression)
      
      data1 = bt.feeds.GenericCSVData(dataname=inFilePath0,
                                                  datetime=0,
                                                  open=1,
                                                  high=2,
                                                  low=3,
                                                  close=4,
                                                  volume=5,
                                                  openinterest=-1,
                                                  timeframe=bt.TimeFrame.Ticks,
                                                  dtformat="%m/%d/%Y %H:%M", 
                                                  )
      
      backtester.resampledata(
                      dataname=data1,
                      timeframe=timeFrameInfo.tframes["daily"],
                      compression=1)
      

      Using optimization with these data I am getting this error:

      Exception in thread Thread-3:
      Traceback (most recent call last):
        File "C:\ProgramData\Anaconda2\envs\Python36\lib\threading.py", line 916, in _bootstrap_inner
          self.run()
        File "C:\ProgramData\Anaconda2\envs\Python36\lib\threading.py", line 864, in run
          self._target(*self._args, **self._kwargs)
        File "C:\ProgramData\Anaconda2\envs\Python36\lib\multiprocessing\pool.py", line 463, in _handle_results
          task = get()
        File "C:\ProgramData\Anaconda2\envs\Python36\lib\multiprocessing\connection.py", line 251, in recv
          return _ForkingPickler.loads(buf.getbuffer())
      AttributeError: Can't get attribute 'Lines_LineSeries_LineIterator_DataAccessor_ObserverBase_Observer_DataTrades_a45e1dc626d14c80b0da9e30da5b6b0c' on <module 'backtrader.lineseries' from 'C:\\ProgramData\\Anaconda2\\envs\\Python36\\lib\\site-packages\\backtrader\\lineseries.py'>
      

      If I remove the second data feed(data1), code runs perfectly fine.

      posted in General Code/Help opstrategy optimization data feed
      R
      RY 93
    • How to do intraday trading in backtrader ?

      Suppose I just want to do intraday trading then how can I do it using timers or filters.I can do it any way by handling the datetime object and check if current time falls within the intraday timing then only i will execute the buy or sell signals but I want some smart way or inbuilt functionality to do it.
      And how to forcefully execute or close all the open orders if these signals(buy,sell) crossed the intraday time limit ?

      posted in General Discussion
      R
      RY 93
    • RE: Backtesting 1 minute data

      @backtrader How to read dataset in following cases:

      1. When there is no time column:
        Date,Open,High,Low,Close,Volume
        12/29/2000,30.87,31.31,28.69,29.06,31655500
        12/28/2000,30.56,31.12,30.37,31.06,25055600
        12/27/2000,30.37,31.06,29.37,30.69,26441700

      2. When time is in separate column:
        "Date","Time","O","H","L","C","U","D"
        01/02/2006,1530,2821.10,2836.70,2804.00,2819.80,0,0
        01/03/2006,1530,2823.00,2872.00,2815.10,2868.70,0,0
        01/04/2006,1530,2885.00,2896.00,2873.30,2890.40,0,0
        01/05/2006,1530,2892.30,2895.80,2868.00,2886.00,0,0

      For "1" case I am trying in this way but is it not working:
      bt.feeds.GenericCSVData(
      dataname='orcl-2000.csv',
      fromdate=datetime.datetime(2000,12,29),
      dtformat=('%m/%d/%y'),
      datetime=0,
      open=1,
      high=2,
      low=3,
      close=4,
      volume=5,
      openinterest=-1)

      It is giving me this error:
      data_string[found.end():])
      ValueError: unconverted data remains: 00

      posted in General Discussion
      R
      RY 93
    • RE: Backtesting 1 minute data

      @backtrader Thanks I got it.

      posted in General Discussion
      R
      RY 93