For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See:

Creating a Custom Broker

  • I'm in the process of creating a custom broker that has a use case that I am not sure if it can be supported in backtrader.
    The account balance potentially could have more then one type of currency that is not easily interchangeable.

    meaning for example, I could have 2 type of currencies. each one can buy/sell different shares. I can convert between the two currencies for a fee,
    but Ideally I would like to have 2 different accounts that only on special cases convert currency between the two.

    my question regards the following broker methods:
    getcash, getvalue and getposition.

    will it make sense to return from the broker a list of cash/value instead of a simple double?

    I could, with some effort, convert between the two and then aggregate which is nice for seeing the balance of the whole portfolio. but for trading this information is less valuable.

    I looked over the code and it seem to be more or less possible but I'm not sure.
    the 'cash' object seem to be past around the system without any arithmetics operating on it (except in CommInfoBase and specifics implementations)
    the rest seem to be waiting for a user implementations to decide what to do with 'cash'

    *still need to do more investigation on value and positions


  • Why not to split backtest into 2 different runs with two separate brokers each has its own currency?

  • I didn't describe it competently but there is a connection in the logic and strategy between the shares

Log in to reply