stochastic processes and advanced mathematical …sdunbar1/mathematicalfinance/lessons/...stochastic...

26
Steven R. Dunbar Department of Mathematics 203 Avery Hall University of Nebraska-Lincoln Lincoln, NE 68588-0130 http://www.math.unl.edu Voice: 402-472-3731 Fax: 402-472-8466 Stochastic Processes and Advanced Mathematical Finance Monte Carlo Simulation of Option Prices Rating Mathematically Mature: may contain mathematics beyond calculus with proofs. 1

Upload: buingoc

Post on 06-Jul-2018

227 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Stochastic Processes and Advanced Mathematical …sdunbar1/MathematicalFinance/Lessons/...Stochastic Processes and Advanced Mathematical Finance Monte Carlo Simulation of Option Prices

Steven R. DunbarDepartment of Mathematics203 Avery HallUniversity of Nebraska-LincolnLincoln, NE 68588-0130http://www.math.unl.edu

Voice: 402-472-3731Fax: 402-472-8466

Stochastic Processes and

Advanced Mathematical Finance

Monte Carlo Simulation of Option Prices

Rating

Mathematically Mature: may contain mathematics beyond calculus withproofs.

1

Page 2: Stochastic Processes and Advanced Mathematical …sdunbar1/MathematicalFinance/Lessons/...Stochastic Processes and Advanced Mathematical Finance Monte Carlo Simulation of Option Prices

Section Starter Question

What is a 95% confidence interval in a statistical experiment?

Key Concepts

1. Monte Carlo methods (or Monte Carlo experiments) are mathemat-ical solution methods that rely on repeated random sampling to obtainnumerical results.

2. Variance reduction techniques create a new Monte Carlo problemwith the same answer as the original but with a smaller value for thevariance to increase the efficiency of the Monte Carlo estimation. Manymethods for variance reduction for Monte Carlo methods exist.

3. The idea behind importance sampling is that some values of the sim-ulation have more effect on the estimation than others. The probabilitydistribution of the sample is carefully changed to give “important” out-comes more weight to achieve some goal such as variance reduction.

Vocabulary

1. Monte Carlo methods (or Monte Carlo experiments) are a largeand diverse class of solution methods using random sampling from aspecified distribution to generate numerical results for a mathematicalmodel.

2

Page 3: Stochastic Processes and Advanced Mathematical …sdunbar1/MathematicalFinance/Lessons/...Stochastic Processes and Advanced Mathematical Finance Monte Carlo Simulation of Option Prices

2. The 95% level Monte Carlo confidence interval for E [g(X)] is(gn − t0.975

s√n, gn + t0.975

s√n

).

3. The quantity s/√n is called the standard error.

4. Variance reduction techniques create a new Monte Carlo problemwith the same answer as the original but with a smaller value for thevariance to increase the efficiency of Monte Carlo estimation.

5. An antithetic sample is a sample that uses an opposite value of f(x),being low when f(x) is high and vice versa, to reduce the variance.

6. Importance sampling is another variance reduction technique. Theidea behind importance sampling is that some values in a simulationhave more influence on the estimation than others. The probabilitydistribution is carefully changed to give “important” outcomes moreweight.

Mathematical Ideas

Confidence Intervals for Option Prices

Monte Carlo methods (or Monte Carlo experiments) are a large and di-verse class of solution methods using random sampling from a specified distri-bution to generate numerical results for a mathematical model. Monte Carlomethods are a statistical solution technique, among the various mathemat-ical techniques that move from a mathematical model to a relation amongthe quantities of interest.

With Geometric Brownian Motion as a stochastic process model for se-curity prices, we can use that process for simulating option prices with a

3

Page 4: Stochastic Processes and Advanced Mathematical …sdunbar1/MathematicalFinance/Lessons/...Stochastic Processes and Advanced Mathematical Finance Monte Carlo Simulation of Option Prices

Monte Carlo method. We assume that a security price is modeled by Geo-metric Brownian Motion, so we know the lognormal probability distributionat the expiration time. Draw n pseudo-random numbers x1, . . . , xn fromthe lognormal distribution modeling the stock price S. Then approximate aput option price as the present value of the expected value of the functiong(S) = max(K − S, 0), with the sample mean

E [g(S)] ≈ 1

n

n∑i=1

g(xi) = gn.

The examples in this section feature put options rather than the call optionsillustrated previously for a reason that will become clear later when we modifythe Monte Carlo simulation with importance sampling.

The Weak and Strong Laws of Large Numbers ensure us that this approx-imation is valid for large n, and improves as the number of samples increases.Even more is true, since the Central Limit Theorem implies that the sam-ple mean gn is approximately normally distributed with mean E [g(S)] andvariance Var [g(S)] /n,

gn ∼ N(E [g(S)] ,Var [g(S)] /n).

This says that the value gn that we estimate with the Monte Carlo simulationswill have a deviation from the true expected value E [g(S)] that is on theorder of the standard deviation divided by

√n. More precisely, recall that

for the standard normal distribution P [|Z| < 1.96] ≈ 0.95. Then by theshifting and rescaling properties of the normal distribution, we can constructa corresponding 95% confidence interval for the estimate gn as(

E [g(S)]− 1.96

√Var [g(S)]

n,E [g(S)] + 1.96

√Var [g(S)]

n

).

We interpret the interval above as saying that the estimate gn will be inthis interval in about 95% of samples. That is, if 100 people perform thesampling experiment with different draws from the pseudo-random numbergenerator, then about 95 of them will generate an expected value that falls inthis interval, but about 5 of them will be unlucky enough to draw a samplethat generates an expected value falling outside the interval.

4

Page 5: Stochastic Processes and Advanced Mathematical …sdunbar1/MathematicalFinance/Lessons/...Stochastic Processes and Advanced Mathematical Finance Monte Carlo Simulation of Option Prices

A problem with obtaining the confidence interval is that the mean E [g(S)]and the variance Var [g(S)] are both unknown. These are respectively esti-mated with the sample mean gn and the sample variance

