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/

    GenericCSVData with different start date

    General Code/Help
    3
    3
    96
    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
      auth87 last edited by

      Hi there,

      I am adding several custom csv feeds to my strategy. The files contain data with different starting dates, and hence, the strategy only seems to start trading at the first date where data is available for all assets.

      Is there an option to enforce trading before this date and only trade what is available?

      Many thanks.

      D run-out 2 Replies Last reply Reply Quote 0
      • D
        davidavr @auth87 last edited by

        @auth87 Yes, the pre_next method in Strategy will be called each time and you can simply call next from it. But you then need to check which of the data items in self.datas have data ready. Something like:

        def pre_next(self):
            self.next()
        
        def next(self):
            available = [d for d in self.datas if len(d)]
            # do something with available list...
        
        1 Reply Last reply Reply Quote 2
        • run-out
          run-out @auth87 last edited by

          @auth87 Another option is to pre-process with pandas. Get the longest date index, and join all csv's on that and fillna = 0. Then when you run the backtest, check each data.close[0] == 0. If true, continue.

          RunBacktest.com

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