How Many Trading Days In A Year?

Sometimes it is useful to know the number of trading days in a year e.g. to annualize returns from a system that trades on a daily basis.

On other occasions, index data can contain errors, and the number of daily bars, in a year, can be compared to the exchange calendar, for the relevant index, to check on this failing.

To count the number of trading days in a calendar year (for any equity market):

a) download the .afl file attached to this post and save it in Program Files/AmiBroker/Formulas/Custom,

b) open AmiBroker and display any index, for the market of interest, in a chart e.g. ^DJI;
c) find p-barsinyear in the Charts list and right click on it, then Insert it as an indicator, (it will be plotted in a new pane in the bottom section of the Chart window);
d) click in the Chart to position the Selector Line in the BarsInYear chart, just after the end of the year being measured (where the cumulative line becomes a constant in the upper section of the chart);
e) read the BarsInYear total from the Chart Title (highlighted in yellow).

(Note that this calculation requires daily bars and also that it is set to calculate the number of trading days for the last full year at the time of writing i.e. 2006. To calculate the number of trading days for a different year e.g. 2007, change the 106 to 107 in both of the DateNum() number sequences).

1
2
3
4
5
6
7
8
9
10
/*P_BarsInYear*/
 
InYearFlag = IIf(DateNum() >= 1060101 AND DateNum() <= 1061231,1,0);
InYear = Cum(InYearFlag);
Plot(InYear,"BarsInYear",colorBlack,styleLine);
 
// Logic.
// line 3 returns one if a bar is within the calendar range, or zero if not, and assigns it to the variable InYearFlag;
// line 4 cumulates the ones from line 3 and assigns the result to the InYear variable;
// line 5 plots the cumulated result in a chart;

BIY001

Attached Files:

Right click and Save Target As to save .afl files to the desktop at Program Files/AmiBroker/Formulas/Custom and access them as formulas within AmiBroker Charts.

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

No comments yet. Be the first.

Leave a reply