Book Image

Python for Finance

By : Yuxing Yan
Book Image

Python for Finance

By: Yuxing Yan

Overview of this book

A hands-on guide with easy-to-follow examples to help you learn about option theory, quantitative finance, financial modeling, and time series using Python. Python for Finance is perfect for graduate students, practitioners, and application developers who wish to learn how to utilize Python to handle their financial needs. Basic knowledge of Python will be helpful but knowledge of programming is necessary.
Table of Contents (14 chapters)
13
Index

Statistic submodule (stats) from SciPy


One special module called stats contained in the SciPy module is worthy of special attention, since many of our financial problems depend on this module. To find out all the contained functions, we have the following lines of code:

>>>from scipy import stats
>>>dir(stats)

To save space, only a few lines are shown in the following screenshot:

From the output, not shown completely in the preceding screenshot, we could find a ttest_1samp() function. To use the function, we generate 100 random numbers drawn from a standard normal distribution, zero mean, and unit standard deviation. For the one-sample T-test, we test whether its mean is 0. Based on the t-value (1.18) and p-value (0.24), we could not reject the null hypothesis. This means that the mean of our x is zero as shown in the following lines of code:

>>>import numpy as np
>>>from scipy import stats
>>>np.random.seed(124) # get the same random values
&gt...