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/

    Implementing strategy entirely from external files

    General Discussion
    2
    2
    783
    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.
    • K
      kctrader last edited by

      Backtrader newbie here. Does anyone have any examples of feeding in strategies from an external file?

      I am primarily interested in historical backtesting in batch. I currently have a complicated modeling process that runs in other software and it would be difficult to execute in line with backtrader, as I've seen in the tutorial examples.

      It is driven on the same data feed that I would use in backtrader. So the first solution that comes to mind is to write the indicators in my custom software in a form that could be directly consumed by backtrader. Then, I'd just read them from the file/join them in as the "strategy."

      Any guidance on this appreciated!

      Thanks,

      Chris

      1 Reply Last reply Reply Quote 0
      • P
        Paska Houso last edited by

        There are two posts about that:

        • https://www.backtrader.com/blog/posts/2016-10-29-strategy-selection/strategy-selection.html
        • https://www.backtrader.com/blog/posts/2017-05-16-stsel-revisited/stsel-revisited.html

        But since you say:

        @kctrader said in Implementing strategy entirely from external files:

        So the first solution that comes to mind is to write the indicators in my custom software in a form that could be directly consumed by backtrader. Then, I'd just read them from the file/join them in as the "strategy."

        You may actually be looking at having an indicator that delivers signals (or simply values) at given moments in time, I guess the approach would be:

        • Load the data for the indicator in __init__ from the external source. It will contain timestamped values.
        • When the next of your indicator is called, check the timestamp of the data and if it maches the timestamp of your external data source ... deliver the value

        If your external data source delivers data with gaps (for example several bars without a value), you should consider if you want that to remain as NaN or you want to deliver something like a no-op in those occasions (0 for example)

        1 Reply Last reply Reply Quote 1
        • 1 / 1
        • First post
          Last post
        Copyright © 2016, 2017, 2018 NodeBB Forums | Contributors
        $(document).ready(function () { app.coldLoad(); }); }