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

Broker position VS Strategy position



  • Hi,

    In Live environment, what would be the best practice to implement a position management of one strategy (different from account position)?

    Let's say I connect a live strategy on a symbol 'XXX' on a broker account that already has a long term position on 'XXX'. I would like to keep long term position and run the model as we were starting with flat position.
    As backtrader based all its strategies, sizers, observers, ... on live broker.getposition or broker getvalue, it will surely affect system s accuracy and expected results.

    My solution would be to keep the position locally in the strategy with all orders notifications.
    But I think I will loose all the features of Backtrader using broker.position.

    Ideally, broker.getposition could be overridden by position updated by strategy (real orders) and we could have access to broker.getOverallPosition (real account position)

    I probably miss a point.

    Thank you for your lights



  • @sirhc why not just get a second account?


  • administrators

    The design chose for backtrader is to not make assumptions. If you connect to an account and a position is open, you know what you are doing. The platform doesn't have to know it.

    The solutions:

    • Use a separate account (as suggested by @bishbashbosh )

    • Subclass your live broker to skip the first position update

      Here you will still have a problem: you may, for example, still manually change the position in your account while the algorithm is running. Which means you have to ignore not only the initial position update, but also others.

    I would use a separate account.