F# for Trading - QuantLabs 2014

Post on 07-Jul-2015

1.372 views 0 download

Tags:

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

F# FOR TRADING & FINANCE

Phillip Trelford, SimCorpLtd

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

F# GROUPS WORLDWIDE

http://c4fsharp.net/groups.html

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

TYPE PROVIDERS F# for Trading

WORLD BANK DATA

R – TYPE PROVIDER

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>

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

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

CALCULATIONS F# for Trading

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

UNITS OF MEASURE

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

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

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