I made a similar presentation a year ago to a bunch of fellow quants at the bank. I chose Scala, and my presentation was mostly code. Quant Finance tends to be one of those areas where Scala really excels. For example, a time series is just a running fold. So instead of having an imperative for block with various indices & guards, you can write a 1-line prefix scan to price a 5 year CDS. My examples also included bond pricing, vanilla calls and puts, binomial trees, monte carlo generators, portfolio optimization, risk calculations ( VaR & CVaR ) and a few graphics. My manager was very open-minded when it came to technology choice, and my fellow quants were somewhat tough on the 2 hour presentation, but the end result was what I believe is called a win-win. We've since pushed a bunch of apps coded in Scala into production, and the group has embraced the language quite enthusiastically.
An awful lot of finance (that used to run in Excel) is just side-effect free, compute-centric transformations over data. Time series, for example, have a relatively nice algebra that makes it easy to manipulate in terms of maps, scans and folds. And anything that makes it easier to avoid off-by-one errors is a big win, especially if your traders and quants aren't trained software engineers.
>An awful lot of finance (that used to run in Excel) is just side-effect free, compute-centric transformations over data
true dat.
For example, in Excel, checkout PV ( Click on Formulas->Financial->PV )
Given a $1K@par 10Y bond paying $50 annual coupon at 2% interest, Excel says the Present Value (PV) of the bond must be $1269.48
Getting rid of the fold produces the list of discounted coupons and the discounted principal...just a trivial teaser example, but most quants look at that & go, wow if you could do all that in 1 line, imagine the possibilities if you are pricing a mortgage with tranches...you could get rid of 4 page spreadsheets & replace with a paragraph of straight math & it would just work...and they'd be right, too.
For offline analysis, I'd eagerly agree.
But have you had any success with FP for online analysis? E.g. you have 100 time series updating every second, and must yield some other series and events.
An eager functional language would probably die here, but it seems like a fine fit for a lazy one: compose a list of the other series/events as you scan.
What about datasets that don't fit in memory? How can a functional language deal with those (let's say we don't want to use a database)? Lazy sequences?
I mean, I loved clojure when I tried it out, I just do not know if I can use it to process data as with other languages with really good libraries (python, for example).
Clojure is very lazy about computation and the loading of values. You can work with sequences of infinite size. Lazy sequences are actually the default.
As to processing data like you would with other really good libraries... if you want to do it like that you can. Clojure gives you easy access to Java.
I moved from C++ to scala for my Quaint work and I have been nothing but happy. The other fun thing to use is Akka for easy migration to multi-threaded code. Nothing like generating a bunch of Futures and then collecting the results. I was able to process two quarters of tick data as part of a test routine simply because I had the cores and an easy way to excersize them.
Comments
I made a similar presentation a year ago to a bunch of fellow quants at the bank. I chose Scala, and my presentation was mostly code. Quant Finance tends to be one of those areas where Scala really excels. For example, a time series is just a running fold. So instead of having an imperative for block with various indices & guards, you can write a 1-line prefix scan to price a 5 year CDS. My examples also included bond pricing, vanilla calls and puts, binomial trees, monte carlo generators, portfolio optimization, risk calculations ( VaR & CVaR ) and a few graphics. My manager was very open-minded when it came to technology choice, and my fellow quants were somewhat tough on the 2 hour presentation, but the end result was what I believe is called a win-win. We've since pushed a bunch of apps coded in Scala into production, and the group has embraced the language quite enthusiastically.
> where Scala really excels.
Functional programming in general.
An awful lot of finance (that used to run in Excel) is just side-effect free, compute-centric transformations over data. Time series, for example, have a relatively nice algebra that makes it easy to manipulate in terms of maps, scans and folds. And anything that makes it easier to avoid off-by-one errors is a big win, especially if your traders and quants aren't trained software engineers.
>An awful lot of finance (that used to run in Excel) is just side-effect free, compute-centric transformations over data
true dat. For example, in Excel, checkout PV ( Click on Formulas->Financial->PV ) Given a $1K@par 10Y bond paying $50 annual coupon at 2% interest, Excel says the Present Value (PV) of the bond must be $1269.48
Getting rid of the fold produces the list of discounted coupons and the discounted principal...just a trivial teaser example, but most quants look at that & go, wow if you could do all that in 1 line, imagine the possibilities if you are pricing a mortgage with tranches...you could get rid of 4 page spreadsheets & replace with a paragraph of straight math & it would just work...and they'd be right, too.For offline analysis, I'd eagerly agree. But have you had any success with FP for online analysis? E.g. you have 100 time series updating every second, and must yield some other series and events.
Yep. We use Haskell for all systems, online and offline, including the soft-real time stuff that watches the live feeds.
An eager functional language would probably die here, but it seems like a fine fit for a lazy one: compose a list of the other series/events as you scan.
What about datasets that don't fit in memory? How can a functional language deal with those (let's say we don't want to use a database)? Lazy sequences?
I mean, I loved clojure when I tried it out, I just do not know if I can use it to process data as with other languages with really good libraries (python, for example).
Clojure is very lazy about computation and the loading of values. You can work with sequences of infinite size. Lazy sequences are actually the default.
As to processing data like you would with other really good libraries... if you want to do it like that you can. Clojure gives you easy access to Java.
Let's say I want to do an SQL group by implementation. Are there examples like this?
In the Finance sector, I suspect the answer would be "doesn't exist". RAM is incredibly cheap.
I moved from C++ to scala for my Quaint work and I have been nothing but happy. The other fun thing to use is Akka for easy migration to multi-threaded code. Nothing like generating a bunch of Futures and then collecting the results. I was able to process two quarters of tick data as part of a test routine simply because I had the cores and an easy way to excersize them.
Can you share the presentation? I'd love to see some code samples.
Can I be so bold as to ask where you work?
You could have checked his profile beforehand. It's there...
I'd love to see the presentation. Will you please post it?