Introductory Mathematica Exercise:  An Example from Mathematical Finance
Copyright 2001.  F. J. Lin

1.  Introduction

This introductory Mathematica exercise will show (1) a method of evaluating the Black-Scholes-Merton formula for the price, c, of a European call option as a function of the asset price, S, and the time, t.  Next, it will show (2) a method of calculating derivatives of the option price; e.g., the derivative of the call option price with respect to the asset price, the derivative of the call option price with respect to time, and the second derivative of the call option price with respect to the asset price.  These derivatives of the option price are called the "Greeks."  Next, it will show (3) a method of making simple x,y-plots for the Greeks.  Finally, it will conclude with (4) an exercise for the reader; i.e., repeat the above three steps for a European put option.

2.  Background

The Black-Scholes-Merton equation (Hull, 2000) for option pricing has the explicit solutions given below for the price of a European call option on a nondividend-paying stock and for the price of a put option on a nondividend-paying stock.

The "Greeks" (short for Greek letters) measure various aspects of the risk in an option position.  For example, the delta of an option, Δ, is the rate of change of the option price with respect to the underlying asset, e.g.,

[Graphics:Images/Intro_Mma_Ex_gr_1.gif]

where [Graphics:Images/Intro_Mma_Ex_gr_2.gif] is the price of a call option.  The theta of an option, Θ, is the rate of change of the option price with respect to the passage of time when all ofther variables are held fixed, i.e.,

[Graphics:Images/Intro_Mma_Ex_gr_3.gif]

The gamma of an option, Γ, is the rate of change of the option's delta with respect to the price of the underlying asset

[Graphics:Images/Intro_Mma_Ex_gr_4.gif]

i.e., it is the second partial derivative of the option price with respect to the asset price.

3.  Evaluate a function, e.g., a Black-Scholes-Merton option pricing formula:

Define the input parameters appearing in the Black-Scholes-Merton formula for the price of a European option:

Define r, the risk-free interest rate per annum (in 1/years), corresponding to the maturity:

[Graphics:Images/Intro_Mma_Ex_gr_5.gif]

Define σ, the volatility of the asset price per annum (in 1/[Graphics:Images/Intro_Mma_Ex_gr_6.gif]):

[Graphics:Images/Intro_Mma_Ex_gr_7.gif]

Define X, the strike price of the option (in dollars):

[Graphics:Images/Intro_Mma_Ex_gr_8.gif]

Define T, the time at maturity (in years):

[Graphics:Images/Intro_Mma_Ex_gr_9.gif]

Define t, the current time (in years):

[Graphics:Images/Intro_Mma_Ex_gr_10.gif]

The time will be one of the independent variables.

Define S, the asset price (in dollars):

[Graphics:Images/Intro_Mma_Ex_gr_11.gif]

The asset price will also be an independent variable.

Define d1 and d2, the arguments of the cumulative normal probability distribution function, to be functions of S and t:[Graphics:Images/Intro_Mma_Ex_gr_12.gif]

[Graphics:Images/Intro_Mma_Ex_gr_13.gif] = [Graphics:Images/Intro_Mma_Ex_gr_14.gif]  
[Graphics:Images/Intro_Mma_Ex_gr_15.gif] = [Graphics:Images/Intro_Mma_Ex_gr_16.gif][Graphics:Images/Intro_Mma_Ex_gr_17.gif]

i.e.,

[Graphics:Images/Intro_Mma_Ex_gr_18.gif]
[Graphics:Images/Intro_Mma_Ex_gr_19.gif]
[Graphics:Images/Intro_Mma_Ex_gr_20.gif]
[Graphics:Images/Intro_Mma_Ex_gr_21.gif]

Load the package that defines continuous probability distributions:

[Graphics:Images/Intro_Mma_Ex_gr_22.gif]

Define the standard normal probability distribution function:

[Graphics:Images/Intro_Mma_Ex_gr_23.gif]

The Black-Scholes-Merton formula for the price of a call option is given by

c(S,t) = SN([Graphics:Images/Intro_Mma_Ex_gr_24.gif]) - X[Graphics:Images/Intro_Mma_Ex_gr_25.gif]N([Graphics:Images/Intro_Mma_Ex_gr_26.gif])

i.e.,

[Graphics:Images/Intro_Mma_Ex_gr_27.gif]
[Graphics:Images/Intro_Mma_Ex_gr_28.gif]

where CDF is the cumulative probability density function.

The Black-Scholes-Merton formula for the price of a put option is given by

p(S,t) = X[Graphics:Images/Intro_Mma_Ex_gr_29.gif]N(-[Graphics:Images/Intro_Mma_Ex_gr_30.gif]) - SN(-[Graphics:Images/Intro_Mma_Ex_gr_31.gif])

i.e.,

[Graphics:Images/Intro_Mma_Ex_gr_32.gif]
[Graphics:Images/Intro_Mma_Ex_gr_33.gif]

4.  Evaluate a derivative of a function, e.g., various Greeks:

