Everyone's opinion needed :-) Are these statistics better looking/more helpful?



  • I created a simple Analyzer that calculates 'bread and butter' popular statistics, all in one place.

    TradeAnalyzer holds alot of information, just when I print output, it scrolls through several pages and therefore difficult to read.

    I also wanted to add some other basic stats like Win:Loss ratio and Reward:Risk (also called 'Risk/reward')

    I have completed the 'BasicTradeStats' Analyzer code.
    I'm now experimenting with subclassing the print() method to make the output easier to read.

    So this..

    0_1506997493882_Untitled.png

    Instead of this..

    0_1506997864214_Untitled2.png
    e.t.c...

    My Questions
    It's going to take me half a day to complete the improved print output and my time is short.

    1. Will this improved output be more helpful to you guys? don't be shy, let me know :)

    2. (more for Backtrader) Are you comfortable I'm overriding the print method? The output is different than the standard output for Analyzers.

    3. Are there any other essential basic statistics that I have missed that you feel belong here? [Drawdown and Sharpe are useful, but already an Analyzer for them, and the output is fine.. so unnecessary to add here.]

    Please let me know asap, I may be able to complete this pull request with my free time tomorrow.
    Cheers guys



  • @Richard-O'Regan thank you for your work. Would be great to introduce MAE and MFE per trade.



  • Hey Ab_trader, thanks for that.
    Funny, a guy wrote a post a month ago asking for MFE&MAE and I wrote down a rough algorithm for calculating.
    Two approaches are

    1. Simple & rough: We can calculate it roughly, with trade data. e.g. for each trade open, for each period, look at the pnl value. Store highest and lowest pnl before trade closed.
      But we are limited to bar period. If daily, the close may be very different than high/low values, so MFE&MAE are at best an approximation (of course approximation gest better as granuality of bar decreases, i.e. from daily -> hourly -> minute data etc)

    2. The better way to do it: would be to read the underlying data, and find high and low for each period, and assuming no stop or target was hit, we can use the high and low for MFE&MAE etc. This is much more accurate than just the close.

    I think it would be a great feature to add, tho my main reason to not add here, is that to use properly, it would need a chart not just a table with couple of averages. e.g.
    0_1507072362602_trades_MFE.png

    I personally feel this is more advanced and should be a separate Analyzer dedicated to MFE&MAE with chart features.

    These stats above are more for simple basic obvious stats.

    This is just my opinion mate , if you disagree let me know, everything is doable.

    Thanks again for replying - if anyone else thinks a major basic popular statistic that fits in here, e.g. like Risk/Reward let me know. Thanks


  • administrators

    @Richard-O'Regan said in Everyone's opinion needed :-) Are these statistics better looking/more helpful?:

    1. (more for Backtrader) Are you comfortable I'm overriding the print method? The output is different than the standard output for Analyzers.

    In Python you can do monkey-patching and override the default behavior of the print method for all analyzers, or just keep it for the analyzers you want. Nothing to be comfortable or uncomfortable with. You can do it.



  • @backtrader said in Everyone's opinion needed :-) Are these statistics better looking/more helpful?:

    monkey-patching

    Noted, just I thought it would be helpful for everyone, hence why I'm considering making public in the code of my Analyzer pull-request (rather than just a monkey-patch on my local computer). Just it is breaking the default convention for BT and wanted to check would be ok by you:)


  • administrators

    The monkey-patching statement is not only addressed at your local code. Your open source code can monkey-patch the print method for any user. It may be named as: extension.

    Example usage (there are for sure many patterns)

    import backtrader as bt
    import bt_analyzer_mega_print
    
    # just work with your code as usual ...
    

    During the import bt_analyzer_mega_print your code patches the print method.

    You may try something more advance like

    import bt_analyzer_mega_print as bt
    

    Here your module is imported, which in turn imports backtrader internally. Before returning your replace the entry in sys.modules for your module with the imported backtrader

    Note: unsure if as bt will be a direct reference to the module in sys.modules or a variable referencing your original module. But it's worth a try.

    See:



  • Hey backtrader, I read and clicked links, didn't really understand, buts its late here and I'm tired, at computer all day. I will take a look with fresher eyes tomorrow - always something new I can learn :) cheers mate


  • administrators

    The key is here, from Van Rossum

      # module foo.py
    
      import sys
    
      class Foo:
        def funct1(self, <args>): <code>
        def funct2(self, <args>): <code>
    
      sys.modules[__name__] = Foo()
    

    This works because the import machinery is actively enabling this
    hack, and as its final step pulls the actual module out of
    sys.modules, after loading it. (This is no accident. The hack was
    proposed long ago and we decided we liked enough to support it in the
    import machinery.)

    You can then (according to the description) try:

      # module foo.py
    
      import backtrader
    
      do_the_monkey_patching()
      sys.modules[__name__] = backtrader
    

    And if everything works as expected, importing your module has effectively imported backtrader for the external user after monkey patching.



  • Thank-you for extra explanation, just finishing off some code for BT then I will investigate your links thoroughly. Kind Regards


Log in to reply
 

Looks like your connection to Backtrader Community was lost, please wait while we try to reconnect.