using r for analyzing loans, portfolios and risk: from academic theory to financial practice

78
Using R in Academic Finance Sanjiv R. Das Professor, Santa Clara University Department of Finance h?p://algo.scu.edu/~sanjivdas/

Upload: revolution-analytics

Post on 24-Jun-2015

14.057 views

Category:

Technology


2 download

DESCRIPTION

Dr. Sanjiv Das has held positions as at Citibank, Harvard University Professor and Program Director at the FDIC’s Center for Financial Research. His research relies heavily on R for analysis and decision-making. In this webinar, Dr. Das will present a mix of some of his more current and topical research that uses R-based models, and some pedagogical applications of R. He will present: * An R-based model for optimizing loan modifications on distressed home loans, and the economics of these modifications. * A goal-based portfolio optimization model for investors who use derivatives. *Using network modeling tools in R to detect systemically risky financial institutions. *Using R for web delivery of financial models and random generation of pedagogical problems. Promising to be entertaining and enlightening, this webinar will emphasize the interplay of mathematical models, economic problems, and R.

TRANSCRIPT

Page 1: Using R for Analyzing Loans, Portfolios and Risk:  From Academic Theory to Financial Practice

Using R in Academic Finance 

Sanjiv R. Das Professor, Santa Clara University 

Department of Finance h?p://algo.scu.edu/~sanjivdas/ 

Page 2: Using R for Analyzing Loans, Portfolios and Risk:  From Academic Theory to Financial Practice

Outline •  High‐performance compuGng for Finance •  Modeling the opGmal modificaGon of home loans using R 

•  IdenGfying systemically risky financial insGtuGons using R network models. 

•  Goal‐based porOolio opGmizaGon with R •  Using R to deliver funcGons/models on the web, and for pedagogical purposes. 

R works well with Python and C. 

Page 3: Using R for Analyzing Loans, Portfolios and Risk:  From Academic Theory to Financial Practice

h?p://www.rinfinance.com/RinFinance2010/agenda/ 

h?p://cran.r‐project.org/web/views/Finance.html 

Page 4: Using R for Analyzing Loans, Portfolios and Risk:  From Academic Theory to Financial Practice
Page 5: Using R for Analyzing Loans, Portfolios and Risk:  From Academic Theory to Financial Practice

Calling C from R: An Example of Tax‐opGmized PorOolio Rebalancing 

Page 6: Using R for Analyzing Loans, Portfolios and Risk:  From Academic Theory to Financial Practice

Calling C from R: An Example of Tax‐opGmized PorOolio Rebalancing 

Page 7: Using R for Analyzing Loans, Portfolios and Risk:  From Academic Theory to Financial Practice

R CMD SHLIB tax.c 

Page 8: Using R for Analyzing Loans, Portfolios and Risk:  From Academic Theory to Financial Practice

MODIFYING HOME LOANS WITH R MODELS 

Topic 1 

THE PRINCIPAL PRINCIPLE: OpGmal ModificaGon of Distressed Home Loans (Why Lenders should Forgive, not Foresake Mortgages)  STRATEGIC LOAN MODIFICATION: An OpGons based response to strategic default (joint work with Ray Meadows)  

Page 9: Using R for Analyzing Loans, Portfolios and Risk:  From Academic Theory to Financial Practice
Page 10: Using R for Analyzing Loans, Portfolios and Risk:  From Academic Theory to Financial Practice
Page 11: Using R for Analyzing Loans, Portfolios and Risk:  From Academic Theory to Financial Practice
Page 12: Using R for Analyzing Loans, Portfolios and Risk:  From Academic Theory to Financial Practice
Page 13: Using R for Analyzing Loans, Portfolios and Risk:  From Academic Theory to Financial Practice

Game theoreGc problem:   Lender determines the loan modificaGon that maximizes value of loan given that the borrower will act strategically in his best interest.  

Page 14: Using R for Analyzing Loans, Portfolios and Risk:  From Academic Theory to Financial Practice

Model 

h?p://algo.scu.edu/~sanjivdas/  14 

Home value 

HJM 

CorrelaGon 

Page 15: Using R for Analyzing Loans, Portfolios and Risk:  From Academic Theory to Financial Practice

“Iso‐Service” Surface 

2/27/12  h?p://algo.scu.edu/~sanjivdas/  15 

Loan balance = $300,000 Home value = $250,000  Remaining maturity = 25 years A = $1,933 per month   Amax = $20,000 per year 

 ($1,667 per month) 

