F# FOR TRADING

Phillip Trelford, Trayport
CodeMesh London, 2013
F#UNCTIONAL LONDONERS
Founded Feb 2010
600+ Members
50+ Meetups
3 Conferences
Topics





Finance
Machine Learning
Rea...
F# GROUPS WORLDWIDE
F# IN FINANCE
Prop
shops
Hedge
funds
Investment Banks

Utilities

Insurance
F# FOR PROFIT

F# for Trading
F# FOR PROFIT
Time to Market
Efficiency
Correctness
Complexity
TIME TO MARKET
order of magnitude increase in productivity
GameSys

Source http://fsharp.org/testimonials
EFFICIENCY
performance is phenomenal. We can now re-calculate the entire bank
portfolio from scratch in less than a second...
CORRECTNESS
leads to virtually bug-free code
Fixed Income

Source http://fsharp.org/testimonials
COMPLEXITY
F# is the night vision goggles I need when I go into the dark and attempt to
solve previously unsolved problems...
SHOW ME THE MONEY

F# for Trading
JOULE ENERGY TRADING
SCREEN

http://www.trayport.com/en/products/joule
TICKSPEC: DEBUG
EXAMPLES

https://tickspec.codeplex.com/
ORDER – RECORD TYPE
F#
type Order = {
LimitPrice : decimal
Quantity : int
Side : Side
}

C#
a
TIME IN FORCE – UNION
TYPE
type TimeInForce =
| GoodTillCancel
| GoodForDay
| GoodTillDate of DateTime
THOUGHTWORKS TECH
RADAR
MARCH 2012
F# is excellent at concisely expressing
business and domain logic.”

Developers trying ...
CALCULATIONS

F# for Trading
CURRENCY CONVERSIONS
[<Measure>] type EUR
[<Measure>] type GBP
let rateEurGbp = 0.783M<GBP/EUR>
// Converts amount in EUR ...
UNITS OF MEASURE
FCELL = F# IN EXCEL
UNITS IN CELLS
type formula =
| Neg of formula
| Exp of formula * formula
| ArithmeticOp of
formula * arithmetic * formula...
SPREADSHEET HORROR
STORIES
anomaly, audit finding, bug, bungled, chaos, cock-up, corrupt, damage,
debug, defect, deficienc...
TYPE PROVIDERS

F# for Trading
XML TYPE PROVIDER
<Order ClOrdID="123456"
Side="2"
TransactTm="2001-09-11T09:30:47-05:00"
OrdTyp="2"
Px="93.25"
Acct="2652...
R – TYPE PROVIDER
WORLD BANK DATA
GARBAGE

F# in Finance
.NET 4.5 GARBAGE
COLLECTOR
Latency Mode

Application Scenarios

Batch

Command line
Server Side

Interactive

LOB applicat...
MONO SGEN
GC
Run on
•

Android

•

iOS

•

Linux

•

Mac

(Example from GraphDB)
SOLD

F# in Finance
F# KOANS
[<Koan>]
let SquareEvenNumbersWithPipelineOperator() =
(* In F#, you can use the pipeline operator to get the ben...
TRY IT BEFORE YOU BUY IT
BUY THE BOOK
GET THE T-SHIRT
GET A JOB
QUESTIONS?
Community
F# Foundation http://fsharp.org
F#unctional Londoners http://meetup.com/fsharplondon
Twitter #fsharp
...
Upcoming SlideShare
Loading in …5
×

FSharp for Trading - CodeMesh 2013

1,583 views
1,315 views

Published on

F# for Trading talk at CodeMesh in London, 2013

Published in: Economy & Finance, Business
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,583
On SlideShare
0
From Embeds
0
Number of Embeds
184
Actions
Shares
0
Downloads
13
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide
  • Fsharp.org map
  • See alsohttp://www.simple-talk.com/opinion/geek-of-the-week/dr-byron-cook-geek-of-the-week/
  • Leverage
  • http://www.schrankmonster.de/2010/09/01/taking-the-new-and-shiny-mono-simple-generational-garbage-collector-mono-sgen-for-a-walk/
  • FSharp for Trading - CodeMesh 2013

    1. 1. F# FOR TRADING Phillip Trelford, Trayport CodeMesh London, 2013
    2. 2. F#UNCTIONAL LONDONERS Founded Feb 2010 600+ Members 50+ Meetups 3 Conferences Topics     Finance Machine Learning Reactive Programming Functional Programming http://meetup.com/fsharplondon
    3. 3. F# GROUPS WORLDWIDE
    4. 4. F# IN FINANCE Prop shops Hedge funds Investment Banks Utilities Insurance
    5. 5. F# FOR PROFIT F# for Trading
    6. 6. F# FOR PROFIT Time to Market Efficiency Correctness Complexity
    7. 7. TIME TO MARKET order of magnitude increase in productivity GameSys Source http://fsharp.org/testimonials
    8. 8. 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
    9. 9. CORRECTNESS leads to virtually bug-free code Fixed Income Source http://fsharp.org/testimonials
    10. 10. 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
    11. 11. SHOW ME THE MONEY F# for Trading
    12. 12. JOULE ENERGY TRADING SCREEN http://www.trayport.com/en/products/joule
    13. 13. TICKSPEC: DEBUG EXAMPLES https://tickspec.codeplex.com/
    14. 14. ORDER – RECORD TYPE F# type Order = { LimitPrice : decimal Quantity : int Side : Side } C# a
    15. 15. TIME IN FORCE – UNION TYPE type TimeInForce = | GoodTillCancel | GoodForDay | GoodTillDate of DateTime
    16. 16. 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#
    17. 17. CALCULATIONS F# for Trading
    18. 18. CURRENCY CONVERSIONS [<Measure>] type EUR [<Measure>] type GBP let rateEurGbp = 0.783M<GBP/EUR> // Converts amount in EUR to GBP let euroToPounds (eur:decimal<EUR>) = eur * rateEurGbp
    19. 19. UNITS OF MEASURE
    20. 20. FCELL = F# IN EXCEL
    21. 21. UNITS IN CELLS type 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
    22. 22. 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
    23. 23. TYPE PROVIDERS F# for Trading
    24. 24. 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>
    25. 25. R – TYPE PROVIDER
    26. 26. WORLD BANK DATA
    27. 27. GARBAGE F# in Finance
    28. 28. .NET 4.5 GARBAGE COLLECTOR Latency Mode Application Scenarios Batch Command line Server Side Interactive LOB applications LowLatency Trading Screens SustainedLowLatency Financial Applications
    29. 29. MONO SGEN GC Run on • Android • iOS • Linux • Mac (Example from GraphDB)
    30. 30. SOLD F# in Finance
    31. 31. 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 __
    32. 32. TRY IT BEFORE YOU BUY IT
    33. 33. BUY THE BOOK
    34. 34. GET THE T-SHIRT
    35. 35. GET A JOB
    36. 36. QUESTIONS? Community F# Foundation http://fsharp.org F#unctional Londoners http://meetup.com/fsharplondon Twitter #fsharp Me Blog http://trelford.com/blog Twitter @ptrelford

    ×