bob mcdonald
TRANSCRIPT
-
8/12/2019 Bob Mcdonald
1/41
Using Rto Teach MBA Derivatives
Robert L. McDonald
Kellogg School of Management
Northwestern University
May 19, 2014
Page 1
-
8/12/2019 Bob Mcdonald
2/41
Outline
How I got started with R
Why use Rin an MBA class?
Binomial pricing example
The Radoption decision as an option exercise
problem
Examples of Rin action
Everyone in this audience made a decision to useR
; myfocus will be on persuadingothersto use R
Page 2
-
8/12/2019 Bob Mcdonald
3/41
Context
Derivatives Markets II is an advanced elective
Topics include: The lognormal model Brownian motion and Its Lemma Black-Scholes-Merton analysis
Stochastic volatility Exotic options One-factor fixed income models Credit risk
Focus on computation. Originally we used Excel/VBA
Fully transitioned to Rthis year
All Kellogg students receive Stata
Page 3
-
8/12/2019 Bob Mcdonald
4/41
Educational Goals
In addition to the obvious (for example, learning about
different kinds of exotic options), major themes include:
Simple data skills (e.g., historical volatility)
Monte Carlo valuation Appreciation of Jensens inequality
Implications of normality and why it is inadequate for
modeling stock returns
Page 4
-
8/12/2019 Bob Mcdonald
5/41
Why R?
Vectorization Hard to overstate pedagogical importance set.seedpermits comparison of loops and vectors
High quality graphics
Integrated statistics
RStudio: Makes Rfeasible for students
knitr a terrific tool for the instructor
Free and cross-platform
Page 5
-
8/12/2019 Bob Mcdonald
6/41
Example: Binomial Option Pricing
Major topic in an introductory derivatives class
Assume the stock moves discretely up or down, from
S touSordS
Probability of up move is the risk-neutral probability,p
uanddare calibrated to match volatility
The binomial model has great pedagogical value and
it can be used to price American options
Page 6
-
8/12/2019 Bob Mcdonald
7/41
Binomial Stock Price Tree
0.0 0.2 0.4 0.6 0.8 1.0
60
80
100
140
00
118.9
84.1
141.40
100.00
70.72
168.
118.
84.1
59.
Page 7
-
8/12/2019 Bob Mcdonald
8/41
American Options
American options may be exercised by the holder at
any time
When is it optimal to exercise the option: payingK inexchange for the stock, earning the intrinsic value,
S K?
Page 8
-
8/12/2019 Bob Mcdonald
9/41
The Economics of Early Exercise
WhenS>K, three factors determine whether to exercisea standard American call prior to expiration
Dividend payments induce exercise (the holder of an
unexercised call forgoes dividends)
Interest leads to delay of exercise (defer payment ofthe strike price)
Volatility leads to delay of exercise (with higher
volatility, greater chance of later regret for having
exercised)
Page 9
-
8/12/2019 Bob Mcdonald
10/41
Illustrating Early Exercise
An Rplot can be used to show simultaneously
The possible values of future stock prices
The probability of each price Whether the option is exercised at a given node
(green means exercise, red means not)
Page 10
-
8/12/2019 Bob Mcdonald
11/41
Illustrating Early Exercise: ExampleS = 100,K = 95, = 0.3,r = 0.08, = 0.08,T = 1,
n= 20:
0.0 0.2 0.4 0.6 0.8 1.0
100
200
30
0
400
Page 11
-
8/12/2019 Bob Mcdonald
12/41
Drawing the Stock Price Points
The circles are color-coded to denote early exercise(green) or not (red):
exer 0])*pointsize
Page 12
-
8/12/2019 Bob Mcdonald
13/41
Comparative Statics for Early ExerciseS = 100,K = 95,T = 10,n= 20:
0 2 4 6 8 1 0
= 0.03,r =0.1, =0.3
0 2 4 6 8 1 0
0
200
400
600
800
= 0.1,r = 0.03, = 0.3
= 0.1,r = 0.03, =0.1
0
200
400
600
800
= 0.1,r = 0.03, = 0.5
Page 13
-
8/12/2019 Bob Mcdonald
14/41
Application to the RAdoption Decision
Adopting software is analogous to exercising anAmerican call
The adoption cost is the strike price The value from adopting is the stock price The flow of benefits lost by not adopting is the
dividend yield The cost reduction by waiting is the interest rate Volatility measures uncertainty about the value of
adopting
Page 14
-
8/12/2019 Bob Mcdonald
15/41
The Adoption Decision, cont.
Optimal to adopt when The flow of value is great (dividends are large) The cost reduction from waiting is small
interest rate is small
strike price is constant or increasing Likelihood of regret is small (volatility is low and/or
intrinsic value is great)
All of these must be assessed relative to
alternatives. . .
Page 15
-
8/12/2019 Bob Mcdonald
16/41
Adoption Decision
Table :Comparison of Software for MBA Use
VBA/Excel Stata Matlab R SAS
Programming? Y Y/N Y Y Y
Ease of learning Medium Easy/Hard Med/Hard Med/Hard Med
Versatility Low Medium High High Low
Transferability
of Skills Medium Low High High Low
Future use likely High Low ? Med ?
Longevity ? High High High HighCost Low Medium High Very Low High
Page 16
-
8/12/2019 Bob Mcdonald
17/41
Questions to Consider. . .
What backgrounds and capabilities do students
have?
Should students be active or passive users?
Is the software intended for class only, or for
long-term student use (after graduation)
Student believe that VBA and Matlab are important
Page 17
-
8/12/2019 Bob Mcdonald
18/41
Adoption Issues Specific to R
Interface / RStudio
Necessity of programming Doessource('foo.R')count as programming?
Instructor friendly? Should one use base Ror packages?
I use base Runless there is a compelling reason to
do otherwise
Page 18
-
8/12/2019 Bob Mcdonald
19/41
The Decision to Adopt
Large dividend flow from R Whether its greater than for alternatives depends on
context
Prior to RStudio, high gain to waiting
Volatility (relative to alternatives) was high, now
seems low For example, Octave looked like a contender, raising
volatility, delaying my adoption of R
IsS>K?
Depends on course, student, and instructor RStsudio made the adoption decision much easier
Page 19
D E l
-
8/12/2019 Bob Mcdonald
20/41
Data: Example
Even students with some statistics background often
have little or no experience dealing with primarydata
Usingread.csvto obtain web data gets their attention
Following example is not trivial, but It illustrates the power of a script It demonstrates time variation in volatility The same exercise could be done in Excel (students
can compare the difficulty and reproducibility) Deciphering the code is a worthwhile exercise
The example is easy to generalize (looping across
tickers, for example)
Page 20
D t E l
-
8/12/2019 Bob Mcdonald
21/41
Data: Example
1 ## Yahoo format is date, open, high, low, close,volume, adj close
2 URL
-
8/12/2019 Bob Mcdonald
22/41
Data: Result
1960 1970 1980 1990 2000 2010
0.1
5
0.2
0
0.2
5
0.3
0
0.3
5
0.4
0
0.4
5
Annual Volatility for IBM
Year
Volatility
Page 22
-
8/12/2019 Bob Mcdonald
23/41
Val ing a E ropean Call
-
8/12/2019 Bob Mcdonald
24/41
Valuing a European Call
Some cases display a perfect correspondence between
equations in the book and equations in R:
1 s0
-
8/12/2019 Bob Mcdonald
25/41
Valuing a European Call (jump version)
Merton: lognormal jumps occur as a Poisson process
Letgbe the jump intensity,J = ea
1 the mean
jump, andvJthe jump volatility.
On paths when no jumps occur, the price is
st0
-
8/12/2019 Bob Mcdonald
26/41
Simulating the Merton Jump Model
1 s0
-
8/12/2019 Bob Mcdonald
27/41
Arithmetic Asian Options
The payoff of an Arithmetic Asian call is
max
0,
n
i=1
Si
n K
where theSis are sampled at regular intervals
Because each subsequent stock price is based on
the previous, it is tempting to write a loop.
This is not necessary, but the correct code is tricky
Page 27
The Problem
-
8/12/2019 Bob Mcdonald
28/41
The Problem
Rcan be too lenient:
1 > 1:3 + matrix(1, nrow=6, ncol=2)2 [,1] [,2]3 [1,] 2 24 [2,] 3 35 [3,] 4 4
6 [4,] 2 27 [5,] 3 38 [6,] 4 49 > 1:3 + matrix(1, nrow=2, ncol=6)
10 [,1] [,2] [,3] [,4] [,5] [,6]
11 [1,] 2 4 3 2 4 312 [2,] 3 2 4 3 2 4
Page 28
Arithmetic Asian Call: Code
-
8/12/2019 Bob Mcdonald
29/41
Arithmetic Asian Call: Code
1 s0
-
8/12/2019 Bob Mcdonald
30/41
Black-Scholes Pricing
bsOpt(s=100, k=95, v=0.3, r=0.08, tt=1, d=0,greeks=TRUE)
## Call Put## Price 18.38706 6.083114
## Delta 0.7216145 -0.2783855## Gamma 0.0111875 0.01119105## Vega 0.3356785 0.3356785## Rho 0.5377439 -0.3392167## Theta -0.02558117 -0.00636012## Psi -0.7216145 0.2783855## Elasticity 3.924577 -4.576365
Page 30
Code to show off R
-
8/12/2019 Bob Mcdonald
31/41
Code to show off R
bsOptreturns a data frame:
columns are calls and puts rows are price and Greeks
1 k
-
8/12/2019 Bob Mcdonald
32/41
Output
0 100 200
0
100
Call Price
S
Price
0 100 200
0.0
0.6
Call Delta
S
De
lta
0 100 200
0.0
00
0.0
10
Call Gamma
S
Gamma
0 100 200
0.0
0.3
Call Vega
S
Vega
0 100 200
0.0
1.0
Call Rho
S
Rho
0 100 200
0
.020
0.0
00
Call Theta
S
The
ta
0 100 200
5
2
0
Call Psi
S
Ps
i
0 100 200
5
20
Call Elasticity
S
Elas
tic
ity
0 100 200
0
40
80
Put Price
S
Price
0 100 200
1
.0
0
.2
Put Delta
S
De
lta
0 100 200
0.0
00
0.0
10
Put Gamma
S
Gamma
0 100 200
0.0
0.3
Put Vega
S
Vega
0 100 200
1
.5
0.0
Put Rho
S
Rho
0 100 200
0.0
00
Put Theta
S
The
ta
0 100 200
0.0
0.6
Put Psi
S
Ps
i
0 100 200
7
3
0
Put Elasticity
S
Elas
tic
ity
Page 32
The Batman: Expiration
-
8/12/2019 Bob Mcdonald
33/41
The Batman: Expiration
40 60 80 100 120 140 160
30
20
10
0
10
s
profit
Sell two 85 puts, buy one 95 put, buy one 105 call, sell two 115 calls
Page 33
The Batman: Price
-
8/12/2019 Bob Mcdonald
34/41
The Batman: Price
StockPrice
4060
80100
120140
160
Tim
e
0.2
0.4
0.6
0.8
1.0
Positio
nP
rofit
30
20
10
0
10
Page 34
The Batman: Delta
-
8/12/2019 Bob Mcdonald
35/41
The Batman: Delta
StockPrice
4060
80100
120140
160
Matu
rity
0.5
1.0
1.5
2.0
Delta
1.0
0.5
0.0
0.5
1.0
Delta
Page 35
The Batman: Gamma
-
8/12/2019 Bob Mcdonald
36/41
The Batman: Gamma
StockPrice
4060
80100
120140
160
Matu
rity
0.5
1.0
1.5
2.0
Gamma
0.5
0.0
Gamma
Page 36
The Batman: Theta
-
8/12/2019 Bob Mcdonald
37/41
The Batman: Theta
StockPrice
4060
80100
120140
160
Matu
rity
0.5
1.0
1.5
2.0
Theta
0.5
0.0
0.5
1.0
Theta
Page 37
The Batman: Rho
-
8/12/2019 Bob Mcdonald
38/41
StockPrice
4060
80100
120140
160
Matu
rity
0.5
1.0
1.5
2.0
Rho
1.5
1.0
0.5
0.0
0.5
1.0
Rho
Page 38
The Quincunx
-
8/12/2019 Bob Mcdonald
39/41
A quincunx, or Galton board, is a physical device that
illustrates the Central Limit Theorem
Balls hit a series of pegs, randomly falling left or right
Rcan (very crudely) simulate the appearance of aquincunx
With R, unlike with a physical quincunx, it is possible
to alter the probability from 50-50.
Page 39
The Quincunx
-
8/12/2019 Bob Mcdonald
40/41
0 1 2 3 4 5 6 7 8
Number of Rightward Bounces
0
100
200
300
Page 40
Thank You
-
8/12/2019 Bob Mcdonald
41/41
Thanks to all the fantastic folks who push this great
software forward: R Core Team
the RStudio team
the Revolution Analytics team
Hadley Wickham
Yihui Xie
Dirk Eddelbuettel
R/Finance organizers and UIC etc.
Page 41