Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Mastering Python for Finance. - Second Edition

You're reading from  Mastering Python for Finance. - Second Edition

Product type Book
Published in Apr 2019
Publisher Packt
ISBN-13 9781789346466
Pages 426 pages
Edition 2nd Edition
Languages
Author (1):
James Ma Weiming James Ma Weiming
Profile icon James Ma Weiming

Table of Contents (16) Chapters

Preface Section 1: Getting Started with Python
Overview of Financial Analysis with Python Section 2: Financial Concepts
The Importance of Linearity in Finance Nonlinearity in Finance Numerical Methods for Pricing Options Modeling Interest Rates and Derivatives Statistical Analysis of Time Series Data Section 3: A Hands-On Approach
Interactive Financial Analytics with the VIX Building an Algorithmic Trading Platform Implementing a Backtesting System Machine Learning for Finance Deep Learning for Finance Other Books You May Enjoy

Numerical Methods for Pricing Options

A derivative is a contract whose payoff depends on the value of some underlying asset. In cases where closed-form derivative pricing may be complex or even impossible, numerical procedures excel. A numerical procedure is the use of iterative computational methods in attempting to converge to a solution. One such basic implementation is a binomial tree. In a binomial tree, a node represents the state of an asset at a certain point of time associated with a price. Each node leads to two other nodes in the next time step. Similarly, in a trinomial tree, each node leads to three other nodes in the next time step. However, as the number of nodes or the time steps of trees increase, so do the computational resources that are consumed. Lattice pricing attempts to solve this problem by storing only the new information at each time step, while reusing...

Introduction to options

An option is a derivative of an asset that gives an owner the right but not the obligation to transact the underlying asset at a certain date for a certain price, known as the maturity date and strike price, respectively.

A call option gives the buyer the right to buy an asset by a certain date for a certain price. A seller or writer of a call option is obligated to sell the underlying security to the buyer at the agreed price, should the buyer exercise his/her rights on the agreed date.

A put option gives the buyer the right to sell the underlying asset by a certain date for a certain price. A seller or writer of a put option is obligated to buy the underlying security from the buyer at the agreed price, should the buyer exercise his/her rights on the agreed date.

The most common options that are available are the European options and American options...

Binomial trees in option pricing

In the binomial option pricing model, the underlying security at one time period, represented as a node with a given price, is assumed to traverse to two other nodes in the next time step, representing an up state and a down state. Since options are derivatives of the underlying asset, the binomial pricing model tracks the underlying conditions on a discrete-time basis. Binomial option pricing can be used to value European options, American options, as well as Bermudan options.

The initial value of the root node is the spot price S0 of the underlying security with a risk-neutral probability of increase q, and a risk-neutral probability of loss 1-q, at the next time step. Based on these probabilities, the expected values of the security are calculated for each state of price increase or decrease for every time step. The terminal nodes represent...

Pricing European options

Consider a two-step binomial tree. A non-dividend paying stock price starts at $50, and, in each of the two time steps, the stock may go up by 20 percent or go down by 20 percent. Suppose that the risk-free rate is five percent per annum and that the time to maturity, T, is two years. We would like to find the value of a European put option with a strike price K of $52. The following diagram shows the pricing of the stock and the payoffs at the terminal nodes using a binomial tree:

Here, the nodes are calculated as follows:

At the terminal nodes, the payoff from exercising a European call option is given as follows:

In the case of a European put option, the payoff is as follows:

European call and put options are usually denoted by lowercase letters, c and p, while American call and put options are usually denoted by uppercase...

Writing the StockOption base class

Before going any further and implementing the various pricing models that we are about to discuss, let's create a StockOption class to store and calculate the common attributes of the stock option that will be reused throughout this chapter:

In [ ]:
import math

