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/

    Generic way to get len() of data feed?

    General Code/Help
    1
    1
    42
    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.
    • J
      josipbt last edited by

      Is there a generic way to get the len(), if I don't pass the whole pandas DataFrame to cerebro?

      In my case I did it like this:

      df = pd.read_csv(
          'ticks.csv',
          header=0,
          parse_dates=[0],   
          date_parser=lambda x: datetime.datetime.fromtimestamp(int(x)/1000)
          )
          
      todate = datetime.datetime(2021, 5, 28,22,00)
      datalen = len(df[df["timestamp"] < todate])
         
      data = bt.feeds.PandasData(
          dataname=df,
          fromdate=datetime.datetime(2000, 1, 1),
          todate=todate,
          timeframe=bt.TimeFrame.Ticks
          datetime=0,
          high=9,
          low=10,
          open=7,
          close=8,
          volume=11,
          )
      

      Overall, my goal is to have a simple progress bar/indicator. This solution was a bit more than I actually needed.

      Any hints are more than welcome.

      1 Reply Last reply Reply Quote 0
      • 1 / 1
      • First post
        Last post
      Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors