Thursday, 5 December 2013

Testing MyCalcs and Exotics

This post first looks at how to set the number of second and third place standouts in System Selector's new "Expert Mode" and then proceeds to look at how to test MyCalcs. In both cases settings must be defined in the very first line of your Expert Mode system on a line that starts with the number zero followed by a full stop (0.). As you will see in the examples below the syntax is to use the constant name followed by an equals sign followed by the value you wish to set (followed by a comma if another constant setting follows).

Testing Exotics

The default for exotics is for a system test to use the win selections for first place and the top 6 rated horses for second and third. If you want to change the number of top rated horses for second and third to say 8 and 10 receptively then the first line of your system file must be as follows:


Note this line must be the first line in your system file and must start with "0.". The format of this line (after the "0.") is to have a "constant name" followed by an equals sign followed by a value. So in the above example TRI2 (the number of top rated horses used for second place) is set to 8 and TRI3 (the number of top rated horses used for third place) is set to 10. Make sure you use the comma separator between the two.

Note that system tests use the second place horses as described above to report exactas and quinella results while the number of third place horses are added for the purpose of trifecta results. First four results are also reported and these assume the number of top rated horses for fourth is the same as the number used for third.

Testing MyCalcs

Now to MyCalc which is a module off the program's pull down RUN menu for creating and saving user defined calculations (eg ratings and point scores) for use in systems. Note some users may also have used MyCalc in the past to apply system rules but this should no longer be necessary as these rules can now be created in the new "Expert Mode" in System Selector.

To access a MyCalc calculation in a system you must set its name to the "constant name" CALCNAME in the first line of your system file. For example if you have a MyCalc called "poll points" then you would link to it by placing the following as the first line of your system:

0.CALCNAME=poll points

Note you can also set the MyCalc name at the same time as setting the number of second and third place standouts but the MyCalc name must always be at the end of the line as follows:

0.TRI2=8,TRI3=10,CALCNAME=poll points

In the case of the above two examples the system test will display selection poll points as calculated by the selection poll points calculation in the MyCalc "poll points". This calculation is saved in a file called "poll points.bsc" but you don't need to know that as MyCalc and System Selector take care of all the file saving/writing. Note if you'd like to set up a MyCalc for selection poll points there are instruction on how to do so in the next section of this blog post.

If you just link to a MyCalc as in the above examples then all that will happen is that the calculation results will appear in your system test selection list where the rated prices usually appear. Normally when using a MyCalc in a system you want to do more than just display the calculation results. The most common things you would want to do are set limits on the values and the rankings for such calculations. This is done by setting minimum and maximum values for the MyCalc values and rankings using the following constants:

  • CALCMIN - This constant is set to your minimum bound for MyCalc values
  • CALCMAX - This constant is set to your maximum bound for MyCalc values
  • CALCRANKMIN - This constant is set to your minimum bound for MyCalc rankings
  • CALCRANKMAX - This constant is set to your maximum bound for MyCalc rankings

Note you can set as many or as few of the above as you need. For example if you are using the "poll points" MyCalc and wanted the top selection in the poll you would just set the maximum rank to 1 as follows:


Note that rankings always go from 1 for the top ranked horse to 24 for the lowest ranked horse which is why you don't in this case also need a minimum bound for the rankings. Remember you can still set second and third standouts for exotics as long as you use commas between constant declarations and always put the CALCNAME at the end of the line. For example:

0.TRI2=10,TRI3=12,CALCRANKMAX=1,CALCNAME=poll points

Following is another example where the same "poll points" MyCalc is used but this time values of 16 and above only are required:

0.CALCMIN=16,CALCNAME=poll points

Finally here is an example where you use the "poll points" calc and require the top raked horse but only if it has a points score between 10 and 16:


Remember the "declaration" line must always be the first in your system file, you must use commas between declarations and the CALCNAME must always be at the end of the line.

New: If you have a one line MyCalc you wish to use in an Expert Mode system you can now do so without referring to a separate MyCalc file. To do this, in place of using CALCNAME= in the first line just use CALCCODE= followed by the code for the calculation.

How to do points calculations

A special function called “MyPts” helps you allocate points for numeric items like TAB number, barrier position etc. It has 6 parameters with the first parameter indicating the item you want to convert into points, eg H:TNO for TAB number. The next two parameters represent the range of items you want points allocated for and the following two parameters the range of points you want to allocate. For example if you want TAB numbers 1 to 3 to get 3 to 1 points then you would use:


If you want barrier numbers 1 to 24 to get 10 to 1 points then you would use:


The last parameter is normally 0 indicating you do not want points allocated outside the range you specify but if set to 1 points will be allocated outside the range (using straight line extrapolation). Calcs can be added together like in the following calc that creates a selection poll consensus points total (by allocating 4 points for first through to 1 for fourth for each of the API, win%, place%, Better Ratings, Plus Ratings and normal ratings rankings):


Testing MyCalc Gaps

