Name Chris Marshall @oxbow_lakes GSA Capital Partners LLP March 2012 Private & Confidential. Not for distribution. GSA Capital Partners LLP is authorised and regulated by the Financial Services Authority. Registered in England & Wales. Stratton House, 5 Stratton Street, London, W1J 8LA. Number OC309261
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
NameChris Marshall @oxbow_lakes
GSA Capital Partners LLPMarch 2012
Private & Confidential. Not for distribution. GSA Capital Partners LLP is authorised and regulated by the Financial Services Authority.
Registered in England & Wales. Stratton House, 5 Stratton Street, London, W1J 8LA. Number OC309261
Building Financial Systems in Scala
3
Mathematics Degree
Working in financial software since 1999
• Smalltalk for ~6 months
• Java thereafter
• Scala since Dec 2008
JP Morgan for 6 years
• ~200,000 employees
GSA Capital for 5 ¾ years
• Quant hedge fund
• ~90 employees
Backgroundwho am i
Private & Confidential. Not for distribution. GSA Capital Partners LLP is authorised and regulated by the Financial Services Authority. Registered in England & Wales. Stratton House, 5 Stratton Street, London, W1J 8LA. Number OC309261
GSAWhat do we do? Roughly half the company are technologists
Private & Confidential. Not for distribution. GSA Capital Partners LLP is authorised and regulated by the Financial Services Authority. Registered in England & Wales. Stratton House, 5 Stratton Street, London, W1J 8LA. Number OC309261
5
Fragmentation / Diversity
• Vertical business silos (Equity, fixed-income etc)
Java
• Widespread adoption in the first decade of this century
Willing to try new technologies
• Even in large organizations
• Potentially driven by M & A
Financial ITDoes financial IT differ from IT elsewhere?
Private & Confidential. Not for distribution. GSA Capital Partners LLP is authorised and regulated by the Financial Services Authority. Registered in England & Wales. Stratton House, 5 Stratton Street, London, W1J 8LA. Number OC309261
Financial IT nowWhere do we find ourselves in 2012?
Private & Confidential. Not for distribution. GSA Capital Partners LLP is authorised and regulated by the Financial Services Authority. Registered in England & Wales. Stratton House, 5 Stratton Street, London, W1J 8LA. Number OC309261
Straw Poll
val mustReport = trades filter (uncoveredShort ∨ exceedsDollarMax)
val european = { val Europe = (_ : Market).exchange.country.region == Region.EU trades filter (_.market ∈: Europe)}
scala> val fibs: Stream[Int] = 0 #:: 1 #:: (fibs zip fibs.tail map { case (x, y) => x + y })fibs: Stream[Int] = Stream(0, ?)
• Function types (A ⇒ B) built in to the language, including closures
• Pattern matching and ADTs
• Fully-immutable collections library
• Syntactic support for monads and functors (for-comprehensions)
• Lazy evaluation (optional)
• Everything is an expression
– That goes for if/else, try/catch etc
What is Scala?An “object-functional language”
Private & Confidential. Not for distribution. GSA Capital Partners LLP is authorised and regulated by the Financial Services Authority. Registered in England & Wales. Stratton House, 5 Stratton Street, London, W1J 8LA. Number OC309261
• Implicits - values, type conversions, definitions
• Multi-threading support (actors, parallelism, STM – via libraries)
What is Scala?Scala is broad where other languages are deep
Private & Confidential. Not for distribution. GSA Capital Partners LLP is authorised and regulated by the Financial Services Authority. Registered in England & Wales. Stratton House, 5 Stratton Street, London, W1J 8LA. Number OC309261
Private & Confidential. Not for distribution. GSA Capital Partners LLP is authorised and regulated by the Financial Services Authority. Registered in England & Wales. Stratton House, 5 Stratton Street, London, W1J 8LA. Number OC309261
11
Binary incompatibility
• Libraries compiled against 2.9.x will not be compatible with 2.10.x
Unwelcoming “academic” community
• FP advocacy
• Do I need to learn Haskell first?
Too Complex!
• Intersection of features
• Unrestrictive syntax options can lead to confusion
• Places too high a burden on a library designer
The flip sideThe problems of Scala
Private & Confidential. Not for distribution. GSA Capital Partners LLP is authorised and regulated by the Financial Services Authority. Registered in England & Wales. Stratton House, 5 Stratton Street, London, W1J 8LA. Number OC309261
12
Java interfaces contain no implementation
• Means API designers are miserly about adding methods to them
• If you want to implement Collection, you must implement 13 methods
– OK, you can extend AbstractCollection and implement 2 methods
• If you want to implement TraversableLike, you must implement 1 method
The scala collection library is unbelievably awesome
• Creating new collections from existing ones
• Getting data out of your collection
• Collapsing your collection (folds)
traitsWhy Java’s collections are useless
Private & Confidential. Not for distribution. GSA Capital Partners LLP is authorised and regulated by the Financial Services Authority. Registered in England & Wales. Stratton House, 5 Stratton Street, London, W1J 8LA. Number OC309261
scala> val isEven = (_ : Int) % 2 == 0 isEven: Int => Boolean = <function1>
• Usually refer to some (embarrassingly simple) mathematical concepts (like monoids)
Typeclasses
• Scala does not have typeclasses
• This is why you should have asked Santa for a proper type system
– Java’s type system is so poor, most developers don’t realize it has one
– Scala’s type system includes higher-kinds
– Scala’s implicit resolution mechanism allows the compiler to solve your problems for you
Functional ProgrammingNot so complex up to now?
Private & Confidential. Not for distribution. GSA Capital Partners LLP is authorised and regulated by the Financial Services Authority. Registered in England & Wales. Stratton House, 5 Stratton Street, London, W1J 8LA. Number OC309261
25
Definitions
• A Set with an associative operation and an identity under the operation
• Without the identity, this is a Semigroup
Defined trivially in scala as an interface
With some implementations marked as implicit
MonoidsPreparation ace
Private & Confidential. Not for distribution. GSA Capital Partners LLP is authorised and regulated by the Financial Services Authority. Registered in England & Wales. Stratton House, 5 Stratton Street, London, W1J 8LA. Number OC309261
trait Monoid[A] { def identity: A def mplus(a1: A, a2: A): A }
implicit val IntMonoid = new Monoid[Int] {
def identity = 0
def mplus(i1: Int, i2: Int) = i1 + i2
}
26
Retrofit functionality to anything
“Pimp my Library”Adding methods to any type
Private & Confidential. Not for distribution. GSA Capital Partners LLP is authorised and regulated by the Financial Services Authority. Registered in England & Wales. Stratton House, 5 Stratton Street, London, W1J 8LA. Number OC309261
trait Id[A] { val value: A
def mplus(b: A)(implicit m: Monoid[A]) = m.mplus(value, b) }
object Syntax { implicit def mkId[A](a: A) = new Id[A] { val value = a } }
Private & Confidential. Not for distribution. GSA Capital Partners LLP is authorised and regulated by the Financial Services Authority. Registered in England & Wales. Stratton House, 5 Stratton Street, London, W1J 8LA. Number OC309261
– The amount I have made or lost on the position I started the day with
• Trading P&L
– The amount I have lost or gained on the trades I have done today
• Now, suppose I have a bunch of positions in my trading book, keyed by investment
Academic nonsenseWhat use is this stuff in the real world?
Private & Confidential. Not for distribution. GSA Capital Partners LLP is authorised and regulated by the Financial Services Authority. Registered in England & Wales. Stratton House, 5 Stratton Street, London, W1J 8LA. Number OC309261
trait Position { def investment: Investment def tradingPnL: Option[Double] def inventoryPnL: Option[Double] final def totalPnL = inventoryPnL → tradingPnL}
ConclusionsWith great power comes great responsibility
Private & Confidential. Not for distribution. GSA Capital Partners LLP is authorised and regulated by the Financial Services Authority. Registered in England & Wales. Stratton House, 5 Stratton Street, London, W1J 8LA. Number OC309261
Private & Confidential. Not for distribution. GSA Capital Partners LLP is authorised and regulated by the Financial Services Authority. Registered in England & Wales. Stratton House, 5 Stratton Street, London, W1J 8LA. Number OC309261
Private & Confidential. Not for distribution. GSA Capital Partners LLP is authorised and regulated by the Financial Services Authority. Registered in England & Wales. Stratton House, 5 Stratton Street, London, W1J 8LA. Number OC309261