Define the delta of the call option (in dimensionless units); i.e., the rate of change of the option price with respect to the price of the underlying asset.  Thus, the delta of the call option is the partial derivative of the call option price with respect to the asset price.

[Graphics:Images/Intro_Mma_Ex_gr_34.gif]
[Graphics:Images/Intro_Mma_Ex_gr_35.gif]

Define the theta of the call option (in dollars/year); i.e., the rate of change of the option price with respect to the time when the asset price is held constant.  Thus, the theta of the call option is the partial derivative of the call option price with respect to time.

[Graphics:Images/Intro_Mma_Ex_gr_36.gif]
[Graphics:Images/Intro_Mma_Ex_gr_37.gif]

Define the gamma of the call option (in 1/dollars); i.e., the rate of change of the option's delta with respect to the price of the underlying asset.  Thus, the gamma of the call option is the second partial derivative of the call option price with respect to the asset price.

[Graphics:Images/Intro_Mma_Ex_gr_38.gif]
[Graphics:Images/Intro_Mma_Ex_gr_39.gif]

5.  Graph a function, e.g., various Greeks:

5.a.  Define a set of parameters for plotting the functions

Assign numerical values for r, σ, X, and T.  These values are chosen for ease in plotting. i.e., they produce graphs showing the variation in each of the Greeks for three different values of the moneyness on a single set of axes.  Except for the graph of theta as a function of the asset price, this set of values for r, σ, X, and T produces graphs showing a rather typical dependence of each of the Greeks on the various independent variables.  (In section 4.e, realistic values for r, σ, X, and T are input to produce a graph showing the typical dependence of theta on the asset price.)

[Graphics:Images/Intro_Mma_Ex_gr_40.gif]
[Graphics:Images/Intro_Mma_Ex_gr_41.gif]
[Graphics:Images/Intro_Mma_Ex_gr_42.gif]
[Graphics:Images/Intro_Mma_Ex_gr_43.gif]
[Graphics:Images/Intro_Mma_Ex_gr_44.gif]
[Graphics:Images/Intro_Mma_Ex_gr_45.gif]
[Graphics:Images/Intro_Mma_Ex_gr_46.gif]
[Graphics:Images/Intro_Mma_Ex_gr_47.gif]

Define various parameters to be used in plotting the Greeks.

First, define the parameters to be used to plot each of the Greeks as a function of the asset price.

Define two values of the independent variable S.

[Graphics:Images/Intro_Mma_Ex_gr_48.gif]
[Graphics:Images/Intro_Mma_Ex_gr_49.gif]
[Graphics:Images/Intro_Mma_Ex_gr_50.gif]
[Graphics:Images/Intro_Mma_Ex_gr_51.gif]

Define a fixed value of the independent variable t:

[Graphics:Images/Intro_Mma_Ex_gr_52.gif]
[Graphics:Images/Intro_Mma_Ex_gr_53.gif]

Next, define the parameters to be used to plot each of the Greeks as a function of the time to maturity.  Three fixed values of the asset price will be defined, corresponding to three different values of the moneyness.

For an in-the-money option, S - X > 0.  Fix S to be greater than X.

[Graphics:Images/Intro_Mma_Ex_gr_54.gif]
[Graphics:Images/Intro_Mma_Ex_gr_55.gif]

For an at-the-money option, S - X = 0.  Fix S to be equal to X.

[Graphics:Images/Intro_Mma_Ex_gr_56.gif]
[Graphics:Images/Intro_Mma_Ex_gr_57.gif]

For an out-of-the-money option, S - X < 0.  Fix S to be less than X.

[Graphics:Images/Intro_Mma_Ex_gr_58.gif]
[Graphics:Images/Intro_Mma_Ex_gr_59.gif]

Let y = T - t be the time to maturity with 0 ≤ y ≤ T.  (Then t = T - y  with T ≥ t ≥ 0.)

5.b.  Plot delta

Plot the delta of a call option as a function of the asset price for a fixed value of time.

[Graphics:Images/Intro_Mma_Ex_gr_60.gif]

[Graphics:Images/Intro_Mma_Ex_gr_61.gif]

[Graphics:Images/Intro_Mma_Ex_gr_62.gif]

Plot the delta of a call option as a function of the time to maturity for three different values of the moneyness.

[Graphics:Images/Intro_Mma_Ex_gr_63.gif]
[Graphics:Images/Intro_Mma_Ex_gr_64.gif]
[Graphics:Images/Intro_Mma_Ex_gr_65.gif]
[Graphics:Images/Intro_Mma_Ex_gr_66.gif]

[Graphics:Images/Intro_Mma_Ex_gr_67.gif]

[Graphics:Images/Intro_Mma_Ex_gr_68.gif]

Legend:
Black = in the money
Gray = at the money
Dashed = out of the money

5.c.  Plot theta

Plot the theta of a call option as a function of the asset price for a fixed value of time.

[Graphics:Images/Intro_Mma_Ex_gr_69.gif]

