Composing
contracts
An adventure in financial engineering
Simon Peyton Jones and Julian Seward,
Microsoft Research
and
Jean Marc Eber, LexiFi Technologies
The big picture
Financial engineering
Programming language
design and implementation
Jean Marc
Simon
and
Julian
The big picture
Financial engineering
Programming language
design and implementation
Jean Marc
Simon
and
Julian
Swaps, caps, options, european, bermudan, straddle, floors, swaptions, swallows, spreads, futures
Combinatorlibrary
Denotational semantics
Operational semantics
What we want to do
Precise description of
a contract
Scheduling for back office
Valuation and hedging
Legal and documentation
What we want to do
Precise description of
a pudding
Compute sugar content
Estimate time to make
Instructions to make
it
What we want to do
Precise description of
a pudding
Compute sugar content
Estimate time to make
Instructions to make
it
Bad approach
List all puddings (trifle, lemon upside down pudding, Dutch apple cake, Christmas pudding) For each pudding, write down sugar content, time to make, instructions etcWhat we want to do
Precise description of
a pudding
Compute sugar content
Estimate time to make
Instructions to make
it
Good approach
Define a small set of 00b>pudding combinators00/font> Define all puddings in terms of these combinators Calculate sugar content from these combinators tooCreamy fruit salad
On top of
Take
Whipped
1 pint
Cream
Mixture
Take
Chopped
3
Apples
Take
6
Oranges
Optional
Combinators combine small puddings into bigger puddings
Trees can be written
as text
On top of
Take
Whipped
1 pint
Cream
Mixture
Take
Chopped
3
Apples
Take
6
Oranges
Optional
salad = onTopOf topping main_part
topping = whipped (take pint cream)
main_part = mixture apple_part orange_part
apple_part = chopped (take 3 apple)
orange_part = optional (take
6 oranges)
Notation:
parent child1 child2 function arg1 arg2Slogan: a domain-specific language for describing puddings
Building a simple contract
c1 :: Contract
c1 = zcb (date 00 Jan 201000
100 Pounds
zcb :: Date -> Float -> Currency -> Contract
-- Zero coupon bond
00eceive 拢100 on
1 Jan 201000/font>
Combinators will appear in blue boxes
Combing contracts
c1,c2,c3 :: Contract
c1 = zcb (date 00 Jan 201000 100 Pounds
c2 = zcb (date 00 Jan 201100
100 Pounds
c3
= and c1 c2
and :: Contract -> Contract -> Contract
-- Both c1 and c2
and
zcb
t1 100 Pounds
zcb
t2 100 Pounds
c1
c2
c3
Inverting a contract
and
zcb
t1 100 Pounds
zcb
t2 100 Pounds
give :: Contract -> Contract
-- Invert role of parties
c4
= c1 `and` give c2
give
c2
c4
c1
Backquotes for infix notation
New combinators from
old
andGive :: Contract -> Contract -> Contract
andGive u1 u2 = u1 `and` give
u2
Defining zcb
Indeed, zcb is not primitive:
zcb :: Date -> Float -> Currency -> Contract
zcb t f k = at t (scaleK f (one
k))
one :: Currency -> Contract
-- Receive one unit of currency immediately
scaleK :: Float -> Contract -> Contract
-- Acquire specified number
of contracts
at :: Date -> Contract -> Contract
-- Acquire the contract at specified date
Acquisition dates
one :: Currency -> Contract
-- Receive one unit of currency
immediately
at :: Date -> Contract -> Contract
-- Acquire the underlying contract
at specified date
Choice
An option gives the flexibility to
Choose which contract to acquire (or, as a special case, whether to acquire a contract) Choose when to acquire a contract(exercising the option = acquiring the underlying contract)
Choose which
or :: Contract -> Contract -> Contract
-- Acquire either c1 or c2 immediately
zero :: Contract
-- A worthless contract
european :: Date -> Contract -> Contract
european t u = at t (u `or`
zero)
Reminder00/font>
Remember that the underlying contract
is arbitrary
c5 :: Contract
c5 = european t1 (european t2
c1)
This is already beyond what current systems can handle
Choose when:
American options
anytime :: Contract -> Contract
-- Acquire the underlying contract at
-- any time before it expires (but
-- you must acquire it)
golden_handcuff
= anytime shares
shares = zero `or` (scaleK -100 (one Dollar) `and`
scaleK 10 (one MSShare))
anytime: Choose when
MS shares are a 00urrency00/font>
or: Choose whether
Setting the window
golden_handcuff
= at
t1
(anytime (truncate
t2
shares))
truncate :: Date -> Contract -> Contract
-- Truncate the horizon of
a contract
at :: Date -> Contract -> Contract
-- Acquire the underlying contract
at specified date
Can00
acquire shares after t2
Acquire the anytime rights at t1
Observables
Pay me $1000 * (the number of inches
of snow - 10) on 1 Jan 2002
c :: Contract
c = at 00 Jan 200200(scale
scale_factor (one Dollar))
scale_factor :: Observable
scale_factor = 1000 * (snow
- 10)
scale :: Observable -> Contract -> Contract
-- Scale the contract by the value of the observable
-- at the moment of acquisition
snow :: Observable
(*), (-) :: Observable -> Observable -> Observable
Summary so far
But what does it all
mean?
Processing puddings
S(onTopOf p1 p2) = S(p1) + S(p2)
S(whipped p) = S(p)
S(take q i) = q * S(i)
00tc00/font>
Processing puddings
S(onTopOf p1 p2) = S(p1) + S(p2)
S(whipped p) = S(p)
S(take q i) = q * S(i)
00tc00/font>
S is compositional
To compute S for a compound pudding,
Compute S for the sub-puddings Combine the results in some combinator-dependent wayWhat is the denotation
of a contract?
What is the denotation
of a contract?
Main idea: the denotation
of a contract is a random
process that models the value
of acquiring the contract at that moment.
00/b> : Contract -> RandomProcess
RandomProcess = Time -> RandomVariable
Uncertainty increases with time
Time
Compositional valuation
00/b>(c1 `and` c2) = 00/b> (c1) + 00/b> (c2)
00/b>(c1 `or` c2) = max(00/b>(c1), 00/b>(c2) )
00/b>(give c) = - 00/b> (c)
00/b>(anytime c) = snell( 00/b>(c) )
00/b>(at t c) = discount( 00/b>(c)[t] )
00tc00/font>
Add random processes point-wise
Valuation
Contract
Model of world
(e.g. interest rates)
Valuation engine
One possible evaluation
model: BDT
contract C
5%
6%
4%
zcb
3 100 Pounds
interest rate model M
100
100
95
Value tree 00/b>(C)
Valuation engine
100
100
0
1
2
3
Space and time
at
t
t
simple discounting
Haskell to the rescue
00azy evaluation00means that
data structures are computed incrementally, as they are needed (so the trees never exist in memory all at once) parts that are never needed are never computedSlogan
We think of the tree as a first class value 00ll at once00/font>
but it is only materialised 00iecemeal00/font>
An operational semantics
e.g. zcb t1 n k `and` zcb t2 n k
Want to value your current contract 00ook00/font> So we want to say formally how a contract, or group of contract evolves with time, and how it interacts with its environment (e.g. emit cash, make choice) Work on the operational semantics of programming languages is directly relevant (e.g. bisimulation)Reasoning about equivalence
anytime (anytime c) = anytime c
Depends on algebra of random processes (snell, discount, etc). Bring on the mathematicians!
A compiler for contracts
Contract
Take semantics
Random process
Transform using algebraic
laws
Code generation
Valuation program
A compiler for contracts
Contract
Take semantics
Random process
Code generation
Valuation program
Evolve using operational semantics
Summary
Routine for us, radical stuff for financial engineers
Summary
Routine for us, radical stuff for financial engineers
download Compositional description and valuation of financial contracts
