Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    1. Home
    2. Kjiessar
    3. Posts
    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 12
    • Posts 33
    • Best 6
    • Groups 0

    Posts made by Kjiessar

    • Multi-Broker

      Hi,
      I still trying to optimize my simulation runs.
      Optstrategy is good but I still have the issue with memory leaks and if it crashes all results are lost, so could split up and let run multiple of them but still...

      What I was thinking was to create a Broker, that handles multiple other Broker, so that at each next a strategy with it's own account (broker) is called.

      I don't got enough inside into the interplay of cerebro and broker if that would be an option.

      posted in General Code/Help
      Kjiessar
      Kjiessar
    • RE: Transaction Analyzer: price <backtrader.linebuffer.LineBuffer object [...]>

      @kjiessar
      Aaand again. After long debugging session I found the culprit and it wasn't even in the code I had shown.

      Errorness:

      self.sell(data=self.data0, exectype=bt.Order.Limit, price=self.datas[0].close, size=entry["size"], valid=datetime.timedelta(minutes=self.p.tis))
      

      correct one:

      self.sell(data=self.data0, exectype=bt.Order.Limit, price=self.datas[0].close[0], size=entry["size"], valid=datetime.timedelta(minutes=self.p.tis))
      

      Note the proce parameter and the last [0]

      posted in General Code/Help
      Kjiessar
      Kjiessar
    • RE: Transaction Analyzer: price <backtrader.linebuffer.LineBuffer object [...]>

      @kjiessar

      And more Information:
      GitHub: BT Transaction Analyzer

          def next(self):
              # super(Transactions, self).next()  # let dtkey update
              entries = []
              for i, dname in self._idnames:
                  pos = self._positions.get(dname, None)
                  if pos is not None:
                      size, price = pos.size, pos.price
                      if size:
                          entries.append([size, price, i, dname, -size * price])
      
              if entries:
                  self.rets[self.strategy.datetime.datetime()] = entries
      
              self._positions.clear()
      
      posted in General Code/Help
      Kjiessar
      Kjiessar
    • RE: Transaction Analyzer: price <backtrader.linebuffer.LineBuffer object [...]>

      @kjiessar
      In the above code sample a run is performed, just tried to put in the relevant information

      Some more info not sure if it can help but thought couldn't hurt

      Trade:

      1970-01-01 19:45:46,-5.0,2.224e-05,0,,0.0001112

      1970-01-01 19:45:54,-5.0,<backtrader.linebuffer.LineBuffer object at 0x0000029F82F3DF70>,0,,0.00011485

      OHLC

      1970-01-01 19:45:53+00:00,1629356760,2.271e-05,2.271e-05,2.271e-05,2.271e-05,0.0,0

      1970-01-01 19:45:54+00:00,1629356820,2.279e-05,2.297e-05,2.279e-05,2.297e-05,0.0,0

      1970-01-01 19:45:55+00:00,1629356880,2.275e-05,2.275e-05,2.275e-05,2.275e-05,0.0,0

      posted in General Code/Help
      Kjiessar
      Kjiessar
    • RE: Simplest Way to Add Stop Loss & Take Profit

      @frenzyy
      Alternative
      https://www.backtrader.com/docu/strategy/#how-to-buysellclose

      take a look at the parameters
      price, limit, plimit and exectype

      posted in General Code/Help
      Kjiessar
      Kjiessar
    • Transaction Analyzer: price <backtrader.linebuffer.LineBuffer object [...]>

      Hi,
      the output of the analyser gives object str instead of the actual price.
      Any idea what I'm doing wrong here?

          cerebro.addanalyzer(bt.analyzers.Transactions, _name='transactions')
          d =strat.analyzers.getbyname("transactions").get_analysis()
          print(d)
      

      One correct and one outputted wrong

      OrderedDict(
      [(datetime.datetime(1970, 1, 1, 19, 9, 27),
      [[23.10281162, 2.05e-05, 0, '', -0.00047360763821]]),
      [...]
      [[-23.10281162, <backtrader.linebuffer.LineBuffer object at 0x000001847D964400>, 0, '', 0.0005489228040912]]),
      [...]])

      posted in General Code/Help
      Kjiessar
      Kjiessar
    • RE: Live Data Feed time steps

      @kjiessar
      Its a bit embarassing to say but I found the issue

          data = store.getdata(dataname=symbol, name=symbol,
                                  timeframe=bt.TimeFrame.Minutes, 
                                  compression=1, ohlcv_limit=70 )
      #fromDate is missing
      

      I had the parameter but with the wrong name, becuase of all the dynamic handling of the parameters, no error was raised.

      Sorry for the trouble.

      posted in General Code/Help
      Kjiessar
      Kjiessar
    • Live Data Feed time steps

      Hi,

      I'm using ccxtbt or my own fork of it ccxtbt-fork.

      My issue is, that my strategy assumes time slices of a minute and the strategy produces slices of around 10 seconds (could be unrelated and based on runtime [debugging therfore slow]).

          data = store.getdata(dataname=symbol, name=symbol,
                                  timeframe=bt.TimeFrame.Minutes, 
                                  compression=1, ohlcv_limit=70 )
      

      Thats how i create the feed. I changed code in the broker (fixed bugs with order handling). But don't think I changed anything regarding the handling of the time.

      I just reinstalled the original version to check if I messed up but couldn't find any difference.

      So my expected behaviour is, that my Strategy is called once a Minute.
      Am I expecting somthing on wrong assumption? ( Don't think so, why choose timeframe and compression if not used)

      Any idea where to start to look? Is that a bug or just missing feature not yet implemented in bt-ccxt-store?

      posted in General Code/Help
      Kjiessar
      Kjiessar
    • RE: Warning bt.analyzers.Transactions multiple transactions

      @kjiessar
      Aaaaand 5 minutes later. Trying to fix it, it seems that the issue is something else. Will come back as soon as I found out

      posted in General Code/Help
      Kjiessar
      Kjiessar
    • Warning bt.analyzers.Transactions multiple transactions

      Hi,
      I know it seems stupid but can happen, that more tan one transaction is triggering at a time.
      The bt.analyzers.Transactions will use a map and use the date as key putting in only 1 of the transactions, overriding the beforehand added.
      Code Link

      def next(self):
      [...]
              if entries:
                  self.rets[self.strategy.datetime.datetime()] = entries
      

      This can compromise your analysis, just be aware of it.

      posted in General Code/Help
      Kjiessar
      Kjiessar
    • Doc Issue Custom Commission

      Documentation issue:
      Custom Schemes

      class CommInfo_Fut_Perc_Mult(bt.CommInfoBase):
          params = (
            ('stocklike', False),  # Futures
            ('commtype', bt.CommInfoBase.COMM_PERC),  # Apply % Commission
            ('percabs', True),  # pass perc as 0.xx
          )
      
      comminfo = CommInfo_Fut_Perc_Mult(
          commission=0.001,  # 0.1%
          mult=10,
          margin=2000  # Margin is needed for futures-like instruments
      )
      
      cerebro.addcommissioninfo(comminfo)
      
      

      last line should be:
      cerebro.broker.addcommissioninfo(comminfo)

      posted in General Discussion
      Kjiessar
      Kjiessar
    • OptStrategy: Equivalent broker.get_value() or the return

      Hi there,

      at the end of a run I'm usually take cerebro.broker.get_value() to sort my strategy paramters.
      Now I'm givin OptStrategy a try and can't find the value for each strategy.
      If not any preferred way to implement it? E.g. an Analyzer seems a bit overkill.

      posted in General Code/Help
      Kjiessar
      Kjiessar
    • RE: Understanding Order.Margin and remaining margin

      @kjiessar
      Ok tested a bit around.
      New assumption: Stupid me forgot to include the commision fees.

      That meens i got enoug money for the share to buy but as the fees will be added to the price, I will not get as much as I ordered, because it is downsized as much as needed, to pay the fee.

      Correct?

      posted in General Code/Help
      Kjiessar
      Kjiessar
    • Understanding Order.Margin and remaining margin

      Hi there,

      I'm struggling a bit withthe Order.Margin. So here are is my base assumption:

      Order.Margin is the status, when:

      remaining_cash - all( open_orders size * prize) < 0

      Some of my cash is "blocked" because i have open orders and the "free" cash is not enough to "block" enough cash for the new order.

      If thats correct, is there an api call that gives me the remaining "free" cash aka margin(?)?

      posted in General Code/Help
      Kjiessar
      Kjiessar
    • RE: Setting only the fromdate parameter in Yahoo Data Feed

      @vladisld

      Done:
      https://github.com/backtrader2/backtrader/issues/65

      Not that good at filling those, so hope it is enough like that.

      posted in General Code/Help
      Kjiessar
      Kjiessar
    • RE: Setting only the fromdate parameter in Yahoo Data Feed

      @borutf
      Would agree, looks like a bug:

      if self.p.todate is not None:
                  period2 = (self.p.todate.date() - posix).total_seconds()
                  urlargs.append('period2={}'.format(int(period2)))
      
      if self.p.todate is not None:
                  period1 = (self.p.fromdate.date() - posix).total_seconds()
                  urlargs.append('period1={}'.format(int(period1)))
      
      

      yahoo.py

      posted in General Code/Help
      Kjiessar
      Kjiessar
    • How can broker.get_value() be negative after a run

      Hi everybody,

      sorry if this is noob question but I'm struggeling with getting the value (is that called portfolio value?) after a run.
      I'm currently using cerebro.broker.get_value() as I can also see it my plots

      -0.00372466_savefig__f2021q1-XDGXBT_1_sSlotStrategy_ti_lookback-10_ti-60_buypercentage-1.01_profitpercentage-1.02_buystopcounter-0_buyamount-0.75_tis-1800_ds-True_limDif-0.001.png

      The small values are because cryptotrading data is used.
      So my issue here is:

      I'm starting with 0.0019 BTC here and buy some other crypto.

      Even if this other crypto drops to nearly 0, lets just say the remaing complete value of my portfolio is 0.000000001BTC.
      If I sell it (so adding the remaining value), it should still have remaining cash +0.000000001BTC

      It seems that I'm still missinterpreting something here.

      Another topic: why is my plot so damn ugly compared to the on in the docs? (can create another thread if it isn't a short answer)

      posted in General Code/Help
      Kjiessar
      Kjiessar
    • RE: Memory Leak with multiple cerebros

      @vladisld
      Another thing I forgot ( sorry it's hard to find the relevant parts here) is that I'm saving the plots:

      def saveplots(strats, numfigs=1, iplot=True, start=None, end=None,
                  width=640, height=360, dpi=300, use=None, file_path = '', **kwargs):
          plotter = plot.Plot(**kwargs)
          figs = []
          for stratlist in strats:
              for si, strat in enumerate(stratlist):
                  rfig = plotter.plot(strat, figid=si * 100,
                                      numfigs=numfigs, iplot=iplot,
                                      start=start, end=end, use=use, width=width, height=height, dpi=dpi, constrained_layout=True, )
                  
                  figs.append(rfig)
      
          for fig in figs:
              for f in fig:
                  f.savefig(file_path, dpi=dpi, width=width, height=height, bbox_inches='tight', )
      

      I tried a lot like f.clf() and so on but nothing seemed to help.

      posted in General Code/Help
      Kjiessar
      Kjiessar
    • RE: Memory Leak with multiple cerebros

      @vladisld
      Hi sorry for not providing that:

      memory-profile5.png

      Mhh maybe not the only issue I'm facing. Still continiously growing.

      My current workaround:

      results = []
      with Pool(multiprocessing.cpu_count, maxtasksperchild=1) as pool: 
          result =pool.apply_async(run)
          results.append(result)
          [result.wait() for result in results]
          pool.close()
          pool.join()
      
      posted in General Code/Help
      Kjiessar
      Kjiessar
    • 1
    • 2
    • 1 / 2