Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Release 2.0
Algosport
i
ii
CHAPTER
ONE
INTRODUCTION
STL (Settlement Templating Language) is a domain-specific language used to define sporting formats and settlement
rules in sports betting.
Formats define the rules, progression and incidents that occur with a sporting contest, e.g.
• Football with regular time, extra-time and a penalty shootout may have goals, cards, corners, offsides, etc.
• 3-set tennis with a tie-break in each set is a nested collection of sets, games and points.
• NBA basketball consists of two halves of two quarters and repeating over-time periods if necessary. 1-, 2- and
3-point shots may be scored and fouls recorded.
Rules define how a selection should be settled within a given sporting format. For example, winner(*) ?= vs1,
is a winning selection when the first competitor wins the contest, however what it means to win the contest will depend
upon the sporting format.
Pricing of selections is achieved by attaching an algorithmic model to a format and running STL rules against it.
1.1.1 Productivity
1.1.2 Extensible
STL rules are incredibly flexible. Letting customers combine and manipulate those rules over the liftime of a bet
brings a wealth of new potential products and user experiences.
• Bet builder allows customers to create their own individual bets by combining pre-existing selections. If selec-
tions 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
1
Settlement Templating Language (STL), Release 2.0
then we only need to request the price for the combined selection
and
• Cash out is a special case of bet editor where all selections are removed from the initial bet.
2 Chapter 1. Introduction
CHAPTER
TWO
PRIMITIVES TYPES
2.1.1 Integers
2.1.2 Reals
2.2 Strings
2.4 Enumerations
An enumeration is some named type which may take one of a list of possible values. For example, the enumeration
type, card-type, with possible values yellow, yellow2 and red, is defined as
3
Settlement Templating Language (STL), Release 2.0
2.4.1 Side
A side is one of the two competitors within a contest. It is defined as the enumeration:
2.4.2 None
The none type is used to augment another type with the lack of a value, e.g. a goal with no assist, and is defined as the
enumeration:
2.4.3 Unknown
The unknown type is used to augment another type when its value is not known at all, e.g. if it is unknown which
player on particular side received a card, an is defined as the enumeration:
2.5 Head-to-head
A head-to-head records the total of some incident group for each side.
Values are represented as (m, n) with m and n both being integer numbers, e.g. (1,0) or (12, 28).
2.6 Settlements
A settlement, ⟨𝑤, 𝑣⟩, contains a winning part, 𝑤, and voiding part, 𝑣, such that
• 0≤𝑤≤1
• 0≤𝑣≤1
• 0≤𝑤+𝑣 ≤1
A bet struck at odds, 𝑜, with stake, 𝑠, and settled at ⟨𝑤, 𝑣⟩ will have payout, 𝑝, given by
𝑝=𝑜·𝑠·𝑤+𝑠·𝑣
Settlement values are represented as in the functional form settled(w, v) taking a real valued winning part, w,
and a real valued voiding part, v, with restrictions as above.
The aliases
win = settled(1,0)
void = settled(0,1)
lose = settled(0,0)
2.7 Collections
2.7.1 Sets
2.7.2 Intervals
Mathematical interval notation is used to denote the set of values between two endpoints.
• [a,b] denotes {𝑥 | 𝑎 ≤ 𝑥 ≤ 𝑏}
• [a,b) denotes {𝑥 | 𝑎 ≤ 𝑥𝑏}
• (a,b] denotes {𝑥 | 𝑎𝑥 ≤ 𝑏}
• (a,b] denotes {𝑥 | 𝑎𝑥𝑏}
For finite sets of this form interval notation provides a succinct way to express the possible values without having to
explicitly enumerate them in a set literal.
2.7.3 Records
record incident =
{ group: identifier
}
record extended =
{ extra-key-1: type-1
, extra-key-2: type-2
. ...
| original
}
which adds two extra keys, extra-key-1 and extra-key-2, with types, type-1 and type-2, respectively, to
the previously defined original record type.
For example, the match-play-incident type extends the incident type above
record match-play-incident =
{ winner: side
| incident
}
2.7. Collections 5
Settlement Templating Language (STL), Release 2.0
which is equivalent to
record match-play-incident =
{ group: identifier
, winner: side
}
record card =
{ player: unknown | string
, assist: unknown | none | string
| incident
}
which has a player attribute that must be scored by some potentially unknown player and an potential assist
attribute that may or may not be known.
Time periods and instants in STL are represented as a path comprised of path segments that are dependent on the
format of the contest they refer to.
• 10 minutes into the second half, /H2/10:00.
• The first three games of the 2nd set, /sets[2]/[start,games[3]/end].
• 2nd and 3rd quarters, [Q2/start, Q3/end].
• Time of 3rd yellow card in regulation time, RT/cards{type=yellow}[3].
A path may refer to an interval or a single instant of time dependent on the final segment of the path.
References
References give a phase independent way of refering to common instants and intervals of a phase. The valid values
are:
• start: the start of a phase.
• end: the end of a phase.
• now: the current time in a phase. Equal to start before the phase begins and end after it has completed.
• remaining: the remaining time within a phase. A synonym for [start, end].
• *: the entirety of a phase. Usually only used to represent the entire contest.
A clock time, found within a timed phase is always represented in the format [±]m:ss[.ssssss].
• [±] is an optional plus (the default) or minus signifying whether the clock is counting from the start or the end
of the period, respectively.
• m refers to non-negative minutes.
• ss refers to zero-padded seconds in the interval [00, 59].
• [.ssssss] refers to optional microseconds.
Negative clock times are always assumed to count back from the least possible duration of the period they belong to,
e.g. even though the 1st half of football may run longer than 45 minutes we convert a clock time of -2:00 in the 1st
half to 43:00 and -5:00 in 90 minute regulation time to 85:00. It is unusual to require a negative clock time but it
does allow for some settlement rules to be defined in a format independent manner. Team to win the last ten minutes
could be defined for 90 minute and 80 minute football formats if only the period lengths change.
Phase segments
Phase segements directly reference the format and incidents of a contest, e.g. regulation time, sets, goals, innings.
Each such segment may optionally be filtered or indexed.
A filter applies some restriction to the set of incidents that are considered when creating the path and take the
form of a record instance.For example, if we only want to consider the games that player 1 serves, we may write
games{server=vs1}.
An index consider the progression of incidents. We can reference the nth incident from the start using positive indices
and from the end using negative indices.
• frames[-2]: penultimate frame.
• innings[4]: 4th innings.
Explicit intervals
THREE
FORMATS
Each sporting contest within the STL framework requires a format. The format defines both
1. the structure and progression of passages of play, or phases; and
2. the incidents that may occur during or as a result of one of these passages of play.
Note: It is not possible to construct your own format in STL at present, but the following section gives a better
understanding of how phases and incidents interact when building STL rules.
Contests in STL are organised into a progression of structural phases which are also organised into a progression of
structural phases. They form the basis around which the rules are defined and determine what kinds of incidents can
occur during each phase of play.
• Football has regulation time, comprised of two halves, potentially followed by extra time and possibly penalties.
• 3-set tennis has sets 1, 2 and 3 follow each other with each set being comprised of a progression of games each
consisiting of a progression of points.
• Post-season ice hockey has regulation time, comprised of three periods, potentially followed by one or more
over time periods.
Note: Exact clocks don’t require the period ends as soon as the clock reaches that time. This is the case in
some sports, e.g. ice hockey, but not in others, e.g. basketball and american football, where a final act or play is
allowed to run until completion.
• A period group contains multiple timed phases, i.e. a collection of single periods and period groups.
Common conventions for naming timed phases include
9
Settlement Templating Language (STL), Release 2.0
Examples
1. Football
• Regulation time, RT, consists of two halves, H1 and H2, of at least 45 minutes:
RT [ H1 >= 45:00
, H2 >= 45:00
]
• Extra time, ET, consists of two halves, ET1 and ET2, of at least 15 minutes:
2. Ice hockey
• Regulation time, RT, consists of three periods, P1, P2 and P3, of exactly 20 minute duration:
RT [ P1 = 20:00
, P2 = 20:00
, P3 = 20:00
]
OT = 5:00
The possibility of the period ending early due to a goal is not represented here.
• Play-off overtime, OT, consists of (a potentially repeated) period of 20 minute duration:
OT = 20:00
The possible early ending of the period due to a goal and the repetition of the period is not represented here.
3. Basketball
• Regulation time, RT, consists of two halves, H1 and H2, each consisting of two quarters, Q1 and Q2, and
Q3 and Q4, respectively, each lasting 12 minutes:
RT [ H1 [ Q1 = 12:00
, Q2 = 12:00
]
, H2 [ Q3 = 12:00
(continues on next page)
10 Chapter 3. Formats
Settlement Templating Language (STL), Release 2.0
Match play phases are those that competitors play to win from one another.
• Points, games and sets in tennis
• Legs and sets in darts
• Frames in snooker
• Holes in match play golf
• Contests in a play-off series, e.g. NBA play-offs and MLB post-season
Dependent on the sport it may or may not be able to draw a match play phase, e.g. golf match-play and tennis games,
respectively.
Match play phases that award the same result to the winner don’t necessarily have the same internal structure.
• A set of tennis may have advantage games up until a score of 6-6 and then play a tie-break game.
• The final set of tennis and volleyball contests often have different rules to the previous sets.
To accomodate this, each match play phase is assigned to a group which determines the incident type that is awarded
when that phase is won. Differences in the rules of play are determined by a match play phase’s subgroup.
3.2 Incidents
An incident in STL records a change in state at some given instant in a contest, e.g. a free-throw being scored, a
yellow card being given to a player or a table-tennis set being won.
Each incident has a mandatry group attribute, e.g. games, cards, legs or sets.
The incident will also carray attributes relating to the structural phase the incident occurred in as well as any other
incident specific metadata. Any attributes that are unknown may be omitted from an incident record.
• A timed incident is generated during a timed phase. It records the clock time of the incident in a time attribute.
type timed-incident =
{ time: clock-time
| incident
}
type goal =
{ side: side
, player: unknown | none | playerId
, assist: unknown | playerId
, method: unknown | goal-method
| timed-incident
}
3.2. Incidents 11
Settlement Templating Language (STL), Release 2.0
{ group: goals
, time: RT/13:00
, side: vs2
, player: 'Kane'
, assist: none
, method: unknown
}
{ group: goals
, time: H1/46:15
, side: vs1
, player: none
, assist: 'Robertson'
, method: shot
}
• A match play incident is generated when a match play phase completes. It will include a winner attribute,
any appropriate state inherited from the phase and any other metadata that may be attached.
type match-play-incident =
{ winner: side
| incident
}
{ group: games
, subgroup: advantage
, winner: vs1
, server: vs2
}
– A snooker frame
{ group: frames
, winner: vs1
, breakOff: unknown
, score: (147,4)
}
3.3.1 Football
Incidents
• Incidents
12 Chapter 3. Formats
Settlement Templating Language (STL), Release 2.0
record goals =
{ team: side
, player: unknown | string
, method: unknown | goal-method
| timed-incident
};
record cards =
{ team: side
, player: unknown | string
, type: unknown | card-type
| timed-incident
}
record corners =
{ team: side
| timed-incident
}
• Phases
– Regulation time, RT, consists of two halves, H1 and H2, of at least 45 minutes
RT [ H1 >= 45:00
, H2 >= 45:00
]
14 Chapter 3. Formats
CHAPTER
FOUR
RULES
STL rules are used to define individual settlement rules for a contest.
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
• Booking points
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
15
Settlement Templating Language (STL), Release 2.0
even(total(<RT, goals>))
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
not(settlement)
Returns the opposite settlement.
• Away team never leads
16 Chapter 4. Rules
Settlement Templating Language (STL), Release 2.0
4.2 Samples
Samples form the basis of all settlement rules in STL. They are expressed as a pair, <time interval, incident
group>. See the sections on times, formats and incidents for more information on each component.
• <H1, goals{side=vs1}>: home team goals in the 1st half.
• <*, sets>: sets in the entire contest.
• <sets[3]/games[4], points{win-method=ace}>: aces in the 4th game of the 3rd set.
4.3 Aggregates
Aggregation functions take a sample and perform a calculation over all the relevant incidents that have occured within
the specified time period.
total(sample)
Total number of occurences of a particular sample.
supremacy(sample)
Supremacy (vs1 total - vs2 total) of a given sample.
h2h(sample)
Head-to-head score of a given sample.
winner(sample)
Three-way result of given sample - vs1, vs2 or none.
Using the example of the goals score being 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
asian(aggregate)
Convert the resulting rules on a integer based aggregate - total, supremacy and any combination thereof -
to asian based resulting.
4.2. Samples 17
Settlement Templating Language (STL), Release 2.0
anytime(rule)
Does the settlement rule iwin at any point within the time period rather than just at the end.
• home team scores first
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, sample)
The nth occurence of a given incident within a sample. The count starts from 1, so the 2nd corner in the 2nd
half would be given by
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
firstTo(n, sample)
Return the side (if it exists) who first reach a count of n occurences of a given sample. Like nth() it may not
exist, e.g. first to 2 yellow cards
raceTo(n, sample)
A synonym for firstTo().
ifExists(possible :: none | x, onExists :: x -> a, onNone :: 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
18 Chapter 4. Rules
Settlement Templating Language (STL), Release 2.0
• Home team win 3-way race to 5 corners in first half (lose if no-one reaches 5)
• Away team win 2-way race to 5 corners in first half (void if no-one reaches 5)