Settlement Templating Language (STL) : Release 1.2

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 23

Settlement Templating Language (STL)

Release 1.2

Algosport

May 18, 2018


CONTENTS:

1 Introduction 1

2 Samples 3
2.1 Contest phases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.2 Time periods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.3 Incidents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

3 Defining settlements 7
3.1 Basic operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
3.2 Aggregates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.3 Incident properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

4 Sports 13

5 Examples 15

Index 19

i
ii
CHAPTER

ONE

INTRODUCTION

STL (Settlement Templating Language) is a domain-specific language used to define settlement rules within sports
betting. Separating the settlement rules from the underlying mathematical models enables much greater flexibility in
growing a sportsbook offering.
1. Automatic pricing of selections is performed by linking a model to the settlement rules. Whilst STL primarily
defines how a selection is to be settled we can easily recover the odds for a selection by calculating its expected
settlement over all possible match outcomes generated by the model.
2. New selections can be quickly and easily defined - and hence priced - by settlement rules entered by traders or
product managers without the required expertise of the quant and/or algorithm implementation teams.
3. New products can be innovated or replicated because we have the ability to directly interact with the structure
of the settlement rules for the bet.
(a) Bet builder allows customers to create their own individual bets by combining pre-existing selections. If
selections are already defined in STL then combining multiple selections into a single bet is incredibly
simple. For example, if a customer wishes to get a price for the combination of home win:

supremacy(<RT, goals>) > 0

and total goals over 2.5:

total(<RT, goals>) > 2.5

then we only need to request the price for the combined selection:

supremacy(<RT, goals>) > 0 and total(<RT, goals>) > 2.5

from the underlying model.


(b) Bet editor allows customers to add and remove selections from a combined bet. As with bet builder, when
all selections are defined in STL then the interface for making such changes to bets is as simple changing
the list of selections that define the bet. Customers are then charged based on the change in expected value
for the bet as well as some level of commission.
For example, if a customer thinks that there will be over 2.5 goals in a match but now prefer the away team
over the home team, they simply edit their selections from
i. Home win, defined as supremacy(<RT, goals>) > 0
ii. Over 2.5 goals, defined as total(<RT, goals>) > 2.5
to
i. Away win, defined as supremacy(<RT, goals>) < 0
ii. Over 2.5 goals, defined as total(<RT, goals>) > 2.5

1
Settlement Templating Language (STL), Release 1.2

and we price the cost to edit the bet based on the expected payouts for:

supremacy(<RT, goals>) > 0 and total(<RT, goals>) > 2.5

and:

supremacy(<RT, goals>) < 0 and total(<RT, goals>) > 2.5

(c) Cash out is a special case of bet editor where all selections are removed from the initial bet.

2 Chapter 1. Introduction
CHAPTER

TWO

SAMPLES

Samples form the basis of all settlement rules in STL. They are expressed as a pair, <phase interval,
incident type>, where the two component parts are
1. Phase interval
A period of play within a contest, e.g.
• regulation time
• 11th frame
• 3rd quarter of regulation time
• last 10 minutes of over time
• first 5 points of 3rd game in 2nd set
2. Incident type
Actions that are recorded throughout the contest, e.g.
• goals
• sets
• yellow cards
• home team points
• aces
The permissible pairs of phase intervals and incident types in a a sample are determined by the structure of the sport.
How STL defines this structure is discussed in Contest phases. The ways in which samples may be manipulated to
build up settlement rules is discussed in Defining settlements.

2.1 Contest phases

Within STL, contests are organised into a collection of sport-specific phases. Each phase has a notion of time, sub-
phases, and a set of incidents associated with it. Not all phases will be present in every contest nor all sub-phases in
each phase. This is best understood through a few examples.
1. Football
Football contests are divided into timed phases
• regulation time; and
• extra time

3
Settlement Templating Language (STL), Release 1.2

