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 >...