choose 

Page 16: Using R for Analyzing Loans, Portfolios and Risk:  From Academic Theory to Financial Practice

Some R 

Page 17: Using R for Analyzing Loans, Portfolios and Risk:  From Academic Theory to Financial Practice

Values of Iso‐Service Loans 

h?p://algo.scu.edu/~sanjivdas/  17 

Page 18: Using R for Analyzing Loans, Portfolios and Risk:  From Academic Theory to Financial Practice

Default Put Exercise Region 

h?p://algo.scu.edu/~sanjivdas/  18 

L=225,000 

L=250,000 

Page 19: Using R for Analyzing Loans, Portfolios and Risk:  From Academic Theory to Financial Practice

Cure risk and Re‐default Risk 

h?p://algo.scu.edu/~sanjivdas/  19 

The risk of unnecessary relief, i.e., the borrower would not have ulGmately defaulted. 

Providing fuGle relief, leading to ulGmate default anyway.  

Value of loan accounGng for willingness to pay 

A: borrower income available for housing service, with mean μ and std. dev σ.  

Page 20: Using R for Analyzing Loans, Portfolios and Risk:  From Academic Theory to Financial Practice

h?p://algo.scu.edu/~sanjivdas/  20 

Page 21: Using R for Analyzing Loans, Portfolios and Risk:  From Academic Theory to Financial Practice

h?p://algo.scu.edu/~sanjivdas/ 

Logit: Explaining Re‐default 

Page 22: Using R for Analyzing Loans, Portfolios and Risk:  From Academic Theory to Financial Practice

h?p://algo.scu.edu/~sanjivdas/ 22 

Reduced‐Form Analysis of SAMs 

Home values 

Normalize iniGal home value to 1. The opGon to default is ITM when (H > L).   There is a home value D at which the borrower will default. D is a “default level” or default exercise barrier.   D is a funcGon of the lender share θ, we write it as D(L, θ).  D increases in L and in θ.  Foreclosure recovery as a fracGon of H is ϕ. 

Page 23: Using R for Analyzing Loans, Portfolios and Risk:  From Academic Theory to Financial Practice

h?p://algo.scu.edu/~sanjivdas/ 23 

Default Barrier and Lender Share 

Page 24: Using R for Analyzing Loans, Portfolios and Risk:  From Academic Theory to Financial Practice

h?p://algo.scu.edu/~sanjivdas/ 24 

Barrier Model IntuiGon 

D=L exp[‐γ(1‐θ)] 

Region of no default and gains to SAM 

Region of default  

H0 = 1 

Default Payoff=фD

No default Payoff=L 

Page 25: Using R for Analyzing Loans, Portfolios and Risk:  From Academic Theory to Financial Practice

h?p://algo.scu.edu/~sanjivdas/ 25 

A Barrier OpGon DecomposiGon Non‐default  component 

Default component 

Shared AppreciaGon component 

PDE 

Page 26: Using R for Analyzing Loans, Portfolios and Risk:  From Academic Theory to Financial Practice

h?p://algo.scu.edu/~sanjivdas/ 26 

The Closed‐Form SoluGon 

Page 27: Using R for Analyzing Loans, Portfolios and Risk:  From Academic Theory to Financial Practice

h?p://algo.scu.edu/~sanjivdas/ 27 

SAM or not? 

Page 28: Using R for Analyzing Loans, Portfolios and Risk:  From Academic Theory to Financial Practice

MANAGING SYSTEMIC RISK BY ANALYZING NETWORKS USING R   THE MIDAS PROJECT @IBM   

Topic 2 

  Paper: “Unleashing the Power of Public Data for Financial Risk Measurement, RegulaGon, and Governance” (with Mauricio A. Hernandez, Howard Ho, Georgia Koutrika, Rajasekar Krishnamurthy, Lucian Popa, Ioana R. Stanoi, Shivakumar Vaithyanathan) IBM Almaden) 

Page 29: Using R for Analyzing Loans, Portfolios and Risk:  From Academic Theory to Financial Practice

Midas Financial Insights 

29 

Annual Report

Proxy Statement Insider Transaction

Loan Agreement

Extract Integrate

Related Companies

Loan Exposure

Exposure by subsidiary

… 

… 

Raw Unstructured Data 

Data for Analysis 

Raw Unstructured Data 

