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

suggest using enum instead of int for status defination

  • There are lots of constant status definiation in backtest, for example:

    bt.Order.Submitted, however they are simply integer. How about using enum instead.

    the prons are:

    • the enum value are truely constant, prevent people from change it by mistake
    • the enum value could give meaningful string represent when print, instead of 1 we get order.Submitted

    The API could stay compatible after the change and python2.7 could also be supported with third party enum library.

  • administrators

    One of the goals of backtrader was (and still is) to remain as much as possible Pure Python and only dependent on the standard packages available in the standard python distribution.

    Being the only exception matplotlib for plotting purposes. There is actually no need to have it installed if only backtesting is wished.

    Other dependencies like the ones needed for example for statsmodels were added by means of declarations (or meta-programming) which allow defining an Indicator as needing that dependency.

    Using enums will be considered when a major rework of the platform is done and dependencies (or maybe python 2.7 support is dropped altogether) are included.

    To print the name of bt.Order.Submitted you can query the order instance:

    status_text = order.getstatusname(bt.Order.Submitted)

Log in to reply