Tiling, tiling, tra la la

Hola fellow seekers,

Let's say that I have a ranking system that ranks stocks on a scale of zero to five and I would like to find out how well it works. The old way would be to start at week one, create six portfolios, measure their returns on a number of horizons, say one, four, eight, 13, and 26 weeks, then step forward to the next week and repeat aggregating the results at the end. If one had perfect foresight one might get a result like this.

       1      2      4
5      10     12     ...
4       8      9     ...
3       5      6     ...
2       1      2     ...
1      -1     -2     ...
0      -3     -5     ...

Where the rows are the results by rank and the columns are results by horizon.

Another way to think about this is via indicators, for example: What are the futures results in the wake of RSI readings of 10, 20, 30... ?

Can anyone point me to a trailhead where I can explore how this is best done in AB?

Wishing you all a safe, healthy and happy 2021!

Good trading,


@BBands, did you evaluate "Optimize" as a quick approach to test your idea?

As an example, please, see this past thread to learn how to test a combination of signals (in particular, check the elegant @fxshrat solution).

In your case, I think you could use 2 "optimizable" parameters.

The first one to conditionally set your Buy array when your score (let's say calculated using bitmasks values (1+2+4+8+16+32) to clearly detect the significant factors in the combined score) is == to the optimized variable (Buy = score == buyScore; where "score" is the calculated one and "buyScore" is the optimized variable).

The second one, used to control a switch conditional (or getting values from a matrix similar to the first example in the "optimize" documentation) to set your holding periods to non-contiguous values corresponding to the number of bars to hold.
You will exit the trades using:
Sell = 0;
ApplyStop( stopTypeNBar, stopModeBars, bars, True );

Set your Analysis periodicity to weekly.

Then you "Optimize" your formula. When complete, you apply multiple sorts to the last 2 columns to get the desired ordering to verify if the results correspond to your perfect foresight!
(The resulting table is not like your example but easy enough to interpret).

1 Like

Hey Beppe,

Thanks for the trailhead. I don't do any optimization and thus I am not at all familiar with the AB optimizer so it never would have occurred to me to look there. I will dive in and have a look around.

Best regards,

1 Like

@BBands, the approach I suggested will give you results for a single "starting date" (for all the desired signal combinations and multiple holding periods).

If you need to aggregate results over an extended range of weeks, advancing the starting date one week at a time, you need to repeat the process as needed.

You can do it manually, saving all the resulting reports to finally load them, aggregating the data in suitable applications like Excel. Still, it is probably a lot better to automate the procedure.

I suggest employing an external script to do it.

I do not know if this the right solution (sometimes I overcomplicate things), but based on what I did for something similar, I will proceed in the following way.
(I used R that makes tabular data manipulation very easy).

First, in AmiBroker, I will create a "project" and a "batch" that loads the project, execute the optimization, and save the results as a .csv file.
In the "project, "I will set the "To" date to the current one. This date will never change; the formula anyway exits all the trades after the holding period; moreover, do not forget to disable the "time-consuming" warning in the Analysis Settings - Report tab.


In my script, I will loop over the weekly dates that I want to include in the study, modifying at each step the "project" (it is a .xml file), simply changing the lines with the starting date of the period to include.

Then I will launch AmiBroker with the command line parameter to execute the optimization "batch".
When AmiBroker is done, at each step, I will load the resulting .csv file in a data frame aggregating the data with the previous (if any) step.
If required, you can also rename the AmiBroker optimization report file to keep a copy of all of the ones generated (since the batch will otherwise overwrite it each time).

At the end of the loop, I will save the resulting aggregated data frame as a new .csv file /report to analyze and/or to reuse it in other scripts/tools.

Maybe there are more straightforward solutions.

I hope some users with more experience than me could suggest a better alternative to achieving your goal.


Thanks Bepe,

Thanks for your thoughtful answer. I actually decided to do something like that in Python.

Best regards,

1 Like

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