"""
Stores common attributes of a stock option
"""
class StockOption(object):
def __init__(
self, S0, K, r=0.05, T=1, N=2, pu=0, pd=0,
div=0, sigma=0, is_put=False, is_am=False):
"""
Initialize the stock option base class.
Defaults to European call unless specified.

:param S0: initial stock price
:param K: strike price
:param r: risk-free interest rate
:param T: time to maturity
:param N:...

The Greeks for free

In the binomial tree pricing models that we have covered so far, we traversed up and down the tree at each point in time to determine the node values. From the information at each node, we can reuse these computed values easily. One such use is the computation of Greeks.

The Greeks measure the sensitivities of the price of derivatives, such as options with respect to changes in the parameters of the underlying asset, often represented by Greek letters. In mathematical finance, the common names associated with Greeks include alpha, beta, delta, gamma, vega, theta, and rho.

Two particularly useful Greeks for options are delta and gamma. Delta measures the sensitivity of the option price with respect to the underlying asset price. Gamma measures the rate of change in delta with respect to the underlying price.

As shown in the following diagram, an additional layer...

Trinomial trees in option pricing

In the binomial tree, each node leads to two other nodes in the next time step. Similarly, in a trinomial tree, each node leads to three other nodes in the next time step. Besides having up and down states, the middle node of the trinomial tree indicates no change in state. When extended over more than two time steps, the trinomial tree can be thought of as a recombining tree, where the middle nodes always retain the same values as the previous time step.

Let's consider the Boyle trinomial tree, where the tree is calibrated so that the probability of up, down, and flat movements, u, d, and m with risk-neutral probabilities qu, qd, and qm are as follows:

We can see that recombines to m =1. With calibration, the no state movement m grows at a flat rate of 1 instead of at the risk-free rate. The variable v is the annualized dividend...

Lattices in option pricing

In binomial trees, each node recombines at every alternative node. In trinomial trees, each node recombines at every other node. This property of recombining trees can also be represented as lattices to save memory without recomputing and storing recombined nodes.

Using a binomial lattice

We will create a binomial lattice from the binomial CRR tree since at every alternate up and down nodes, the prices recombine to the same probability of ud=1. In the following diagram, Su and Sd recombine with Sdu = Sud = S0. The tree can now be represented as a single list:

For a N-step binomial tree, a list of size 2N +1 is required to contain the information on the underlying stock prices. For European...

Finite differences in option pricing

Finite difference schemes are very much similar to trinomial tree option pricing, where each node is dependent on three other nodes with an up movement, a down movement, and a flat movement. The motivation behind the finite differencing is the application of the Black-Scholes Partial Differential Equation (PDE) framework (involving functions and their partial derivatives), where price S(t) is a function of f(S,t), with r as the risk-free rate, t as the time to maturity, and σ as the volatility of the underlying security:

The finite difference technique tends to converge faster than lattices and approximates complex exotic options very well.

To solve a PDE by finite differences working backward in time, a discrete-time grid of size M by N is set up to reflect asset prices over a course of time, so that S and t take on the following...

Putting it all together – implied volatility modeling

In the option pricing methods we have learned so far, a number of parameters are assumed to be constant: interest rates, strike prices, dividends, and volatility. Here, the parameter of interest is volatility. In quantitative research, the volatility ratio is used to forecast price trends.

To derive implied volatilities, we need to refer to Chapter 3, Nonlinearity in Finance, where we discussed the root-finding methods of nonlinear functions. We will use the bisection method of numerical procedures in our next example to create an implied volatility curve.

Implied volatilities of the AAPL American put option

Let's consider the option data of the stock...

Summary

In this chapter, we looked at a number of numerical procedures in derivative pricing, the most common being options. One such procedure is the use of trees, with binomial trees being the simplest structure to model asset information, where one node extends to two other nodes in each time step, representing an up state and a down state, respectively. In trinomial trees, each node extends to three other nodes in each time step, representing an up state, a down state, and a state with no movement, respectively. As the tree traverses upwards, the underlying asset is computed and represented at each node. The option then takes on the structure of this tree and, starting from the terminal payoffs, the tree traverses backward and toward the root, which converges to the current discounted option price. Besides binomial and trinomial trees, trees can take on the form of the...

lock icon The rest of the chapter is locked
You have been reading a chapter from
Mastering Python for Finance. - Second Edition
Published in: Apr 2019 Publisher: Packt ISBN-13: 9781789346466
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.
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}