In Moonshot backtest, how can I change rebalancing interval?

HI,
I'm using Moonshot backtest which outputs to PDF file. I would like to apply my strategy rebalancing only at the beginning of a month. how can I do that?

I've tried REBALANCE_INTERVAL = "M", but it doesn't seem to make a difference.
In zipline, i could use something like 'date_rules.month_start'.

Thank you in advance.

REBALANCE_INTERVAL isn't a built-in Moonshot attribute, so if you're using it, first you need to have code like this in your prices_to_signals or signals_to_target_weights method:

        # Resample using the rebalancing interval.
        # Keep only the last signal of the month, then fill it forward
        signals = signals.resample(self.REBALANCE_INTERVAL).last()
        signals = signals.reindex(closes.index, method="ffill")

The above example comes from umd.py in the Moonshot Intro.

Second, 'M' = month end, use 'MS' for month start. The pandas resample method in the above snippet expects an offset alias, the list of which can be found in the pandas docs.

1 Like

It works! I should have looked at the example more carefully.

Thank you!