structural typing for structured products
play

Structural Typing for Structured Products Tim Williams Peter Marks - PowerPoint PPT Presentation

Structural Typing for Structured Products Tim Williams Peter Marks 8th October 2014 Background The FPF Framework A standardized representation for describing payoffs A common suite of tools for trades which use this representation


  1. Structural Typing for Structured Products Tim Williams Peter Marks 8th October 2014

  2. Background The FPF Framework • A standardized representation for describing payoffs • A common suite of tools for trades which use this representation • UI for providing trade parameters • Mathematical document descriptions • Pricing and risk management • Barrier analysis • Payments and other lifecycle events 1

  3. FPF Lucid • A DSL for describing exotic payoffs and strategies • Control constructs based around schedules • Produces abstract syntax–allowing multiple interpretations • Damas-Hindley-Milner type inference with constraints and polymorphic extensible row types 2

  4. Lucid type system Structural typing with Row Polymorphism Lucid language Articulation driven design 3

  5. Lucid language Lucid type system Articulation driven design Structural typing with Row Polymorphism 4

  6. Monomorphic exp : Double Double x : Double exp x : Double A simple numeric expression exp ( x ) 5

  7. A simple numeric expression Monomorphic exp : Double → Double exp ( x ) x : Double exp ( x ) : Double 6

  8. Polymorphic if _ then _ else _ : Bool, , c : Bool x : y : if c then x else y : • Hindley-Milner type system A conditional expression if c then x else y 7

  9. A conditional expression Polymorphic if _ then _ else _ : ( Bool, a , a ) → a if c then x else y c : Bool x : a y : a if c then x else y : a • Hindley-Milner type system 8

  10. Overloaded numeric literal x + 42 9

  11. Overloaded numeric literal Subtyping x + 42 ( + ) : ( Num, Num ) → Num 42 : Integer x : Num x + 42 : Num • Subtyping constraints difficult to solve with full inference • A complex extension to Hindley-Milner 10

  12. Overloaded numeric literal Polymorphic with type variable constraints x + 42 ( + ) : Num a ⇒ ( a , a ) → a 42 : Num a ⇒ a x : Num a ⇒ a x + 42 : Num a ⇒ a • Any type variable can have a single constraint • Unifier ensures constraints are met • Simple extension to Hindley-Milner 11

  13. • Not obvious which argument when applying function capFloor : Num , , capFloor perf, 0, 1 A simple Lucid function function capFloor ( perf, cap, floor ) return max ( floor, min ( cap, perf )) end 12

  14. • Not obvious which argument when capFloor perf, 0, 1 applying function A simple Lucid function function capFloor ( perf, cap, floor ) capFloor : Num a ⇒ ( a , a , a ) → a return max ( floor, min ( cap, perf )) end 13

  15. A simple Lucid function function capFloor ( perf, cap, floor ) capFloor : Num a ⇒ ( a , a , a ) → a return max ( floor, min ( cap, perf )) end • Not obvious which argument when capFloor ( perf, 0, 1 ) applying function 14

  16. • Don’t want to force users to define data types • Don’t want to force users to name a combination of fields • Want to use the same fields in different data types Records via Nominal typing data Num CapFloor = CapFloor cap : , floor : capFloor : Num , CapFloor Grouping and labelling arguments function capFloor ( perf, { cap, floor } ) return max ( floor, min ( cap, perf )) end 15

  17. • Don’t want to force users to define data types • Don’t want to force users to name a combination of fields • Want to use the same fields in different data types Grouping and labelling Records via Nominal typing arguments data Num a ⇒ CapFloor a = CapFloor function capFloor ( perf, { cap, floor } ) { cap : a , floor : a } return max ( floor, min ( cap, perf )) end capFloor : Num a ⇒ ( a , CapFloor a ) → a 16

  18. • Don’t want to force users to name a combination of fields • Want to use the same fields in different data types Grouping and labelling Records via Nominal typing arguments data Num a ⇒ CapFloor a = CapFloor function capFloor ( perf, { cap, floor } ) { cap : a , floor : a } return max ( floor, min ( cap, perf )) end capFloor : Num a ⇒ ( a , CapFloor a ) → a • Don’t want to force users to define data types 17

  19. • Want to use the same fields in different data types Grouping and labelling Records via Nominal typing arguments data Num a ⇒ CapFloor a = CapFloor function capFloor ( perf, { cap, floor } ) { cap : a , floor : a } return max ( floor, min ( cap, perf )) end capFloor : Num a ⇒ ( a , CapFloor a ) → a • Don’t want to force users to define data types • Don’t want to force users to name a combination of fields 18

  20. Grouping and labelling Records via Nominal typing arguments data Num a ⇒ CapFloor a = CapFloor function capFloor ( perf, { cap, floor } ) { cap : a , floor : a } return max ( floor, min ( cap, perf )) end capFloor : Num a ⇒ ( a , CapFloor a ) → a • Don’t want to force users to define data types • Don’t want to force users to name a combination of fields • Want to use the same fields in different data types 19

  21. • Unifier is agnostic to field order capFloor perf, cap=0, floor=1 capFloor perf, floor=1, cap=0 • Note the above is still not quite what Lucid infers • Pattern matching is just syntactic sugar for field selection Grouping and labelling Structural record types arguments capFloor : Num a ⇒ function capFloor ( perf, { cap, floor } ) ( a , { cap : a , floor : a } ) → a return max ( floor, min ( cap, perf )) end 20

  22. • Note the above is still not quite what Lucid infers • Pattern matching is just syntactic sugar for field selection Grouping and labelling Structural record types arguments capFloor : Num a ⇒ function capFloor ( perf, { cap, floor } ) ( a , { cap : a , floor : a } ) → a return max ( floor, min ( cap, perf )) end • Unifier is agnostic to field order capFloor ( perf, { cap=0, floor=1 } ) capFloor ( perf, { floor=1, cap=0 } ) 21

  23. • Pattern matching is just syntactic sugar for field selection Grouping and labelling Structural record types arguments capFloor : Num a ⇒ function capFloor ( perf, { cap, floor } ) ( a , { cap : a , floor : a } ) → a return max ( floor, min ( cap, perf )) end • Unifier is agnostic to field order capFloor ( perf, { cap=0, floor=1 } ) capFloor ( perf, { floor=1, cap=0 } ) • Note the above is still not quite what Lucid infers 22

  24. Grouping and labelling Structural record types arguments capFloor : Num a ⇒ function capFloor ( perf, r ) ( a , { cap : a , floor : a } ) → a return max ( floor, min ( r.cap, r.perf )) end • Unifier is agnostic to field order capFloor ( perf, { cap=0, floor=1 } ) capFloor ( perf, { floor=1, cap=0 } ) • Note the above is still not quite what Lucid infers • Pattern matching is just syntactic sugar for field selection 23

  25. • How do we allow a superset of fields to be passed to CapFloor? • Subtyping would require a new type system and inference algorithm • Can use parametric polymorphism by using a type variable to represent the remaining fields Ignoring additional fields function kgcf ( perf, r ) return capFloor ( r.part * ( perf - r.strike ) , { cap = r.cap, floor = r.floor } ) end kgcf ( perf, { part=1, strike=0.9, cap=0, floor=1.2 } ) 24

  26. • How do we allow a superset of fields to be passed to CapFloor? • Subtyping would require a new type system and inference algorithm • Can use parametric polymorphism by using a type variable to represent the remaining fields Ignoring additional fields function kgcf ( perf, r ) return capFloor ( r.part * ( perf - r.strike ) , r ) end kgcf ( perf, { part=1, strike=0.9, cap=0, floor=1.2 } ) 25

  27. • Subtyping would require a new type system and inference algorithm • Can use parametric polymorphism by using a type variable to represent the remaining fields Ignoring additional fields function kgcf ( perf, r ) return capFloor ( r.part * ( perf - r.strike ) , r ) end kgcf ( perf, { part=1, strike=0.9, cap=0, floor=1.2 } ) Structural Record types capFloor : Num a ⇒ ( a , { cap : a , floor : a } ) → a kgcf : Num a ⇒ ( a , { part : a , strike : a , cap : a , floor : a } ) → a • How do we allow a superset of fields to be passed to CapFloor? 26

  28. • Can use parametric polymorphism by using a type variable to represent the remaining fields Ignoring additional fields function kgcf ( perf, r ) return capFloor ( r.part * ( perf - r.strike ) , r ) end kgcf ( perf, { part=1, strike=0.9, cap=0, floor=1.2 } ) Structural Record types capFloor : Num a ⇒ ( a , { cap : a , floor : a } ) → a kgcf : Num a ⇒ ( a , { part : a , strike : a , cap : a , floor : a } ) → a • How do we allow a superset of fields to be passed to CapFloor? • Subtyping would require a new type system and inference algorithm 27

  29. Ignoring additional fields function kgcf ( perf, r ) return capFloor ( r.part * ( perf - r.strike ) , r ) end kgcf ( perf, { part=1, strike=0.9, cap=0, floor=1.2 } ) Polymorphic extensible Records capFloor : Num a ⇒ ( a , { cap : a , floor : a | r } ) → a kgcf : Num a ⇒ ( perf, { part : a , strike : a , cap : a , floor : a | s } ) → a • How do we allow a superset of fields to be passed to CapFloor? • Subtyping would require a new type system and inference algorithm • Can use parametric polymorphism by using a type variable to represent the remaining fields 28

Recommend


More recommend