[Graphics:Images/Intro_Mma_Ex_gr_70.gif]

[Graphics:Images/Intro_Mma_Ex_gr_71.gif]

Plot the theta of a call option as a function of the time to maturity for three different values of the moneyness.

[Graphics:Images/Intro_Mma_Ex_gr_72.gif]
[Graphics:Images/Intro_Mma_Ex_gr_73.gif]

[Graphics:Images/Intro_Mma_Ex_gr_74.gif]

[Graphics:Images/Intro_Mma_Ex_gr_75.gif]

Legend:
Black = in the money
Gray = at the money
Dashed = out of the money

5.d.  Plot gamma

Plot the gamma of a call option as a function of the asset price for a fixed value of time.

[Graphics:Images/Intro_Mma_Ex_gr_76.gif]

[Graphics:Images/Intro_Mma_Ex_gr_77.gif]

[Graphics:Images/Intro_Mma_Ex_gr_78.gif]

Plot the gamma of a call option as a function of the time to maturity for three different values of the moneyness.

[Graphics:Images/Intro_Mma_Ex_gr_79.gif]
[Graphics:Images/Intro_Mma_Ex_gr_80.gif]

[Graphics:Images/Intro_Mma_Ex_gr_81.gif]

[Graphics:Images/Intro_Mma_Ex_gr_82.gif]

Legend:
Black = in the money
Gray = at the money
Dashed = out of the money

5.e.  Replot theta for a set of realistic parameter values:

Now, re-assign the numerical values for r, σ, X, and T.  These values are chosen both to be realistic values for r, σ, X, and T and to produce a graph showing the typical dependence of theta on the asset price.

[Graphics:Images/Intro_Mma_Ex_gr_83.gif]
[Graphics:Images/Intro_Mma_Ex_gr_84.gif]
[Graphics:Images/Intro_Mma_Ex_gr_85.gif]
[Graphics:Images/Intro_Mma_Ex_gr_86.gif]
[Graphics:Images/Intro_Mma_Ex_gr_87.gif]
[Graphics:Images/Intro_Mma_Ex_gr_88.gif]
[Graphics:Images/Intro_Mma_Ex_gr_89.gif]
[Graphics:Images/Intro_Mma_Ex_gr_90.gif]

Re-evaluate the price of a call option and its theta for these new parameter values.

[Graphics:Images/Intro_Mma_Ex_gr_91.gif]
[Graphics:Images/Intro_Mma_Ex_gr_92.gif]
[Graphics:Images/Intro_Mma_Ex_gr_93.gif]
[Graphics:Images/Intro_Mma_Ex_gr_94.gif]

Re-evaluate the parameters required for plotting the theta with these new parameter values.

[Graphics:Images/Intro_Mma_Ex_gr_95.gif]
[Graphics:Images/Intro_Mma_Ex_gr_96.gif]
[Graphics:Images/Intro_Mma_Ex_gr_97.gif]
[Graphics:Images/Intro_Mma_Ex_gr_98.gif]

Select values of the input parameters for the Plot command to produce a nicely-scaled graph showing the typical dependence of the theta of a call option on the asset price for a fixed value of the time.

[Graphics:Images/Intro_Mma_Ex_gr_99.gif]

[Graphics:Images/Intro_Mma_Ex_gr_100.gif]

[Graphics:Images/Intro_Mma_Ex_gr_101.gif]

5.f.  Add a legend

For the experts, a legend can be added to each of the graphs of a Greek for the three values of the moneyness by using the package Graphics`Legend`.  This package can be loaded by using the command

[Graphics:Images/Intro_Mma_Ex_gr_102.gif]

For documentaion, go to the menu bar at the top of the screen and select
    Help > Find Selected Function

Then type
    Graphics`Legend`

in the input box.

6.  Exercise

(1)  Evaluate the Black-Scholes-Merton formula for the price of a European put option.
(2)  Evaluate the Greeks for a European put option:  (a) the delta, (b) the theta, and (c) the gamma.
(3)  Make the analogous graphs for a European put option:  (a) the delta as a function of S, (b) the delta as a function of t for an in-the-money option, for an at-the-money option, and for an out-of-the-money option, (c) the theta as a function of S, (d) the theta as a function of t for an in-the-money option, for an at-the-money option, and for an out-of-the-money option, (e) the gamma as a function of S, and (f) the gamma as a function of t for an in-the-money option, for an at-the-money option, and for an out-of-the-money option.  [Note:  It may be necessary to change the values of some of the parameters in order to make the graphs.]

Submit a presentation-quality, printed copy of your Mathematica notebook containing your work.  Also, e-mail a copy of your Mathematica notebook as an attachment to fjlin@math.usc.edu.  Be sure that your name is printed in the notebook.

7.  Reference

J. C. Hull, Options, Futures, and Other Derivatives,4th ed., (Prentice Hall, Upper Saddle River, NJ, 2000).


Converted by Mathematica      January 23, 2001