both of which contain 1st and 2nd half sub-phases, and a point based phase
• penalties
which has no sub-phases with.
Regulation and extra time contain incidents such as goals, corners, cards and free-kicks. Penalty shootouts
consist solely of scored or missed penalties.
League matches will only consist of regulation time. Cup ties may contain one or both of extra time or penalties.
2. Basketball
In basketball, unlike football, the sub-phases of regulation time are dependent on contest format. Some leagues
play matches over 4 quarters and others play over 2 halves.
3. Tennis
The point-based scoring system means that the phases and sub-phases are also incidents within the contest. Sets
are both the top-level phases because they determine the rules for that period of play and the incidents that
determine the final score of the contest.
The sub-phases and incidents within a set are determined by its type.
• Advantage sets consist of game sub-phases made of point incidents.
• Tie-break sets add tie-break games to the phases and incidents of advantage sets.
• Super tie-break sets have no sub-phases and only points as incidents.
The passage of time may be measured in sets, games, points or some combination thereof dependent on the
phase that we are considering.

2.2 Time periods

A time period is an interval within a phase. An interval may be either an entire named phase, or an interval defined
defined in terms of the time instants for that phase.
• regulation time - RT
• 4th quarter - Q4
• frame 11 - frames[11]
• 3rd game of set 2 - sets[2]:games[3]
or a sub-interval within a phase, for example
• 0:00 to 9:59 inclusive - [RT:0, RT:9:59] or [RT:0, RT:10)

2.2.1 Timed phases

Timed phases, often split into multiple timed sub-phases, are played against the clock. Whilst the behaviour of the
clock varies by sport, for example
• does the clock run continously is does it start and stop? e.g. football vs. ice hockey
• does a period end as soon as time has elpased, e.g. ice hockey, or can it run beyond, e.g. rugby union.
this doesn’t affect any STL definitions.

4 Chapter 2. Samples
Settlement Templating Language (STL), Release 1.2

2.2.2 Point based phases

A time instant within a timed phase is expressed as phase:minute:second. The seconds are optional and de-
faulted to zero if not present. For instance,
• 10 minutes through regulation time, named RT is RT:10
• 5 minutes and 30 seconds through the 3rd quarter, named Q3 is Q3:5:30
Time instants may be used to define the instant at which an incident occured, e.g. testing if the first goal happens
after 10:00 and before 20:00

ifExists(nth(1, <RT, goals>), i => RT:10 < $i.time <= RT:20, lose)

They are also used to define custom time periods which are used in Samples.
Incidents that occur within a timed period have a time property associated with them. Time within
• RT: regulation time
• H1: 1st half
• H2: 2nd half

2.2.3 Point based phases

Example tennis markets