Page 30: Using R for Analyzing Loans, Portfolios and Risk:  From Academic Theory to Financial Practice

30 

Systemic Analysis Systemic Analysis  •  DefiniGon: the measurement and analysis of relaGonships across enGGes 

with a view to understanding the impact of these relaGonships on the system as a whole.  

•  Challenge: requires most or all of the data in the system; therefore, high‐quality informaGon extracGon and integraGon is criGcal.  

Systemic Risk  •  Current approaches: use stock return correlaGons (indirect). [Acharya, et 

al 2010; Adrian and Brunnermeier 2009; Billio, Getmansky, Lo 2010; Kritzman, Li, Page, Rigobon 2010] 

•  Midas: uses semi‐structured archival data from SEC and FDIC to construct a co‐lending network; network analysis is then used to determine which banks pose the greatest risk to the system.  

 

Page 31: Using R for Analyzing Loans, Portfolios and Risk:  From Academic Theory to Financial Practice

31 

Co‐lending Network 

•  DefiniGon: a network based on links between banks that lend together.  

•  Loans used are not overnight loans. We look at longer‐term lending relaGonships.  

•  Lending adjacency matrix:  •  Undirected graph, i.e., symmetric   •  Total lending impact for each bank:   

Page 32: Using R for Analyzing Loans, Portfolios and Risk:  From Academic Theory to Financial Practice

32 

Centrality 

•  Influence relaGons are circular: 

•  Pre‐mulGply by scalar to get an eigensystem: 

•  Principal eigenvector of this system gives the “centrality” score for a bank. 

•  This score is a measure of the systemic risk of a bank.  

Page 33: Using R for Analyzing Loans, Portfolios and Risk:  From Academic Theory to Financial Practice

33 

Data 

•  Five years: 2005—2009. •  Loans between FIs only.  •  Filings made with the SEC. •  No overnight loans. •  Example: 364‐day bridge loans, longer‐term credit arrangement, 

Libor notes, etc.  •  Remove all edge weights < 2 to remove banks that are minimally 

acGve. Remove all nodes with no edges. (This is a choice for the regulator.) 

Page 34: Using R for Analyzing Loans, Portfolios and Risk:  From Academic Theory to Financial Practice
Page 35: Using R for Analyzing Loans, Portfolios and Risk:  From Academic Theory to Financial Practice
Page 36: Using R for Analyzing Loans, Portfolios and Risk:  From Academic Theory to Financial Practice

2005 

CiGgroup Inc. 

J.P. Morgan Chase 

Bank of America Corp. 

Page 37: Using R for Analyzing Loans, Portfolios and Risk:  From Academic Theory to Financial Practice

37 

2006  2007 

2008  2009 

Page 38: Using R for Analyzing Loans, Portfolios and Risk:  From Academic Theory to Financial Practice

38 

Network Fragility •  DefiniGon: how quickly will the failure of any one bank 

trigger failures across the network? •  Metric: expected degree of neighboring nodes 

averaged across all nodes.  

•  Neighborhoods are expected to “expand” when  •  Metric: diameter of the network. 

R ! 2

Page 39: Using R for Analyzing Loans, Portfolios and Risk:  From Academic Theory to Financial Practice

39 

Top 25 banks by systemic risk 

Page 40: Using R for Analyzing Loans, Portfolios and Risk:  From Academic Theory to Financial Practice

PORTFOLIO OPTIMIZATION USING R    

Topic 3 

The research papers for this work are on my web page – just google it. h?p://algo.scu.edu/~sanjivdas/research.htm/  1.  Das, Markowitz, Scheid, and Statman (JFQA 2010), “PorOolio OpGmizaGon with 

 Mental Accounts” 2.  Das & Statman (2008), “Beyond Mean‐Variance: PorOolio with  

 Structured Products and non‐Gaussian returns.”    

Page 41: Using R for Analyzing Loans, Portfolios and Risk:  From Academic Theory to Financial Practice

Standard OpGmizaGon Problem 

Sanjiv Das 41

Mean Covariance matrix Risk aversion

Portfolio weights

SOLUTION:

See D, Markowitz, Scheid, Statman (JFQA 2010)

Page 42: Using R for Analyzing Loans, Portfolios and Risk:  From Academic Theory to Financial Practice

SoluGon Math 

Sanjiv Das  42

Page 43: Using R for Analyzing Loans, Portfolios and Risk:  From Academic Theory to Financial Practice

Final soluGon 

