Upload
others
View
1
Download
0
Embed Size (px)
Citation preview
1 © 2016 The MathWorks, Inc.
MATLAB as a Financial Engineering
Development Platform Delivering Financial /
Quantitative Models to the Enterprise
Eugene McGoldrick
2
MATLAB – Development Environment for Financial Services
Development Environment has increasing number of productivity tools built
into the base product
– Test Harness modeled on JUnit, customizable and extensible
– Support for version control
Subversion
GIT
API available to support other version control systems
– GUI development tools
Guide
App Designer
– Performance analysis tools
Profiler
Code Analyzer
3
MATLAB in the Enterprise
Goals:
– Enable customers to rapidly develop and deploy MATLAB applications onto the
desktop.
– Seamlessly integrate MATLAB generated components into other languages,
applications and enterprise production systems.
4
Integrating MATLAB into production systems
Development
Algorithm Developers
IT professionals Software Engineers
Business – End Users
Traders
Portfolio managers
Business Analysts
Managers
Production Component Model/Algorithm/Analytic
Desktop Applications
Production Databases
Analytic Engines
Web Applications
Trading Systems
Develop, Test,
Implement, Install
Use everyday for
business decisions
Requirements
5
Share with non-MATLAB Users: MATLAB Compiler
MATLAB
C/C ++
Excel Add-in
Hadoop
MATLAB
Compiler
Standalone Application
Package as a standalone executable
Package as an Excel Add-in
Package as a Map Reduce Application to
run in Apache Hadoop MATLAB
Runtime
6
Application Author
End User
1
2
MATLAB Compiler Workflow
MATLAB
Excel Add-in Hadoop
Standalone Application
Toolboxes
MATLAB Compiler
MATLAB
Runtime 3
7
MATLAB in the Enterprise
Goals:
– Enable customers to rapidly develop and deploy MATLAB applications onto the
desktop.
– Seamlessly integrate MATLAB generated components into other languages,
applications and enterprise production systems.
8
Share with non-MATLAB Users: MATLAB Compiler SDK
MATLAB
C/C ++
Java
.NET
MATLAB
Compiler
MATLAB Production
Server
MATLAB
Compiler SDK
Python
Package as components that
can be integrated in C/C++,
Java, .Net, or Python
applications
Package as deployable archives
for execution on MATLAB
Production Server
MATLAB
Runtime
9
1
2
MATLAB
Toolboxes
MATLAB
Runtime
Application Author
Software Developer
4 3 C/C ++
Java
.NET MATLAB
Production Server
Python
MATLAB Compiler SDK
MATLAB Compiler SDK Workflow
10
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)
HTML
XML
Java Script Web
Server(s)
11
MATLAB Production Server
Request
Broker
&
Program
Manager
Enterprise Application
HTTP
MWHttpClient
object
Calling Functions
Calculation
Process
Calculation
Process
Worker Pool
12
Development
Enterprise
Application
Developer
Production
MATLAB
Developer
Production Deployment Workflow
MATLAB Production Server
MATLAB Production Server
CTF
Server/Web
Application
Client
Library
. . .
Function Call
Algorithm
Server/Web
Application
Client
Library
MATLAB
Compiler
13
Centrally run and manage numerical algorithms
• Simplifies applications
– Analytics run within datacenter
– UI and business functionality
• Simplifies change management
– Independent update of numerical algorithms
MATLAB Production Server
Central Management
Application
Servers
Distributed
Applications
14
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 .NET and Java frameworks, C/C++,
and Python are supported.
Reduces the Total Cost Of Ownership for building and supporting
in-house financial analytics development and deployment.
15
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 is installed in house
enabling rapid updating and deployment of
analytics/models
Accessed by any front end application by means of thin
client communications library, or through JSON/Restful
interface
16
MATLAB Production Server … Customer Configurations (1)
MATLAB Production Server
Request
Broker
&
Program
Manager
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
17
MATLAB Production Server … Customer Configurations (2)
MATLAB Production Server
Request
Broker
&
Program
Manager
MATLAB Production Server
Request
Broker
&
Program
Manager
Auto Deploy CTF
repository
18
Easy Integration
IT can efficiently integrate models/analytics in to
production system
Seamless integration into .NET and Java development
environments … only a few lines of code required
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
19
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)
20
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)
21
JSON/Restful API
Enterprise Application
var cp = parseFloat(document.getElementById('coupon_payment_value').value);
var np = parseFloat(document.getElementById('num_payments_value').value);
var ir = parseFloat(document.getElementById('interest_rate_value').value);
var vm = parseFloat(document.getElementById('facevalue_value').value);
// A new XMLHttpRequest object
var request = new XMLHttpRequest();
//Use MPS RESTful API to specify URL
var url = "http://localhost:9910/BondTools/pricecalc";
//Use MPS RESTful API to specify params using JSON
var params = { "nargout":1,"rhs": [vm, cp, ir, np] };
request.open("POST", url);
//Use MPS RESTful API to set Content-Type
request.setRequestHeader("Content-Type", "application/json");
request.send(JSON.stringify(params));
MATLAB Function
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;
• Easy API to use
• No client library required
22
Where we are today with MATLAB
Production Server
50 µsec latency for 1 through 1000
concurrent users
R2016a
R2015b
Improved throughput and overall performance
1.5 Gb/sec transfer rate for 1
through 1000 concurrent users
24
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
25
MATLAB Developer
MATLAB & Toolboxes,
Access to Compiler
Systems Developer
Visual Studio Tools, Web
Development Tools
MATLAB Production Server
Request
Broker
&
Program
Manager
Web
Server
Web Applications
Desktop 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
.Net, JAVA Frameworks, C/C++
and Python 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
Separation of Roles in Building and Deploying
In-House Analytics
26
Desktop and Server Based Excel Add-ins
Desktop Excel Add-ins with compiler
Server based Excel Add-ins with Compiler SDK
MATLAB Production Server
Request
Broker
&
Program
Manager
.
.
.
XLA
MATLAB Model
MATLAB Runtime
XLA
XLA
XLA
Generated by
MATLAB
Compiler SDK
Generated by
MATLAB
Compiler
27
Sharing algorithms across the organization
Web
Server
Application
Server
Database Server
Pricing
Risk
Analytics
Portfolio
Optimization
MATLAB Production Server
MATLAB
Compiler
Web Applications
Desktop Applications
Batch Applications
28
Web Applications - Using JAVA, C# client libraries
Architecture
MATLAB Production Server
Request
Broker
&
Program
Manager
Database Server
Web Server
ZeroCurveServlet
genScenServlet
.
.
.
.
computeCVAServlet
CCRWeb
HTML & JavaScript
front end
30
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 Client
Library
Stored
Procedure
MATLAB Production Server
Request
Broker
&
Program
Manager
31
Integration with Databases
Native in database JSON/Restful call
ORACLE, MS SQL Server, SAS support this in database
Database Server
Enterprise
Application JSON/
Restful
Stored
Procedure
MATLAB Production Server
Request
Broker
&
Program
Manager
32
MATLAB Components in Production Databases
MATLAB Production Server can provide predictive analytics in the database
Oracle (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
Request
Broker
&
Program
Manager
Database Server
33
MATLAB Big Data Analytic Components - Hadoop
Hadoop Grid
Compiled MATLAB
Hadoop Targets
Compiled MATLAB
Hadoop Targets
Compiler generated Hadoop components on each node of Hadoop
Grid
• MATLAB is the analytics for big data
systems such as Hadoop
• Embedded on-node custom
algorithms can be developed in
MATLAB and deployed to the grid
MATLAB Model
MATLAB Runtime