• winner: supremacy(<*, sets>) > 0
• point winner (game 12, point 8): ifExists(period(game[12]:point[8]), p => p.winner =
p1, lose
• game winner (game 13): ifExists(period(game[13]), g => g.winner = p1, lose
• games in set 2: total(<set[2], games>) > 9

Note: Future extensions will include


• Overtime and penalty periods
• More flexible time ranges, for example
– 00:00 - 14:59 in 1st half, [H1.0, H1.15)
– last 10 minutes of regulation time, [RT.80, FT]

2.3 Incidents

Each sport defines a set of incidents which each have an associated set of properties.
For football the current set of incidents are
• goals
– team: home or away
– player: id of the player who scored

2.3. Incidents 5
Settlement Templating Language (STL), Release 1.2

– minute: the minute the goal was scored


• corners
– team: home or away
– minute: the minute the corner was awarded
• cards
– team: home or away
– player: id of the player who was carded
– type: yellow or red
– minute: the minute the goal was scored
Incidents may be filtered on to provide more specific sets of incidents. For example,
• home team goals:

goals[team=home])

• away team yellow cards:

corners[team=away, type=yellow]

• yellow cards awarded to player “123”:

cards[player="123",type=yellow]

Note: Future extensions to include


• Extending filtering syntax to enable comparisons other than equality e.g. nth(1, <RT,
goals[method<>ownGoal]>) when required to settle goal scorer bets which do not count own
goals.

Incidents may also be tested for a particular property e.g.


• Home team score first:

ifExists(nth(1, <RT, goals>), i => $i.team = home, lose)

• Player “123” scores last:

ifExists(nth(-1, <RT, goals>), i => $i.player = "123", lose)

• No goal before 27 minutes (wins if no goals):

ifExists(nth(1, <RT, goals>), i => $i.minute >= 27, win)

6 Chapter 2. Samples
CHAPTER

THREE

DEFINING SETTLEMENTS

3.1 Basic operations

3.1.1 Arithmetic operations

STL supports three basic arithmetic operations which all act only on integer types:
• Addition (+)
• Multiplication (*)
• Subtraction (-)
These are useful for defining complex aggregates such as
• Multi-corners:

total(<H1, corners>) * total(<H2, corners>)

• Booking points:

10 * total(<RT, cards[type=yellow]>) + 25 * total(<RT, cards[type=red]>)

STL also support unary negation, (-), which acts on any numeric type. This is most often seen when defining
• incidents in reverse order e.g. last goal:

nth(-1, <RT, goals>)

• handicap values e.g. home wins with 0.5 handicap:

asian(supremacy(<RT, goals>)) > -0.5

3.1.2 Parity operations

The parity of an integer can be tested with


odd(integer)
Return whether an integer is odd or not.
even(integer)
Return whether an integer is even or not.
Used for example in even total goals:

7
Settlement Templating Language (STL), Release 1.2

even(total(<RT, goals>))

3.1.3 Comparison operations

STL supports equality comparisons


• Equals (=)
• Not equals (<>)
and ordering comparisons
• Less than (<)
• Less than or equal to (<=)
• Greater than or equal to (>=)
• Greater than (>)
These give rise to the basic settlement conditions e.g.
• Correct score is 3-2:

h2h(<RT, goals>) = (3,2)

• Home/away double chance:

supremacy(<RT, goals>) <> 0

• Under 2.25 goals:

asian(total(<RT, goals>)) < 2.25

Note: Future extensions to enable tidier comparisons


• Range comparisons e.g. 1 <= total(<RT, goals>) <= 3
• Checking for values in lists e.g. h2h(<RT, goals>) in [(0,0), (1,1), (2,2)]

3.1.4 Logical operations

Settlement condtions may be combined using the logical operators and and or. This enables more complicated
settlement rules to be built up.
• Home wins from behind:

anytime(supremacy(<RT, goals>) < 0) and supremacy(<RT, goals>) > 0

• Either team keeps a clean sheet:

total(<RT, goals[team=home]>) = 0 or total(<RT, goals[team=away]>) = 0

The unary function not may also be used to negate a settlement condition.
• Away team never leads:

8 Chapter 3. Defining settlements


Settlement Templating Language (STL), Release 1.2

not(anytime(supremacy(<RT, goals>) < 0))

3.1.5 Literals

STL understands the following types of literals


• Integer literals e.g. 1, -3, 201
• Floating literals - must contain a decimal point e.g. 0.0, 3.14
• String literals - free text surrounded in double quotes e.g. "player_id"
• Score literals - tuples of integers e.g. (2, 1)
• Settlement literals - a pre-defined bet settlement. Bet settlements contain are of the form:

settlement(w, v)

where 𝑤, 𝑣 ∈ [0.0, 1.0] such that 𝑤 + 𝑣 ≤ 1.0. As well as the general form above we define
– win = settlement(1.0, 0.0)
– void = settlement(0.0, 1.0)
– lose = settlement(0.0, 0.0)
which are useful when defining settlements dependent on the existence of an incident.
– Home first to score:

ifExists(nth(1, <RT, goals>), i => i.team = home, lose)

– No goal before 27 minutes:

ifExists(nth(1, <RT, goals>), i => i.minute >= 27, win)

3.2 Aggregates

Aggregation functions take a statistic and perform some sort of calculation all the relevant incidents that have occured
within the specified time period.
total(statistic)
Total number of occurences of a particular statistic.
supremacy(statistic)
Supremacy (home total - away total) of a given statistic.
h2h(statistic)
Head-to-head score of a given statistic.
Using the example of the goals score beingn 2-1 during regulation time then the above functions would settle as wins
in the following scenarios
• Exactly 3 total goals:

total(<RT, goals>) = 3

• Over 1.5 goals:

3.2. Aggregates 9
Settlement Templating Language (STL), Release 1.2

asian(total(<RT, goals>)) > 1.5

• Home team wins

supremacy(<RT, goals>) > 0

• Not an away win

not(supremacy(<RT, goals>) < 0)

• 2-1 correct score:

h2h(<RT, goals>) = (2,1)

3.2.1 Altering aggregates

asian(aggregate)
Convert the resulting rules on a integer based aggregate - total, supremacy and any combination thereof -
to asian based resulting.
e.g. Home wins draw no bet:

asian(supremacy(<RT, goals>)) > 0

e.g. Over 2.25 first half corners:

asian(total(<H1, corners>)) > 2.25

anytime(settlementCondition)
Is the settlement condition met at any point within the time period rather than just at the end of the interval. e.g.
home team win from behind:

anytime(supremacy(<RT, goals>) < 0) and supremacy(<RT, goals>) > 0

3.3 Incident properties

As well as talking about the aggregation of a collection of incidents over a time period we can also refer to the nth
occurence of an incident within a time period.
nth(n, statistic)
The nth occurence of a given statistic. The count starts from 1, so the 2nd corner in the 2nd half would be given
by:

nth(2, <H2, corners>)

Conversely, you can count backwards with the last incident having n = -1, the penultimate having n = -2,
and so on. e.g. The last home goal in regular time would be:

nth(-1, <RT, goals[team=home]>)

raceTo(n, statistic)
Return the team (if it exists) who first reach a count of n occurences of a given statistic. Like nth() it may not
exist, e.g. first to 2 yellow cards:

10 Chapter 3. Defining settlements


Settlement Templating Language (STL), Release 1.2

raceTo(2, <RT, cards[type=yellow]>)

ifExists(possible :: maybe outcome, f :: outcome -> a, x :: a)


If a given incident exists then perform some operation on it such as projecting a property, otherwise produce
some static property.
• Home team scores 2nd goal or lose if no 2nd goal:

ifExists(nth(2, <RT, goals>), i => $i.team = home, lose)

• Home team win 3-way race to 5 corners in first half (lose if no-one reaches 5):

ifExists(raceTo(5, <H1, corners>), i => $i = home, lose)

• Home team win 2-way race to 5 corners in first half (void if no-one reaches 5):

ifExists(raceTo(5, <H1, corners>), i => $i = home, void)

3.3. Incident properties 11


Settlement Templating Language (STL), Release 1.2

12 Chapter 3. Defining settlements


CHAPTER

FOUR

SPORTS

13
Settlement Templating Language (STL), Release 1.2

14 Chapter 4. Sports
CHAPTER

FIVE

EXAMPLES

Market Selection STL


1 supremacy(<RT, goals>) > 0
1x2 X supremacy(<RT, goals>) = 0
2 supremacy(<RT, goals>) < 0
1 or X supremacy(<RT, goals>) >= 0
Double Chance 2 or X supremacy(<RT, goals>) <= 0
1 or 2 supremacy(<RT, goals>) <> 0
1 asian(supremacy(<RT, goals>)) > 0
Draw no Bet
2 asian(supremacy(<RT, goals>)) < 0
1 -N supremacy(<RT, goals>) > N
European Handicap X -N supremacy(<RT, goals>) = N
2 +N supremacy(<RT, goals>) < N
1 -N asian(supremacy(<RT, goals>)) > N
Asian Handicap
2 +N asian(supremacy(<RT, goals>)) < N
1 by 1 supremacy(<RT, goals>) = 1
1 by 2-3 2 <= supremacy(<RT, goals>) <= 3
1 by 4+ supremacy(<RT, goals>) >= 4
Winning Margin X supremacy(<RT, goals>) = 0
2 by 1 supremacy(<RT, goals>) = -1
2 by 2-3 -3 <= supremacy(<RT, goals>) <= -2
2 by 4+ supremacy(<RT, goals>) <= -4
Over N asian(total(<RT, goals>)) > N
Over/Under Goals
Under N asian(total(<RT, goals>)) < N
Over N total(<RT, goals>) > N
Over/Under/Exactly Goals Under N total(<RT, goals>) < N
Exactly N total(<RT, goals>) = N
0 total(<RT, goals>) = 0
Total Goals 1-2 1 <= total(<RT, goals>) <= 2
3+ 3 <= total(<RT, goals>)
Odd odd(total(<RT, goals>))
Odd/Even Total Goals
Even even(total(<RT, goals>))
1 supremacy(<H1, goals>) > 0
Half-Time Result X supremacy(<H1, goals>) = 0
2 supremacy(<H1, goals>) < 0
1/1 supremacy(<H1, goals>) > 0 and supremacy(<RT, goals>) > 0
1/X supremacy(<H1, goals>) > 0 and supremacy(<RT, goals>) = 0
1/2 supremacy(<H1, goals>) > 0 and supremacy(<RT, goals>) < 0
X/1 supremacy(<H1, goals>) = 0 and supremacy(<RT, goals>) > 0
Half-Time/Full-Time Result X/X supremacy(<H1, goals>) = 0 and supremacy(<RT, goals>) = 0

15
Settlement Templating Language (STL), Release 1.2

Table 5.1 – continued from previous page


Market Selection STL
X/2 supremacy(<H1, goals>) = 0 and supremacy(<RT, goals>) < 0
2/1 supremacy(<H1, goals>) < 0 and supremacy(<RT, goals>) > 0
2/X supremacy(<H1, goals>) < 0 and supremacy(<RT, goals>) = 0
2/2 supremacy(<H1, goals>) < 0 and supremacy(<RT, goals>) < 0
Over N asian(total(<RT, goals[team=home]>)) > N
Home Over/Under Goals
Under N asian(total(<RT, goals[team=home]>)) < N
0-0 h2h(<RT, goals>) = (0,0)
1-0 h2h(<RT, goals>) = (1,0)
Correct Score 0-1 h2h(<RT, goals>) = (0,1)
1-1 h2h(<RT, goals>) = (1,1)
X-Y h2h(<RT, goals>) = (X,Y)
1-0 anytime(h2h(<RT, goals>) = (1,0))
0-1 anytime(h2h(<RT, goals>) = (0,1))
Anytime Correct Score
1-1 anytime(h2h(<RT, goals>) = (1,1))
X-Y anytime(h2h(<RT, goals>) = (X,Y))
Yes total(<RT, goals[team=home]>) > 0 and total(<RT, goals[team=away]>) > 0
Both Teams to Score
No total(<RT, goals[team=home]>) = 0 or total(<RT, goals[team=away]>) = 0
1 anytime(supremacy(<RT, goals>) < 0) and supremacy(<RT, goals>) > 0
Win from Behind
2 anytime(supremacy(<RT, goals>) > 0) and supremacy(<RT, goals>) < 0
1 supremacy(<RT, goals>) > 0 and total(<RT, goals[team=away]>) = 0
Win to Nil
2 supremacy(<RT, goals>) < 0 and total(<RT, goals[team=home]>) = 0
1 supremacy(<H1, goals>) > 0 and supremacy(<H2, goals>) > 0
Win Both Halves
2 supremacy(<H1, goals>) < 0 and supremacy(<H2, goals>) < 0
1 supremacy(<H1, goals>) > 0 or supremacy(<H2, goals>) > 0
Win Either Half
2 supremacy(<H1, goals>) < 0 or supremacy(<H2, goals>) < 0
1st total(<H1, goals>) > total(<H2, goals>)
Highest Scoring Half 2nd total(<H1, goals>) < total(<H2, goals>)
Tie total(<H1, goals>) = total(<H2, goals>)
1 ifExists(nth(1, <RT, goals>), i => $i.team = home, lose)
First Team to Score No Goal total(<RT, goals>) < 1
2 ifExists(nth(1, <RT, goals>), i => $i.team = away, lose)
1 ifExists(nth(N, <RT, goals>), i => $i.team = home, lose)
Nth Team to Score No Goal total(<RT, goals>) < N
2 ifExists(nth(N, <RT, goals>), i => $i.team = away, lose)
1 ifExists(nth(-1, <RT, goals>), i => $i.team = home, lose)
Last Team to Score No Goal total(<RT, goals>) < 1
2 ifExists(nth(-1, <RT, goals>), i => $i.team = away, lose)
1 ifExists(raceTo(N, <RT, goals>), i => $i = home, lose)
Race to N Goals No Goal total(<RT, goals[team=home]>) < N and total(<RT, goals[team=away]>) < N
2 ifExists(raceTo(N, <RT, goals>), i => $i = away, lose)
1 ifExists(raceTo(N, <RT, goals>), i => $i = home, void)
Two-way Race to N Goals
2 ifExists(raceTo(N, <RT, goals>), i => $i = away, void)
Nth Player to Score ID ifExists(nth(N, <RT, goals>), i => $i.player = ‘ID’, lose)
Nth Home Player to Score ID ifExists(nth(N, <RT, goals[team=home]>), i => $i.player = ‘ID’, lose)
Player to Score At Least N ID total(<RT, goals[player=‘ID’]>) >= N
ID/1 total(<RT, goals[player=‘ID’>) >= 1 and supremacy(<RT, goals>) > 0
Player to Score and Team to Win
ID/2 total(<RT, goals[player=‘ID’>) >= 1 and supremacy(<RT, goals>) < 0
Yes total(<RT, cards[type=red]>) > 0
Player to be Sent Off
No total(<RT, cards[type=red]>) = 0
1 ifExists(winner(*), t => $t = home, lose)
Team to Qualify

16 Chapter 5. Examples
Settlement Templating Language (STL), Release 1.2

Table 5.1 – continued from previous page


Market Selection STL
2 ifExists(winner(*), t => $t = away, lose)
Yes ifExists(phase(PS), p => win, lose)
Will There be Penalties?
No ifExists(phase(PS), p => lose, win)
1/RT ifExists(winner(*), t => $t = home, lose) and ifExists(phase(ET), p => lose, win) and
1/ET ifExists(winner(*), t => $t = home, lose) and ifExists(phase(ET), p => win, lose) and
1/PS ifExists(winner(*), t => $t = home, lose) and ifExists(phase(PS), p => win, lose)
Method of Qualification
2/RT ifExists(winner(*), t => $t = away, lose) and ifExists(phase(ET), p => lose, win) and
2/ET ifExists(winner(*), t => $t = away, lose) and ifExists(phase(ET), p => win, lose) and
2/PS ifExists(winner(*), t => $t = away, lose) and ifExists(phase(PS), p => win, lose)

17
Settlement Templating Language (STL), Release 1.2

18 Chapter 5. Examples
INDEX

A
anytime() (built-in function), 10
asian() (built-in function), 10

E
even() (built-in function), 7

H
h2h() (built-in function), 9

I
ifExists() (built-in function), 11

N
nth() (built-in function), 10

O
odd() (built-in function), 7

R
raceTo() (built-in function), 10

S
supremacy() (built-in function), 9

T
total() (built-in function), 9

19

You might also like