fsharp for trading - codemesh 2013
DESCRIPTION
F# for Trading talk at CodeMesh in London, 2013TRANSCRIPT
F# FOR TRADING Phillip Trelford, TrayportCodeMesh London, 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
F# GROUPS WORLDWIDE
F# IN FINANCE
Investment Banks
Hedge funds
Prop shops
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
Handelsbanken
Source http://fsharp.org/testimonials
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
Byron Cook
Source http://fsharp.org/testimonials
SHOW ME THE MONEY F# for Trading
JOULE ENERGY TRADING SCREEN
http://www.trayport.com/en/products/joule
ORDER – RECORD TYPE
F#
type Order = { LimitPrice : decimal Quantity : int Side : Side }
C#
a
TIME IN FORCE – UNION TYPEtype TimeInForce = | GoodTillCancel | GoodForDay | GoodTillDate of DateTime
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#
CALCULATIONS F# for Trading
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
UNITS OF MEASURE
FCELL = F# IN EXCEL
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
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
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="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>
R – TYPE PROVIDER
WORLD BANK DATA
GARBAGE F# in Finance
.NET 4.5 GARBAGE COLLECTOR
Latency Mode Application Scenarios
Batch Command lineServer Side
Interactive LOB applications
LowLatency Trading Screens
SustainedLowLatency Financial Applications
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 benefit of the parens style with the readability of the statement style. *)
let result = [0..5] |> List.filter isEven |> List.map square AssertEquality result __
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
Me
Blog http://trelford.com/blog
Twitter @ptrelford