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 get the indicator data alone?

    Indicators/Strategies/Analyzers
    2
    8
    3030
    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.
    • M
      mothee last edited by

      I am a new user of bt, a very good framework. I need to analyze the indicator's statisics, how do I get the the indicator data alone? anyone knows it? thanks!

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

        The question alone is probably not clear enough.

        • You have created an indicator and probably stored it in an attribute of the strategy

        Why can't you access the data? Where is the problem?

        1 Reply Last reply Reply Quote 0
        • M
          mothee last edited by

          By the sample or test in BT, seems the indicator added into the strategy to calculate values of the indicator. If I donot add the indicator into the strategy, how can i to calculate the values of indicator? for I only care about the values of the indicator to get the statistics of it.

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

            @mothee said in how to get the indicator data alone?:

            If I donot add the indicator into the strategy, how can i to calculate the values of indicator?

            If you don't add the indicator to a Strategy, no values will be calculated. You are probably looking for something different like the python bindings for ta-lib: https://github.com/mrjbq7/ta-lib

            There is a downloadable and installable file at: https://www.lfd.uci.edu/~gohlke/pythonlibs/

            1 Reply Last reply Reply Quote 0
            • M
              mothee last edited by

              Thanks your responds!
              I found I could add the indicator into the cerebro, then call the 'run' function, the indicator values are calculated. but seems the Indicator class is a little complicated, I do not know how can I extract the timeseries of indicator(what member variables keep the values in the object of Indicator?). If the bt could provide some design big pictures for classes, it would be nice.

              1 Reply Last reply Reply Quote 0
              • M
                mothee last edited by

                The below test code could get the indicator time series:

                #get the date feed
                data = ...

                cerebro = bt.Cerebro(stdstats=False) # I don't want the default plot objects

                Add the Data Feed to Cerebro

                cerebro.adddata(data)

                cerebro.addindicator(indcls=btind.RSI)
                pars ={'period':60, 'plotname': "FastMA"}
                cerebro.addindicator(indcls=btind.SimpleMovingAverage, **pars )

                cerebro.run()

                strategy = cerebro.runstrats[0][0]

                inds = strategy.getindicators()
                ind = inds[0]

                get the datetime and indicator_data

                st_dtime = strategy.lines.datetime.plot()
                ind_data = ind.array[:]

                get the statistics of time-series of indicator

                ....

                B 1 Reply Last reply Reply Quote 1
                • M
                  mothee last edited by

                  I think the belw code should work also without the cerebro/strategy object, but failed with some error in data.preload().

                  get the date feed

                  data = ...

                  rsi_ind = btind.RSI(data)
                  data.reset()
                  data.extend(size=0)
                  data._start()
                  data.preload()
                  indicator._once()

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

                    @mothee said in how to get the indicator data alone?:

                    cerebro.addindicator(indcls=btind.RSI)
                    

                    That adds an indicator into a sample strategy class. It is meant for experimentation purposes.

                    You should read the top of the forum. It will help you posting and coding:

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

                    The Indicator class it not complex or simple. It is meant to be used withing the backtrader echosystem.

                    See: Docs - Platform Concepts - Getting a Slice

                    It shows how to get the data (from the current point backwards). You may also access the attribute array of each line of the indicator if you want it all.

                    data = indicator_instance.lines[0].array
                    
                    1 Reply Last reply Reply Quote 1
                    • 1 / 1
                    • First post
                      Last post
                    Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors