Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

    Rerun cerebro with same data: how to refresh Broker?

    General Code/Help
    3
    3
    42
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Abdul Mokhammed
      Abdul Mokhammed last edited by

      Hello!
      I need to optimize strategy parameters but for some reasons i can't use optstrategy

      The problem i got is that trying to run cerebro with same data i still have position remaining open from previos run which leads to incoherency

      The question is, how can i refresh all Broker attribute values back to initial before running again?

      INIT_VAL = 1e06
      strats = []
      i = 1
      l = len(combs_filtred)
      
      cerebro = bt.Cerebro(cheat_on_open = False)
      data = PandasData_feed(dataname = df)
      cerebro.adddata(data, name = 'main')
      cerebro.broker.setcommission(0.04/100)
      
      for f, s, llqt, lw, slqt, sw, lp, sp, tp, sl, bbp, bbm in combs_filtred:
          print('{}\{} '.format(i,l), end = '')
          cerebro.broker.setcash(INIT_VAL)
          strat = cerebro.addstrategy(
              LiqStrategy,
              log = False,
              opt_mode = True,
              fast=f,  # period for the fast moving average
              slow=s,   # period for the slow moving average
              long_lq_thresh = llqt,
              long_window = lw,
              short_lq_thresh = slqt,
              short_window = sw,
              long_period = lp,
              short_period = sp,
              tp_size = tp,
              sl_size = sl,
              bb_period = bbp,
              bb_mult = bbm)
          
          t = dt.datetime(2022, 1, 20, 22, 15)
          cerebro.run()
          strats.append(strat)
          i += 1
      
      B 1 Reply Last reply Reply Quote 0
      • N
        noufbouf last edited by

        Create a new instance of cerebro ? basicaly run this line again : cerebro = bt.Cerebro(cheat_on_open = False)

        1 Reply Last reply Reply Quote 0
        • B
          bartjs @Abdul Mokhammed last edited by

          @abdul-mokhammed

          I would suggest getting optstrategy to work, rather than re-running new instances of cerebro, try to have optstrategy run, and post your code and errors here.

          1 Reply Last reply Reply Quote 1
          • 1 / 1
          • First post
            Last post
          Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors