For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

resample for extra information in lines



  • i add the extra information like P/E in the line, if i use the resample, the P/E line will be gone.
    I checked the source code and find that in _Bar class only the OHLC volume openinterest will be resampled,
    after resampled, the P/E line value is NAN.

    can you just keep the P/E original value ? thanks



  • As you've correctly mentioned, resampling will ignore any extra information added to the feed ( it was already discussed in this post )

    However, it seems that the resampling process could be customized.

    TL;DR

    As was described here the resampling is implemented in Backtrader as a data filter that will be attached to the given data upon a call to the celebro.resampledata. Looking at the implementation of this method:

    def resampledata(self, dataname, name=None, **kwargs):
            if any(dataname is x for x in self.datas):
                dataname = dataname.clone()
    
            dataname.resample(**kwargs)
            self.adddata(dataname, name=name)
            self._doreplay = True
    

    we may see that resample method of the data is eventually called. This method is implemented in AbstractDataBase class which is ancestor class for all data feeds

        def resample(self, **kwargs):
            self.addfilter(Resampler, **kwargs)
    

    Reimplementing this method in your custom data feed will allow you to use a custom Resampler filter that may use a custom _Bar class that is free to implement whatever aggregation behavior for the extra fields you choose.

    I never used it this way myself, but at least it seems theoretically feasible.



  • @vladisld good idea. i will try. thanks a lot.



  • @jandy Answered here


Log in to reply
 

});