[Graphics:Images/index_gr_4.gif]

Andrzej  Kozlowski

Toyama University of International Studies, Toyama, Japan

andrzej@tuins.ac.jp

Abstract.

We present a Mathematica-based introduction to the theory and practice of financial derivative pricing and risk management and a quick survey of some Mathematica resources available for this purpose.

Key words: Stocks, optiosn, arbitrage, Ito's lemma, Black­Scholes equation

1. Brownian Motion and Securities.

We shall be dealing with securities. Some of these, e. g. stocks  (shares) will be risky, others (bonds) not (this is an ideal world).   So we start by defining a Mathematica view of a security.  We think of a security  as a stochastic process characterized by  several parameters rather than a tradable piece of paper. These parameters will be its volatility, drift, current value, and possibly the dividend it pays. Here is a function that defines a new security.

[Graphics:Images/index_gr_5.gif]

We create "stocks" like this:

[Graphics:Images/index_gr_6.gif]

NEC is now actually a function, but you can thing of it as an "object" with built in "methods", getVolatility, setVolatility, getDrift etc.

[Graphics:Images/index_gr_7.gif]
[Graphics:Images/index_gr_8.gif]

We would like to be able to simulate and plot the time series representing the change in price of our security. Essentially all models  in finance are based on Brownian motion (Wiener process). There are almost countless ways to construct approximations to Brownian motion in Mathematica. The one I will use here is based on approximation by binomial random walks (see below).  I shall call these random walks Brownian paths, although they are of course only good approximations when n is large.

[Graphics:Images/index_gr_9.gif]

Using the central limit theorem we can show that as [Graphics:Images/index_gr_10.gif] the distribution of [Graphics:Images/index_gr_11.gif] does indeed tend to the normal distribution with mean [Graphics:Images/index_gr_12.gif] and standard deviation [Graphics:Images/index_gr_13.gif] and that W[n] has all the other properties of the standard Brownian motion (e.g. see [1] or [7]). Note the usage of  "dynamic programming". Its purpose is to create a concrete Brownian path   (random walk) with BrownianPath[], which we can keep using until we reset the definition by evaluating BrownianPath[] again. Of course one can achieve the same thing by using SeedRandom[] as in [10], but our approach is more convenient, particularly when working with several independent random walks.
Now we  define a function  that generates a random walk  of the values of our security, based on the (approximate) geometric Brownian motion (the exponential of a Brownian motion) with volatility and drift taken from our security.

[Graphics:Images/index_gr_14.gif]

Finally, we define a function which plots random walks representing the movement of prices of our security:

[Graphics:Images/index_gr_15.gif]
[Graphics:Images/index_gr_16.gif]

We can change the volatility of our security and compare the corresponding time series, based on the same BrownianPath.

[Graphics:Images/index_gr_17.gif]

[Graphics:Images/index_gr_18.gif]

Much more about generating, manipulating and plotting diffusions (using a quite different approach)  can be found in [10].

In what follows we shall make the usual assumptions of about the market in which we are operating: completeness and the absence of arbitrage. The latter basically asserts that the best way to make money without risk is by putting it in a bank account and collecting interest. This is sometimes described as the principle that "there is no such thing as a  free lunch". (I have always thought that this ought to be "there is no such thing as a risk­free lunch", but that may sound too unnervingly true in the age of BSE etc.)
More precisely, it means that any two portfolios (see below) which always bring the same outcome should have the same value. If this was not true then by selling one and buying the other we could earn our lunch, risk free. In particular, the absence of arbitrage implies the following result. Suppose we have some risk free scheme that guarantees us income [Graphics:Images/index_gr_19.gif] after time [Graphics:Images/index_gr_20.gif]. Then the price of such a scheme ought to be: [Graphics:Images/index_gr_21.gif], where [Graphics:Images/index_gr_22.gif] is the bank rate of interest. Indeed, this is the amount of money that deposited in a bank at interest rate [Graphics:Images/index_gr_23.gif] will return [Graphics:Images/index_gr_24.gif] after time [Graphics:Images/index_gr_25.gif].

