Reader small image

You're reading from  Python for Finance

Product typeBook
Published inApr 2014
Reading LevelBeginner
Publisher
ISBN-139781783284375
Edition1st Edition
Languages
Tools
Right arrow
Author (1)
Yuxing Yan
Yuxing Yan
author image
Yuxing Yan

Yuxing Yan graduated from McGill University with a PhD in finance. Over the years, he has been teaching various finance courses at eight universities: McGill University and Wilfrid Laurier University (in Canada), Nanyang Technological University (in Singapore), Loyola University of Maryland, UMUC, Hofstra University, University at Buffalo, and Canisius College (in the US). His research and teaching areas include: market microstructure, open-source finance and financial data analytics. He has 22 publications including papers published in the Journal of Accounting and Finance, Journal of Banking and Finance, Journal of Empirical Finance, Real Estate Review, Pacific Basin Finance Journal, Applied Financial Economics, and Annals of Operations Research. He is good at several computer languages, such as SAS, R, Python, Matlab, and C. His four books are related to applying two pieces of open-source software to finance: Python for Finance (2014), Python for Finance (2nd ed., expected 2017), Python for Finance (Chinese version, expected 2017), and Financial Modeling Using R (2016). In addition, he is an expert on data, especially on financial databases. From 2003 to 2010, he worked at Wharton School as a consultant, helping researchers with their programs and data issues. In 2007, he published a book titled Financial Databases (with S.W. Zhu). This book is written in Chinese. Currently, he is writing a new book called Financial Modeling Using Excel — in an R-Assisted Learning Environment. The phrase "R-Assisted" distinguishes it from other similar books related to Excel and financial modeling. New features include using a huge amount of public data related to economics, finance, and accounting; an efficient way to retrieve data: 3 seconds for each time series; a free financial calculator, showing 50 financial formulas instantly, 300 websites, 100 YouTube videos, 80 references, paperless for homework, midterms, and final exams; easy to extend for instructors; and especially, no need to learn R.
Read more about Yuxing Yan

Right arrow

Chapter 9. The Black-Scholes-Merton Option Model

In modern finance, the option theory and its applications play an important role. Many trading strategies, corporate incentive plans, and hedging strategies include various types of options. In Chapter 6, Introduction to NumPy and SciPy, we showed that you can write a five-line Python program to price a call option based on the Black-Scholes-Merton option model even without understanding its underlying theory and logic. In this chapter, we will explain the option theory and its related applications in more detail.

In particular, we will cover the following topics:

  • Payoff and profit/loss functions and their graphical representations of call and put

  • European versus American options

  • Normal distribution, standard normal distribution, and cumulative normal distribution

  • The Black-Scholes-Merton option model with/without dividend

  • Various trading strategies and their visual presentations, such as covered call, straddle, butterfly, and calendar spread

  • Delta...

Payoff and profit/loss functions for the call and put options


An option gives its buyer the right to buy (call option) or sell (put option) something in the future to the option seller at a predetermined price (exercise price). For example, if we buy a European call option to acquire a stock for X dollars, such as $30, at the end of three months, our payoff on maturity day will be the one calculated using the following formula:

Here, is the stock price at the maturity date (T), and the exercise price is X (X is equal to 30 in this case). Assume that three months later the stock price will be $25. We would not exercise our call option to pay $30 in exchange for the stock, since we could buy the same stock with $25 in the open market. On the other hand, if the stock price is $40, we will exercise our right to reap a payoff of $10, that is, buy the stock at $30 and sell it at $40. The following program presents the payoff function for a call:

>>>def payoff_call(sT,x):
      return...

European versus American options


A European option can be exercised only on the maturity date, while an American option can be exercised any time before or on its maturity date. Since an American option could be held until it matures, its price (option premium) should be higher than or equal to its European counterparty.

An important difference is that for a European option, we have a closed-form solution, that is, the Black-Scholes-Merton option model. However, we don't have a closed-form solution for an American option. Fortunately, we have several ways to price an American option. Later in the chapter, we will show how to use the binomial tree method, also called the CRR method, to price an American option.

Cash flows, types of options, a right, and an obligation


We know that for each business contract, we have two sides, a buyer and a seller. This is true for an option contract as well. A call buyer will pay upfront (cash output) to acquire a right. Since this is a zero-sum game, a call option seller would enjoy an upfront cash inflow and assumes an obligation. The following table presents those positions (buyer or seller), directions of the initial cash flows (inflow or outflow), the option buyer's rights (buy or sell), and the option seller's obligations (that is, to satisfy the option seller's demand):

Normal distribution, standard normal distribution, and cumulative standard normal distribution


In finance, normal distribution plays a central role. This is especially true for option theory. The major reason is that it is commonly assumed that the stock prices follow a log normal distribution while the stock returns follow a normal distribution. The density of a normal distribution is defined as follows:

Here, μ is the mean and σ is the standard deviation.

By setting μ as 0 and σ as 1, the preceding general normal distribution density function collapses to the following standard normal distribution:

The following code generates a graph for the standard normal distribution. The SciPy's stats.norm.pdf() function is used for the standard normal distribution. The default setting is with a zero mean and unit standard deviation, that is, the standard normal density function:

>>>from scipy import exp,sqrt,stats
>>>stats.norm.pdf(0)
0.3989422804014327
>>>1/sqrt(2*pi)   ...

The Black-Scholes-Merton option model on non-dividend paying stocks


The Black-Scholes-Merton option model is a closed-form solution to price a European option on a stock that does not pay any dividends before its maturity date. If we use for the price today, X for the exercise price, r for the continuously compounded risk-free rate, T for the maturity in years, and for the volatility of the stock, the closed-form formulae for a European call (c) and put (p) will be as follows:

Here, N() is the cumulative standard normal distribution. The following Python code snippet represents the preceding formulae to evaluate a European call:

from scipy import log,exp,sqrt,stats
def bs_call(S,X,T,r,sigma):
    d1=(log(S/X)+(r+sigma*sigma/2.)*T)/(sigma*sqrt(T))
    d2 = d1-sigma*sqrt(T)
    return S*stats.norm.cdf(d1)-X*exp(-r*T)*stats.norm.cdf(d2)

In the preceding program, the stats.norm.cdf() function is the cumulative normal distribution, that is, N() in the Black-Scholes-Merton option model. The current...

The p4f module for options


In Chapter 3, Using Python as a Financial Calculator, we recommended the combining of many small Python programs as one program. In this chapter, we adopted the same strategy to combine all the programs in a big file p4f.py. For instance, the preceding Python program, that is, the bs_call() function is included. Such a collection of programs offers several benefits. First, when we use the bs_call() function, we don't have to type those five lines. To save space, we will only show a few functions included in p4f.py. For brevity, we will remove all the comments included for each function. Those comments are designed to help future users when issuing the help() function, such as help(bs_call()).

def bs_call(S,X,T,rf,sigma):
    from scipy import log,exp,sqrt,stats
    d1=(log(S/X)+(rf+sigma*sigma/2.)*T)/(sigma*sqrt(T))
    d2 = d1-sigma*sqrt(T)
    return S*stats.norm.cdf(d1)-X*exp(-rf*T)*stats.norm.cdf(d2)

The following program uses a binomial model to price a call...

European options with known dividends


Assume that we have a known dividend d distributed at time T1, T1 < T, where T is our maturity date. We can modify the original Black-Scholes-Merton option model by replacing S0 with S, where:

In the previously discussed example, if we have a known dividend of $1.5 delivered in one month, what is the price of the call?. The price is calculated as follows:

>>>import p4f
>>>s0=40
>>>d=1.5
>>>r=0.015
>>>T=6/12
>>>s=s0-exp(-r*T*d)
>>>x=42
>>>sigma=0.2 
>>>round(p4f.bs_call(s,x,T,r,sigma),2)
1.18

The first line of the program imports the p4f module, which contains the call option model. The result shows that the price of the call is $1.18, which is lower than the previous value ($1.56). It is understandable since the price of the underlying stock would drop roughly by $1.5 in one month. Because of this, the chance that we could exercise our call option will be less, that is...

Various trading strategies


In the following table, we will summarize several commonly used trading strategies involving various types of options:

 

Buyer

(long position)

Seller

(short position)

European

options

American

options

Call

A right to buy a security (commodity) at a prefixed price

An obligation to sell a security (commodity) at a prefixed price

Are exercised on the maturity date only

Could be exercised any time before or on the maturity date

Put

A right to sell a security with a prefixed price

An obligation to buy...

Relationship between input values and option values


When the volatility of an underlying stock increases, both its call and put values increase. The logic is that when a stock becomes more volatile, we have a better chance to observe extreme values, that is, we have a better chance to exercise our option. The following Python program shows this relationship:

import numpy as np
import p4f as pf
s0=30;T0=0.5;sigma0=0.2;r0=0.05;x0=30
sigma=np.arange(0.05,0.8,0.05)
T=np.arange(0.5,2.0,0.5)
call_0=pf.bs_call(s0,x0,T0,r0,sigma0)
call_sigma=pf.bs_call(s0,x0,T0,r0,sigma)
call_T=pf.bs_call(s0,x0,T,r0,sigma0)
plot(sigma,call_sigma,'b')
plot(T,call_T)

Greek letters for options


In the option theory, several Greek letters, usually called Greeks, are used to represent the sensitivity of the price of derivatives such as options to bring a change in the underlying security. Collectively, those Greek letters are also called the risk sensitivities, risk measures, or hedge parameters.

Delta () is defined as the derivative of the option to its underlying security price. The delta of a call is defined as follows:

We could design a hedge based on the delta value. The delta of a European call on a non-dividend-paying stock is defined as follows:

For example, if we write one call, we could buy delta number of shares of stocks so that a small change in the stock price is offset by the change in the short call. The definition of the delta_call() function is quite simple. Since it is included in the p4f.py file, we can call it easily, as shown in the following code:

>>>from p4f import *
>>>round(delta_call(40,40,1,0.1,0.2),4)
0.7257

The...

The put-call parity and its graphical representation


Let's look at a call with an exercise price of $20, a maturity of three months, and a risk-free rate of 5 percent. The present value of this future $20 price is calculated in the following code:

>>>x=20*exp(-0.05*3/12)   
>>>round(x,2)
19.75
>>>

In three months, what will be the wealth of our portfolio, which consists of a call on the same stock and $19.75 cash today? If the stock price is below $20, we don't exercise the call and keep the cash. If the stock price is above $20, we use our cash of $20 to exercise our call option to own the stock. Thus, our portfolio value will be the maximum of those two values, that is, the stock price in three months or $20, max(s,20).

On the other hand, how about a portfolio with a stock and a put option with an exercise price of $20? If the stock price falls below $20, we exercise the put option and get $20. If the stock price is above $20, we simply keep the stock. Thus, our...

Binomial tree (the CRR method) and its graphical representation


The binomial tree method was proposed by Cox, Ross, and Robinstein in 1979. Because of this, it is also called the CRR method. Based on the CRR method, we have the following two-step approach. First, we draw a tree, such as the following one-step tree. If we assume that our current stock value is S, there are two outcomes S*u and S*d, where u > 1 and d < 1, as shown in the following code:

import matplotlib.pyplot as plt 
xlim(0,1)
plt.figtext(0.18,0.5,'S')
plt.figtext(0.6,0.5+0.25,'Su')
plt.figtext(0.6,0.5-0.25,'Sd')
plt.annotate('',xy=(0.6,0.5+0.25), xytext=(0.1,0.5), arrowprops=dict(facecolor='b',shrink=0.01))
plt.annotate('',xy=(0.6,0.5-0.25), xytext=(0.1,0.5), arrowprops=dict(facecolor='b',shrink=0.01))
plt.axis('off')

The following is its corresponding graph:

Obviously, the simplest tree is a one-step tree. Assume that today's price is $10, the exercise price is $11, and a call option would mature in six months. In...

Hedging strategies


After selling a European call, we could hold shares of the same stock to hedge our position. This is named delta hedge. Since delta () is a function of the underlying stock (S), to maintain an effective hedge, we have to rebalance our holding constantly. This is called dynamic hedging. The delta of a portfolio is the weighted deltas of individual securities in the portfolio. Note that when we short a security, its weight will be negative.

Assume that a US importer will pay 10 million pounds in three months. He or she is concerned with a potential depreciation of the US dollar against the UK pound. There are several ways to hedge such a risk: buy pounds now, enter a futures contract to buy 10 million pounds in three months with a fixed exchange rate, or buy call options with a fixed exchange rate as its exercise price. The first choice is costly since the importer does not need UK pounds today. Entering a future contract is risky as well, since an appreciation of the US...

Summary


In this chapter, we discussed the Black-Scholes-Merton option model in detail. In particular, we covered the payoff and profit/loss functions and their graphical representations of call and put options; various trading strategies and their visual presentations, such as covered call, straddle, butterfly, calendar spread, normal distribution, standard normal distribution, and cumulative normal distribution; delta, gamma and other Greeks; the put-call parity; European versus American options; and the binomial tree method to price options and hedging.

In the next chapter, Python Loops and Implied Volatility, first we will discuss several types of Python loops. Then, we will explain how to find the implied volatility for a call or put option. In addition, we will explain how to download real-world option data from several public available sources. Using that data, we will estimate implied volatility, volatility skewness, and their applications.

Exercises


1. What is the difference between an American call and a European call?

2. What is the unit of rf in the Black-Scholes-Merton option model?

3. If we are given the annual rate of 3.4 percent, compounded semi-annually, what will the value of rf be that we should use for the Black-Scholes-Merton option model ?

4. How do we use options to hedge?

5. How do we treat predetermined cash dividends to price a European call?

6. Why is an American call worth more than a European call?

7. Assume you are a mutual fund manager and your portfolio's β is strongly correlated with the market. You are worried about the short-term fall in the market. What you could do to protect your portfolio?

8. The current price of stock A is $38.5 and the strike prices for a call and a put options are both $37. If the continuously compounded risk-free rate is 3.2 percent, maturity is six months, and the volatility of stock A is 0.25, what are the prices for a European call and put?

9. Use the put-call parity to verify...

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Python for Finance
Published in: Apr 2014Publisher: ISBN-13: 9781783284375
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Yuxing Yan

Yuxing Yan graduated from McGill University with a PhD in finance. Over the years, he has been teaching various finance courses at eight universities: McGill University and Wilfrid Laurier University (in Canada), Nanyang Technological University (in Singapore), Loyola University of Maryland, UMUC, Hofstra University, University at Buffalo, and Canisius College (in the US). His research and teaching areas include: market microstructure, open-source finance and financial data analytics. He has 22 publications including papers published in the Journal of Accounting and Finance, Journal of Banking and Finance, Journal of Empirical Finance, Real Estate Review, Pacific Basin Finance Journal, Applied Financial Economics, and Annals of Operations Research. He is good at several computer languages, such as SAS, R, Python, Matlab, and C. His four books are related to applying two pieces of open-source software to finance: Python for Finance (2014), Python for Finance (2nd ed., expected 2017), Python for Finance (Chinese version, expected 2017), and Financial Modeling Using R (2016). In addition, he is an expert on data, especially on financial databases. From 2003 to 2010, he worked at Wharton School as a consultant, helping researchers with their programs and data issues. In 2007, he published a book titled Financial Databases (with S.W. Zhu). This book is written in Chinese. Currently, he is writing a new book called Financial Modeling Using Excel — in an R-Assisted Learning Environment. The phrase "R-Assisted" distinguishes it from other similar books related to Excel and financial modeling. New features include using a huge amount of public data related to economics, finance, and accounting; an efficient way to retrieve data: 3 seconds for each time series; a free financial calculator, showing 50 financial formulas instantly, 300 websites, 100 YouTube videos, 80 references, paperless for homework, midterms, and final exams; easy to extend for instructors; and especially, no need to learn R.
Read more about Yuxing Yan

Names

Description

Direction of initial cash flow

Expectation of future price movement

Bull spread with calls

Buy a call (x1) sell a call (x2) [x1 < x2]

Outflow

Rise

Bull spread with puts

Buy a put (x1), sell a put (x2) [x1 < x2]

Inflow

Rise

Bear spread with puts

Buy a put (x2), sell a put (x1) [x1 < x2]

Outflow

Fall

Bear spread with calls

Buy a call (x2), sell a call (x1) [x1 < x2]

Inflow

Fall

Straddle

Buy a call and sell a put with the same x value

Outflow

Rise or fall

Strip

Buy two puts and a call (with the same x value)

Outflow

prob (fall) > prob (rise)

Strap

Buy two calls and one put (with the same x value)

Outflow

prob (rise) > prob (fall)

Strangle

Buy a call (x2) and buy a put (x1) [x1 < x2]

Outflow

rise or fall

Butterfly with calls

Buy two calls (x1, x3) and sell two calls (x2)

...