F# for Trading - QuantLabs 2014

32
F# FOR TRADING & FINANCE Phillip Trelford, SimCorp Ltd QuantLabs, 2014

description

Accompanying slides to talk http://quantlabs.net/blog/2014/12/meetup-tonite-python-programming-phillip-trelford-presents-dotnet-f-for-trading-and-finance/

Transcript of F# for Trading - QuantLabs 2014

Page 1: F# for Trading -  QuantLabs 2014

F# FOR TRADING & FINANCE

Phillip Trelford, SimCorpLtd

QuantLabs, 2014

Page 2: F# for Trading -  QuantLabs 2014

F#UNCTIONAL LONDONERS

Founded Feb 2010

800+ Members

80+ Meetups

4 Conferences

Topics Finance

Machine Learning

Functional Programming

GPU/OpenCL/LLVM

http://meetup.com/fsharplondon

Page 3: F# for Trading -  QuantLabs 2014

F# GROUPS WORLDWIDE

http://c4fsharp.net/groups.html

Page 4: F# for Trading -  QuantLabs 2014

F# IN FINANCE

Investment Banks

Hedge

funds

Prop

shops

Utilities

Insurance

Page 5: F# for Trading -  QuantLabs 2014

F# FOR PROFIT F# for Trading

Page 6: F# for Trading -  QuantLabs 2014

F# FOR PROFIT

Time to Market

Efficiency

Correctness

Complexity

Page 7: F# for Trading -  QuantLabs 2014

TIME TO MARKET

order of magnitude increase in productivity

GameSys

Source http://fsharp.org/testimonials

Page 8: F# for Trading -  QuantLabs 2014

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: F# for Trading -  QuantLabs 2014

CORRECTNESS

leads to virtually bug-free code

Fixed Income

Source http://fsharp.org/testimonials

Page 10: F# for Trading -  QuantLabs 2014

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: F# for Trading -  QuantLabs 2014

TYPE PROVIDERS F# for Trading

Page 12: F# for Trading -  QuantLabs 2014

WORLD BANK DATA

Page 13: F# for Trading -  QuantLabs 2014

R – TYPE PROVIDER

Page 14: F# for Trading -  QuantLabs 2014

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 15: F# for Trading -  QuantLabs 2014

FSHARP.ORG/TESTIMONIALS -MICROSOFT

For a machine learning scientist, speed of experimentation is the critical factor to optimize.

Compiling is fast but loading large amounts of data in memory takes a long time.

With F#’s REPL, you only need to load the data once

and you can then code and explore in the interactive environment.

Unlike C# and C++, F# was designed for this mode of interaction.

- Patrice Simard, Microsoft

Page 16: F# for Trading -  QuantLabs 2014

FSHARP.ORG/TESTIMONIALS -AMYRIS BIOTECH

F# has been phenomenally useful.

I would be writing a lot of this in Python otherwise

and F# is more robust, 20x - 100x faster to run

and for anything but the most trivial programs,

faster to develop.

- Darren Platt, Amyris Biotechnology

Page 17: F# for Trading -  QuantLabs 2014

CALCULATIONS F# for Trading

Page 18: F# for Trading -  QuantLabs 2014

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 19: F# for Trading -  QuantLabs 2014

UNITS OF MEASURE

Page 20: F# for Trading -  QuantLabs 2014

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

Page 21: F# for Trading -  QuantLabs 2014

FCELL = F# IN EXCEL

Page 22: F# for Trading -  QuantLabs 2014

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 23: F# for Trading -  QuantLabs 2014

GARBAGE F# in Finance

Page 24: F# for Trading -  QuantLabs 2014

.NET 4.5 GARBAGE COLLECTOR

Latency Mode Application Scenarios

Batch Command lineServer Side

Interactive LOB applications

LowLatency Trading Screens

SustainedLowLatency Financial Applications

Page 25: F# for Trading -  QuantLabs 2014

MONO SGEN GC

Run on

• Android

• iOS

• Linux

• Mac

(Example from GraphDB)

Page 26: F# for Trading -  QuantLabs 2014

SOLD F# in Finance

Page 27: F# for Trading -  QuantLabs 2014

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 28: F# for Trading -  QuantLabs 2014

TRY IT BEFORE YOU BUY IT

Page 29: F# for Trading -  QuantLabs 2014

BUY THE BOOK

Page 30: F# for Trading -  QuantLabs 2014

GET THE T-SHIRT

Page 31: F# for Trading -  QuantLabs 2014

GET A JOB

Page 32: F# for Trading -  QuantLabs 2014

QUESTIONS?

Community

F# Foundation http://fsharp.org

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

Twitter #fsharp

Me

Blog http://trelford.com/blog

Twitter @ptrelford