Book Image

Python for Finance

By : Yuxing Yan
Book Image

Python for Finance

By: Yuxing Yan

Overview of this book

Table of Contents (20 chapters)
Python for Finance
About the Author
About the Reviewers

Cumulative standard normal distribution

In Chapter 4, 13 Lines of Python to Price a Call Option, we used 13 lines of Python codes to price a call option since we have to write our own cumulative standard normal distribution. Fortunately, the cumulative standard normal distribution is included in the submodule of SciPy. The following example shows the value of the cumulative standard normal distribution at zero:

>>>from scipy.stats import norm

Thus, we could simplify our call option model considerably using just five lines. The following code is a typical example of the benefits we can enjoy using various modules:

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

Now, we could use the following function by inputting a set of values: