Backtrader Community

    • 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/

    Self.broker.get_cash() not getting updated after selling

    Indicators/Strategies/Analyzers
    2
    2
    338
    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.
    • Sumit Pandey
      Sumit Pandey last edited by

      Hello,

      As a part of weekly rebalancing, I want to sell some securities in my portfolio and use the proceeds to buy others meeting my custom criteria.
      I have written a function that gets executed when notify_time is invoked on weekly basis.
      The problem is when I sell the security,

      pos = self.getposition(d).size
      if pos:
          self.o[d]=self.close(data=d)
      cash = self.broker.get_cash()
      

      Here, cash does not get updated, so that I can use it to place a buy order in the incoming lines of code.

      1 Reply Last reply Reply Quote 0
      • vladisld
        vladisld last edited by

        AFAIU, the cash position is updated upon order execution and not upon order creation.

        self.close will just issue the order - it doesn't mean it will be immediately executed. IMHO it is probably better to check for the broker cash in notify_order method.

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