Presentation is loading. Please wait.

Presentation is loading. Please wait.

UCL Algo Trading. Programming Expressivity for Mathematical tasks “Fresh Code” Performance Professional Development F#F# C++C++ Math-ematica…Math-ematica…

Similar presentations


Presentation on theme: "UCL Algo Trading. Programming Expressivity for Mathematical tasks “Fresh Code” Performance Professional Development F#F# C++C++ Math-ematica…Math-ematica…"— Presentation transcript:

1 UCL Algo Trading

2

3

4 Programming Expressivity for Mathematical tasks “Fresh Code” Performance Professional Development F#F# C++C++ Math-ematica…Math-ematica… C#JavaC#Java Python…Python… Programming QF modelling Financial engineering Algorithmic Trading

5

6

7 type Command = Command of (Rover -> unit) let BreakCommand = Command(fun rover -> rover.Accelerate(-1.0)) let TurnLeftCommand = Command(fun rover -> rover.Rotate(-5.0 )) abstract class Command { public virtual void Execute(); } abstract class RoverCommand : Command { protected Rover Rover { get; private set; } public RoverCommand(MarsRover rover) { this.Rover = rover; } class BreakCommand : RoverCommand { public BreakCommand(Rover rover) : base(rover) { } public override void Execute() { Rover.Rotate(-5.0); } class TurnLeftCommand : RoverCommand { public TurnLeftCommand(Rover rover) : base(rover) { } public override void Execute() { Rover.Rotate(-5.0); } OO

8 let swap (x, y) = (y, x) let rotations (x, y, z) = [ (x, y, z); (z, x, y); (y, z, x) ] let reduce f (x, y, z) = f x + f y + f z Tuple Swap (Tuple t) { return new Tuple (t.Item2, t.Item1) } ReadOnlyCollection > Rotations (Tuple t) { new ReadOnlyCollection (new Tuple [] { new Tuple (t.Item1,t.Item2,t.Item3); new Tuple (t.Item3,t.Item1,t.Item2); new Tuple (t.Item2,t.Item3,t.Item1); }); } int Reduce (Func f,Tuple t) { return f(t.Item1) + f(t.Item2) + f (t.Item3); } C#

9 THE CLOUDMULTICORE

10 |> Async.RunSynchronously Parallel I/O

11 |> Async.RunSynchronously Parallel CPU

12

13

14

15 MS Confidential

16

17

18

19

20

21 async { let! res =... } React to a GUI Event React to a Timer Callback React to a Query Response React to a HTTP Response React to a Web Service Response React to a Disk I/O Completion Agent reacts to Message

22 F# async + immutable ParallelServer Agents

23 let EarthMass = e24 // Average between pole and equator radii let EarthRadius = e3 // Gravitational acceleration on surface of Earth let g = PhysicalConstants.G * EarthMass / (EarthRadius * EarthRadius)

24 [ ] type money [ ] type shares [ ] type volume type Price = { Open: float ; High: float ; Low: float ; Close: float ; Volume: float }

25 F# Futures: Language Integrated Data demo

26

27 without explicit codegen strongly typed extensible, open

28 Simple, expressive, productive addition to.NET Ready for supported use in VS2010 F# greatly simplifies parallelism An amazing data-rich future ahead F#

29 Jul 4, 6:30pm SkillsMatter A great place to meet F# users, trainers, architects, consultants, …

30 Visit

31

32 F# Today? F# Advanced? F# Tomorrow?

33 F# Today! F# Advanced? F# Tomorrow!

34 F# Today!

35 topic

36 Language Integrated Web Data demo

37 // Freebase.fsx // Example of reading from freebase.com in F# // by Jomo Fisher #r "System.Runtime.Serialization" #r "System.ServiceModel.Web" #r "System.Web" #r "System.Xml" open System open System.IO open System.Net open System.Text open System.Web open System.Security.Authentication open System.Runtime.Serialization [ ] type Result = { [ ] Code:string [ ] Result:'TResult [ ] Message:string } [ ] type ChemicalElement = { [ ] Name:string [ ] BoilingPoint:string [ ] AtomicMass:string } // Freebase.fsx // Example of reading from freebase.com in F# // by Jomo Fisher #r "System.Runtime.Serialization" #r "System.ServiceModel.Web" #r "System.Web" #r "System.Xml" open System open System.IO open System.Net open System.Text open System.Web open System.Security.Authentication open System.Runtime.Serialization [ ] type Result = { [ ] Code:string [ ] Result:'TResult [ ] Message:string } [ ] type ChemicalElement = { [ ] Name:string [ ] BoilingPoint:string [ ] AtomicMass:string } let Query (query:string) : 'T = let query = query.Replace("'","\"") let queryUrl = sprintf "http://api.freebase.com/api/service/mqlread?query=%s" "{\"query\":"+query+"}" let request : HttpWebRequest = downcast WebRequest.Create(queryUrl) request.Method <- "GET" request.ContentType <- "application/x-www-form-urlencoded" let response = request.GetResponse() let result = try use reader = new StreamReader(response.GetResponseStream()) reader.ReadToEnd(); finally response.Close() let data = Encoding.Unicode.GetBytes(result); let stream = new MemoryStream() stream.Write(data, 0, data.Length); stream.Position <- 0L let ser = Json.DataContractJsonSerializer(typeof >) let result = ser.ReadObject(stream) :?> Result if result.Code<>"/api/status/ok" then raise (InvalidOperationException(result.Message)) else result.Result let elements = Query ("[{'type':'/chemistry/chemical_element','name':null,'boiling_point':null,'atomic_mass':null}]") elements |> Array.iter(fun element->printfn "%A" element) let Query (query:string) : 'T = let query = query.Replace("'","\"") let queryUrl = sprintf "http://api.freebase.com/api/service/mqlread?query=%s" "{\"query\":"+query+"}" let request : HttpWebRequest = downcast WebRequest.Create(queryUrl) request.Method <- "GET" request.ContentType <- "application/x-www-form-urlencoded" let response = request.GetResponse() let result = try use reader = new StreamReader(response.GetResponseStream()) reader.ReadToEnd(); finally response.Close() let data = Encoding.Unicode.GetBytes(result); let stream = new MemoryStream() stream.Write(data, 0, data.Length); stream.Position <- 0L let ser = Json.DataContractJsonSerializer(typeof >) let result = ser.ReadObject(stream) :?> Result if result.Code<>"/api/status/ok" then raise (InvalidOperationException(result.Message)) else result.Result let elements = Query ("[{'type':'/chemistry/chemical_element','name':null,'boiling_point':null,'atomic_mass':null}]") elements |> Array.iter(fun element->printfn "%A" element) How would we do this today?

38 F# Web Data Cloud Data Enterprise Data Local Data Web Services Your Data

39

40

41 type Netflix = ODataService

42 type SQL = SqlEntityConnection

43 type EmeaSite = SharePointSite

44 let avatarTitles = query { for t in netflix.Titles do where (t.Name.Contains "Avatar") }

45 let computeDerivative f x = let p1 = f (x ) let p2 = f (x ) (p2 – p1) / 0.1 Offside (bad indentation)

46 let computeDerivative f x = let p1 = f (x ) let p2 = f (x ) (p2 – p1) / 0.1

47 printfn "Hello World" C:\test> fsc test.fs C:\test> test.exe Hello World C:\test> C:\test> fsc test.fs C:\test> test.exe Hello World C:\test>

48 open System.Windows.Form let form = new Form (Visible=true) form.Click.Add (fun _ -> printfn "click") Application.Run form

49 x |> f The pipeline operator

50 x |> f1 |> f2 |> f3 Successive stages in a pipeline

51 type Vector2D (dx:double, dy:double) = let d2 = dx*dx+dy*dy member v.DX = dx member v.DY = dy member v.Length = sqrt d2 member v.Scale(k) = Vector2D (dx*k,dy*k) Inputs to object construction Exported properties Exported method Object internals

52 let avatarTitles = query { for t in netflix.Titles do where (t.Name.Contains "Avatar") sortBy t.Name take 100 }

53 F#’s powerful type inference means less typing, more thinking Type-inferred code is easily refactored “Hands-on” exploration. Immediate scaling to massive data sets mega-data structures, 16GB machines Live in the domain, not the language Schema compilation and “Schedules” Especially Excel, SQL Server

54 Await!

55

56


Download ppt "UCL Algo Trading. Programming Expressivity for Mathematical tasks “Fresh Code” Performance Professional Development F#F# C++C++ Math-ematica…Math-ematica…"

Similar presentations


Ads by Google