Duplicate: Different results backtest vs. explore / rotational trading

Dear Community,
I am chasing an error in rotational trading. Using backtest and exploration I have narrowed down the situation.

  1. a watchlist with 7 symbols from Norgate: AABA-201910, AEO, AMZN, BVSN-202005, MFNXQ-200209, NSOL-200006, STCN. Filter applied to this watchlist.
  2. a piece of code, modified from the published ExampleRotational.afl
MaxPositions = 3;
SetOption("MaxOpenPositions", MaxPositions  );
SetOption("WorstRankHeld", MaxPositions  );
SetPositionSize( 100 / MaxPositions, spsPercentOfEquity ); 

SetTradeDelays( 1, 1, 1, 1 );
BuyPrice = Open;

SetBacktestMode( backtestRotational );

change = ROC( Close, 10 ); 
PositionScore = 10000 + change;

if( Status( "action" ) == actionExplore )
    Filter = 1;
    AddColumn( Close,         "Close   ", 6.2 );
    AddColumn( PositionScore, "PositionScore", 6.2 );
  1. Setting is monthly, range 01.07.1998-01.08.1998. Trade next bar on open (also in the code). Align to $NDX.

Explore gives me this list, sorted by PositionScore:
Ticker,Date/Time,Close ,PositionScore

Backtest gives me this list (columns deleted after ex.price):

Symbol,Trade,Date,Price,Ex. date,Ex. Price,
AMZN,Open Long,31.07.1998,0.8484375,31.07.1998,0.9239584,
STCN,Open Long,31.07.1998,79.39613,31.07.1998,73.3405,
BVSN-202005,Open Long,31.07.1998,611.8776,31.07.1998,478.9042,

I have two strange findings:

  1. BVSN is on backtest 3rd rank. From PositionScore I would expect BVSN on 5th rank, and instead AEO on the 3rd rank.

  2. the prices in backtest are not the opening prices of the next period (01.08.1998) but the opening prices of the past period (01.07.1998). This contradicts the delay setting.

Is there an error in my code? Or do I have a big misunderstanding in the application of the system?



As usual... Yes, there is.

Apparently the backtest has one bar delay so in the exploration you have to add delay too.

if( Status( "action" ) == actionExplore )
    Filter = Buy;
    AddColumn( Close,         "Close   ", 6.2 );
    AddColumn( Ref(PositionScore, -Status("buydelay")), "PositionScore", 6.2 );

And in rotational mode there are used delay and price array of UI backtester setting not of the code.

It is all mentioned in the manual of rotational trading.


1 Like

@fxshrat thank you for your advice! After reading a number of forum discussions, I do unterstand your "as usual". Thank you for your patience!

I am trying to bring my mind around the concepts. The thinking in arrays and the complexity of AB is demanding at first. I want to ask three more questions, if I may:

1.In your response you inserted in the exploration code the line Filter = Buy;
This is producing an error in rotational trading. I am using Filter = 1; In the context of rotational trading there is no simple alternative for this, because of the complexity of the backtester, is this right?

  1. Regarding the usage of
SetTradeDelays( 1, 1, 1, 1 );
BuyPrice = Open;

I now understand , that this is working for other backtests, but not for rotational. Would it be a good practice, to avoid these statements generally, and rely on the settings, to avoid the trap?

  1. regarding exploration: The delay setting is guiding the calculation not only in backtest, but also within the exploration-code. So Explore uses the correct delay on buy, sell, short, cover and the corresponding prices. But I need an extra REF() on all other values that I want to report. Is that right?

Thanks again, and have a good day


No. That is wrong. You are making invalid assumptions. SetTradeDelays affects rotational mode as well.
What @fxshrat wrote you is that difference between EXPLORATION and backtest.

Exploration is NOT backtest. Read this:

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.