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/

    Sanity testing on loaded data in BT.

    General Code/Help
    2
    2
    27
    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.
    • Sumit Pandey
      Sumit Pandey last edited by

      Hello,
      I am currently writing a script to load multiple securities data and perform operations on them. Since I am loading the CSV data into BT, I wish to see all the data which is loaded, to make sure BT is correctly reading what I am passing it. Is there any way to do this.
      The reason arised because of implementation of one of the strategy, https://teddykoker.com/2019/05/momentum-strategy-from-stocks-on-the-move-in-python/
      where I am passing cnx 200 stocks data.

      for ticker in tickers:
          data =  bt.feeds.GenericCSVData(dataname=f"G:\\{ticker}.csv",
                                  nullvalue=0.0,dtformat=('%d-%m-%Y'),
                                  fromdate=datetime(2015, 1, 1),
                                  todate=datetime(2020, 7, 31),
                                  datetime=0,open=1,high=2,low=3,close=4,volume=5,openinterest=-1
                                  )
          cerebro.adddata(data)
      

      and defining a momentum strategy where regression slope will be calculated on rolling 90 dataclose.

      class Momentum(bt.Indicator):
          lines = ('trend',)
          params = (('period', 90),)
      
          #def __init__(self):
              #self.addminperiod(self.params.period)
      
          def next(self):
              returns = np.log(self.data.get(size=self.p.period))
              x = np.arange(len(returns))
              #mask = ~np.isnan(x) & ~np.isnan(returns)
              slope, _, rvalue, _, _ = linregress(x, returns)
              annualized = (1 + slope) ** 252
              self.lines.trend[0] = annualized * (rvalue ** 2)
      

      The error which is being thrown is : ValueError: Inputs must not be empty.
      I need to know whether the data stored in cerebro is correct.

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

        Is there any way to do this.

        Docs - Quick start Guide

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