Finally, let us check whether the end-of-period values are indeed log-normally distributed.
This boils down to a normality test as well, since we only have to transform the data by
applying the log function to it (to then arrive at normally distributed data — or maybe
not). Figure 11-4 plots both the log-normally distributed end-of-period values and the
transformed ones (“log index level”):
In [ 15 ]: f, (ax1, ax2) = plt.subplots( 1 , 2 , figsize=( 9 , 4 ))
ax1.hist(paths[- 1 ], bins= 30 )
ax1.grid(True)
ax1.set_xlabel(‘index level’)
ax1.set_ylabel(‘frequency’)
ax1.set_title(‘regular data’)
ax2.hist(np.log(paths[- 1 ]), bins= 30 )
ax2.grid(True)
ax2.set_xlabel(‘log index level’)
ax2.set_title(‘log data’)
Figure 11-4. Histogram of simulated end-of-period index levels
The statistics for the data set show expected behavior — for example, a mean value close
to 105 and a standard deviation (volatility) close to 20%:
In [ 16 ]: print_statistics(paths[- 1 ])
Out[16]: statistic value
––––––––––
size 250000.00000
min 42.74870
max 233.58435
mean 105.12645
std 21.23174
skew 0.61116
kurtosis 0.65182
The log index level values also have skew and kurtosis values close to zero:
In [ 17 ]: print_statistics(np.log(paths[- 1 ]))
Out[17]: statistic value
––––––––––
size 250000.00000
min 3.75534
max 5.45354
mean 4.63517
std 0.19998
skew -0.00092
kurtosis -0.00327
This data set also shows high p-values, providing strong support for the normal
distribution hypothesis:
In [ 18 ]: normality_tests(np.log(paths[- 1 ]))