Whether you have a complex MyCalc or just a simple one like the rated price or market price, there will be times when you want to test for the gap between the top two horses. For example you may want the rated price gap to be at least $2. You might also want to test the gap between the second and third top horses (what we call the second gap). The following constants are available for doing these sort of tests:

  • GAPDIFFMIN - This constant is set to your minimum bound for the gap
  • GAPDIFFMAX - This constant is set to your maximum bound for the gap
  • GAPNO - This constant is set to the desired Gap Number (only needed if not 1)

Following is an example that requires a minimum gap of 3 between the selection poll points of the top two horses in the poll:


Note that the default gap is number 1 (between the top two horses) so you don't need to do anything special to select this gap. If you want to select a different gap for example between the second and third top horses then use GAPNO=2 on the first line of your system.

One final point to remember is that the constants explained in this post can only be used in the first line of your Expert Mode code. They are separate from the variables that can be used in MyCalcs and Expert Mode rules.

Let’s say you wanted for example to pick horses that are rated on top with a gap in rated price to the next horse of at least $3. To do this we start with the following calc which ensures the top rated horses are ranked on top:


Then we set the MyCalc Gap Diff min setting to 3. Note the rated price H:PRICE is stored as a character string so the BOOK2DIV function converts it to a numeric dividend (note this function can also be used to convert bookmaker style odds like 9/2 to numeric dividends).

A similar calc can be used to test for gaps in the early market price as follows:


Note that we have been talking about testing for gaps not horses so in addition you must also include a system rule to pick the desired horse (normally the top ranked but you might want to pick others). Note also if testing for gaps in Better Ratings (BRVAL), AAP 100 point ratings (AAPDRY), official handicapper ratings (HCP) etc you do not need to negate these as the top ranked horses already have the higher number ratings.

Using functions

In MyCalc or Expert Mode you can add a horse’s last 4 finishing positions as follows:


But rather than just add the last 4 finishing positions, suppose you wanted to add the best 3 of the last 4? Fortunately you can use Max and Min functions to do these sort of things. Note that unlike in Excel Max and Min functions can only handle two arguments at a time. So Max(a,b) gives the maximum of a and b. And Min(a,b) gives the minimum of a and b.

Using some clever maths the easiest way to add the best 3 of the last 4 finishing positions is to add them all and subtract the largest of the 4. The following calc does this:


Notice how we have used nested Max functions to get around the fact that they only allow two arguments to be used.

Other functions that can be used are as follows:
· Upper(a) converts the character string “a” all to upper case
· Left(a,n) returns the “n” leftmost characters of the string “a”
· Right(a,n) returns the “n” rightmost characters of the string “a”
· Dow(d) converts the date “d” to a “day of week” number (1 for Sun through to 7 for Sat)

Create your own rankings

Variables already exist for ranking ratings, API, win percentage, place percentage and so on but to rank something of your own making you need to set it up as a calculation in MyCalc. For example if you wanted to rank horses by the result of their weight less their barrier position you would set up the following calc:


Then you would use the MyCalc Rank rule to pick the ranks you wanted to include. Please note that MyCalc always ranks large numbers higher than lower numbers. So if ranking weights, the highest weighted horse would have a top rank of 1 and so on.

There is a way to reverse the normal rankings order (highest on top to lowest at bottom). For example if you were using weights and wanted the lowest weighted horse given the top rank of 1 then the following calc will achieve this:


Note that you can’t just negate the weight as MyCalc does not handle negative numbers. This is why we have subtracted the weight from 100 (you can subtract the weight from any number that is larger than the largest weight that might be encountered).

Similarly if you wanted to rank TAB numbers and have TAB number 1 given the top rank of 1 then you would set up the following calc:


Just remember to use the MyCalc Rank rule to pick the ranks you want to include.

10 Base Rating Calcs

MyCalc is often used to do simple calculations but it can also be used to calculate ratings.
Usually (but not always) you start with what we call a “Base Rating” and then add bonuses and subtract penalties to arrive at a final rating figure for each horse. Bet Selector’s base rating is a weighted average of a horse’s last 3 ratings but there is no reason why you can’t use different calculations and possibly get an edge over the average user.

For our first example the calc to average a horse’s last 3 ratings is as follows:


The above calc takes the sum of the last 3 ratings for a horse and then divides the sum by 3. The only problem with this is that if a horse has less than 3 starts then you should divide by the number of starts it has had. The following accommodates this as well as ensuring you don’t divide by zero:

(H:RS1+H:RS2+H:RS3)/Min(3,Max(1, H:STARTS))

Our second example to returns the highest of a horse’s last 3 ratings is as follows:


Remember the Max function can only take 2 arguments which is why we have used two nested Max functions.

Our third example gives the “Median” of the last 3 ratings which is the middle rating (ie not the highest or the lowest but the one in between). The calc to do this is as follows:


The above calc is a bit long but what it does is takes the sum of the last 3 ratings and subtracts both the maximum of the 3 and minimum of the 3. Note you can split the calc into 3 separate lines as follows:


Our fourth example gives the average of a horse’s last 2 ratings as follows:

(H:RS1+H:RS2)/Min(2,Max(1, H:STARTS))

