production deployment of matlab algorithms - … · production deployment of matlab algorithms...

33
1 © 2014 The MathWorks, Inc. Production Deployment of MATLAB Algorithms Eugene McGoldrick

Upload: vohuong

Post on 16-Jul-2018

227 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Production Deployment of MATLAB Algorithms - … · Production Deployment of MATLAB Algorithms Eugene McGoldrick. 2 MathWorks Evolution in Financial Services 1995 † Quick prototyping

1© 2014 The MathWorks, Inc.

Production Deployment ofMATLAB Algorithms

Eugene McGoldrick

Page 2: Production Deployment of MATLAB Algorithms - … · Production Deployment of MATLAB Algorithms Eugene McGoldrick. 2 MathWorks Evolution in Financial Services 1995 † Quick prototyping

2

MathWorks Evolution in Financial Services

1995• Quick prototyping environment

• Ad-hoc research tool

• Data pulled from flat files, Excel

• Limited financial functionality

'06

'07

'08

'09

2 4 6 8 10 12 14 16 18

0%5%

10%15%20%25%

0-0.05 0.05-0.1 0.1-0.15 0.15-0.2 0.2-0.25

Page 3: Production Deployment of MATLAB Algorithms - … · Production Deployment of MATLAB Algorithms Eugene McGoldrick. 2 MathWorks Evolution in Financial Services 1995 † Quick prototyping

3

MATLAB & FinanceMATLAB & Finance

Today

• Financial market is the 3rd largest Industry for the MathWorks

• Strong growth in all countries, and has become largest industry in many countries for the company

•Over 5000 financial companies worldwide use MathWorks software for financial modeling

• MATLAB is now recognized as one of the leading financial development platforms.

• 3rd party vendors constantly talk to us about integrating into the MATLAB platform.

Page 4: Production Deployment of MATLAB Algorithms - … · Production Deployment of MATLAB Algorithms Eugene McGoldrick. 2 MathWorks Evolution in Financial Services 1995 † Quick prototyping

4

Financial

Statistics Optimization

MATLAB

Parallel Computing MATLAB Distributed Computing Server

Files

Databases

Datafeeds

Access

Reporting

Applications

Production

ShareResearch and Quantify

Datafeed

Database

Spreadsheet Link EX

Research and Quantify

Data Analysis & Visualization

Financial Modeling

Application Development

Reporting

Applications

Production

Share

Automate

Files

Databases

Datafeeds

Access

Capturing and Sharing Innovation

Customizing the foundation for your needs

Page 5: Production Deployment of MATLAB Algorithms - … · Production Deployment of MATLAB Algorithms Eugene McGoldrick. 2 MathWorks Evolution in Financial Services 1995 † Quick prototyping

5

Integrating MATLAB into production systems

Develop, Test, Implement, Install

Use everyday for business decisions

Requirements

Page 6: Production Deployment of MATLAB Algorithms - … · Production Deployment of MATLAB Algorithms Eugene McGoldrick. 2 MathWorks Evolution in Financial Services 1995 † Quick prototyping

6

MATLAB Production Server

Directly deploy MATLAB programs into production– Centrally manage multiple MATLAB programs & MCR versions

– Automatically deploy updates without server restarts

Scalable & reliable– Service large numbers of concurrent requests

– Add capacity or redundancy with additional servers

Use with web, database & application servers– Lightweight client library isolates MATLAB processing

– Access MATLAB programs using native data types

MATLAB Production Server(s)

HTMLXML

Java ScriptWeb

Server(s)

Page 7: Production Deployment of MATLAB Algorithms - … · Production Deployment of MATLAB Algorithms Eugene McGoldrick. 2 MathWorks Evolution in Financial Services 1995 † Quick prototyping

7

Benefits of the MATLAB Production Server

Enterprise class framework for running packaged MATLAB programs

Server software– Manages packaged MATLAB programs & worker pool

Manages MATLAB Runtime libraries for multiple releases– MATLAB Compiler Runtime (MCR) for various versions of MATLAB from R2012b

onward live on the server.

– Compiled MATLAB analytics from different versions of MATLAB from R2012b onward can co-exist on the server.

Lightweight client library for both .NET and Java frameworks aresupported.

Reduces the Total Cost Of Ownership for building and supporting in-house financial analytics development and deployment.

Page 8: Production Deployment of MATLAB Algorithms - … · Production Deployment of MATLAB Algorithms Eugene McGoldrick. 2 MathWorks Evolution in Financial Services 1995 † Quick prototyping

8