s2 =1

n− 1

n∑i=1

(g(xi)− gn)2

to obtain the 95% level Monte Carlo confidence interval for E [g(S)](gn − tn−1,0.975

s√n, gn + tn−1,0.975

s√n

).

The quantity s/√n is called the standard error. Note that the standard

error is dependent on the drawn numbers x1, x2, . . . , xn so it is subject tosample variability too. In fact, the sample quantity

(gn − E [g(S)])

s/√n

has a probability distribution known as Student’s t-distribution, so the 95%confidence interval limits of ±1.96 must be modified with the corresponding95% confidence limits of the appropriate Student’s t-distribution.

Another problem with the Monte Carlo confidence interval is that thewidth of the interval decreases as 1/

√n, which is not particularly fast. To

decrease the width of the confidence interval by half requires 4 times as manysample variates.

Simplified Example

Now apply confidence interval estimation to the present value of a simple putoption price for a simplified security. The simplified security has a stochasticdifferential equation dS = rS dt+σS dW with a starting price S(0) = z0 =1 at t = 0 with risk-free interest rate r = σ2/2, and a standard deviationσ = 1. Then the stochastic process is S(t) = eW (t) where W (t) is standardBrownian Motion. (The parameters are financially unrealistic, but lead tothe simple exponential.) For the simplified put option the strike price isK = 1, and the time to expiration is T − t = T − 0 = 1. Short programs tocreate 95% confidence intervals for 100, 1,000, and 10,000 samples are in theScripts section. The random seed is set to the arbitrary value 2015 so that

5

Page 6: Stochastic Processes and Advanced Mathematical …sdunbar1/MathematicalFinance/Lessons/...Stochastic Processes and Advanced Mathematical Finance Monte Carlo Simulation of Option Prices

n gn 95% Monte Carlo confidence interval100 0.1580783 (0.1206047, 0.1955519)1000 0.1539137 (0.1425191, 0.1653084)10000 0.1451896 (0.1416714, 0.1487078)

Table 1: Monte Carlo confidence intervals for the present value of a simpleput option values. The present value of the put option from the Black-Scholesformula is 0.1446101.

for replication of the Monte Carlo simulation the sample script always yieldsthe same results. The true value comes from the Black-Scholes put optionvalue formula in Put-Call Parity Principle. Some typical results from the Rscript are in Table 1.

Although the Monte Carlo simulation yields good results fairly easily, adisadvantage is that it applies for only one set of parameter values. To findvalues for a variety of parameters requires more computations, but even thatdoes not demonstrate the functional relationship among the parameters andthe values. The next chapter will derive a complete mathematical solution forthe value of European call and put options. However, mathematical solutionis not always possible for more complex security derivatives, and then MonteCarlo simulation is a good alternative.

Variance Reduction Techniques

Applying Monte Carlo estimation to a random variable with a large variancecreates a confidence interval that is correspondingly large. The width of theconfidence interval can be reduced by increasing the sample size, but the rateof reduction is

√n. Reducing the width of the confidence interval by half

requires 4 times more sample points. Sometimes we can find a way to reduces instead. To do this, we construct a new Monte Carlo problem with thesame answer as our original problem but with a smaller value for s. Methodsto do this are known as variance reduction techniques. Since Geomet-ric Brownian Motion has a variance that grows exponentially, Monte Carloestimates of quantities based on Geometric Brownian Motion are excellentcandidates for variance reduction techniques.

Variance reduction techniques increase the efficiency of Monte Carlo es-timation. Having methods to reduce variability with a given number ofsample points, or for efficiency to achieve the same variability with fewer

6

Page 7: Stochastic Processes and Advanced Mathematical …sdunbar1/MathematicalFinance/Lessons/...Stochastic Processes and Advanced Mathematical Finance Monte Carlo Simulation of Option Prices

sample points, is desirable. Following are two methods that illustrate typicalvariance reduction techniques.

Antithetic Sampling

An antithetic sample is a sample that gives a opposite value of g(x), beinglow when g(x) is high and vice versa. Ordinarily we get an opposite g bysampling at a point that is somehow opposite to x. The idea of antitheticsampling can be applied when it is possible to find transformations of X thatleave its probability distribution unchanged. For example, if X is normallydistributed N(0, 1), then X = −X is normally distributed as well, thatis the antithetic sample we will apply here. More generally, if X has asymmetric distribution about 0, then X = −X has the same distribution.Another antithetic sample occurs when X is uniformly distributed on [0, 1]so X = 1−X has the same probability distribution.

The antithetic sampling estimate of a value µ = E [g(X)] with asample size n is

µanti =1

2n

n∑j=1

(g(Xj) + g(Xj)

).

Suppose the variance is σ2 = E [(g(X)− µ)2] <∞. Then the variance inthe antithetic sample of size n is

Var [µanti] = Var

[1

2n

n∑j=1

g(Xj) + g(Xj)

]=

n

4n2

(Var

[g(X) + g(X)

])=

1

4n

(Var [g(X)] + Var

[g(X)

]+ 2 Cov

[g(X), g(X)

])=σ2

2n(1 + ρ).

Previously, we have often assumed different samples are independent so thatthe covariance term ρ is 0, reducing the number of terms in an expression.However, here is a situation where we deliberately create statistical depen-dence with negative covariance −1 ≤ ρ < 0 to reduce the variance in theantithetic sampling estimate.

Table 2 gives the results of antithetic sampling on the simplified putoption example after a simple change of variables to make the sampling

7

Page 8: Stochastic Processes and Advanced Mathematical …sdunbar1/MathematicalFinance/Lessons/...Stochastic Processes and Advanced Mathematical Finance Monte Carlo Simulation of Option Prices

n gn 95%Monte Carlo confidence interval100 0.1429556 (0.1267189, 0.1591923)1000 0.1432171 (0.1383814, 0.1480529)10000 0.1452026 (0.1437125, 0.1466926)

Table 2: Monte Carlo confidence intervals with antithetic sampling for thepresent value of a simple put option. The present value of the put optionfrom the Black-Scholes formula is 0.1446101.

distribution normal. Table 2 shows that for the put option Monte Carlo es-timation not only are the option value estimates much better with antitheticsampling, but the confidence intervals are reduced to less than half of thewidth compared with Table 1.

Note that if g(x) is a function with odd symmetry, for example g(x) =cx, and X is symmetric about 0, for example normally distributed withantithetic sample X = −X, then µ = 0. Furthermore, the statistical estimateµanti would be always be 0 and in fact the estimate could be achieved withjust one sample point and no variance. If g is not symmetric, as in optionestimation with g(x) = max(K−x, 0), we can still expect some improvement.The degree of improvement in antithetic sampling depends on the relativecontribution of the odd and even parts of the function g, see [1] for details.

Importance Sampling

Importance sampling is another variance reduction technique. The ideabehind importance sampling is that some values in a simulation have moreinfluence on the estimation than others. The probability distribution is care-fully changed to give “important” outcomes more weight. If “important”values are emphasized by sampling more frequently, then the estimator vari-ance can be reduced. Hence, the key to importance sampling is to choose anew sampling distribution that “encourages” the important values.

Let f(x) be the density of the random variable, so we are trying to esti-mate

E [g(x)] =

∫Rg(x)f(x) dx .

Estimate E [g(x)] with respect to another strictly positive density h(x). Then

8

Page 9: Stochastic Processes and Advanced Mathematical …sdunbar1/MathematicalFinance/Lessons/...Stochastic Processes and Advanced Mathematical Finance Monte Carlo Simulation of Option Prices

easily

E [g(x)] =

∫R

g(x)f(x)

h(x)h(x) dx .

or equivalently, estimate

E[g(Y )f(Y )

h(Y )

]= E [g(Y )]

where Y is a new random variable with density h(y) and g(y) = g(y)f(y)/h(y).For variance reduction, we wish to determine a new density h(y) so thatVar [g(Y )] < Var [g(X)]. Consider

Var [g(Y )] = E[g(Y )2

]− (E [g(Y )])2 =

∫R

g2(x)f 2(x)

h(x)dx−E [g(X)]2 .

By inspection, we can see that we can make Var [g(Y )] = 0 by choosingh(x) = g(x)f(x)/E [g(X)]. This is the ultimate variance reduction but itrelies on knowing E [g(X)], the quantity we are trying to estimate. It alsorequires that g(x) is strictly positive.

To choose a good importance sampling distribution requires some edu-cated guessing. Importance sampling is equivalent to a change of variables,and like a change of variables often requires insight. Each instance of im-portance sampling depends on the function and the distribution. A specificexample will illustrate importance sampling.

The example is again to calculate confidence intervals for the presentvalue of a Monte Carlo estimate of a European put option price, where g(x) =max(K − x, 0) and S is distributed as a geometric Brownian motion derivedfrom dS = rS dt+σS dW with S(0) = z0. To set some simple parameters,we take the initial value z0 = 1, the risk free interest rate r = σ2/2, thestandard deviation σ = 1, the strike price K = 1 and the time to expirationT = 1. The security process is then S(t) = eW (t). At T = 1 the process has alognormal distribution with parameters µ = 0 and σ

√T = 1. Thus we start

with ∫ ∞0

max(K − x, 0)1√

2πσx√T

exp(−1

2(ln(x)/σ

√T )2) dx .

Using K = 1, σ = 1, and T = 1 after a first change of variable the integral

9

Page 10: Stochastic Processes and Advanced Mathematical …sdunbar1/MathematicalFinance/Lessons/...Stochastic Processes and Advanced Mathematical Finance Monte Carlo Simulation of Option Prices

n gn 95% Monte Carlo confidence interval100 0.1465861 (0.1395778, 0.1535944)1000 0.1449724 (0.1427713, 0.1471736)10000 0.1443417 (0.1436435, 0.1436435)

Table 3: Monte Carlo confidence intervals with importance sampling for thepresent value of a simple put option. The present value of the put optionfrom the Black-Scholes formula is 0.1446101.

we are estimating is

E [g(S)] =

∫ ∞−∞

max(1− ex, 0)e−x

2/2

√2π

dx

=

∫ 0

−∞(1− ex)

e−x2/2

√2π

dx .

Introduce the exponential distribution e−y/2 with a second change of vari-ables x = −√y. Then the expectation integral becomes∫ ∞

0

1− e−√y

√2π√y

e−y/2

2dy .

This change of probability distribution has the added advantage that nowthe sampling from the exponential distribution is concentrated where thefunction contributes most to the integral. This explains why the examplesuse put options, not call options.

Now apply this importance sampling to the confidence interval estimationfor the present value of put option prices. Short programs to create theconfidence intervals for 100, 1,000, and 10,000 samples are in the Scriptssection. Some typical results from the R script are in Table 1.

Table 3 shows that the put option Monte Carlo estimates with importancesampling are closer to the Black-Scholes value than the simple Monte Carlosampling. The confidence intervals are about one-fifth the width comparedwith Table 1.

10

Page 11: Stochastic Processes and Advanced Mathematical …sdunbar1/MathematicalFinance/Lessons/...Stochastic Processes and Advanced Mathematical Finance Monte Carlo Simulation of Option Prices

Application to Data

Standard and Poor’s 500 Index, with symbol SPX, is a weighted index of500 stocks. This index is designed to measure performance of the broaddomestic economy through changes in the aggregate market value of 500stocks representing all major industries. As such, it is a good candidate fora stock index modeled by Geometric Brownian Motion. The index startedwith a level of 10 for the 1941-43 base period.

To test Monte Carlo simulation on real data, use historical data on putoptions on the SPX that provides values for K, T − t, and z0. Values for rand σ can be inferred from historical data.

