"""
  Name     : c14_10_correlated_random_numbers.py
  Book     : Python for Finance (2nd ed.)
  Publisher: Packt Publishing Ltd. 
  Author   : <NAME>
  Date     : 6/6/2017
  email    : <EMAIL>
             <EMAIL>
"""

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
y2=rho*x1+sp.sqrt(1-rho**2)*x2
print(sp.corrcoef(y1,y2))

"""
  Name     : c14_10_correlated_random_numbers.py
  Book     : Python for Finance (2nd ed.)
  Publisher: Packt Publishing Ltd. 
  Author   : <NAME>
  Date     : 6/6/2017
  email    : <EMAIL>
             <EMAIL>
"""

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
y2=rho*x1+sp.sqrt(1-rho**2)*x2
print(sp.corrcoef(y1,y2))

Name     : c14_10_correlated_random_numbers.py   Book     : Python for Finance (2nd ed.)   Publisher: Packt Publishing Ltd.    Author   : <NAME>   Date     : 6/6/2017   email    : <EMAIL>              <EMAIL>