Python for Finance: Analyze Big Financial Data

(Elle) #1
Figure 10-3. Simulated geometric Brownian motion (via standard_normal)

Figure 10-3 suggests that the distribution of the random variable as defined in


Equation 10-1 is log-normal. We could therefore also try to use the lognormal function to


directly derive the values for the random variable. In that case, we have to provide the


mean and the standard deviation to the function:


In  [ 12 ]: ST2 =   S0  *   npr.lognormal((r    -   0.5 *   sigma   **   2 )    *   T,
sigma * np.sqrt(T), size=I)

Figure 10-4 shows the output of the following simulation code:


In  [ 13 ]: plt.hist(ST2,   bins= 50 )
plt.xlabel(‘index level’)
plt.ylabel(‘frequency’)
plt.grid(True)

Figure 10-4. Simulated geometric Brownian motion (via lognormal)

By visual inspection, Figure 10-4 and Figure 10-3 indeed look pretty similar. But let us


verify this more rigorously by comparing statistical moments of the resulting distributions.


To compare the distributional characteristics of simulation results we use the scipy.stats


sublibrary and the helper function print_statistics, as defined here:


In  [ 14 ]: import scipy.stats as scs
In [ 15 ]: def print_statistics(a1, a2):
”’ Prints selected statistics.

                                                    Parameters
==========
a1, a2 : ndarray objects
results object from simulation
Free download pdf