The expectation to calculate for the Monte Carlo simulation of the valueof a put option is∫ ∞0

max(K−x, 0)1√

2πσx√t

exp

(−1

2

[ln(x)− ln(z0)− (r − σ2/2)t

σ√t

]2)dx .

Then the expectation integral is equivalent to∫ ∞0

max(K − z0e(r−σ2/2)t+σ

√t√u, 0) + max(K − z0e(r−σ

2/2)t−σ√t√u, 0)

1√2π 2√u

exp

(−u2

)du .

This is now the importance sampling estimate of the value of a put optionon the SPX index. The Scripts section has programs to evaluate confidenceintervals for the put option value using real data.

Sources

This section is adapted from: Simulation and Inference for Stochastic Dif-ferential Equations, by Stephen Iacus, Sections 1.3 and 1.4, Springer-Verlag,2008. The section on antithetic sample is adapted from Owen, VarianceReduction and Lehna. Interest rates are from Treasury.gov

11

Page 12: Stochastic Processes and Advanced Mathematical …sdunbar1/MathematicalFinance/Lessons/...Stochastic Processes and Advanced Mathematical Finance Monte Carlo Simulation of Option Prices

Algorithms, Scripts, Simulations

Algorithm

This script calculates the value of a put option on the Standard & Poor’s 500stock index (SPX) in several ways. First the script uses the Black Scholes for-mula for a put option to calculate the theoretical value for a put option. Thenthe script uses Monte Carlo simulation based on the Geometric Brownian Mo-tion with the SPX parameters to find an estimate for the put option value.Finally, the script uses Monte Carlo simulation with antithetic sampling andimportance sampling variance reduction methods to refine the estimates. Theultimate purpose is to compare the various Monte Carlo methods with theput option value. The output will be a table of SPX put option value from theBlack Scholes formula, Monte Carlo simulation with 95% confidence interval,antithetic sampling with 95% confidence interval and importance samplingwith 95% confidence interval Set the total number of trials: n = 10000 Setthe values of S, r, σ, K, T − t Calculate the theoretical value of put optionwith Black-Scholes formula Fill the vector x[1..n] with random normal vari-ates y1 = max(0, K−S exp((r−σ2/2)(T−t)+σx

√(T−t))) y2 = max(0, K−

S exp((r−σ2/2)(T−t)+σ(−x)√

(T−t))) The antithetic sample becomes y =(y1 +y2)/2 Fill vector u[1..n] with random normal variates. The importancesample becomes u1 = (max(0, K−S exp((r−σ2/2)(T − t)−σ

√T − t

√x))+

max(0, K−S exp((r−σ2/2)(T − t)+σ√T − t

√x)))/

√2πx. Apply the t-test

to calculate mean and confidence intervals of the Monte Carlo simulationsy1[1 : 100], y1[1 : 1000]and y1[1 : n]. Apply the t-test to calculate meanand confidence intervals of the antithetic samples y[1 : 100], y[1 : 1000] andy[1 : n] Apply the t-test to calculate mean and confidence intervals of theimportance samples u1[1 : 100], u1[1 : 1000] and u1[1 : n]. Finally, collectand display a table of theoretical value and means and confidence intervals.

Scripts

R R script for simplified option pricing with Monte Carlo simulation, anti-thetic sampling, and importance sampling.

1 set.seed (2015)

2 n <- 10000

3

4 S <- 1

12

Page 13: Stochastic Processes and Advanced Mathematical …sdunbar1/MathematicalFinance/Lessons/...Stochastic Processes and Advanced Mathematical Finance Monte Carlo Simulation of Option Prices

5 sigma <- 1

6 r <- sigma ^2/2

7 K <- 1

8 Tminust <- 1

9

10 ## the value of the put option by Black -Scholes

11 d2 <- (log(S/K) + (r - sigma^2/2) * (Tminust))/(sigma *

sqrt(Tminust))

12 d1 <- (log(S/K) + (r + sigma^2/2) * (Tminust))/(sigma *

sqrt(Tminust))

13 VP <- K * exp(-r * Tminust) * pnorm(-d2) - S * pnorm(-d1)

14

15 x <- rlnorm(n) #Note use of default meanlog=0, sdlog =1

16 y <- sapply(x, function(z) max(0, K - z))

17

18 mc100 <- t.test(exp(-r * Tminust) * y[1:100]) # first

100 simulations

19 mc1000 <- t.test(exp(-r * Tminust) * y[1:1000]) # first

1000 simulations

20 mcall <- t.test(exp(-r * Tminust) * y) # all simulation

results

21

