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/

    Passing a dataframe with all indicator/signal precalculated

    General Code/Help
    4
    5
    107
    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.
    • A
      azuric last edited by

      Hi,

      Looking to use use backtrader as a quick way of prototyping signals.

      If I have a data frame with mid price of closes and some (one for simplicity) signals, how do I pass them to backtrader. I assume

      I do not need to build a custom indicator and instantiate them to do this but in effect just pass the frame directly and iterate over it.

      Arun Lama 1 Reply Last reply Reply Quote 0
      • Arun Lama
        Arun Lama @azuric last edited by

        @azuric This is how I add Pandas Dataframe to datafeeds

        cerebro = bt.Cerebro()  
        feed = pd.read_csv('test.csv',index_col = 'Date',parse_dates = True)
        data = bt.feeds.PandasData(dataname = feed)
        

        and this is how I used talib library to calculate indicators (you can get indicator calculations from backtrader itself too)

        class SmaCross(bt.Strategy):    
                params = dict(pslow=20,order_percentage= 0.99,ticker = 'NEPSE')         
                    def __init__(self):    
                    sma = bt.talib.SMA(self.data.close,timeperiod=self.p.pslow)    
                    self.crossover = bt.ind.CrossOver(self.data.close, sma, plot = True)  
            
                ``
        1 Reply Last reply Reply Quote 1
        • A
          ab_trader last edited by

          You can have data and indicators in the data frame which you will pass to bt as a data feed, but this data feed should be extended - additional lines for indicators added. Couple links -

          Docs - Data Feeds - Extending

          Community - Create Indicator Line from DataFrame (not from data in Cerebros)

          1 Reply Last reply Reply Quote 1
          • A
            azuric last edited by

            Thanks guys that puts me on the right track.

            1 Reply Last reply Reply Quote 0
            • run-out
              run-out last edited by

              The answers over here might help.

              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(); }); }