Python for Finance: Analyze Big Financial Data

(Elle) #1
Out[18]:    Skew    of  data    set                                     -0.001
Skew test p-value 0.851
Kurt of data set -0.003
Kurt test p-value 0.744
Norm test p-value 0.931

Figure 11-5 compares again the frequency distribution with the pdf of the normal


distribution, showing a pretty good fit (as now is, of course, to be expected):


In  [ 19 ]: log_data    =   np.log(paths[- 1 ])
plt.hist(log_data, bins= 70 , normed=True, label=‘observed’)
plt.grid(True)
plt.xlabel(‘index levels’)
plt.ylabel(‘frequency’)
x = np.linspace(plt.axis()[ 0 ], plt.axis()[ 1 ])
plt.plot(x, scs.norm.pdf(x, log_data.mean(), log_data.std()),
‘r’, lw=2.0, label=‘pdf’)
plt.legend()

Figure 11-5. Histogram of log index levels and normal density function

Figure 11-6 also supports the hypothesis that the log index levels are normally distributed:


In  [ 20 ]: sm.qqplot(log_data, line=‘s’)
plt.grid(True)
plt.xlabel(‘theoretical quantiles’)
plt.ylabel(‘sample quantiles’)

Figure 11-6. Quantile-quantile plot for log index levels

NORMALITY

The normality assumption with regard to returns of securities is central to a number of important financial

theories. Python provides efficient statistical and graphical means to test whether time series data is normally
Free download pdf