Centrally run and manage numerical algorithms

•Simplifies applications

– Analytics run within datacenter

– UI and business functionality

•Simplifies change management

– Independent update of numerics

MATLAB Production Server

Central Management

Application Servers

DistributedApplications

Page 9: Production Deployment of MATLAB Algorithms - … · Production Deployment of MATLAB Algorithms Eugene McGoldrick. 2 MathWorks Evolution in Financial Services 1995 † Quick prototyping

9

MATLAB Production Server

RequestBroker

&ProgramManager

Enterprise Application

HTTP

MWHttpClientobject

Calling Functions

Worker Pool

Page 10: Production Deployment of MATLAB Algorithms - … · Production Deployment of MATLAB Algorithms Eugene McGoldrick. 2 MathWorks Evolution in Financial Services 1995 † Quick prototyping

10

Reduce Cost of Building and Deploying In-House Analytics Single development environment for model

development and testing.

Quants/Analysts/Financial Modelers do not have to rewrite code in another language.

IT can efficiently integrate models/analytics in to production system

Time to deploy greatly reduced – Only need to supply function signature from Quant to IT for

implementation into Enterprise system

– Updates easily implemented and redeploy new model version

Page 11: Production Deployment of MATLAB Algorithms - … · Production Deployment of MATLAB Algorithms Eugene McGoldrick. 2 MathWorks Evolution in Financial Services 1995 † Quick prototyping

11© 2014 The MathWorks, Inc.

MATLAB Development to Production Workflow

Page 12: Production Deployment of MATLAB Algorithms - … · Production Deployment of MATLAB Algorithms Eugene McGoldrick. 2 MathWorks Evolution in Financial Services 1995 † Quick prototyping

12

Development

EnterpriseApplicationDeveloper

Production

MATLABDeveloper

Production Deployment Workflow

MATLAB Production Server

MATLAB Production Server

CTFCTF

Server/WebApplication

ClientLibrary

...

Function Call

AlgorithmAlgorithm

Server/WebApplication

ClientLibrary

MATLABCompiler

Page 13: Production Deployment of MATLAB Algorithms - … · Production Deployment of MATLAB Algorithms Eugene McGoldrick. 2 MathWorks Evolution in Financial Services 1995 † Quick prototyping

13

MATLAB DeveloperMATLAB & Toolboxes, Access to Compiler

Systems DeveloperVisual Studio Tools, Web Development Tools

MATLAB Production Server

RequestBroker

&ProgramManager

WebServer

Web ApplicationsDesktop Applications

MATLAB Developer:Builds, tests models in MATLAB,Compiles them with the compiler into a MPS ctf file and deploys it to the server

MATLAB Developer:Describes function signature to the Systems developer so that they can integrate MPS models into variety of front end/Server Applications

Integrates MPS functions into C#/.Net or JAVA Framework so that they can be called from a variety of different client applications

Models reside on the server and can be updated regularly by the development team without bringing the server down

MATLAB Production Server for development and testing analytics can be a small 4 worker thread system

Page 14: Production Deployment of MATLAB Algorithms - … · Production Deployment of MATLAB Algorithms Eugene McGoldrick. 2 MathWorks Evolution in Financial Services 1995 † Quick prototyping

14

Sharing algorithms across the organization

WebServer

ApplicationServer

Database Server

PricingPricing

RiskAnalytics

RiskAnalytics

PortfolioOptimization

PortfolioOptimization

MATLAB Production Server

MATLABCompiler

Web Applications

Desktop Applications

Batch Applications

Page 15: Production Deployment of MATLAB Algorithms - … · Production Deployment of MATLAB Algorithms Eugene McGoldrick. 2 MathWorks Evolution in Financial Services 1995 † Quick prototyping

15© 2014 The MathWorks, Inc.

Easy integration into existing Enterprise Systems

Page 16: Production Deployment of MATLAB Algorithms - … · Production Deployment of MATLAB Algorithms Eugene McGoldrick. 2 MathWorks Evolution in Financial Services 1995 † Quick prototyping

16

MATLAB Function

Enterprise Application

Integration Example … Java

function B = BlackScholes(CP,S,X,T,r,v)

d2=d1-v*sqrt(T);if CP=='c' B = (S*normcdf(d1)-X*exp(-r*T)*normcdf(d2))-noise;

import com.mathworks.mps.client.MWClient;import com.mathworks.mps.client.MWHttpClient;import com.mathworks.mps.client.MATLABException;;

public interface BlkSchInterface{ double BlackScholes(string C, double S, double X, double T, double r, double v); }

