31
1 © 2013 The MathWorks, Inc. MATLAB for Use in Finance Portfolio Optimization (Mean Variance, CVaR & MAD) Market, Credit, Counterparty Risk Analysis and beyond Marshall Alphonso [email protected] Senior Application Engineer MathWorks

MATLAB for Use in Finance · “Because MATLAB enables us to build and distribute applications to analysts that are accessible from Excel, we are quickly bringing to market products

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Page 1: MATLAB for Use in Finance · “Because MATLAB enables us to build and distribute applications to analysts that are accessible from Excel, we are quickly bringing to market products

1 © 2013 The MathWorks, Inc.

MATLAB for Use in Finance Portfolio Optimization (Mean Variance, CVaR & MAD)

Market, Credit, Counterparty Risk Analysis and beyond

Marshall Alphonso [email protected]

Senior Application Engineer

MathWorks

Page 2: MATLAB for Use in Finance · “Because MATLAB enables us to build and distribute applications to analysts that are accessible from Excel, we are quickly bringing to market products

2

Agenda

Introduction: Knowing your risk

Overview of the MATLAB Solution – Connect to financial data sources

– Perform financial modeling & analysis

– Share results & deploy applications

Finance Application Examples – Portfolio Construction using Frameworks

– Evaluating Risks

– Constructing your own Portfolio Management Framework

Page 3: MATLAB for Use in Finance · “Because MATLAB enables us to build and distribute applications to analysts that are accessible from Excel, we are quickly bringing to market products

3

Challenges in Financial Analysis

Volatile markets

– Ever-changing needs

Lack of computing power

– Large data, large models

Increased transparency

– More auditing and regulation

– More sharing with colleagues

Management Traders

Quant Group

Financial

Engineer

Regulators Clients Partners

Other groups

Page 4: MATLAB for Use in Finance · “Because MATLAB enables us to build and distribute applications to analysts that are accessible from Excel, we are quickly bringing to market products

4

Traditional Approach Challenge

Challenges Faced During Model Development

Off-the-shelf software Inability to customize

Third-party consulting Lack of transparency

Spreadsheets, Excel Subpar computational

speed, limited data size

In-house development with

traditional languages Long development time

Combination of the above Inefficiencies in

Integration & Automation

Page 5: MATLAB for Use in Finance · “Because MATLAB enables us to build and distribute applications to analysts that are accessible from Excel, we are quickly bringing to market products

5

Who uses MATLAB in Financial Services?

The top 15 asset-

management companies

9 of the top 10 U.S.

commercial banks

12 of the top 15 hedge funds

The reserve banks of all

OECD member countries

The top 3 credit rating

agencies

Page 6: MATLAB for Use in Finance · “Because MATLAB enables us to build and distribute applications to analysts that are accessible from Excel, we are quickly bringing to market products

6

Agenda

Introduction: Knowing your risk

Overview of the MATLAB Solution – Connect to financial data sources

– Perform financial modeling & analysis

– Share results & deploy applications

Finance Application Examples – Macroeconomic modeling & forecasting

– Cash flow hedging & scenario analysis

– Credit risk assessment

Page 7: MATLAB for Use in Finance · “Because MATLAB enables us to build and distribute applications to analysts that are accessible from Excel, we are quickly bringing to market products

7

Computational Finance Workflow

Research and Quantify

Data Analysis

& Visualization

Financial

Modeling

Application

Development

Reporting

Applications

Production

Share

Automate

Files

Databases

Datafeeds

Access

Page 8: MATLAB for Use in Finance · “Because MATLAB enables us to build and distribute applications to analysts that are accessible from Excel, we are quickly bringing to market products

8

Portfolio Optimization

0.005 0.01 0.015 0.021

1.5

2

2.5

3

3.5x 10

-3 Efficient Frontier

Standard Deviation of Portfolio Returns

Mean o

f P

ort

folio

Retu

rns