2.Options and Arbitrage.

At this point we need to explain what we mean by a "portfolio". Our portfolios will be rather limited compared with those in the real world. They will consist of stocks and only one kind of derivatives, options on stocks.  We shall assume we can hold any real amount of these, both positive and negative. This latter fact, the ability to hold negative amount of stock and options may surprise those who have not had much to do with financial markets, but this is indeed possible. (This is related the other condition mentioned above, the completeness of our market). In effect having a negative amount of a share is the same as borrowing it. In reality borrowing shares (known as short selling) does incur a certain small cost but we shall assume that it can be done for free. In the same way as stock we can hold (in positive and negative quantities) options on stock. The options we shall first consider will be of two kinds: the so called European calls and puts (more precisely, what is known as "European vanilla calls and puts"). A European call option with a strike price [Graphics:Images/index_gr_26.gif] and maturity date [Graphics:Images/index_gr_27.gif] gives the holder the right (but not the obligation) to buy the underlying asset at time [Graphics:Images/index_gr_28.gif] for the price [Graphics:Images/index_gr_29.gif]. (In our case the underlying asset will be always one of the securities we defined above, but in the real world one can trade options on a variety of assets, including options on options etc. Our approach can be extended to include these cases).  European put option with a strike price [Graphics:Images/index_gr_30.gif] and maturity date [Graphics:Images/index_gr_31.gif] gives the holder the right to sell the underlying asset at time [Graphics:Images/index_gr_32.gif] for the price [Graphics:Images/index_gr_33.gif]. To hold a negative amount of an option is the same as "writing" the respective option, in other words, to undertake the obligation to purchase (if required)  Each financial instrument stock, put or call has a pay­off function,

[Graphics:Images/index_gr_34.gif]

Note that we distinguish the "abstract" security (essentially an index) like NEC and  a unit tradable amount of NEC stock, denoted by stock[NEC]. A portfolio is now is an element of the real vector space generated by the basic instruments (calls, puts and stock), that is a "formal sum" of these.
We shall now use the functions we have developed to prove one of the oldest  theorems about options, the so called "Put­Call" parity.  The proof is a triviality but it illustrates a characteristic use of the "no free lunch" principle, and in some sense is a prototype of everything that follows. Let us first define a perfectly general stock

[Graphics:Images/index_gr_35.gif]

We now construct a "risk free" portfolio with generalStock as the underlying asset. By risk free I mean one that produced exactly the same payoff no matter what happens.

[Graphics:Images/index_gr_36.gif]

Let's compute the payoff of this portfolio at time T. This is trivial to do by hand but let Mathematica do the work for us. There are three cases to consider, when on the expiration date [Graphics:Images/index_gr_37.gif], [Graphics:Images/index_gr_38.gif], and [Graphics:Images/index_gr_39.gif]. We check that the payoff of the portfolio is [Graphics:Images/index_gr_40.gif] in each case.

[Graphics:Images/index_gr_41.gif]
[Graphics:Images/index_gr_42.gif]

We see that our portfolio gives us a guaranteed payoff of e (==s) at time [Graphics:Images/index_gr_43.gif], no matter what happens to the stock! Hence by the principle of no arbitrage the values of the portfolio must be [Graphics:Images/index_gr_44.gif] Thus we get the putt­call parity : [Graphics:Images/index_gr_45.gif].

3.Trees and Derivative Pricing

One of the most remarkable achievements in mathematical finance  was the development by Black, Scholes and Merton of the modern theory of pricing of derivative instruments. The origin of the subject  is the following  simple but profound observation. Let's imagine the following situation. Suppose a stock has current value of 2 dollars and we know that only two things can happen to it: it can either go up by 0.5 dollars or go down by the same amount. Suppose the probability of it going up is 2/3. Suppose we are offered the option of purchasing the stock for 2 dollars at the next instant. How much should such an option be worth?  Let us assume that the rate of interest is 0. The classic probabilistic answer would have been: if the price of the stalk goes up to 2.5 we shall buy it for 2.0 dollars gaining 0.5 dollar but if it goes down we do not exercise the option.Thus our expected gain is [Graphics:Images/index_gr_46.gif]=0.333333. However, this intuitive answer is wrong. The correct answer is obtained as follows. First of all we replace the "actual"  probabilities by probabilities which ensure that the expected value of our stock is exactly the same as the starting value (such a process is called a martingale). In other words we want to find p from:

