1. Trang chủ
  2. » Công Nghệ Thông Tin

a taste of fsharp today and future

56 406 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 56
Dung lượng 4,69 MB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Why is F# appealing in finance?Functional programming fits with much financial work “Programmatic modelling” A typed, efficient scripting language gets you a long way Plays differently

Trang 2

What is F# and why is it interesting?

Trang 3

F# is…

a productive, supported, interoperable, functional-first programming language that

allows you to write simple code to solve complex problems

Trang 4

ematica…

Algorithmic Trading

Trang 5

Why is F# appealing in finance?

Functional programming fits with much financial work

“Programmatic modelling”

A typed, efficient scripting language gets you a long way

Plays differently for different roles:

Enable quants to contribute to component development

Enables architects to explore hard problems fluently Enables developers to tackle parallel and async programming

Trang 6

Simple Code, Strongly Typed

Trang 7

    }     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);

      }   }

Simplicity: Functions as Values

Trang 8

    return new Tuple<U,T>(t.Item2, t.Item1) }

ReadOnlyCollection<Tuple<T,T,T>> Rotations<T>(Tuple<T,T,T> t)  { 

#

Trang 9

The Big Trends

Trang 10

Async.Parallel [ httpAsync "www.google.com"; httpAsync "www.bing.com";

httpAsync "www.yahoo.com"; ]

|> Async.RunSynchronously

Parallel I/O

Trang 11

Async.Parallel [ for i in 0 200 -> computeTask i ]

|> Async.RunSynchronously

Parallel CPU

Trang 12

F# 2.0 ships with Visual Studio 2010

Trang 13

Demo

Trang 14

F# can be used for everything,

Trang 15

Benchmark Performance by Language

MS Confidential

Trang 16

Example #1 (Power Company)

I have written an application to balance the national power generation schedule … for an energy company

the calculation engine was written in F#

The use of F# to address the complexity at the heart of this application clearly demonstrates a sweet spot for the language … algorithmic analysis of large data sets

Simon Cousins (Eon Powergen)

Trang 17

Examples #2/#3: Finance companies

Trang 18

Example #4: Biotech

F# rocks - building algorithms for DNA processing

and it's like a drug 12-15 at Amyris use F#

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 faster to develop

Darren Platt, Amyris BioTechnologies

Trang 19

Case Study #5: Microsoft “adPredict”

Trang 20

Case Study #5: Microsoft “adPredict”

4 week project, 4 machine learning experts

100million probabilistic variables

Processes 6TB of training data

Real time processing ( N,000 impression updates / sec)

“F# was absolutely integral to our success”

“We delivered a robust, high-performance solution on-time.”

“We couldn’t have achieved this with any other tool given the constraints of the task”

“F# programming is fun – I feel like I learn more about programming every day”

Trang 21

Asynchronous & Parallel & Reactive

async {  let!  res = <async-event>

           }

 

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

Trang 22

F# async + immutable

Parallel

Server

Agents

Trang 24

Units of Measure – Typical Example

[<Measure>]  type  money 

[<Measure>]  type  shares

Trang 25

F# Futures:

Language Integrated Data

demo

Trang 27

Type Providers: The Vision

Trang 28

le, exp ress

ive , pr od

uctive addi tion

to

.NET

Ready for supported use in VS2010

F# greatly simplifies parallelism

An amaz

ing data-r

ich futur

e ahe ad

F#

In Summary

Trang 29

http://meetup.com/FSharpLondon

Jul 4, 6:30pm SkillsMatter

A great place to meet F# users, trainers,

architects, consultants, …

Trang 30

Latest Books about F#

Visit www.fsharp.net

Trang 31

The world is information rich

Our languages need to be information-rich too

The Type Provider Manifesto?

Consume anything! Directly!

Strongly typed! No walls!

Trang 34

F# Today!

F# Today!

Which talk?

Trang 35

Some Basics

topic

Trang 36

Language Integrated Web Data

demo

Trang 37

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<Result<'T>>) let result = ser.ReadObject(stream) :?> Result<'T>

if result.Code<>"/api/status/ok" then raise (InvalidOperationException(result.Message)) else

result.Result

let elements = Query<ChemicalElement array>("[{'type':'/chemistry/chemical_element','name':null,'boiling_point':null,'atomic_mass':null}]")

let Query<'T>(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<Result<'T>>) let result = ser.ReadObject(stream) :?> Result<'T>

if result.Code<>"/api/status/ok" then raise (InvalidOperationException(result.Message)) else

result.Result

let elements = Query<ChemicalElement array>("[{'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?

Trang 38

Web Data

Cloud Data

Enterprise Data

Enterprise Data

Local Data Web Services

Your Data

The Magic: Type Providers

Trang 39

A Type Provider is….

A design-time component that provides a computed space of types and methods…

A compiler/IDE extension…

An adaptor between data/services and NET languages…

Trang 40

Note: F# still contains no data

Open architecture

You can write your own type provider

Trang 41

type Netflix = ODataService< "http://odata.netflix.com" >

Fluent, Typed Access To OData

Trang 42

SQL Server/Entity Framework

type SQL = SqlEntityConnection< "Server='.\\SQLEXPRESS' " >

Fluent, Typed Access To SQL

Trang 43

type EmeaSite = SharePointSite< "http://myemea/" >

Fluent, Typed Access To SharePoint Lists

Fluent, Typed Access To SharePoint Lists

Trang 44

F# Futures: Queries

let avatarTitles =

query { for t in netflix.Titles do

where (t.Name.Contains "Avatar" ) }

Declarative LINQ queries

Trang 45

Fundamentals - Whitespace Matters

Trang 46

Fundamentals - Whitespace Matters

let   computeDerivative f x = 

     let   p1 = f (x - 0.05)

     let   p2 = f (x + 0.05)

    (p2 – p1) / 0.1

Trang 47

Your First F# Application

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>

Trang 48

Your Second F# Application

open  System.Windows.Form

let  form = new Form (Visible=true)

form.Click.Add (fun _ -> printfn "click")

Application.Run form

Trang 49

Functional– Pipelines

x |> f

The pipeline operator

Trang 50

Functional– Pipelines

      x |> f1       |> f2       |> f3

Successive stages

in a pipeline

Trang 51

Exported properties Exported method Object internals

Trang 52

F# Futures: Queries

let avatarTitles =

query { for t in netflix.Titles do

where (t.Name.Contains "Avatar" )

sortBy t.Name

take 100 }

Declarative LINQ queries

Trang 53

AdPredict: What We Observed

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

Trang 54

Await! Await! Await!

F# example: Serving 50,000+ simultaneous TCP connections with ~10 threads

Trang 55

Case Study #5: Microsoft adCenter “adPredict”

Weeks of data in training:

N,000,000,000 impressions, 6TB data

2 weeks of CPU time during training:

2 wks × 7 days × 86,400 sec/day =

1,209,600 seconds Learning algorithm speed requirement:

N,000 impression updates / sec N00.0 μs per impression update

Trang 56

Example #4: Biotech

F# rocks - building algorithms for DNA processing

and it's like a drug 12-15 at Amyris use F#

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 faster to develop

Darren Platt, Amyris BioTechnologies

Ngày đăng: 24/10/2014, 22:24

TỪ KHÓA LIÊN QUAN

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN

w