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/

    suggest using enum instead of int for status defination

    General Code/Help
    2
    2
    689
    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.
    • Z
      zhuoqiang last edited by

      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.

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

        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)
        
        1 Reply Last reply Reply Quote 0
        • 1 / 1
        • First post
          Last post
        Copyright © 2016, 2017, 2018 NodeBB Forums | Contributors
        $(document).ready(function () { app.coldLoad(); }); }