Life In The 16th Century By Keira, Danielle, Lewis Sharp And Lewis F.
F sharp - an overview
-
Upload
christoph-santschi -
Category
Technology
-
view
30 -
download
0
Transcript of F sharp - an overview
![Page 1: F sharp - an overview](https://reader030.fdocuments.in/reader030/viewer/2022032502/55b9b01abb61ebd8578b46af/html5/thumbnails/1.jpg)
F# 3.0:
Strongly Typed Programming in the Information Rich World
![Page 2: F sharp - an overview](https://reader030.fdocuments.in/reader030/viewer/2022032502/55b9b01abb61ebd8578b46af/html5/thumbnails/2.jpg)
Proposition 1
The world is incredibly
information-rich
Christoph Santschi – dipl. Natw. ETHZ
![Page 3: F sharp - an overview](https://reader030.fdocuments.in/reader030/viewer/2022032502/55b9b01abb61ebd8578b46af/html5/thumbnails/3.jpg)
Proposition 2
Modern financial enterprises are
incredibly information-rich
![Page 4: F sharp - an overview](https://reader030.fdocuments.in/reader030/viewer/2022032502/55b9b01abb61ebd8578b46af/html5/thumbnails/4.jpg)
Proposition 3
Our languages are information-
sparse
![Page 5: F sharp - an overview](https://reader030.fdocuments.in/reader030/viewer/2022032502/55b9b01abb61ebd8578b46af/html5/thumbnails/5.jpg)
Proposition 4
This is a Problem
(especially for strongly typed Programming)
![Page 6: F sharp - an overview](https://reader030.fdocuments.in/reader030/viewer/2022032502/55b9b01abb61ebd8578b46af/html5/thumbnails/6.jpg)
With F# we want to help fix this...
The mechanism we're adding
to F# is called Type Providers
![Page 7: F sharp - an overview](https://reader030.fdocuments.in/reader030/viewer/2022032502/55b9b01abb61ebd8578b46af/html5/thumbnails/7.jpg)
LINQ + Type Providers
=
Language Integrated Data and
Services
![Page 8: F sharp - an overview](https://reader030.fdocuments.in/reader030/viewer/2022032502/55b9b01abb61ebd8578b46af/html5/thumbnails/8.jpg)
F# is...
...a practical, supported, interoperable,
functional language that allows you to write
simple code to solve complex problems.
![Page 9: F sharp - an overview](https://reader030.fdocuments.in/reader030/viewer/2022032502/55b9b01abb61ebd8578b46af/html5/thumbnails/9.jpg)
Crossing boundaries
“Fresh Code” Performance
Professional Development
Expressivity for Programming
Mathematical tasks
C++ C#
Java
Programming
F#
Python
...
Financial engineering
Algorithmic Trading
DSL programming
Math‐ ...
ematica
QF modelling
![Page 10: F sharp - an overview](https://reader030.fdocuments.in/reader030/viewer/2022032502/55b9b01abb61ebd8578b46af/html5/thumbnails/10.jpg)
Why is F# appealing in finance?
Functional programming fits with financial work
– Programmatic modelling
– Compositional parallel & GPU programming
– Domain specific languages – internal and external
– Efficient execution
Plays differently for different roles:
– Quants contribute to component development
– Architects explore hard problems fluently
– Developers tackle parallel and async programming
![Page 11: F sharp - an overview](https://reader030.fdocuments.in/reader030/viewer/2022032502/55b9b01abb61ebd8578b46af/html5/thumbnails/11.jpg)
![Page 12: F sharp - an overview](https://reader030.fdocuments.in/reader030/viewer/2022032502/55b9b01abb61ebd8578b46af/html5/thumbnails/12.jpg)
Simplicity: Functions as Values 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.ø); }
} class TurnLeftCommand : RoverCommand {
}
type Command = Command of (Rover -> unit)
let BreakCommand =
Command(fun rover -> rover.Accelerate(-1.ø))
let TurnLeftCommand =
Command(fun rover -> rover.Rotate(-5.ø<degs>))
public TurnLeftCommand(Rover rover) : base(ro
{ } public override void Execute() {
Rover.Rotate(-5.ø);
}
![Page 13: F sharp - an overview](https://reader030.fdocuments.in/reader030/viewer/2022032502/55b9b01abb61ebd8578b46af/html5/thumbnails/13.jpg)
Simplicity: Functional Data
Tuple<U,T> Swap<T,U>(Tuple<T,U>
t) {
return new Tuple<U,T>(t.Item2, t.Item1)
}
}
let reduce f (x, y, z)
= f x + f y + f z
return f(t.Item1) + f(t.Item2) + f (t.Item3);
C#
ReadOnlyCollection<Tuple<T,T,T>> Rotations<T>(Tuple<T,T,T> t)
{
new ReadOnlyCollection<int>
(new Tuple<T,T,T>[]
{ new Tuple<T,T,T>(t.Item1,t.Item2,t.Item3);
new Tuple<T,T,T>(t.Item3,t.Item1,t.Item2);
new Tuple<T,T,T>(t.Item2,t.Item3,t.Item1); });
let rotations (x, y,
z) = [ (x, y,
z); (z, x, y);
(y, z, x) ]
}
int Reduce<T>(Func<T,int> f,Tuple<T,T,T>
t) {
let swap (x, y) = (y, x)
![Page 14: F sharp - an overview](https://reader030.fdocuments.in/reader030/viewer/2022032502/55b9b01abb61ebd8578b46af/html5/thumbnails/14.jpg)
Examples #2/#3: Finance companies
Insurance Company Improves Time-to-
Market with Enhanced Rating Engine
Grange
OV er ;eW
Country or Region: United States
Industry: Financial services—Insurance
Customer Profile
Headquartered in Co I umb us, Ohio,
GrargeInsurance offers automobile,
home,and business insurance protection
to po I icyho Iders in 13 US. states.It em
ploys 1,500 people.
Business Situation
To maintain its compefitivestancling
and ifsreputationarnorg agents for
beim] easyto do business with, Orange
Insurance needed to keep its rating
erkgineworking attop performarKe.
Solulieff
Llsi ng M icrosoftle Visua I Stud 'Off Tea m
System and Visual F:rf, the company
Insurance
"With this streamlined development cycl
rapidly deliver more powerful solutionsl
they can deliver more choices and bette
policyholdersthat much faster." GlennWaton, Associate Vice President, Personal Li nes, IT, Orange
For nearly 75 years, Grange Insurance has offer
products and services to policyholders in more
states. To maintain its well-earned reputation
company decided to enhance its rating engine-
for rating policies and performing what-if modi
analyses, and other vital activities. Working wit
Group and using the Microsoft! Visual Studio!
development environment and Microsoft ViSLIE
ming language, Grange Insurance parallelized i
husto men. Financial services firm
Country or Region: Europe Industry:
Financial services—Banking
Customer Profile
A la rge Europeanfinancial services firm
offers banking and asset-management
services to clients in 50 countries. In
2004, the bank earned morethan 11.5.$6
billion in income.
Software and Services
MicrosoftVisual Studio
MicrosoftVisua l
MicrosoftVisual Studio 2010
Technologies
Microsoft .NET Framework
Windows Presentation Foundation
Banking Firm Uses Functional Language to
Speed Development by 50 Percent
"VVe could not have developed 200 models in two
yearswithout F# and Visual Studio. lt would have
taken us at least twice as lang with our previaustools."
Directerata la rge Europeant na ncia I servicefirm
A large financial services firm in Europe sought new
development tools that could cut costs, boost productivity, and
improvethe quality of its mathematical models. To address its
needs, the bank deployed Microsoft F#, the Microsoft .NET
Framework, and Microsoft Visual Studio. It will sonn upgrade to
Visual Studio 2010 and the integrated Microsoft Visual F#. With
its new tools, the bank can speed development by 50 percent
or more, improve quality, and reduce costs.
Business Needs desktop and ona remotecluster of senyers
![Page 15: F sharp - an overview](https://reader030.fdocuments.in/reader030/viewer/2022032502/55b9b01abb61ebd8578b46af/html5/thumbnails/15.jpg)
A Typeprovide is:
“A compile-time component
that provides a computed
space of types and methods
on-demand ...”
“A compiler plug-in...”
“An adaptor between data/services and the .NET
type
system...”
![Page 16: F sharp - an overview](https://reader030.fdocuments.in/reader030/viewer/2022032502/55b9b01abb61ebd8578b46af/html5/thumbnails/16.jpg)
// Freebase.fsx // Example of reading from freebase.com in F#
// by Jomo Fisher #r "System.Runtime.Serial #r "System.ServiceModel.Wbl #r "System.Web" #r "System.Xml"
" et Query<'T>(query:string) : 'T = let query = query.Replace("'","\"") let queryUrl = sprintf "http://api.freebase.com/api/service/mqlread?query=%s"
"{\"query\":"+query+"}" open System open System.IO open System.Netopen System.Text open System.Web
open System.Security.Authation let response = request.GetResponse() open System.Runtime.Seria
let request : HttpWebRequest = downcast WebRequest.Create(queryUrl) request.Method <- "GET" request.ContentType <- "application/x-www-form-urncoded"
How would we do
this previously? [<DataContract>] type Result<'TResult> = {
[<field: DataMember(N Code:string
[<field: DataMember(N re>
Result:'TResult [<field: DataMember(Nmessage"let data = Message:string }
let result = try
use reader = new StreamReader(response.GetResponseStream()) ] reader.ReadToEnd();
finally
] sponse.Close()
] Encoding.Unicode.GetBytes(result);
let stream = new MemoryStream() stream.Write(data, 0, data.Length); stream.Position <- 0L
[<DataContract>] type ChemicalElement = {
[<field: DataMember(Nname")let resu> Name:string
[<field: DataMember(Ningpoint")raise (Invali >
let ser = Json.DataContractJsonSerializer(typeof<Result<'T>>) ] lt = ser.ReadObject(stream) :?> Result<'T>
if result.Code<>"/api/status/ok" then ] dOperationException(result.Message))
BoilingPoint:string else
[<field: DataMember(Nicmass")result.Result>] AtomicMass:string } 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)
![Page 17: F sharp - an overview](https://reader030.fdocuments.in/reader030/viewer/2022032502/55b9b01abb61ebd8578b46af/html5/thumbnails/17.jpg)
Note: F# itself still contains
no data
Open architecture
You can write your
own type
provider
![Page 18: F sharp - an overview](https://reader030.fdocuments.in/reader030/viewer/2022032502/55b9b01abb61ebd8578b46af/html5/thumbnails/18.jpg)
Language Integrated Data Market Directory
![Page 19: F sharp - an overview](https://reader030.fdocuments.in/reader030/viewer/2022032502/55b9b01abb61ebd8578b46af/html5/thumbnails/19.jpg)
SQL
![Page 20: F sharp - an overview](https://reader030.fdocuments.in/reader030/viewer/2022032502/55b9b01abb61ebd8578b46af/html5/thumbnails/20.jpg)
Web Services
type Data = WsdlService<uhttp://teny. xignite • c ornixF ut ures .asmx?WSDL"
let financials = DataiGetServiceContext()
financials.GetQuotes "IBM"
Fluent Typed Access To
WSDL
![Page 21: F sharp - an overview](https://reader030.fdocuments.in/reader030/viewer/2022032502/55b9b01abb61ebd8578b46af/html5/thumbnails/21.jpg)
F# 3.0: Queries let avatarTitles =
query { for t in netflix.Titles do
where (t.Name.Contains "Avatar")
select t }
let avatarTitles =
query { for t in netflix.Titles do
where (t.Name.Contains "Avatar")
sortBy t.Name
select t }
let avatarTitles =
query { for t in netflix.Titles do
where (t.Name.Contains "Avatar")
sortBy t.Name
select t
take 100 }
![Page 22: F sharp - an overview](https://reader030.fdocuments.in/reader030/viewer/2022032502/55b9b01abb61ebd8578b46af/html5/thumbnails/22.jpg)
Conclusion 1
Huge Information Spaces can be
Software Components
![Page 23: F sharp - an overview](https://reader030.fdocuments.in/reader030/viewer/2022032502/55b9b01abb61ebd8578b46af/html5/thumbnails/23.jpg)
Conclusion 2
Multiple data standards with one
simple mechanism
![Page 24: F sharp - an overview](https://reader030.fdocuments.in/reader030/viewer/2022032502/55b9b01abb61ebd8578b46af/html5/thumbnails/24.jpg)
Conclusion 3
Integrated Data Access Empowers
Both Programmers and Analysts
![Page 25: F sharp - an overview](https://reader030.fdocuments.in/reader030/viewer/2022032502/55b9b01abb61ebd8578b46af/html5/thumbnails/25.jpg)
Summary
The financial world is massively
information rich
Our enterprise financial programming needs
to be information‐rich too
Information‐richness changes how we think
about programming and analysis