Backtrader Community

    • 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/

    How do i normalize volume on resampled data?

    Indicators/Strategies/Analyzers
    2
    3
    1481
    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.
    • T
      Taewoo Kim last edited by

      I used Python's MinMaxScaler to normalize volume data before calling

      cerebro.adddata(base_data)
      

      When I add the same data via resample

      cerebro.resampledata(base_data, timeframe=bt.TimeFrame.Days, compression=1)
      

      .. the reported volume seems to be summed when I call

      higher_tf_vol = self.datas[1].volume.get(0, 10).tolist()
      

      in strategy, but i would like to normalize this (0 to 1 scale, just like minmaxscaler)

      How do I achieve this?

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

        .. the reported volume seems to be summed when I call

        That's how resampling works for volume. All bars being part of a period contribute to the total of the resampled bar.

        in strategy, but i would like to normalize this (0 to 1 scale, just like minmaxscaler)

        How do I achieve this?

        The resampler would need to know in advance the upper limit of the volume to normalize between 0 and 1. The upper limit cannot be known until the last bar is delivered.

        By the time the bar is delivered you cannot normalize.

        If backtrader only worked with preloaded data and additional pass over the data could be considered, but the data can also be read in next steps.

        Option 1

        You resample outside of the platform and normalize

        Option 2

        • You are only working with preloaded data (only backtesting)

        • You use resampledata with a name=xxxx parameter

          Unfortunately resampledata doesn't return the data stream it creates. Will be added.

        • Until it is added you find get the data in data = cerebro.databynames[xxxx]

        • You monkey patch the method preload with your own version which will

          • Call the original preload via super
          • Go over the self.volume.array iterable and normalize the volume

        You probably want to go forward with Option 1.

        1 Reply Last reply Reply Quote 0
        • T
          Taewoo Kim last edited by

          Uhh yeah.. option #1 seems a lot easier. ;)

          Thank you

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