MWClient client = new MWHttpClient();BlkSchInterface blksch_1 = client.CreateProxy(new URL("http://192.168.240.220:9910/BlkSch1"), BlkSchInterface);double optionprice = blksch_1.BlackScholes("c", BasePrice.Value, 1, 1, 1, Volatility.Value));

Reference client library

Define function signatures

Define connection (server & CTF)

Page 17: Production Deployment of MATLAB Algorithms - … · Production Deployment of MATLAB Algorithms Eugene McGoldrick. 2 MathWorks Evolution in Financial Services 1995 † Quick prototyping

17

MATLAB Function

Enterprise Application

Integration Example … .NET

function B = BlackScholes(CP,S,X,T,r,v)

d2=d1-v*sqrt(T);if CP=='c' B = (S*normcdf(d1)-X*exp(-r*T)*normcdf(d2))-noise;

using Mathworks.MATLAB.ProductionServer.Client;

public interface BlkSchInterface{ double BlackScholes(string C, double S, double X, double T, double r, double v); }

MWClient client = new MWHttpClient();BlkSchInterface blksch_1 = client.CreateProxy<BlkSchInterface>(new Uri("http://192.168.240.220:9910/BlkSch1"));double optionprice = blksch_1.BlackScholes("c", BasePrice.Value, 1, 1, 1, Volatility.Value));

Reference client library

Define function signatures

Define connection (server & CTF)

Page 18: Production Deployment of MATLAB Algorithms - … · Production Deployment of MATLAB Algorithms Eugene McGoldrick. 2 MathWorks Evolution in Financial Services 1995 † Quick prototyping

18

Workflow for Embedding MATLAB Components in Production Systems

The development to production process is a two step process

Step 1: Bring Data to MATLAB– Multiple data sources– Build algorithms/models– Test– Compile to target platform component

Step 2: Bring algorithm to the Data– Install MATLAB component into the enterprise production

applications.– Same functionality/single source

Page 19: Production Deployment of MATLAB Algorithms - … · Production Deployment of MATLAB Algorithms Eugene McGoldrick. 2 MathWorks Evolution in Financial Services 1995 † Quick prototyping

19© 2014 The MathWorks, Inc.

Easy to configure to existing hardware

Page 20: Production Deployment of MATLAB Algorithms - … · Production Deployment of MATLAB Algorithms Eugene McGoldrick. 2 MathWorks Evolution in Financial Services 1995 † Quick prototyping

20

Flexible System to Manage

Licensed on workers/worker threads not on Broker process

Infinitely configurable to take advantage of existing in-house hardware

Hosted Analytics platform that can be installed enabling rapid updating and deployment of analytics/models

Accessed by any front end application by means of thin client communications library.

Page 21: Production Deployment of MATLAB Algorithms - … · Production Deployment of MATLAB Algorithms Eugene McGoldrick. 2 MathWorks Evolution in Financial Services 1995 † Quick prototyping

21

MATLAB Production Server … Customer Configurations (1)

MATLAB Production Server

RequestBroker

&ProgramManager

Request Broker and 24 worker processes

Can have multiple instances of the MATLAB Production Server– 2 request brokers and twelve worker servers

– 3 request brokers and eight worker servers

– 4 request brokers and six worker servers

– 6 request brokers and four worker servers

Increase capacity by increasing number of servers and combining them– One request broker and 48 worker processes

Page 22: Production Deployment of MATLAB Algorithms - … · Production Deployment of MATLAB Algorithms Eugene McGoldrick. 2 MathWorks Evolution in Financial Services 1995 † Quick prototyping

22

MATLAB Production Server … Customer Configurations (2)

MATLAB Production Server

RequestBroker

&ProgramManager

MATLAB Production Server

RequestBroker

&ProgramManager

Auto Deploy CTF repository

Page 23: Production Deployment of MATLAB Algorithms - … · Production Deployment of MATLAB Algorithms Eugene McGoldrick. 2 MathWorks Evolution in Financial Services 1995 † Quick prototyping

23© 2014 The MathWorks, Inc.

Customer use cases

Page 24: Production Deployment of MATLAB Algorithms - … · Production Deployment of MATLAB Algorithms Eugene McGoldrick. 2 MathWorks Evolution in Financial Services 1995 † Quick prototyping

24

MATLAB Production Server Use Cases

MATLAB Production Server

RequestBroker

&ProgramManagerClient Front End

Applications

Web Applications Database Servers

Application Servers

Spreadsheet Applications