Sanjiv Das  43

Page 44: Using R for Analyzing Loans, Portfolios and Risk:  From Academic Theory to Financial Practice

Example: ConstrucGon of PorOolios: Available securiGes 

Expected returns Standard deviations

Bond 5% 5%

Low-risk stock 10% 20%

High-risk stock 25% 50%

Sanjiv Das 44

The correlation between the two stocks is 0.2. Other correlations are zero.

Page 45: Using R for Analyzing Loans, Portfolios and Risk:  From Academic Theory to Financial Practice

Investor goals (sub‐porOolios) 

45

Page 46: Using R for Analyzing Loans, Portfolios and Risk:  From Academic Theory to Financial Practice

Sub‐porOolios and overall porOolio 

The expected return of the overall porOolio is the weighted average of the expected returns of the sub‐porOolios. 

The risk of the overall porOolio is not the weighted average of the risk of the sub‐porOolios. 

Sanjiv Das 46

Page 47: Using R for Analyzing Loans, Portfolios and Risk:  From Academic Theory to Financial Practice

Mean‐variance efficient fronGer 

Sanjiv Das 47

Page 48: Using R for Analyzing Loans, Portfolios and Risk:  From Academic Theory to Financial Practice

Real porOolios versus virtual porOolios 

Sanjiv Das 48

Page 49: Using R for Analyzing Loans, Portfolios and Risk:  From Academic Theory to Financial Practice

An alternate problem 

Sanjiv Das 49

For normal returns

Solve for γ

Page 50: Using R for Analyzing Loans, Portfolios and Risk:  From Academic Theory to Financial Practice
Page 51: Using R for Analyzing Loans, Portfolios and Risk:  From Academic Theory to Financial Practice
Page 52: Using R for Analyzing Loans, Portfolios and Risk:  From Academic Theory to Financial Practice

Risk as probability of losses 

Sanjiv Das 52

Mean-variance problem: Minimize Risk (variance) subject to minimum level of Expected Return.

Behavioral portfolio theory: Maximize Return subject to a maximum probability of falling below a threshold.

Page 53: Using R for Analyzing Loans, Portfolios and Risk:  From Academic Theory to Financial Practice

Efficient FronGers in the BPT  (Mental Account) World 

Sanjiv Das 53

Page 54: Using R for Analyzing Loans, Portfolios and Risk:  From Academic Theory to Financial Practice

Short‐Selling Constraints 

54

Linear program with non‐linear constraints. This is not a standard quadraGc programming problem (QP) like the Markowitz model.  

MVT uses a standard QP: quadra6c objecGve funcGon with linear constraints.  

Page 55: Using R for Analyzing Loans, Portfolios and Risk:  From Academic Theory to Financial Practice

Modified Problem 

San Diego, 12‐Nov‐2007  55

Standard QP 

Amenable to industrial opGmizers; we use the R system with the quadprog package and minpack.lm library. 

Standard QP problem with linear constraints

Page 56: Using R for Analyzing Loans, Portfolios and Risk:  From Academic Theory to Financial Practice

MV FronGer with Short‐selling 

Sanjiv Das 56

Page 57: Using R for Analyzing Loans, Portfolios and Risk:  From Academic Theory to Financial Practice

DeviaGng from Normality with Copulas 

Sanjiv Das 57

Page 58: Using R for Analyzing Loans, Portfolios and Risk:  From Academic Theory to Financial Practice

Gaussian Copula 

Sanjiv Das 58

Page 59: Using R for Analyzing Loans, Portfolios and Risk:  From Academic Theory to Financial Practice

Extended OpGmizaGon Problem 

Sanjiv Das 59

Page 60: Using R for Analyzing Loans, Portfolios and Risk:  From Academic Theory to Financial Practice
Page 61: Using R for Analyzing Loans, Portfolios and Risk:  From Academic Theory to Financial Practice

SoluGon 

Sanjiv Das 61

Page 62: Using R for Analyzing Loans, Portfolios and Risk:  From Academic Theory to Financial Practice

Non‐Linear Products 

Sanjiv Das 62

U is a set of states over n assets

r(u) is a n-vector of random returns

Compute p[r(u)]

Page 63: Using R for Analyzing Loans, Portfolios and Risk:  From Academic Theory to Financial Practice

Restatement of the problem 

Sanjiv Das 63

This is a quadratic optimization with linear constraints. Not a quadratic optimization with non-linear constraints.

