10.12.2019 Views

Python for Finance

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Monte Carlo Simulation

The histogram of our simulated terminal prices is shown as follows:

As we mentioned in Chapter 9, Portfolio Theory, in order to generate two correlated

random number time series, there are two step involved: generate two random time

series x1 and x2 with a zero-correlation; and then apply the following formulae:

Here, ρ is the predetermined correlation between those two time series. Now, y1 and

y2 are correlated with a predetermined correlation. The following Python program

will implement the preceding approach:

import scipy as sp

sp.random.seed(123)

n=1000

rho=0.3

x1=sp.random.normal(size=n)

x2=sp.random.normal(size=n)

y1=x1

[ 440 ]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!