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/

    Access get_credit_interest in next()

    General Code/Help
    2
    3
    286
    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.
    • C
      cwse last edited by

      Hello again!

      I am trying to get the interest expense in Next() block, but the problem is when an position is closed, the bbroker self.d_credit[data] is reset to zero, so I cannot get the interest applicable to the last day the stock was held. Is it possible to get interest each day in next()?

      Also: I notice the credit interest is included in order.executed.comm; is it possible to get the interest separately out of this?

      Thanks!!

      1 Reply Last reply Reply Quote 0
      • B
        backtrader administrators last edited by

        No. It is obvious you need a custom commission scheme which keeps track of the interest in a separate member attribute.

        1 Reply Last reply Reply Quote 0
        • C
          cwse last edited by

          Thanks @backtrader, sounds good. Any tips how I could edit the following commission scheme to do just that?

          class CommInfo_Custom(bt.CommInfoBase):
              params = (
                  ('commtype', bt.CommInfoBase.COMM_PERC), #commission to be understood as %
                  # Custom broker commission fee params:
                  ('min_fee', 0),  # The broker uses a %commission fee, with the "min_fee" as the minimum fee per trade. 
              )
          
              def _getcommission(self, size, price, pseudoexec):
                  commvalue = abs(size) * price * self.p.commission         # %based commission value
                  commvalue = max(self.p.min_fee,commvalue)                 # choose the greater of $min_fee and percentage calculated
                  return commvalue
          

          Much appreciated

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