In backtest, it does not indicate the correct date (user misunderstanding)

Hello, let me see if I can explain myself. I'm pretty new.
I do the monthly backtest of the attached code.

//Inercia Alcista entre RF y RV - Quantonomics - Javier ALfayate - pag 8/91
//SPY (Renta Variable: ETF del SP500) vs AGG (Renta Fija: ETF de Bonos, Letras del Tesoro de corto plazo)
//Mensual
//Solo Largos
//Elegir el que tenga la IA más alta (siempre que sea superior a 0)

//Se habilita el trading rotacional
SetBacktestMode(BacktestRotational);
EnableRotationalTrading(); //Es anticuado

//Numero de posiciones para negociar y ordenar
NumberHeld=1;
SetOption("WorstRankHeld", NumberHeld);
SetOption("MaxOpenPositions", NumberHeld);
PositionSize = -100/(NumberHeld*1.00);

//Empleamos el Optimize para ver que valores son mas rentables. ROC 6 por defecto
M = Optimize ("M", 6, 1, 24, 1);
ROC6 = ROC (C, M);
InerciaAlcista = ROC6;

//Sin cortos
AllowShort = 0;

//Puntuamos los valores de Inercia de cada ETF siempre que IA sea positiva
Corte = 0;
Score = IIf(InerciaAlcista<Corte,0,Max (InerciaAlcista,0));

//Posicionamos los ETF
PositionScore = Score;

//Mostramos por pantalla exporador
Filter=InerciaAlcista;
Nombre = FullName();
AddTextColumn ( Nombre, "Nombre", 1.2, IIf(Score>0, colorGreen, colorRed));
AddColumn (InerciaAlcista, "IAlcista", 1.2);

I also take an explore to see how it works.
This system calculates the bullish momentum of two assets at the end of the month and buys the one that has the highest (and that is also higher than zero) at the beginning of the following month.
Screenshot_29

In the explore I see that on 29/10/2004, the asset AGG has the highest Bullish Momentum, therefore, it should be bought at the beginning of the following month (01/11/2004).

My problem/doubt is that in the backtest, the purchase date indicated is 30/11/2004, that is, the last day of the month and not the first.
What am I doing wrong?
Thank you very much

@yonsi72 check your preferences and uncheck this flag and see what changes if you execute again your backtest in monthly periodicity:

image

Hello beppe and thank you very much for your reply.
By doing what you mentioned, the correct purchase date now appears in the backtest (in this case, at the beginning of the month) but on the other hand, now in the explore...the date is no longer correct (end of the month), it has also changed to the beginning of the month.

It is just a BAR timestamp. A convention. The bar itself is the same.

You might choose whatever timestamping convention you need. Generally it is advised to stay with default setting which is:

  • START time of interval (recommended)
    (plus uncheck "Override" setting)

It is a bit different setting than what @beppe has shown.

Say you have DECEMBER bar that covers December 1st till December 31st.
Depending on preferences setting it might be seen as having Dec 1, 2024 timestamp or Dec 31, 2024 timestamp but it is STILL THE SAME DECEMBER MONTH bar.

It is just display convention. It is just for the display. In fact you should be really mentally ignoring the "day" because it is irrelevant. It is just december bar.

The "date" in backtest does NOT represent exact millisecond of trade but timestamp of BAR when trade was entered. It does not say when within the bar trade ocurred as when you use monthly bar the time quantum is ONE MONTH. And timestamp says you bought in december, not specifying when within december. You could be exiting in the middle of the month via stop but this does not change the exit would be accounted for given month and timestamp would represent the BAR timestamp. When you backtest using MONTHLY DATA your time quantum is ONE MONTH.

If you want per-day resolution, use DAILY INTERVAL for backtesting.

3 Likes

Thank you very much Dr.Tomasz