Monthly rebalance

Is it possible to run a screen backtest with a monthly rebalance as opposed to every 4 weeks?

Marco just introduced a new function to indicate the length of time since the last trading day, so you should be able to do this now with this rule:

MonthDay=1 or (MonthDay=2 and PrevBarDaysAgo>2)

The first part would trade on the first of the month; the second part of the rule says to trade on the second if the first wasn’t a trading day.

Thanks Paul! Nice!! I don’t think I would have thought of that. But you got me thinking…

If the first is on Saturday and the second is on Sunday will this addition work? Also will this work if January 1 is on a Friday?

BUY: MonthDay=1 or (MonthDay=2 and PrevBarDaysAGO>2) or (MonthDay = 3 and PrevBarDaysAGO >2) or (MonthDay = 4 and PrevBarDaysAGO > 3)

SELL: AND (MonthDay=1 or (MonthDay=2 and PrevBarDaysAGO>2) or (MonthDay = 3 and PrevBarDaysAGO >2) or (MonthDay = 4 and PrevBarDaysAGO > 3))

@ mm123: Place the sell rule after each of your present sell rules. Not as a separate rule. This is due to the implicit or of the sell rules.

This didn’t work for me, the test returned a null set of stocks for all time periods (yeah, the model otherwise works fine without this syntax).

And just to be clear, did you mean to say ‘last trading day’ or did you mean ‘last rebalance’? I’m not concerned about the last trading day, per se. Rather, I want a portfolio rebalance on the first trading day of each month, not every 4 weeks.

mm123,

Make sure to put rebalance on daily.

Put the above rule in the both the buy and sell rules.

In the sell rules make sure not to just add it but put it after the each sell rule after an AND. Also note the parentheses. You can copy the below rule and paste if after each sell rule.

AND (MonthDay=1 or (MonthDay=2 and PrevBarDaysAGO>2) or (MonthDay = 3 and PrevBarDaysAGO >2) or (MonthDay = 4 and PrevBarDaysAGO > 3))

Did seem to work on one of my randomly selected sims.


Thanks Jrinne. So does this only work in a sim? I was hoping to use it in a screen.

mm123,

Not so much for the screen, I think

It works, but not in a way that you’d like, probably.

That rule will only be true on the days in question. In the portfolio, that produces triggering events and is really useful. In the screen, it will only be true once a month, and that means that the screen will only hold stocks for one day a month. Less helpful than expected. :slight_smile:

Hello!

I would like to confirm that I am doing it correctly.

I am creating a portfolio of two ETFs that rebalances the first day of each month.

if the MTUM is above its 200 SMA → Buys MTUM
If not → Buys TLT.

for this, I set the following rules:
Rebalance every day.

BUY:
Eval (close(0, GetSeries(“MTUM”)) > SMA(200 ,0, GetSeries(“MTUM”)), ticker (“MTUM”), ticker(“TLT”))

SELL:
(MonthDay=1 or (MonthDay=2 and PrevBarDaysAGO>2) or (MonthDay = 3 and PrevBarDaysAGO >2) or (MonthDay = 4 and PrevBarDaysAGO > 3))

The point is that with these rules, every month the system sells and buys again, which creates a problem with the fees.

Could you check if this is correct??

(being able to implement a monthly rebalance in the screener would be fantastic!)

Thank you very much in advance!

“I am creating a portfolio of two ETFs that rebalances the first day of each month” and “Every month the system sell and buys again, which creates a problem with the fees” would seem to be mutually exclusive.

That said, if you mean to do what I think you mean to do, it’s more complicated than accepting the Buy/Sell Difference transactions. But these two sell rules might work:

(MonthDay=1 or (MonthDay=2 and PrevBarDaysAGO>2) or (MonthDay = 3 and PrevBarDaysAGO >2) or (MonthDay = 4 and PrevBarDaysAGO > 3)) and Ticker("MTUM") and Close(0,GetSeries("MTUM"))<SMA(200,0,GetSeries("MTUM"))
(MonthDay=1 or (MonthDay=2 and PrevBarDaysAGO>2) or (MonthDay = 3 and PrevBarDaysAGO >2) or (MonthDay = 4 and PrevBarDaysAGO > 3)) and Ticker("TLT") and Close(0,GetSeries("MTUM"))>SMA(200,0,GetSeries("MTUM"))

Those are untested, but the idea is that you’re evaluating whether you should sell on the first day of the month and you will do nothing if you wouldn’t switch.

Thank you very much.

It seems to work properly.

Indeed, what I did to compare the results is an Screener and a Strategy with the same rules but rebalancing every 4 weeks.
these two backtests show very similar results.

However, If I apply the “monthly” rebalance (rebalancing only the first day of the month), the Annualized Return is +2% higher every year.

Does it make sense for you? it shouldn’t have such a difference.

Again, thank you very much

Two thoughts.

First, the end of the month is a magical, happy time when professionals buy and sell to minimize taxes and maximize returns. It wouldn’t particularly surprise me if the markets tended to be unusually down on the last day of the month and unusually up on the first day of the month. (Though that’s just a guess.)

But much more importantly for our purposes, screens and simulations should never be expected to exactly match because screens use partial shares and simulations use whole shares. Depending on the length of the testing period, a difference of two percentage points can be practically nothing. (If your testing period is a few months, though, please send me a link to the sim. It might be a bug.)

Again, Thank you very much for your time.

I am completaly aware that the screen and the portfolio create different results for the same rules.

In this case, the difference appears when instead of rebalancing every 4 weeks, we rebalance the first day of the month.

Here are the examples:
Porfolio 4 weeks: https://www.portfolio123.com/port_summary.jsp?portid=1611856
Screen 4 weeks: https://www.portfolio123.com/app/screen/summary/242779?st=1&mt=9
Portfolio 1st day of the month: https://www.portfolio123.com/port_summary.jsp?portid=1611835

The period I tested is 20 years, so 2% per year for me seems to high.
I am very involved in the diversification of this kind of systems varying the date of start, period of rebalance, small changes in the parameters, etc. and 2% per year is quite high in general. Feasible, but high.

This is why I would like to be completaly sure that the rules are correct.

Thank you !

Hello Everyone,

I have the constant feeling that it never works properly.

At this moment I am trying to replicate the GEM from Gary Antonacci. I am not looking for a perfect backtest, but only to understand the rules behind P123 for a proper monthly rebalance.

This is the model I created:
https://www.portfolio123.com/holdings.jsp?portid=1613291

Has anyone worked on it, or with similar conditions that can share their findings?

thanks in advance.

BR!

The following sim intends to do a monthly rebalance on the 1st Monday of each month. Notice it tries to rebalance each week but only satisfies the sell rule on the 1st Monday of the month.

https://www.portfolio123.com/port_summary.jsp?portid=1535267

It also has (commented out) a rule to allow the last Monday of the month to be the monthly rebalance if you want to try that instead of the 1st Monday. Prior to 2020, the strategy outperformed.

The ETFs in the universe are: Ticker(“VTI,EFA,SHV”)

Ranking is the 253 day total return.

My investigation into Dual Momentum.

Jim