22 type <- c("Blacksholes", "Monte Carlo 100", "Monte Carlo

1000", "Monte Carlo all")

23 putestimate <- c(VP, mc100$estimate , mc1000$estimate ,

mcall$estimate)

24 putconfintleft <- c(NA , mc100$conf.int[1], mc1000$conf.

int[1], mcall$conf.int [1])

25 putconfintright <- c(NA, mc100$conf.int[2], mc1000$conf.

int[2], mcall$conf.int [2])

26 d <- data.frame(type , putestimate , putconfintleft ,

putconfintright)

27

28 print(d)

29

30 x <- rnorm(n)

31 y1 <- sapply(x, function(z) max(0, K - exp(z)))

32 y2 <- sapply(-x, function(z) max(0, K - exp(z)))

33 y <- (y1 + y2)/2

34

35 anti100 <- t.test(exp(-r * Tminust) * y[1:100]) # first

100 simulations

36 anti1000 <- t.test(exp(-r * Tminust) * y[1:1000]) #

first 1000 simulations

37 antiall <- t.test(exp(-r * Tminust) * y) # all

13

Page 14: Stochastic Processes and Advanced Mathematical …sdunbar1/MathematicalFinance/Lessons/...Stochastic Processes and Advanced Mathematical Finance Monte Carlo Simulation of Option Prices

simulation results

38

39 type <- c("Blacksholes", "Antithetic 100", "Antithetic

1000", "Antithetic all")

40 putestimate <- c(VP, anti100$estimate , anti1000$estimate ,

antiall$estimate)

41 putconfintleft <- c(NA , anti100$conf.int[1], anti1000$

conf.int[1], antiall$conf.int [1])

42 putconfintright <- c(NA, anti100$conf.int[2], anti1000$

conf.int[2], antiall$conf.int [2])

43 d <- data.frame(type , putestimate , putconfintleft ,

putconfintright)

44

45 print(d)

46

47 xN <- rnorm(n)

48 yN <- sapply(xN, function(z) max(0, K - exp(z)))

49

50 mcN100 <- t.test(exp(-r * Tminust) * yN [1:100]) # first

100 simulations

51 mcN1000 <- t.test(exp(-r * Tminust) * yN [1:1000]) #

first 1000 simulations

52 mcNall <- t.test(exp(-r * Tminust) * yN) # all

simulation results

53

54 type <- c("Blacksholes", "Monte Carlo 100", "Monte Carlo

1000", "Monte Carlo all")

55 putestimate <- c(VP, mcN100$estimate , mcN1000$estimate ,

mcNall$estimate)

56 putconfintleft <- c(NA , mcN100$conf.int[1], mcN1000$conf.

int[1], mcNall$conf.int [1])

57 putconfintright <- c(NA, mcN100$conf.int[2], mcN1000$conf

.int[2], mcNall$conf.int [2])

58 d <- data.frame(type , putestimate , putconfintleft ,

putconfintright)

59

60 print(d)

61

62 xE <- rexp(n, rate = 1/2)

63 yE <- sapply(xE, function(z) max(0, K - exp(-sqrt(z)))/(

sqrt(2 * pi) * sqrt(z)))

64

65 mcE100 <- t.test(exp(-r * Tminust) * yE [1:100]) # first

100 simulations

66 mcE1000 <- t.test(exp(-r * Tminust) * yE [1:1000]) #

14

Page 15: Stochastic Processes and Advanced Mathematical …sdunbar1/MathematicalFinance/Lessons/...Stochastic Processes and Advanced Mathematical Finance Monte Carlo Simulation of Option Prices

first 1000 simulations

67 mcEall <- t.test(exp(-r * Tminust) * yE) # all

simulation results

68

69 type <- c("Blacksholes", "Monte Carlo 100", "Monte Carlo

1000", "Monte Carlo all")

70 putestimate <- c(VP, mcE100$estimate , mcE1000$estimate ,

mcEall$estimate)

71 putconfintleft <- c(NA , mcE100$conf.int[1], mcE1000$conf.

int[1], mcEall$conf.int [1])

72 putconfintright <- c(NA, mcE100$conf.int[2], mcE1000$conf

.int[2], mcEall$conf.int [2])

73 d <- data.frame(type , putestimate , putconfintleft ,

putconfintright)

74

75 print(d)

R script for SPX option pricing.

Octave Octave script for SPX option pricing.

1 n = 10000;

2

3 S = 1614.96; # Standard and Poors 500 Index , on 07 / 01 /

2013

4 r = 0.008; # implied risk free interest rate , between 3

year and 5 year T - bill rate

5 sigma = 0.1827; # implied volatility

6 K = 1575; # strike price

7 Tminust = 110 / 365; # 07 / 01 / 2013 to 10 / 19 / 2013

8

9 ## the true value from the Black Scholes Formula for put

option

10 numerd1 = log(S / K) + (r + sigma ^ 2 / 2) * (Tminust);

11 numerd2 = log(S / K) + (r - sigma ^ 2 / 2) * (Tminust);

12 d1 = numerd1 / (sigma * sqrt(Tminust));

13 d2 = numerd2 / (sigma * sqrt(Tminust));

14 part1 = S * (stdnormal_cdf(d1) - 1);

15 part2 = K * exp(- r * (Tminust)) * (stdnormal_cdf(d2) -

1);

16 VP = part1 - part2;

17

18 x = stdnormal_rnd(n, 1);

15

Page 16: Stochastic Processes and Advanced Mathematical …sdunbar1/MathematicalFinance/Lessons/...Stochastic Processes and Advanced Mathematical Finance Monte Carlo Simulation of Option Prices

19 y1 = max(0, K - S * exp((r - sigma ^ 2 / 2) * Tminust +

sigma * x * sqrt(Tminust)));

20 y2 = max(0, K - S * exp((r - sigma ^ 2 / 2) * Tminust +

sigma * (- x) * sqrt(Tminust)));

21 y = (y1 + y2) / 2;

22

23 u = exprnd (1 / 0.5, [n, 1]); # note exponential parameter

24 tildeg = ...

25 (...

26 max(0, K - S * exp((r - sigma ^ 2 / 2) * Tminust -

sigma * sqrt(Tminust) * sqrt(u))) + ...

27 max(0, K - S * exp((r - sigma ^ 2 / 2) * Tminust +

sigma * sqrt(Tminust) * sqrt(u)))...

28 ) ./ sqrt(2 * pi * u); # note use of broadcasting

29

30 function [m, confintleft , confintright] = ttest(data ,

confidence)

31 m = mean(data);

32 se = std(data) / sqrt(length(data));

33 df = length(data) - 1;

34 q = tinv ((1 + confidence) / 2, df);

35 confintleft = m - q * se;

36 confintright = m + q * se;

37 endfunction

38

39 [mc100mu , mc100cil , mc100cir] = ttest(exp(- r * Tminust)

* y1 (1:100) , 0.95);

40 [mc1000mu , mc1000cil , mc1000cir] = ttest(exp(- r *

Tminust) * y1 (1:1000) , 0.95);

41 [mcallmu , mcallcil , mcallcir] = ttest(exp(- r * Tminust)

* y1 , 0.95);

42

43 [anti100mu , anti100cil , anti100cir] = ttest(exp(- r *

Tminust) * y(1:100) , 0.95);

44 [anti1000mu , anti1000cil , anti1000cir] = ttest(exp(- r *

Tminust) * y(1:1000) , 0.95);

45 [antiallmu , antiallcil , antiallcir] = ttest(exp(- r *

Tminust) * y, 0.95);

46

47 [imp100mu , imp100cil , imp100cir] = ttest(exp(- r *

Tminust) * tildeg (1:100) , 0.95);

48 [imp1000mu , imp1000cil , imp1000cir] = ttest(exp(- r *

Tminust) * tildeg (1:1000) , 0.95);

49 [impallmu , impallcil , impallcir] = ttest(exp(- r *

Tminust) * tildeg , 0.95);

16

Page 17: Stochastic Processes and Advanced Mathematical …sdunbar1/MathematicalFinance/Lessons/...Stochastic Processes and Advanced Mathematical Finance Monte Carlo Simulation of Option Prices

50

51 putestimate = [VP, ...

52 mc100mu , mc1000mu , mcallmu , ...

53 anti100mu , anti1000mu , antiallmu , ...

54 imp100mu , imp1000mu , impallmu ];

55 putconfintleft = [NA , ...

56 mc100cil , mc1000cil , mcallcil , ...

57 anti100cil , anti1000cil , antiallcil , ...

58 imp100cil , imp1000cil , impallcil ];

59 putconfintright = [NA, ...

60 mc100cir , mc1000cir , mcallcir , ...

61 anti100cir , anti1000cir , antiallcir , ...

62 imp100cir , imp1000cir , impallcir ];

63 d = transpose ([ putestimate; putconfintleft;

putconfintright ])

Perl Perl script for SPX option pricing.

1 use PDL:: NiceSlice;

2 use PDL::GSL::RNG;

3 $rng = PDL::GSL::RNG ->new(’taus’);

4 $rng ->set_seed( time() );

5 use PDL:: Constants qw(PI E);

6 use Statistics :: Distributions;

7

8 $n = 10000;

9

10 $S = 1614.96; # Standard and Poors 500 Index , on

07/01/2013

11 $r =

12 0.008; # implied risk free interest rate , between 3

and 5 year T-bill rate

13 $sigma = 0.1827; # implied volatility

14 $K = 1575; # strike price

15 $Tminust = 110 / 365; # 07/01/2013 to 10/19/2013

16

17 sub pnorm {

18 my ( $x , $sigma , $mu ) = @_;

19 $sigma = 1 unless defined($sigma);

20 $mu = 0 unless defined($mu);

21

22 return 0.5 * ( 1 + erf( ( $x - $mu ) / ( sqrt (2) *

$sigma ) ) );

23 }

17

Page 18: Stochastic Processes and Advanced Mathematical …sdunbar1/MathematicalFinance/Lessons/...Stochastic Processes and Advanced Mathematical Finance Monte Carlo Simulation of Option Prices

24

25 $numerd1 = log( $S / $K ) + ( ( $r + $sigma **2 / 2 ) * (

$Tminust) );

26 $numerd2 = log( $S / $K ) + ( ( $r - $sigma **2 / 2 ) * (

$Tminust) );

27 $d1 = $numerd1 / ( $sigma * sqrt($Tminust) );

28 $d2 = $numerd2 / ( $sigma * sqrt($Tminust) );

29 $part1 = $S * ( pnorm($d1) - 1 );

30 $part2 = $K * exp( -$r * $Tminust ) * ( pnorm($d2) - 1 );

31 $VP = $part1 - $part2;

32

33 $x = $rng ->ran_gaussian( 1, $n ); # tested to here

34 $y1 = pdl(

35 zeroes($n),

36 $K - $S * exp(

37 ( $r - $sigma **2 / 2 ) * $Tminust + $sigma * $x *

sqrt($Tminust)

38 )

39 )->transpose ->maximum;

40 $y2 = pdl(

41 zeroes($n),

42 $K - $S * exp(

43 ( $r - $sigma **2 / 2 ) * $Tminust + $sigma * ( -

$x ) * sqrt($Tminust)

44 )

45 )->transpose ->maximum;

46 $y = ( $y1 + $y2 ) / 2;

47

48 $u = $rng ->ran_exponential( 1 / 0.5, $n ); # note

exponential parameter

49 $tildeg1 = pdl(

50 zeroes($n),

51 $K - $S * exp(

52 ( $r - $sigma **2 / 2 ) * $Tminust - $sigma * sqrt

($Tminust) * sqrt($u)

53 )

54 )->transpose ->maximum;

55 $tildeg2 = pdl(

56 zeroes($n),

57 $K - $S * exp(

58 ( $r - $sigma **2 / 2 ) * $Tminust + $sigma * sqrt

($Tminust) * sqrt($u)

59 )

60 )->transpose ->maximum;

61 $tildeg = ( $tildeg1 + $tildeg2 ) / sqrt( 2 * PI * $u );

18

Page 19: Stochastic Processes and Advanced Mathematical …sdunbar1/MathematicalFinance/Lessons/...Stochastic Processes and Advanced Mathematical Finance Monte Carlo Simulation of Option Prices

62

63 sub ttest {

64 my ( $data , $confidence ) = @_;

65 $confidence = 0.95 unless defined($confidence);

66 ( $mean , $prms , $median , $min , $max , $adev , $rms ) =

stats($data);

67 $df = nelem($data) - 1;

68 $q = Statistics :: Distributions :: tdistr( $df , ( 1 -

$confidence ) / 2 );

69

70 # Note use of level (1- $confidence)/2) instead of

percentile (1 + $confidence)/2

71 $widthci = $q * $rms / sqrt( nelem($data) );

72 $confintleft = $mean - $widthci;

73 $confintright = $mean + $widthci;

74 return ( $mean , $confintleft , $confintright );

75 }

76

77 ( $mc100mu , $mc100cil , $mc100cir ) =

78 ttest( exp( -$r * $Tminust ) * $y1 ( 0 : 99 ), 0.95 )

;

79 ( $mc1000mu , $mc1000cil , $mc1000cir ) =

80 ttest( exp( -$r * $Tminust ) * $y1 ( 0 : 999 ), 0.95

);

81 ( $mcallmu , $mcallcil , $mcallcir ) =

82 ttest( exp( -$r * $Tminust ) * $y1 , 0.95 );

83

84 ( $anti100mu , $anti100cil , $anti100cir ) =

85 ttest( exp( -$r * $Tminust ) * $y ( 0 : 99 ), 0.95 );

86 ( $anti1000mu , $anti1000cil , $anti1000cir ) =

87 ttest( exp( -$r * $Tminust ) * $y ( 0 : 999 ), 0.95 )

;

88 ( $antiallmu , $antiallcil , $antiallcir ) =

89 ttest( exp( -$r * $Tminust ) * $y, 0.95 );

90

91 ( $imp100mu , $imp100cil , $imp100cir ) =

92 ttest( exp( -$r * $Tminust ) * $tildeg ( 0 : 99 ),

0.95 );

93 ( $imp1000mu , $imp1000cil , $imp1000cir ) =

94 ttest( exp( -$r * $Tminust ) * $tildeg ( 0 : 999 ),

0.95 );

95 ( $impallmu , $impallcil , $impallcir ) =

96 ttest( exp( -$r * $Tminust ) * $tildeg , 0.95 );

97

98 $d = pdl(

19

Page 20: Stochastic Processes and Advanced Mathematical …sdunbar1/MathematicalFinance/Lessons/...Stochastic Processes and Advanced Mathematical Finance Monte Carlo Simulation of Option Prices

99 [ $VP , "NaN", "NaN" ],

100 [ $mc100mu , $mc100cil , $mc100cir ],

101 [ $mc1000mu , $mc1000cil , $mc1000cir ],

102 [ $mcallmu , $mcallcil , $mcallcir ],

103

104 [ $anti100mu , $anti100cil , $anti100cir ],

105 [ $anti1000mu , $anti1000cil , $anti1000cir ],

106 [ $antiallmu , $antiallcil , $antiallcir ],

107

108 [ $imp100mu , $imp100cil , $imp100cir ],

109 [ $imp1000mu , $imp1000cil , $imp1000cir ],

110 [ $impallmu , $impallcil , $impallcir ]

111 );

112

113 print $d;

SciPy Python script for SPX option pricing.

1 import scipy

2 from scipy.stats import norm

3

4 n = 10000

5

6 S = 1614.96 # Standard and Poors 500 Index , on

07/01/2013

7 r = 0.008 # implied risk free interest rate , between 3

year and 5 year T-bill rate

8 sigma = 0.1827 # implied volatility

9 K = 1575 # strike price

10 Tminust = 110. / 365. # 07/01/2013 to 10/19/2013

11

12 numerd1 = scipy.log(S / K) + (r + sigma ** 2 / 2) *

Tminust

13 numerd2 = scipy.log(S / K) + (r - sigma ** 2 / 2) *

Tminust

14 d1 = numerd1 / (sigma * scipy.sqrt(Tminust))

15 d2 = numerd2 / (sigma * scipy.sqrt(Tminust))

16 part1 = S * (norm.cdf(d1) - 1)

17 part2 = K * scipy.exp(-r * Tminust) * (norm.cdf(d2) - 1)

18 VP = part1 - part2

19

20 x = norm.rvs(size=n)

21 y1 = scipy.maximum(0, K - S * scipy.exp((r - sigma ** 2 /

2) * Tminust

20

Page 21: Stochastic Processes and Advanced Mathematical …sdunbar1/MathematicalFinance/Lessons/...Stochastic Processes and Advanced Mathematical Finance Monte Carlo Simulation of Option Prices

22 + sigma * x * scipy.sqrt(Tminust)))

23 y2 = scipy.maximum(0, K - S * scipy.exp((r - sigma ** 2 /

2) * Tminust

24 + sigma * -x * scipy.sqrt(Tminust)))

25 y = (y1 + y2) / 2

26

27 from scipy.stats import expon

28 u = expon.rvs(size=n, scale =1. / 0.5)

29 tildeg = (scipy.maximum(0, K - S * scipy.exp((r - sigma

** 2 / 2)

30 * Tminust - sigma * scipy.sqrt(Tminust) * scipy

.sqrt(u)))

31 + scipy.maximum(0, K - S * scipy.exp((r - sigma

** 2 / 2)

32 * Tminust + sigma * scipy.sqrt(Tminust) * scipy

.sqrt(u)))) \

33 / scipy.sqrt(2 * scipy.pi * u)

34

35

36 def ttest(data , confidence =0.95):

37 m = scipy.mean(data)

38 se = scipy.stats.sem(data)

39 df = len(data) - 1

40 h = se * scipy.stats.t.ppf((1 + confidence) / 2., df)

41 return (m, m - h, m + h)

42

43

44 [mc100mu , mc100cil , mc100cir] = ttest(scipy.exp(-r *

Tminust)

45 * y1[0:99] , 0.95)

46 [mc1000mu , mc1000cil , mc1000cir] = ttest(scipy.exp(-r *

Tminust)

47 * y1[0:999] , 0.95)

48 [mcallmu , mcallcil , mcallcir] = ttest(scipy.exp(-r *

Tminust) * y1 ,

49 0.95)

50

51 [anti100mu , anti100cil , anti100cir] = ttest(scipy.exp(-r

* Tminust)

52 * y[0:99] , 0.95)

53 [anti1000mu , anti1000cil , anti1000cir] = ttest(scipy.exp

(-r * Tminust)

54 * y[0:999] , 0.95)

55 [antiallmu , antiallcil , antiallcir] = ttest(scipy.exp(-r

* Tminust)

21

Page 22: Stochastic Processes and Advanced Mathematical …sdunbar1/MathematicalFinance/Lessons/...Stochastic Processes and Advanced Mathematical Finance Monte Carlo Simulation of Option Prices

56 * y, 0.95)

57

58 [imp100mu , imp100cil , imp100cir] = ttest(scipy.exp(-r *

Tminust)

59 * tildeg [0:99] , 0.95)

60 [imp1000mu , imp1000cil , imp1000cir] = ttest(scipy.exp(-r

* Tminust)

61 * tildeg [0:999] , 0.95)

62 [impallmu , impallcil , impallcir] = ttest(scipy.exp(-r *

Tminust)

63 * tildeg , 0.95)

64

65 putestimate = [

66 VP,

67 mc100mu ,

68 mc1000mu ,

69 mcallmu ,

70 anti100mu ,

71 anti1000mu ,

72 antiallmu ,

73 imp100mu ,

74 imp1000mu ,

75 impallmu ,

76 ]

77 putconfintleft = [

78 scipy.nan ,

79 mc100cil ,

80 mc1000cil ,

81 mcallcil ,

82 anti100cil ,

83 anti1000cil ,

84 antiallcil ,

85 imp100cil ,

86 imp1000cil ,

87 impallcil ,

88 ]

89 putconfintright = [

90 scipy.nan ,

91 mc100cir ,

92 mc1000cir ,

93 mcallcir ,

94 anti100cir ,

95 anti1000cir ,

96 antiallcir ,

97 imp100cir ,

22

Page 23: Stochastic Processes and Advanced Mathematical …sdunbar1/MathematicalFinance/Lessons/...Stochastic Processes and Advanced Mathematical Finance Monte Carlo Simulation of Option Prices

98 imp1000cir ,

99 impallcir ,

100 ]

101 d = scipy.transpose(scipy.array ([ putestimate ,

putconfintleft ,

102 putconfintright ]))

103

104 print(d)

Problems to Work for Understanding

1. Experiment with various values of sample size in the Monte Carlo sim-ulation of the simplified put option to determine how the width of theconfidence interval depends on the sample size.

2. Experiment with various random seeds and values of the parameter σin the simplified put option model to find the relative errors of the basicMonte Carlo method, antithetic sampling and importance sampling.

3. From Options we know the value of a put option increases with increas-ing volatility σ. Additionally the standard deviation of the simplifiedsecurity price increases exponentially with increasing σ. Experimentwith various values of σ in the Monte Carlo simulation of the simpli-fied put option to determine how the put option price and the widthof the confidence intervals vary with sigma.

4. Evaluate the following integrals numerically (that is, with numericalintegration software, not Monte Carlo evaluation):

(a) ∫ ∞0

max(K − x, 0)1√

2πσx√T

exp(−1

2(ln(x)/σ

√T )2) dx;

23

Page 24: Stochastic Processes and Advanced Mathematical …sdunbar1/MathematicalFinance/Lessons/...Stochastic Processes and Advanced Mathematical Finance Monte Carlo Simulation of Option Prices

(b) ∫ 0

−∞(1− ex)

e−x2/2

√2π

dx;

(c) ∫ ∞0

1− e−√y

√2π√y

e−y/2

2dy .

Interpreting each as the expected value of a put option at expiration,find the present value i of each if the interest rate is r = σ2/2 withσ = 1 and T − t = T − 0 = 1.

5. Change the scripts to provide descriptive output.

6. Change the scripts to create a Monte Carlo simulation estimate of thevalue of a put option on the Standard and Poor’s 500 index (SPX)directly using 10, 000 random variates with a lognormal distribution.Use parameters S = 1614.96, r = 0.008, σ = 0.1827, K = 1575,T − t = 110/365. Also construct the 95% confidence interval for theestimate.

7. Change the scripts to create a Monte Carlo simulation estimate of thevalue of a call option on the Standard and Poor’s 500 index (SPX)directly using 10, 000 random variates with a lognormal distribution.Use parameters S = 1614.96, r = 0.008, σ = 0.1827, K = 1575,T − t = 110/365.

8. Provide a detailed explanation of the changes of variables that leadfrom∫ ∞0

max(K−x, 0)1√

2πσx√t

exp

(−1

2

[ln(x)− ln(z0)− (r − σ2/2)t

σ√t

]2)dx .

to∫ ∞0

max(K − z0e(r−σ2/2)t+σ

√t√u, 0) + max(K − z0e(r−σ

2/2)t−σ√t√u, 0)

1√2π 2√u

exp

(−u2

)du .

24

Page 25: Stochastic Processes and Advanced Mathematical …sdunbar1/MathematicalFinance/Lessons/...Stochastic Processes and Advanced Mathematical Finance Monte Carlo Simulation of Option Prices

Reading Suggestion:

References

[1] Art Owen. Monte carlo theory, methods and examples.http://statweb.stanford.edu/ owen/mc/, 2013.

Outside Readings and Links:

1.

2.

3.

4.

I check all the information on each page for correctness and typographicalerrors. Nevertheless, some errors may occur and I would be grateful if you wouldalert me to such errors. I make every reasonable effort to present current andaccurate information for public use, however I do not guarantee the accuracy ortimeliness of information on this website. Your use of the information from thiswebsite is strictly voluntary and at your risk.

I have checked the links to external sites for usefulness. Links to externalwebsites are provided as a convenience. I do not endorse, control, monitor, orguarantee the information contained in any external website. I don’t guarantee

25

Page 26: Stochastic Processes and Advanced Mathematical …sdunbar1/MathematicalFinance/Lessons/...Stochastic Processes and Advanced Mathematical Finance Monte Carlo Simulation of Option Prices

that the links are active at all times. Use the links here with the same caution asyou would all information on the Internet. This website reflects the thoughts, in-terests and opinions of its author. They do not explicitly represent official positionsor policies of my employer.

Information on this website is subject to change without notice.

Steve Dunbar’s Home Page, http://www.math.unl.edu/~sdunbar1Email to Steve Dunbar, sdunbar1 at unl dot edu

Last modified: Processed from LATEX source on August 8, 2016

26