Enterprise Service/Messaging Buses

MSMQ, JMS, IBM MQ

Big Data …HADOOP

Page 25: Production Deployment of MATLAB Algorithms - … · Production Deployment of MATLAB Algorithms Eugene McGoldrick. 2 MathWorks Evolution in Financial Services 1995 † Quick prototyping

25

Trader: Architecture

VB to the .NET client library Adds trade to portfolio New exposures & CVA Small data transfer

Page 26: Production Deployment of MATLAB Algorithms - … · Production Deployment of MATLAB Algorithms Eugene McGoldrick. 2 MathWorks Evolution in Financial Services 1995 † Quick prototyping

26

Database Server

• Optimize numerical processing within databases

– Request MATLAB analytics directly from database servers

– Trigger requests based upon database transactions

• Minimize data handling using Database Toolbox

Integration with Databases

Enterprise Application

ClientLibrary

StoredProcedure

MATLAB Production Server

RequestBroker

&ProgramManager

Page 27: Production Deployment of MATLAB Algorithms - … · Production Deployment of MATLAB Algorithms Eugene McGoldrick. 2 MathWorks Evolution in Financial Services 1995 † Quick prototyping

27

MATLAB Components in Production Databases

MATLAB Production Server can provide predictive analytics in the databaseOracle (Java, .NET)

Microsoft SQL Server (.NET)

Microsoft Access (.NET)

Netezza (JAVA)

SAS (JAVA)Teradata (JAVA)

Thin client with MPS

– Java and .NET supported

Central repository for models … Simplifies change management

MATLAB Production Server

RequestBroker

&ProgramManager

Database Server

Page 28: Production Deployment of MATLAB Algorithms - … · Production Deployment of MATLAB Algorithms Eugene McGoldrick. 2 MathWorks Evolution in Financial Services 1995 † Quick prototyping

28

Risk Manager: Architecture

Architecture

MATLAB Production Server

RequestBroker

&ProgramManager

Database Server

Web ServerWeb Server

ZeroCurveServletgenScenServlet....computeCVAServlet

ZeroCurveServletgenScenServlet....computeCVAServlet

CCRWeb

Page 29: Production Deployment of MATLAB Algorithms - … · Production Deployment of MATLAB Algorithms Eugene McGoldrick. 2 MathWorks Evolution in Financial Services 1995 † Quick prototyping

29

MPS in a multi-tiered financial system

MSMQMSMQ

Trading PadTrading Pad

Options Server

Options Server

FloorFloor

OD

BC

HTTP

HT

TP

MATLAB Production Server

MSMQMSMQ

Load orders to execute

Price

Send order

Price

Compute statistics

Load executed orders

Page 30: Production Deployment of MATLAB Algorithms - … · Production Deployment of MATLAB Algorithms Eugene McGoldrick. 2 MathWorks Evolution in Financial Services 1995 † Quick prototyping

30

HADOOP calling MATLAB Analytic/Model

MATLAB Production Server

RequestBroker

&ProgramManager

Worker Pool

http http

Page 31: Production Deployment of MATLAB Algorithms - … · Production Deployment of MATLAB Algorithms Eugene McGoldrick. 2 MathWorks Evolution in Financial Services 1995 † Quick prototyping

31

Workflow

Build algorithm in MATLAB

Execute Hadoop in pseudo mode enabling interactive debugging of MATLAB code

Compile code into MATLAB Production Server component

Integrate MATLAB Production Server into HADOOP cluster

Execute HADOOP job and MATLAB Production Server component.

Page 32: Production Deployment of MATLAB Algorithms - … · Production Deployment of MATLAB Algorithms Eugene McGoldrick. 2 MathWorks Evolution in Financial Services 1995 † Quick prototyping

32

MATLAB Calling HADOOP

• MATLAB and JAVA are tightly integrated

• Users can instantiate JAVA classes in MATLAB

• Can invoke JAVA Methods from the command prompt

• HADOOP can be invoked directly from the MATLAB prompt

• Set HADOOP configuration files to local file system(for testing) or HDFS for production

Page 33: Production Deployment of MATLAB Algorithms - … · Production Deployment of MATLAB Algorithms Eugene McGoldrick. 2 MathWorks Evolution in Financial Services 1995 † Quick prototyping

33

Development of MATLAB Production Server continues at a significant pace

Https supported in R2013b

MATLAB Builder Ex supports server based xla’s R2014a– Thin client on desktop, compiled MATLAB analytic on the

server

– Install package for both client and server

Support for other programming frameworks/languages in development