0.005 0.01 0.015 0.020.1

0.15

0.2

0.25

0.3

0.35Efficient Frontier

Standard Deviation of Portfolio Returns

Mean o

f P

ort

folio

Retu

rns

Page 9: MATLAB for Use in Finance · “Because MATLAB enables us to build and distribute applications to analysts that are accessible from Excel, we are quickly bringing to market products

9

Modeling Market Risk Factor Time Series

Need model that captures:

Correlation & overall volatilities

Time-varying volatility

Fat-tailed distributions

Candidate model: Geometric Brownian Motion

Correlation & overall volatilities

Time-varying volatility

Fat-tailed distributions

Page 10: MATLAB for Use in Finance · “Because MATLAB enables us to build and distribute applications to analysts that are accessible from Excel, we are quickly bringing to market products

10

Market Risk Using Copulas, GARCH & EVT

“Forecasting risk factors”

Need model that captures:

Time-varying volatility GARCH

Fat-tailed distributions Generalized Pareto

Factor Correlations Copulas

Page 11: MATLAB for Use in Finance · “Because MATLAB enables us to build and distribute applications to analysts that are accessible from Excel, we are quickly bringing to market products

11

Market Risk Using Copulas & Extreme Value Theory

“Asymmetric GARCH using a GJR Model”

Model returns using a asymmetric GARCH Model

Estimate a Marginal CDF – Kernel + Pareto Tails

Fit a Student-T Copula and induce correlation amongst

the simulated residuals

Estimate a VaR & CVaR

Page 12: MATLAB for Use in Finance · “Because MATLAB enables us to build and distribute applications to analysts that are accessible from Excel, we are quickly bringing to market products

12

The GARCH Model

