the anatomy of a gpu based counterparty credit risk system · 2014-07-24 · the anatomy of a gpu...

19
The anatomy of a GPU based counterparty credit risk system Patrik Tennberg, TriOptima July 10 th 2014

Upload: vuongdung

Post on 09-Jun-2018

215 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: The anatomy of a GPU based counterparty credit risk system · 2014-07-24 · The anatomy of a GPU based counterparty credit risk system Patrik Tennberg, ... Valuation Parse Portfolio

The anatomy of a GPU based

counterparty credit risk system

Patrik Tennberg, TriOptima

July 10th 2014

Page 2: The anatomy of a GPU based counterparty credit risk system · 2014-07-24 · The anatomy of a GPU based counterparty credit risk system Patrik Tennberg, ... Valuation Parse Portfolio

Agenda

A new methodology for counterparty credit risk calculations

System Overview

Architecture

CUDA made easy

2

Page 3: The anatomy of a GPU based counterparty credit risk system · 2014-07-24 · The anatomy of a GPU based counterparty credit risk system Patrik Tennberg, ... Valuation Parse Portfolio

A new methodology

for counterparty

credit risk

calculations

3

Page 4: The anatomy of a GPU based counterparty credit risk system · 2014-07-24 · The anatomy of a GPU based counterparty credit risk system Patrik Tennberg, ... Valuation Parse Portfolio

Valuation

• Discretized time and space

• Market factor dynamics described

through transition probability matrices

• Matrices can be used for both:

– Stepping forward in Monte-Carlo

simulation for counterparty credit risk

– Backward induction to price derivatives

• Calculation builds on matrix algebra

– Very fast implementation using modern

GPU technology

4

t0

100

t1

P = 0.05

120 110 100 90 80

120 0.9 0.07 0.03 0 0

110 0.03 0.9 0.05 0.02 0

100 0.01 0.05 0.88 0.05 0.01

90 0 0.02 0.05 0.9 0.03

80 0 0 0.03 0.07 0.9

110

120

90

80

Page 5: The anatomy of a GPU based counterparty credit risk system · 2014-07-24 · The anatomy of a GPU based counterparty credit risk system Patrik Tennberg, ... Valuation Parse Portfolio

Valuation, cont.

• Start from a general model for the underlying

• Use probability theory to generate the transition

probability matrix at a (very) short time period

• Multiply the transition matrix by itself to generate longer

period matrices

5

dttdNStdWStdtSttdtdS tttt