[Graphics:Images/index_gr_47.gif]
[Graphics:Images/index_gr_48.gif]

The answer is the expected value based on this new "probability", i.e.  [Graphics:Images/index_gr_49.gif] The reason why this is the "correct price" of the option is that any other price would allow possibilities of arbitrage. For example, suppose the price of the option was 0.2 dollars. We could buy the option for 0.2 dollars and we short sell 0.5 unit of stock for 1 dollar. Now suppose the stock goes up to 2.5. We use the option to buy the stock for 2.5, return it, gaining 0.5 and we loose 0.5(2 -2.5)= 0.25 on the short sale, giving us the net gain of 0.25.
Or, if the stock falls to 1.5, we do not exercise the option but we gain  0.5(2-1.5) = 0.25 on the short sale. In both cases we have a net, risk free gain of 0.05 dollar.
Similar argument can be used to show that risk free gain is possible if the option price is higher than 0.25 dollar.
Note that the actual probabilities play no role in determining the value of the option. This idea can ba extended to binary trees of arbitrary length. Here we illustrate it with a three stage process, with actual probabilities and martingale probabilities

[Graphics:Images/index_gr_50.gif]

[Graphics:Images/index_gr_51.gif]

This elementary example contains the essence of one approach to both the theory and practical computation of option values. We can use binary trees and discrete martingales to compute approximate value of any option. The virtue of this approach is that it is very easy to implement in Mathematica. For the American put option (see below) this was implemented in Mathematica by Ross.  Miller [6] and for several other well known options by S. Benninga, R. Steinmetz and J. Stroughair [2]. However, this approach is rather inefficient in general the differential equations alternatives offer more  accuracy and performance.

4. The Black­Scholes Differential Equation

There is another approach to option pricing which does not make the use of martingale theory. Let us consider a general stock (without dividends). In the Black­Scholes analysis it is assumed that such a stock performs an infinitesimal random walk given by the stochastic differential equation

[Graphics:Images/index_gr_52.gif]

where σ and μ are constants called the volatility and the drift of the stock. Here W stands for the standard Brownian motion.  Of course S and W are random variables defined on some sample space which one never needs to bother about. (Essentially the space of all possible "continuous random walks").  It can be easily shown that this equation describes a limiting case of a discrete random walk of the type we defined above. Precise meaning can be given to it by considering it in terms of stochastic integrals. To get an intuitive idea of what is going on consider the fundamental theorem of classical calculus:  

[Graphics:Images/index_gr_53.gif]

One wy to think of this is as a statement that every differentiable function can be approximated by straight line segments. Of course a Brownian motion is exactly something that can't be approximated in this way. It is therefore natural to consider a wider class of objects, stochastic processes that can be written in the form:

[Graphics:Images/index_gr_54.gif]

