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

Unlisted stocks handling

  • Can anyone say how Backtrader handles open positions for stocks that became unlisted during the backtesting period?
    Say I'm backtesting stock ABC along with some other stocks, and ABC become unlisted (no more bar data) during the backtesting period, obviously, the positions cant stay open and should be treated somehow.
    Any ideas how?

  • administrators

    There is no handling of unlisted stocks, because that information is not part of the payload of data feeds.

    Data feeds are extensible which means you can add a line named (for example) delisted which has a value of (for example) 1 if the stock becomes delisted (and 0 if not). At that moment in time you can close the position.

    The challenge here:

    • If the 1 is aligned with the end of the listing, the order won't be executed because there is no more data.


    • Use cheat-on-close. But this will affect the entire lifetime of all the listings

    • Add the 1 just one days before the asset is delisted