36
F# FOR TRADING Phillip Trelford, Trayport CodeMesh London, 2013

FSharp for Trading - CodeMesh 2013

Embed Size (px)

DESCRIPTION

F# for Trading talk at CodeMesh in London, 2013

Citation preview

Page 1: FSharp for Trading - CodeMesh 2013

F# FOR TRADING Phillip Trelford, TrayportCodeMesh London, 2013

Page 2: FSharp for Trading - CodeMesh 2013

F#UNCTIONAL LONDONERS

Founded Feb 2010

600+ Members

50+ Meetups

3 Conferences

Topics Finance Machine Learning Reactive Programming Functional Programming

http://meetup.com/fsharplondon

Page 3: FSharp for Trading - CodeMesh 2013

F# GROUPS WORLDWIDE

Page 4: FSharp for Trading - CodeMesh 2013

F# IN FINANCE

Investment Banks

Hedge funds

Prop shops

Utilities

Insurance

Page 5: FSharp for Trading - CodeMesh 2013

F# FOR PROFIT F# for Trading

Page 6: FSharp for Trading - CodeMesh 2013

F# FOR PROFIT

Time to Market

Efficiency

Correctness

Complexity

Page 7: FSharp for Trading - CodeMesh 2013

TIME TO MARKET

order of magnitude increase in productivity

GameSys

Source http://fsharp.org/testimonials

Page 8: FSharp for Trading - CodeMesh 2013

EFFICIENCY

performance is phenomenal. We can now re-calculate the entire bank portfolio from scratch in less than a second

Handelsbanken

Source http://fsharp.org/testimonials

Page 9: FSharp for Trading - CodeMesh 2013

CORRECTNESS

leads to virtually bug-free code

Fixed Income

 

Source http://fsharp.org/testimonials

Page 10: FSharp for Trading - CodeMesh 2013

COMPLEXITY

 F# is the night vision goggles I need when I go into the dark and attempt to solve previously unsolved problems

Byron Cook

Source http://fsharp.org/testimonials

Page 11: FSharp for Trading - CodeMesh 2013

SHOW ME THE MONEY F# for Trading

Page 12: FSharp for Trading - CodeMesh 2013

JOULE ENERGY TRADING SCREEN

http://www.trayport.com/en/products/joule

Page 13: FSharp for Trading - CodeMesh 2013

TICKSPEC: DEBUG EXAMPLES

https://tickspec.codeplex.com/

Page 14: FSharp for Trading - CodeMesh 2013

ORDER – RECORD TYPE

F#

type Order = { LimitPrice : decimal Quantity : int Side : Side }

C#

a

Page 15: FSharp for Trading - CodeMesh 2013

TIME IN FORCE – UNION TYPEtype TimeInForce = | GoodTillCancel | GoodForDay | GoodTillDate of DateTime

Page 16: FSharp for Trading - CodeMesh 2013

THOUGHTWORKS TECH RADAR MARCH 2012

F# is excellent at concisely expressing

business and domain logic.”

Developers trying to achieve explicit business logic within an application may opt to

express their domain in F#

with the majority of plumbing code in C#

Page 17: FSharp for Trading - CodeMesh 2013

CALCULATIONS F# for Trading

Page 18: FSharp for Trading - CodeMesh 2013

CURRENCY CONVERSIONS

[<Measure>] type EUR[<Measure>] type GBPlet rateEurGbp = 0.783M<GBP/EUR>

// Converts amount in EUR to GBPlet euroToPounds (eur:decimal<EUR>) = eur * rateEurGbp

Page 19: FSharp for Trading - CodeMesh 2013

UNITS OF MEASURE

Page 20: FSharp for Trading - CodeMesh 2013

FCELL = F# IN EXCEL

Page 21: FSharp for Trading - CodeMesh 2013

UNITS IN CELLStype formula =

| Neg of formula

| Exp of formula * formula

| ArithmeticOp of

formula * arithmetic * formula

| LogicalOp of

formula * logical * formula

| Num of UnitValue

| Ref of int * int

| Range of int * int * int * int

| Fun of string * formula list

Page 22: FSharp for Trading - CodeMesh 2013

SPREADSHEET HORROR STORIES

anomaly, audit finding, bug, bungled, chaos, cock-up, corrupt, damage, debug, defect, deficiency, disaster, dubious,

embarrassment, error, erroneous, Excel, exposed, failed, failure, false, falsify, fault, faulty, fiasco, flaw, foul-up, fraud, fraudulent,

fubar, garbage, GIGO, glitch, hell, horror story, inaccurate, inadequate, inadvertent, incorrect, insecure, misunderstood, nightmare, non-compliance, not correct, oops, overestimate,

overstatement, problem, risk, rogue, serious, slip, snafu, suspect, suspicious, trap, typo, unchecked, uncontrolled, uncorrected,

uncovered, underestimate, understatement, undetected, untested, violation, weak, weakness, wrong

Page 23: FSharp for Trading - CodeMesh 2013

TYPE PROVIDERS F# for Trading

Page 24: FSharp for Trading - CodeMesh 2013

XML TYPE PROVIDER

<Order ClOrdID="123456" Side="2" TransactTm="2001-09-11T09:30:47-05:00" OrdTyp="2" Px="93.25" Acct="26522154"> <Hdr Snt="2001-09-11T09:30:47-05:00" PosDup="N" PosRsnd="N" SeqNum="521"> <Sndr ID="AFUNDMGR"/> <Tgt ID="ABROKER"/> </Hdr> <Instrmt Sym="IBM" ID="459200101" IDSrc="1"/> <OrdQty Qty="1000"/> </Order>

Page 25: FSharp for Trading - CodeMesh 2013

R – TYPE PROVIDER

Page 26: FSharp for Trading - CodeMesh 2013

WORLD BANK DATA

Page 27: FSharp for Trading - CodeMesh 2013

GARBAGE F# in Finance

Page 28: FSharp for Trading - CodeMesh 2013

.NET 4.5 GARBAGE COLLECTOR

Latency Mode Application Scenarios

Batch Command lineServer Side

Interactive LOB applications

LowLatency Trading Screens

SustainedLowLatency Financial Applications

Page 29: FSharp for Trading - CodeMesh 2013

MONO SGEN GC

Run on

• Android

• iOS

• Linux

• Mac

(Example from GraphDB)

Page 30: FSharp for Trading - CodeMesh 2013

SOLD F# in Finance

Page 31: FSharp for Trading - CodeMesh 2013

F# KOANS

[<Koan>]let SquareEvenNumbersWithPipelineOperator() =(* In F#, you can use the pipeline operator to get the benefit of the parens style with the readability of the statement style. *)

let result = [0..5] |> List.filter isEven |> List.map square AssertEquality result __

Page 32: FSharp for Trading - CodeMesh 2013

TRY IT BEFORE YOU BUY IT

Page 33: FSharp for Trading - CodeMesh 2013

BUY THE BOOK

Page 34: FSharp for Trading - CodeMesh 2013

GET THE T-SHIRT

Page 35: FSharp for Trading - CodeMesh 2013

GET A JOB

Page 36: FSharp for Trading - CodeMesh 2013

QUESTIONS?

Community

F# Foundation http://fsharp.org

F#unctional Londoners http://meetup.com/fsharplondon

Twitter #fsharp

Me

Blog http://trelford.com/blog

Twitter @ptrelford