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/

    Relative Data Input

    Indicators/Strategies/Analyzers
    2
    2
    868
    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 Former User last edited by

      Hi there,

      I wonder is there a way to easily convert close price to relative price based on the first bar of input. Or do I need to do it manually every time?

      And will database such as sqlite be supported for storing data in the future?

      Thank you!

      B 1 Reply Last reply Reply Quote 0
      • B
        backtrader administrators @Guest last edited by

        @Dixing-Xu said in Relative Data Input:

        I wonder is there a way to easily convert close price to relative price based on the first bar of input. Or do I need to do it manually every time?

        You need a Filter which stores the 1st price seen during action and adjusts each price with regards to it. For reference see: Docs - Filters

        But such a filter actually has been implemented (it is used for some of the proprietary tools for the Backtrader Fund (see Esfera Capital - Funds

        It's a very simple filter

        class PercFilter(bt.metabase.ParamsBase):
            params = (
                ('base', 100.0),
            )
        
            def __init__(self, data):
                self._refclose = None
        
            def __call__(self, data, *args, **kwargs):
                if self._refclose is None:
                    self._refclose = data.close[0]
        
                pc = 100.0 * (data.close[0] / self._refclose - 1.0)
                data.close[0] = self.p.base + pc
        
                return False  # no change to stream structure/length
        

        @Dixing-Xu said in Relative Data Input:

        And will database such as sqlite be supported for storing data in the future?

        backtrader has no provisions for data collection/storage. Nothing prevents collecting data from the on-line sources, but how to actually store it is entirely up to the user. The sources contain a tool called rewrite-data which simply takes one of the inputs and outputs a csv in the expected default format for backtrader. The same data could be written to an sqlite database with a simple schema.

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