How to add Indicator over resampled data? E.g. 10-day sma for minute data



  • Hello,

    I'm trying to use btrun, and code a generic strategy which I can control with btrun. My data is typically minute bars, however, in the strategy, I would like to use a 10-day indicator. How can I do this in the strategy? Or btrun options?

    If I script against celebro directly, I would add data0 as usual, then call resampledata to generate resampled data1, and then in the strategy add sma indicator with period=10 against data1.

    Somehow, I wish any indicator could be added with data resampling, e.g.
    self.sma = bt.indicators.SimpleMovingAverage(self.data, resample=bt.TimeFrame.Days, period=self.params.sma)

    I've now tweaked btrun locally to always add data first, and then add resampled one too. Such that I get the minute and daily data feeds for indicators to work on, but this seems extra work.

    I guess I could do sma over 1440... but that assumes 24h trading with no missing minutes and is not the same as resampling to days first, and then doing 10-day sma.

    Regards,

    Dimitri.


  • administrators

    @xnox said in How to add Indicator over resampled data? E.g. 10-day sma for minute data:

    I'm trying to use btrun, and code a generic strategy which I can control with btrun. My data is typically minute bars, however, in the strategy, I would like to use a 10-day indicator. How can I do this in the strategy? Or btrun options?

    If the only data feed in the strategy is has a Minutes/x timeframe/compression specification, you cannot have an indicator calculating in days.

    self.sma = bt.indicators.SimpleMovingAverage(self.data, resample=bt.TimeFrame.Days, period=self.params.sma)

    That's not possible. An indicator can run several levels deep and only be accessing data which has not datetime information. An indicator is a dumb math calculator.

    I guess I could do sma over 1440... but that assumes 24h trading with no missing minutes and is not the same as resampling to days first, and then doing 10-day sma.

    You need to resample the minutes-data-feed to Days/1 and then create the indicator on that data feed.


Log in to reply
 

Looks like your connection to Backtrader Community was lost, please wait while we try to reconnect.