As was done earlier we have used Min and Max functions to ensure the division is by one in the case of one or zero starts.

Our fifth example uses just one past rating as a base. For example the following just takes a horse’s last start rating:


There is an argument that the most recent form is the most important hence the above use of the last start rating. Alternatively you might want to use a horse’s second last start rating using the following calc:


There is an argument that this second option would emphasize horses that had a bad run last start and therefore be useful in picking horse’s that are over the odds.

Our sixth example uses Bet Selector’s Peak Distance rating as follows:


Another option would be to take an average of the peak and base ratings as follows:


Averaging the last start rating and the peak distance rating as follows could also be useful:


The argument for using the above is that if a horse is improving it should rate somewhere between its last start rating and its peak rating. The above calc returns a figure that is half way between the last start rating and the peak rating and can also be written as follows:


Writing the calc in the above fashion makes it easier if you want a figure that is say 80% of the peak and 20% of the last start rating. The following calc does this:


Our seventh example uses the official handicapper rating as follows:


Note the above ratings usually max out at around 120.

Our eighth example uses a horses Average Prize money Index (API) which is determined by its total career prize money divided by 1000 divided by its number of career starts. The following calc does this:


Note the use of the “If” function to avoid a division by zero. API figures are displayed in Bet Selector and some other form guides. Most horses have low figures (under 10) but in quality races the figures can be much higher (in the 20s, 30s and even higher). To help flatten out the steep increase you can take the Square Root of the API as follows:


You can get a feel for this by using the Square Root function in Excel or on a calculator. You will find it converts 1 into 1, 5 into 2.2, 10 into 3.1, 20 into 4.5, 30 into 5.5 and 50 into 7.1. If you want to engineer a base rating that is in the traditional 50 to 65 range then multiply them by 2 and add 50 to the result as follows:


Note you can experiment with the 50 and 2 numbers which vary how high the numbers start at and how spread out they are.

Our ninth example uses a horse's win percentages CWINP. Taking the square root of these will return numbers in the range 0 to 10 instead of 0 to 100. If you want to engineer a base rating that is in the traditional 45 to 65 range then multiply them by 2 and add 45 to the result as follows:


Similarly if you could do the same using the place percentage CPLCP as follows:


Another possibility is to start with an average of the win and place percentages as follows:


Note you can experiment with the 45 and 2 numbers which vary how high the numbers start at and how spread out they are.

Our tenth example gives a horse’s last start speed in meters per second:


Note that speed is determined by time divided by distance but since we only have the time for the winner we must estimate the time taken by non-winners. This is done by taking the winner’s time and adding 0.15 times the horse’s beaten margin (a factor arrived at by dividing the average horse length of 2.5 meters by the average speed of 16.5m/s).

Usually the above speed calc will return a figure in the range 14.5 to 17.5. If you prefer a figure that is in the more traditional 45 to 65 range then you could try multiplying by 6 and subtracting 40 as follows:


In addition to modifying the 40 and 6 numbers which vary how high the numbers start at and how spread out they are, you can also vary the .15 number. For example, if you want to penalise beaten horses more, you could multiply the beaten margin by .2 instead of .15.

Odds and ends

Calcs and Expert Mode rules are limited to 255 character line lengths so you need to be careful when adding lots of things together that you do not exceed this limit. To get around this and to make calcs more readable you can enter calcs over a number of lines provided each line is a separate calc designed to be added to the calcs in the other lines. Fortunately there is no limit to the number of lines you can use. Just be careful not to include extra spaces or line breaks as these can cause problems.

Normally a division by zero would cause Bet Selector to crash but MyCalc and Expert Mode have been programmed to return a zero answer when a calculation attempts to divide something by zero.
As a result the following calc will not crash but will simply return zero if the number of career starts (H:STARTS) is zero:


Note the above calc return a horse’s number of track wins as a percentage of the horses total career starts (something we refer to as an “experience” ratio). If you are using the above as part of a larger calc then you can cater explicitly for a division by zero using an “If” functions as follows:


If you have a number of calcs that simply add together then a division by zero in one of them will cause the whole calc to return zero. You can avoid this by splitting the calc into separate lines as mentioned earlier.

“Operator precedence” dictates that multiplications and divisions are done before additions and subtractions. When this presents a problem you can use parentheses to force a change in the order of calculation. For example the following calc takes a horse's prize money earnings and divides them by the number of placings a horse has had:


As you can see the number of placings is determined by adding the number of wins, seconds and thirds but these must be surrounded in parentheses to ensure they are added together before the division is carried out. 

Finally, you can’t normally apply one system rule and then apply a second system rule to the subset of horses picked by the first rule. With MyCalc however you can sometimes get around this. For example suppose you wanted to pick the horse with the highest weight out of the top 3 rated runners. With a normal system the best you could do is pick a horse that has the highest weight in the race and is also rated in the top 3 which is not the same thing. The following MyCalc returns the weight allocated to a horse if it is rated in the top 3, otherwise it returns zero:<4 p="">


Using this calc and testing for the top MyCalc Rank will select the highest weighted horse out of the top 3 rated.