Here [Graphics:Images/index_gr_55.gif] stands for Brownian motion,  [Graphics:Images/index_gr_56.gif] and [Graphics:Images/index_gr_57.gif] are random processes which are pre­visible with respect to the Brownian motion (meaning that [Graphics:Images/index_gr_58.gif]and [Graphics:Images/index_gr_59.gif]depend only on [Graphics:Images/index_gr_60.gif] for [Graphics:Images/index_gr_61.gif]and the ordinary integral [Graphics:Images/index_gr_62.gif]is finite for all t (with probability 1). Such a process (which can be defined precisely) is called an Ito process. It is often written in differential form:


[Graphics:Images/index_gr_63.gif][Graphics:Images/index_gr_64.gif]+[Graphics:Images/index_gr_65.gif]

For example, the Ito  process used in the Black­Scholes model is given by the stochastic differential equation


[Graphics:Images/index_gr_66.gif][Graphics:Images/index_gr_67.gif]+[Graphics:Images/index_gr_68.gif][Graphics:Images/index_gr_69.gif]

where [Graphics:Images/index_gr_70.gif] and [Graphics:Images/index_gr_71.gif] are constants. Let us now suppose that we have a derivative product which depends only on the value of the stock at time t. In other words, the value of the derivative is a function [Graphics:Images/index_gr_72.gif]The famous formula due to K. Ito ("Ito's Lemma") tells us that a smooth transformation of an Ito process is again an Ito process and tells us how to obtain a representation of the form (3). This leads to a whole subject called "Ito calculus", which is a generalization of traditional calculus  to Ito processes. A particularly powerful Mathematica implementation of the Ito calculus by Wilfrid Kendall can be found in [4] and another  one in [10] in the same volume.  Here we shall use of a simpler  package inspired by the latter, due to Mark Fisher and available from MathSource.

[Graphics:Images/index_gr_73.gif]

Now suppose at time t0 we hold a portfolio consisting of our derivative [Graphics:Images/index_gr_74.gif] and [Graphics:Images/index_gr_75.gif] of stock, where

[Graphics:Images/index_gr_76.gif]

In other words, our portfolio [Graphics:Images/index_gr_77.gif] is

[Graphics:Images/index_gr_78.gif]

Let's compute the change of this portfolio at time t0,

[Graphics:Images/index_gr_79.gif]
[Graphics:Images/index_gr_80.gif]

Note that the instantaneous change in the value of the portfolio is deterministic (no Brownian component). By the "no free­lunch" principle it must therefore be equal to what could be earned by an amount equal to P invested at the risk free interest rate for a period dt.

[Graphics:Images/index_gr_81.gif]
[Graphics:Images/index_gr_82.gif]
[Graphics:Images/index_gr_83.gif]
[Graphics:Images/index_gr_84.gif]

This is the famous Black­Scholes differential equation.It is a second order linear partial differential equation of the parabolic type.Note that it is satisfied by every derivative security whose price value depends only on the current value of X and on t.A slight modification of the argument shows that if the stock pays a constant dividend q the differential equation takes the form

[Graphics:Images/index_gr_85.gif]

This equation must be satisfied by the value of every derivative whose price depends only on the current value of [Graphics:Images/index_gr_86.gif] and on [Graphics:Images/index_gr_87.gif]. The differences between different kinds of options will express itself in the boundary conditions.
At this point there are a number there are two basic methods to proceed if w try to solve the differential equation. One approach using Mathematica is described in the article by Steel and Stine. It is based on the so called Feynman­Kac formula which expresses the solutions of certain second order PDE's in terms of expectation of the corresponding diffusion (solution of a SDE). The other approach is preferred by those who do not know or do not wish to know much about stochastic techniques. By means of  certain standard transformations (for details see the book of Shaw [9] or if you prefer more explanation but no Mathematica code the book of Wilmott at al) one can reduce the Black­Scholes equation to one of the most famous and best studied PDE's in physics: the heat equation,  which can be solved using one of several well known techniques.  For the European call the explicit, Nobel prize winning solution is:

[Graphics:Images/index_gr_88.gif]


5.Risk Management

The purpose of financial derivatives is management of risk. This is done by constructing portfolio's stocks and options with a desired payoff. We know that we cannot guarantee gain above the free interest rate, but  if we have any hypothesis or opinion about the future of a stock (or a stock index) we can build a portfolio that will do well if this hypothesis turns out to be true. We can built risky portfolio's with a potential for high gain, or a safe portfolios, minimizing possible loss.  In fact it is possible to show [8] that any "contingent claim" can be matched by a portfolio of European options.
Now that we can compute the value of a European call or a put we can easily create a Mathematica function that will compute the value of a portfolio, consisting of different calls, puts and stocks. This makes it easy to create a suitable portfolio for any specific purpose. For this purpose we define the function value, which computes the value of a portfolio, which we think of as a formal sum of different derivatives.

[Graphics:Images/index_gr_89.gif]

Let us construct a portfolio based on the NEC stock we have defined, which will make profits provided the stock price stays within a certain range.

[Graphics:Images/index_gr_90.gif]

[Graphics:Images/index_gr_91.gif]


The part of the picture where the thick red graph (payoff) is above the thin green (cost) represents profitable range of final values of the stock, the rest represents a loss. This kind of portfolio is known as a straddle and is very popular with traders.

6. Other Types of Derivatives and Options

So far we have considered  only European options, but the great majority of options actually traded on stock exchanges are so called American options. They differ form European ones in that they can be exercised any time before the expiry date. In the case of call options without dividends this difference turns out to be illusory, for one can show that it is never optimal to exercise an such an option before expiry. However, in the case of American put options when the price of the stock falls low it may be optimal to exercise the option early. The result is that the Black­Scholes equation becomes only an inequality. The problem of finding the value of the American put option also reduces to a well known problem in physics  (the "obstacle problem") and it is known that no analytic solution to it exists. One has therefore to result to other methods. In [2] and [6] this is done by means of binary trees and the Monte carlo method, but much more attractive are the methods considered in [9], which include  approximate analytic solutions and the use of finite difference methods of solving differential equations. The same applies to other options, known as "exotic" Asian options,  look­back options etc.

7. Second Generation Option Pricing

We have only discussed here the use of Mathematica in the Black­Scholes theory , which is actually the "first generation"  of option pricing models. Among it's obvious limitations is the assumption of constant volatility of stocks, which no one who has paid the slightest attention to the behavior of the stock markets in recent years could believe to be realistic. New generation of theories that do not rely on this assumption are the objects of current research. Of course Mathematica is just as useful here as can be seen from the very interesting book [5].  

[Graphics:Images/index_gr_92.gif]

[Graphics:Images/index_gr_93.gif]Baxter, M. and Rennie, A., 1996, Financial Calculus ­ an Introduction to Derivative Pricing, Cambridge University Press.

[Graphics:Images/index_gr_94.gif] S. Benninga, R. Steinmetz and J. Stroughair, Implementing Numerical Option Pricing Models, The Mathematica Journal, 1993, 3,4, 66­73

[Graphics:Images/index_gr_95.gif]J. C. Hull, Options, Futures & Other derivatives, Prentice Hall, 2000.

[Graphics:Images/index_gr_96.gif]W. S. Kendall, Itovsn3: Doing Stochastic Calculus with Mathematica, in H.R. Varian (ed), Economic and Financial Modeling with Mathematica, Springer, 1992, 214­238.

[Graphics:Images/index_gr_97.gif]A. L. Lewis. Option Valuation under Stochastic Volatility with Mathematica Code, Finance Press, 2000.

[Graphics:Images/index_gr_98.gif]R. M. Miller, Option Valuation, in H.R. Varian (ed), Economic and Financial Modeling with Mathematica, Springer, 1992, 266­285.

[Graphics:Images/index_gr_99.gif]B. Øksendal, Stochastic Differential Equations, Springer, 2000.

[Graphics:Images/index_gr_100.gif]P.Protter, A partial introduction to financial asset pricing theory, Stochastic Processes and their Applications 91 (2001) 169­203

[Graphics:Images/index_gr_101.gif]T. Shaw. Modelling Financial Derivatives with Mathematica, Cambridge University Press, 1998

[Graphics:Images/index_gr_102.gif]J. M. Steele, R. A. Stine, Mathematica and Diffusions, in H.R. Varian (ed), Economic and Financial Modeling with Mathematica, Springer, 1992, 192­213.

Two freely available Mathematica packages were used in this notebook. They are: the new version of the Combinatorica package by Sriram Pemmaraju and Steven Skiena <http://www.cs.uiowa.edu/~sriram/Combinatorica/> and the "Ito's Lemma" package by Mark Fisher available from MathSource.


Converted by Mathematica      June 9, 2002