ttat t

)()()()()( )(

120 110 100 90 80

120 0.99 0.01 0 0 0

110 0.01 0.98 0.01 0 0

100 0 0.01 0.98 0.01 0

90 0 0.02 0.01 0.98 0.01

80 0 0 0 0.01 0.99

Sdt

Page 6: The anatomy of a GPU based counterparty credit risk system · 2014-07-24 · The anatomy of a GPU based counterparty credit risk system Patrik Tennberg, ... Valuation Parse Portfolio

Advantages

• Consistency in market dynamics

– Traditional approaches using one dynamic for MC generation and another dynamic for

pricing (implied by standard pricing models)

• Realistic models for market dynamics

– Numerical approach means that you are not confined to models with analytical

solutions

– Caters for wrong-way risk

• Simple implementation of new products

– Only the pay-off profile need to be described

• Very fast calculations when designed for new hardware

– All prices for all paths is pre-calculated during the valuation step

– Enables many more MC simulations which also increase accuracy

6

Page 7: The anatomy of a GPU based counterparty credit risk system · 2014-07-24 · The anatomy of a GPU based counterparty credit risk system Patrik Tennberg, ... Valuation Parse Portfolio

7

The method is developed by Claudio Albanese

www.albanese.co.uk

More information regarding the method can

be found here:

Coherent global market simulation and

securitization measures for counterparty

credit risk

Page 8: The anatomy of a GPU based counterparty credit risk system · 2014-07-24 · The anatomy of a GPU based counterparty credit risk system Patrik Tennberg, ... Valuation Parse Portfolio

System Overview

confidential - sensitive 8

Page 9: The anatomy of a GPU based counterparty credit risk system · 2014-07-24 · The anatomy of a GPU based counterparty credit risk system Patrik Tennberg, ... Valuation Parse Portfolio

triCalculate Overview

9

Valuation

Parse Portfolio

Simulation

Client Service

Manager

simulationengine_cli valuationengine_cli

meta data,

valuation tables,

discount factors,

default

probabilities,

transition kernels

PV for all trades.

Frates

Portfolio Available Upload Portfolio

Start

Batch

Result

Available

Page 10: The anatomy of a GPU based counterparty credit risk system · 2014-07-24 · The anatomy of a GPU based counterparty credit risk system Patrik Tennberg, ... Valuation Parse Portfolio

Architecture

confidential - sensitive 10

Page 11: The anatomy of a GPU based counterparty credit risk system · 2014-07-24 · The anatomy of a GPU based counterparty credit risk system Patrik Tennberg, ... Valuation Parse Portfolio

Architectural Goals

Device Agnostic

MKL and CUDA

Portable

Linux (Prod), OSX and Windows (Development)

Simple and natural programming model

Universal language of mathematics

Application code has no knowledge about devices,

threads and other complicated stuff

Testable

700+ tests, executed at every code commit

Fast Enough!

Simplicity over performance as long as it fast enough

11

Page 12: The anatomy of a GPU based counterparty credit risk system · 2014-07-24 · The anatomy of a GPU based counterparty credit risk system Patrik Tennberg, ... Valuation Parse Portfolio

ComputeEngine

High Level Architecture

12

MKL

Financial Services

API

Valuation Simulation

Models

Curves

Trades

API

Pricers

M. Factors

Calibration

Scenarios

Simulation

API

Evaluator

Common

Export / Import

Logging

API

System

Linear Algebra

CUDA ?

Date / Time Math

Page 13: The anatomy of a GPU based counterparty credit risk system · 2014-07-24 · The anatomy of a GPU based counterparty credit risk system Patrik Tennberg, ... Valuation Parse Portfolio

made easy

13

Page 14: The anatomy of a GPU based counterparty credit risk system · 2014-07-24 · The anatomy of a GPU based counterparty credit risk system Patrik Tennberg, ... Valuation Parse Portfolio

ComputeEngine – Low Level API

Device Management

ceGetDeviceCount, ceEnumDevices, ceCreateDC

Memory management

DataHandle, ceAllocateData, ceFreeData

Supported Types: Vector, Matrix, Float, Double, Integer

Devices has their own memory manager

Operations

Linear Algebra: e.g. FastExp, Floor, Multiplication (MS, MV, MM)

Financial Operations: e.g. ceAddCashFlows, ceGetDailyDiscountFactors

Asynchronous execution

ceAddJobToQueue

14

Page 15: The anatomy of a GPU based counterparty credit risk system · 2014-07-24 · The anatomy of a GPU based counterparty credit risk system Patrik Tennberg, ... Valuation Parse Portfolio

ComputeEngine – High Level API

15

typedef Matrix<float> FloatMatrix;

MatrixFactory mf(DeviceType::CUDA); // DeviceType::MKL

FloatMatrix m = mf.CreateMatrix(3, 3, 1.0f);

m *= 0.005f;

FloatMatrix id = mf.CreateIdentityMatrix(3);

m = m + id;

m.FastExp(3);

A matrix factory represents a device (e.g. CUDA or MKL

(CPU)).

A matrix factory knows how to create data types (e.g. vectors,

matrices, etc.) on a specific device.

All operations on data types are executed on a specific

device without memory transitions

Page 16: The anatomy of a GPU based counterparty credit risk system · 2014-07-24 · The anatomy of a GPU based counterparty credit risk system Patrik Tennberg, ... Valuation Parse Portfolio

Parallel Execution Model

Calculations are partitioned into jobs

When a job is scheduled for execution that job is

assigned a matrix factory (a device)

Jobs are scheduled over all available matrix

factories

As soon as a job is done it returns its matrix factory

to the scheduler

16

Jn

J2 MF2

Scheduler

K401

J1 MF1

K402

Page 17: The anatomy of a GPU based counterparty credit risk system · 2014-07-24 · The anatomy of a GPU based counterparty credit risk system Patrik Tennberg, ... Valuation Parse Portfolio

Performance

Portfolio

5727 trades, IR Swaps, cap-floor, swaptions

and FX forwards in several currencies

505 counterparties

81 time steps

Valuation (2 K40)

Generated data 15 GB

Took 84 seconds

Simulation (2 CPU, 12 cores each)

100,000 scenarios

Took ~2 minutes 24 seconds

17

Page 18: The anatomy of a GPU based counterparty credit risk system · 2014-07-24 · The anatomy of a GPU based counterparty credit risk system Patrik Tennberg, ... Valuation Parse Portfolio

Pros and Cons

Pros

Device Agnostic

Easy and Intuitive to use – mathematical notation

Sandbox development

Cons

Performance is not optimal

18

Page 19: The anatomy of a GPU based counterparty credit risk system · 2014-07-24 · The anatomy of a GPU based counterparty credit risk system Patrik Tennberg, ... Valuation Parse Portfolio

Thank You

[email protected]

www.trioptima.com