Page 64: Using R for Analyzing Loans, Portfolios and Risk:  From Academic Theory to Financial Practice

Introducing Structured Products 

Sanjiv Das 64

Can we improve the risk-adjusted returns in a portfolio by using puts and calls?

Derivatives are very risky.

And so ….

Page 65: Using R for Analyzing Loans, Portfolios and Risk:  From Academic Theory to Financial Practice

Are puts opGmal? 

Sanjiv Das 65

No, they add very little value to the portfolio.

But …

Page 66: Using R for Analyzing Loans, Portfolios and Risk:  From Academic Theory to Financial Practice

Puts are needed when the threshold return is high 

Sanjiv Das 66

For high thresholds the investor cannot get an acceptable portfolio without puts.

Page 67: Using R for Analyzing Loans, Portfolios and Risk:  From Academic Theory to Financial Practice

Should investors use calls? 

Sanjiv Das 67

Calls are risky too.

But have attractive and high mean returns!

Page 68: Using R for Analyzing Loans, Portfolios and Risk:  From Academic Theory to Financial Practice

Calls give be?er porOolios 

Sanjiv Das 68

Improvement is greater than 60 bps !

Page 69: Using R for Analyzing Loans, Portfolios and Risk:  From Academic Theory to Financial Practice

Structured Product:  The Barrier‐M‐note 

Sanjiv Das 69

Page 70: Using R for Analyzing Loans, Portfolios and Risk:  From Academic Theory to Financial Practice

Barrier‐M Note 

Sanjiv Das 70

Page 71: Using R for Analyzing Loans, Portfolios and Risk:  From Academic Theory to Financial Practice

“Truncated Straddle” 

Sanjiv Das 71

Return pick-up greater than 250 bps!

Barrier-M-note

Page 72: Using R for Analyzing Loans, Portfolios and Risk:  From Academic Theory to Financial Practice

Equity‐Indexed Product 

Sanjiv Das 72

Page 73: Using R for Analyzing Loans, Portfolios and Risk:  From Academic Theory to Financial Practice

Conclusion •  Investors find it easier to think in terms of mental accounts or sub‐porOolios 

when trying to reach their separate financial goals.  •  Behavioral porOolio theory deals with maximizing return subject to managing 

the risk of loss. This problem has a mathemaGcal mapping into mean‐variance opGmizaGon, yet is much more general.  

•  Even with short‐selling prohibited, the loss from sub‐porOolio opGmizaGon is smaller than the loss from misesGmaGng investor preferences.  

•  ReporGng performance by sub‐porOolio enables investors to track their goals be?er.  

•  Goal‐based opGmizaGon enables choosing porOolios even when normality is not assumed.  

•  Goal‐based opGmizaGon provides a framework for including structured products in investor porOolios. 

Sanjiv Das 73

The research papers for this work are on my web page – just google it. h?p://algo.scu.edu/~sanjivdas/research.htm/  1.  Das, Markowitz, Scheid, and Statman (JFQA 2010), “PorOolio OpGmizaGon with 

 Mental Accounts” 2.  Das & Statman (2008), “Beyond Mean‐Variance: PorOolio with  

 Structured Products and non‐Gaussian returns.”    

Page 74: Using R for Analyzing Loans, Portfolios and Risk:  From Academic Theory to Financial Practice

PEDAGOGICAL USES FOR R USING THE WEB    

Topic 4 

h?p://sanjivdas.wordpress.com/ 

Page 75: Using R for Analyzing Loans, Portfolios and Risk:  From Academic Theory to Financial Practice

Use the Rcgi package from David Firth: h?p://www.omegahat.org/CGIwithR/  

You need two program files to get everything working. (a)  The html file that is the web form for input data. (b)  The R file, with special tags for use with the CGIwithR package. 

Page 76: Using R for Analyzing Loans, Portfolios and Risk:  From Academic Theory to Financial Practice

R Code called from CGI 

Page 77: Using R for Analyzing Loans, Portfolios and Risk:  From Academic Theory to Financial Practice

h?p://algo.scu.edu/~sanjivdas/Rcgi/mortgage_calc.html 

Page 78: Using R for Analyzing Loans, Portfolios and Risk:  From Academic Theory to Financial Practice

High-performance computing (parallelR)

Calling C from R

Lattice dynamic optimization

Network modeling

Optimization

High-dimensional distributions with copulas

Web functions

Q?