Topic: In search of the fastest Strategy Generator
Hello Traders,
I spent a lot of time analysing the performance of EA Studio and Express Generator's indicators over the last two weeks.
I designed a simulation program to load a particular data file and calculate the Moving Average and RSI indicators.
I made it first in JavaScript using the code from Express Generator.
After testing, refactoring and optimisation, I made a similar program in C.
The C version was 2 times faster for calculating the Moving Average and 15% faster for RSI.
Then, I made it in Fortran. It took me a week to read several Fortran books and to "master" the language.
Expectedly, the Frotran version was about 30% faster than the C version.
I continued researching and learned that Fortran is faster than C, not because of the features it has but because of the features it does not have.
I almost accepted those results. However, I wondered "why" it happens and the particular reason.
Several days later, I learned a lot about modern 64-bit Assembly, disassembled the programs and studied the code.
I was very happy when I found the reason the Fortran code was faster. (It was rather geeky, but if you are interested, I may explain).
On that latter, I decided to use this knowledge to improve my current code.
The first result is compiling C to a similar assembly as Fortran. It practically made the program very similar.
Then, I did the same in JavaScript.
And ... surprise, surprise. All three programs, Fortran, C, and JavaScript, performed similarly.
Calculating 2000 indicators with periods from 1 to 200 on 200k bars.
=======================================
Indicator Language Time
---------------------------------------
MA Fortran 1.70 sec
MA C 1.72 sec
MA JavaScript 1.72 sec
---------------------------------------
RSI Fortran 6.81 sec
RSI C 6.80 sec
RSI JavaScript 6.84 sec
=======================================
The tests are made under Linux with the latest GFortran, GCC, and NodeJS.
The optimisation level for Fortran and C was "O2".
I also made a test with the optimisation level "-Ofast." Both C and Fortran showed double improvement in performance.
"Ofast" option is not suitable for code distribution.
I'm going to use this knowledge in the PineGen generator.