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/

    How to write an indicator equivalent to pandas.expanding().mean()?

    General Discussion
    2
    4
    70
    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.
    • S
      soulmachine last edited by

      I've read the following source code:

      https://github.com/mementum/backtrader/blob/master/backtrader/indicators/basicops.py

      It seems every indicator has a period.

      I found no way to implement an indicator with the following logic:

      import pandas as pd
      data = pd.Series([1.0, 2.0, 3.0, 4.0])
      indicators = data.expanding(2).mean()
      

      Any ideas? Thanks

      1 Reply Last reply Reply Quote 0
      • A
        ab_trader last edited by

        I assume that equivalent will be this formula in the next():

        value = sum(self.data.close.get(size=len(self.data)))/len(self.data)
        
        S 1 Reply Last reply Reply Quote 1
        • S
          soulmachine @ab_trader last edited by

          @ab_trader It works, thanks!

          1 Reply Last reply Reply Quote 1
          • S
            soulmachine last edited by

            I implemented the EWMAC strategy from the book "Systematic Trading" by Robert Carver, Jupyter notebook: https://github.com/soulmachine/crypto-notebooks/blob/master/backtest/backtrader-EWMAC.ipynb

            1 Reply Last reply Reply Quote 1
            • 1 / 1
            • First post
              Last post
            Copyright © 2016, 2017, 2018 NodeBB Forums | Contributors
            $(document).ready(function () { app.coldLoad(); }); }