“Non-symmetric, Non-Gaussian residuals”

)1,0(~

1

2

1

22

11

Nz

z

AG

yCy

t

ttt

Q

j

jtj

P

i

itit

t

M

j

jtj

R

i

itit

GARCH ARCH

ARMA AR

Page 13: MATLAB for Use in Finance · “Because MATLAB enables us to build and distribute applications to analysts that are accessible from Excel, we are quickly bringing to market products

13

Credit Classification

“Logistic Regression Vs. TreeBagger”

>> doc mnrfit

>> doc mnrval

>> doc treebagger

>> doc confusionmat

2.00%

1.43%

0.00%

0.00%

0.00%

0.00%

0.00%

0.00%

3.71%

4.29%

0.00%

0.00%

0.00%

0.00%

0.00%

2.29%

16.29%

3.71%

0.00%

0.00%

0.00%

0.00%

0.00%

5.14%

12.86%

1.71%

0.00%

0.00%

0.00%

0.00%

0.29%

3.71%

9.14%

2.86%

0.00%

0.00%

0.00%

0.00%

0.00%

4.00%

9.14%

1.43%

0.00%

0.00%

0.00%

0.00%

0.00%

1.14%

14.86%

Logistic: [Training Set] Actual Vs Estimated Credit Ratings

CC

C B BB

BBB

A AA

AAA

CCC

B

BB

BBB

A

AA

AAA 0.00%

5.00%

10.00%

15.00%

2.65%

1.09%

0.00%

0.00%

0.00%

0.00%

0.00%

0.39%

2.40%

5.70%

0.00%

0.00%

0.00%

0.00%

0.00%

1.06%

17.06%

3.07%

0.00%

0.00%

0.00%

0.00%

0.00%

5.42%

14.57%

2.21%

0.00%

0.00%

0.00%

0.00%

0.03%

3.38%

10.36%

2.18%

0.00%

0.00%

0.00%

0.00%

0.00%

1.62%

10.16%

1.76%

0.00%

0.00%

0.00%

0.00%

0.00%

1.01%

13.90%

Logistic: [Testing Set] Actual Vs Estimated Credit Ratings

CCC B BB

BBB

A AA

AAA

CCC

B

BB

BBB

A

AA

AAA 0.00%

5.00%

10.00%

15.00%

Popular in classifying the credit quality of instruments is the use of logistic

regression. This example illustrates this classification but takes a step

further by using a Tree Bagger classifier.

Page 14: MATLAB for Use in Finance · “Because MATLAB enables us to build and distribute applications to analysts that are accessible from Excel, we are quickly bringing to market products

14

Credit Value Adjustment – Expected loss on portfolio

100

200

300

Jul07

Jan10

Jul12

Jan15

0.04

0.06

0.08

0.1

Tenor (Months)

Yield Curve Evolution

Observation Date

Rat

es

[Section 3|EX 1]

Page 15: MATLAB for Use in Finance · “Because MATLAB enables us to build and distribute applications to analysts that are accessible from Excel, we are quickly bringing to market products

15

Evaluate Counterparty Exposures

[Section 3 | EX 1]

>> doc IRDataCurve

>> doc hwv

1 2 3 4 50

1000

2000

3000

4000

5000

6000CVA for each counterparty

Counterparty

CVA

$

Page 16: MATLAB for Use in Finance · “Because MATLAB enables us to build and distribute applications to analysts that are accessible from Excel, we are quickly bringing to market products

16

Excel spreadsheets and flat files

ODBC or JDBC compliant databases

Data feeds including Bloomberg, Reuters, Factset®, eSignal® and others

Web services (SOAP)

Connect to Data from Various Sources

Page 17: MATLAB for Use in Finance · “Because MATLAB enables us to build and distribute applications to analysts that are accessible from Excel, we are quickly bringing to market products

17

Mathematics Regression (Linear, Non-Linear)

Curve Fitting

Probability Distributions, RNG

Clustering

Multivariate & Factor Analysis

Predictive Modeling, AI

Optimization, Parameter Estimation

Leverage Built-in Functions to Save Time

Financial Modeling Portfolio Optimization & Analysis

Derivative Pricing & Hedging

Yield Curve Modeling

Monte Carlo Simulation

Risk Quantification

ARMA/GARCH Analysis

Page 18: MATLAB for Use in Finance · “Because MATLAB enables us to build and distribute applications to analysts that are accessible from Excel, we are quickly bringing to market products

18

Share applications with those who do not need MATLAB

Royalty free

MATLAB Production Server provides most efficient path

for secure and scalable enterprise applications

MATLAB

MATLAB

Compiler SDK

C/C ++ Java Hadoop .NET

MATLAB

Compiler

MATLAB Production

Server

Sharing MATLAB Applications

MATLAB

.exe Excel

Page 19: MATLAB for Use in Finance · “Because MATLAB enables us to build and distribute applications to analysts that are accessible from Excel, we are quickly bringing to market products

19

Financial Modeling Workflow

Financial

Statistics & Machine

Learning Optimization

Financial Instruments Econometrics

MATLAB

Parallel Computing MATLAB Distributed Computing Server

Files

Databases

Datafeeds

Access

Reporting

Applications

Production

Share

Data Analysis and Visualization

Financial Modeling

Application Development

Research and Quantify

MATLAB Compiler

SDK

MATLAB Compiler

Rep

ort G

en

era

tor

Production Server

Datafeed

Database

Spreadsheet Link EX

Trading

Research and Quantify

Data Analysis

& Visualization

Financial

Modeling

Application

Development

Reporting

Applications

Production

Share

Automate

Files

Databases

Datafeeds

Access

Page 20: MATLAB for Use in Finance · “Because MATLAB enables us to build and distribute applications to analysts that are accessible from Excel, we are quickly bringing to market products

20

MATLAB Desktop

End-User Machine

1

2

3 Toolboxes

Deploying MATLAB Applications to Excel

MATLAB Builder EX

MATLAB Compiler

.dll .bas/

.xla

Page 21: MATLAB for Use in Finance · “Because MATLAB enables us to build and distribute applications to analysts that are accessible from Excel, we are quickly bringing to market products

21

Development

Enterprise

Application

Developer

Production

MATLAB

Developer

Production Deployment Workflow

MATLAB Production Server

MATLAB Production Server

CTF

Web

Application

Client

Library

. . .

Function Call

Algorithm

Web

Application

Client

Library

MATLAB

Compiler

Page 22: MATLAB for Use in Finance · “Because MATLAB enables us to build and distribute applications to analysts that are accessible from Excel, we are quickly bringing to market products

22

Value of MATLAB Production Server

Directly deploy MATLAB programs into production – Supports multiple MATLAB programs and MCR versions

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

MATLAB Production Server(s)

HTML

XML

Java Script Web

Server(s)

Page 23: MATLAB for Use in Finance · “Because MATLAB enables us to build and distribute applications to analysts that are accessible from Excel, we are quickly bringing to market products

23

CAMRADATA Models Dependencies for

Quantitative Risk Assessment with

MathWorks Tools

Challenge Rapidly develop quantitative tools for factor analysis,

risk analysis, and defensive asset allocation

Solution Use MATLAB to model complex non-linear dependencies

between assets, liabilities, and economic variables using

copulas

Results Development time reduced by 90 percent

Risk calculated in hours, not weeks

Diverse skill sets leveraged

“Using MATLAB we can build a

model in one morning. It would

take two weeks to write the

equivalent code in Visual Basic.”

Martyn Dorey

CAMRADATA

Risk-assessment model developed in

MATLAB.

Link to user story

Page 24: MATLAB for Use in Finance · “Because MATLAB enables us to build and distribute applications to analysts that are accessible from Excel, we are quickly bringing to market products

24

Capgemini Helps Clients Achieve Basel II

Compliance and Deliver Economic Capital,

Risk, and Valuation Models with MATLAB

Challenge Enable banking clients to meet Basel II regulatory

guidelines and perform other risk management tasks

Solution Use MATLAB to develop risk management models and

to perform valuations of complex products

Results Strong competitive advantage established

Scalable solution delivered

Customer portfolio revalued

“With its computational power, matrix

infrastructure, and ability to perform

Monte Carlo simulations, MATLAB gives

us a competitive advantage in

performing complex risk analyses."

Dr. Marco Folpmers

Capgemini

Link to user story

Scatterplots showing 500,000 simulations

drawn from bivariate t-copulas with the same

correlation coefficient but differing degrees

of freedom.

Page 25: MATLAB for Use in Finance · “Because MATLAB enables us to build and distribute applications to analysts that are accessible from Excel, we are quickly bringing to market products

25

Intuitive Analytics Uses MATLAB to Build

Quantitative Tools to Help Bond Issuers

Manage Risk

Challenge Build and market a quantitative tool for reducing

expected cost and risk for municipal bond issuers

Solution Use MathWorks tools to develop algorithms, visualize

results, and simplify deployment of an advanced

analytical tool

Results Development productivity increased by 90%

Deployment simplified

Visual environment created

“Because MATLAB enables us to

build and distribute applications to

analysts that are accessible from

Excel, we are quickly bringing to

market products that are adopted

and deployed by investment banks.”

Peter Orr

Intuitive Analytics

Using MATLAB technical computing

software to provide visual representations

of interest rate models.

Link to user story

Page 26: MATLAB for Use in Finance · “Because MATLAB enables us to build and distribute applications to analysts that are accessible from Excel, we are quickly bringing to market products

26

IPD Develops and Deploys Real

Estate Cash Flow Models with

MathWorks Tools

Challenge Create cash flow models of real estate investment

portfolios and project returns using Monte Carlo

simulations

Solution Use MATLAB and MATLAB Builder NE to develop

optimization algorithms, build financial models, and

deploy solutions

Results Development time cut by 16 weeks

Updates completed in hours

Deployment simplified

“The only other approach we

seriously considered involved

developing a class library in

.NET and C#. Development,

debugging, and testing would

have taken us 37 weeks. Using

MATLAB, we completed the

project in 21 weeks.”

Peter McAnena

Investment Property Databank

MATLAB graph generated to indicate how total returns

from industrial property are likely to behave.

'06

'07

'082 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

Link to user story

Page 27: MATLAB for Use in Finance · “Because MATLAB enables us to build and distribute applications to analysts that are accessible from Excel, we are quickly bringing to market products

27

Nykredit Develops Risk Management and

Portfolio Analysis Applications to Minimize

Operational Risk

Challenge Enable financial analysts to make rapid, fact-based

decisions by providing them with direct access to risk

management and portfolio analysis information

Solution Develop and deploy easy-to-use graphical financial

analysis applications using MATLAB and MATLAB

Compiler

Results Productivity increased threefold

Operational risk mitigated

Analysis time reduced from days to hours

Link to user story

Nykredit’s tool for calculating and

visualizing risk statistics. The plot

shows portfolio expected tracking

error broken out by industry.

“Data handling, programming, debugging,

and plotting are much easier in MATLAB,

where everything is in one environment.

For performance calculation GUIs,

MATLAB provides a real error-checked

application that makes cool customized

plots for client reports. This has turned a

several-hour task in a spreadsheet into a

two-minute no-brainer.”

Peter Ahlgren

Nykredit Asset Management

Page 28: MATLAB for Use in Finance · “Because MATLAB enables us to build and distribute applications to analysts that are accessible from Excel, we are quickly bringing to market products

28

Macroeconomic Modeling and Inflation

Rate Forecasting at the Reserve Bank of

New Zealand

Challenge

Support New Zealand monetary policy with a

theoretically well-founded model

Solution

Use MATLAB to analyze and forecast macroeconomic

variables, and communicate results to stakeholders

Results

Entire workflow completed in a single environment

Code shared with other central banks and

financial institutions

Technical rigor of macroeconomic forecasting

increased

“With all RBNZ models now

implemented in MATLAB, the

RBNZ has a common platform

for evaluating the economy and

making informed decisions.”

Jaromir Benes

International Monetary Fund

Link to article

Sample fancharts produced by RBNZ’s

macroeconomic model.

Page 29: MATLAB for Use in Finance · “Because MATLAB enables us to build and distribute applications to analysts that are accessible from Excel, we are quickly bringing to market products

29

Robeco Develops Quantitative Stock

Selection and Portfolio Optimization

Models with MathWorks Tools

Challenge Develop, distribute, and maintain quantitative

tools for portfolio construction and management

Solution Use MATLAB and MATLAB Builder NE to develop

algorithms, build quantitative models, and deploy

solutions

Results Applications updated faster

Black-box solutions eliminated

Scalability and flexibility increased

“Unlike companies that rely on off-the-

shelf quantitative analysis solutions, we

can see our process improving all the

time. We have the flexibility to

continuously improve our algorithms

and models in MATLAB—and that is a

big advantage.”

Willem Jellema

Robeco

Interest rate paths for the risk analysis of a

savings product.

Link to user story

Page 30: MATLAB for Use in Finance · “Because MATLAB enables us to build and distribute applications to analysts that are accessible from Excel, we are quickly bringing to market products

30

Challenge Solution

Inability to customize Flexible modeling

Complete development environment

Lack of transparency White-box modeling

Viewable-source functions

Subpar computational

speeds Powerful computation engine

Run fast Monte-Carlo simulations

Long development time Quick prototyping

Focus on modeling not programming

Inefficiencies in

Integration Easy to Integrate & Deploy

Point-and-click workflow

MATLAB Solutions

Page 31: MATLAB for Use in Finance · “Because MATLAB enables us to build and distribute applications to analysts that are accessible from Excel, we are quickly bringing to market products

31

Questions