A tip to handle AFL file changes

An issue I've encountered is piling changes on top of changes in an *.afl file and forgetting where I started from. One way of knowing what you did is after running a backtest you can see the formula used in the Report Viewer. This feature is awesome, but it's not intended to be used to dig thru code changes.

In programming people keep track of changes in the code thru a Version Control System.
For someone who's not a programmer, this simply means you make some changes to some files and then "save" a snapshot of those changes into a commit. This will also include some text you write to describe the changes. If you change a variable or a formula for instance you can say "Optimization of formula X" and commit the change. The version control system will keep track of this changes and creates a "ledger" of changes of the code/files/codebase.

The beautiful part is you can go back to those commits from the past easy and given the nature of the system, the whole folder and file structure of the 'codebase' will be as it was in that point in time when the commit happened.

The most used system that does this is git.

While git is just a command line tool, there are tools on top of it that makes handling these changes/commits very very easy. One such free(but not open source) tool is Sourcetree. Sourcetree is a visual way of dealing with the changes tracked by git.

Glad to say it works very nice with AFL files. It's easy to initialize it in the Custom formula folder of AB and you can get all the benefits that I mentioned.

I've included a screenshot of a change I did to an afl file and it's easy to know that on line 25 I've commented //variableSpreadUS500() and changed it with 0.9. This is an uncommited change and if I feel it's something I want to keep I can commit it and add it to the folder 'history'. In 5 months time I can go back to this exact snapshot and run the exact code. Going back is called "checking out a commit".

Regarding AB and AFL, with such powerful tools you can go thru the history of the whole Custom formula folder and see which files you changed and when, and what exactly you did, or you can even inspect one single file and see how it changed over time.

While git works locally, the next level is to have it sync to a "git server" and have your code uploaded there with all your changes. This also gives you the ability to run AB on 2 PCs and sync the code between them.

As a note, what I noticed with AB is that is best to checkout different commits is best done with the code editor turned off or the file you want to check out not being opened.

While what I described is simple and things can get way more complex and detailed, it's quite easy to get git and Sourcetree running on Windoze in the AB formulas folder. If anyone is interested to get this running on their PC let me know as I can post a few screenshots and commands on how to get it going. Both tools are free and git is also open source.

Cheers,
DBV

2 Likes

Very helpful thanks for posting!

1 Like