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

import scipy as sp

sigma1=0.06
sigma2=0.24
var1=sigma1**2
var2=sigma2**2
rho=-1
n=1000
portVar=10   # assign a big number
tiny=1.0/n

for i in sp.arange(n):
    w1=i*tiny
    w2=1-w1
    var=w1**2*var1 +w2**2*var2+2*w1*w2*rho*sigma1*sigma2
    if(var<portVar):
        portVar=var
        finalW1=w1
    #print(vol)
print("min vol=",sp.sqrt(portVar), "w1=",finalW1) 



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

import scipy as sp

sigma1=0.06
sigma2=0.24
var1=sigma1**2
var2=sigma2**2
rho=-1
n=1000
portVar=10   # assign a big number
tiny=1.0/n

for i in sp.arange(n):
    w1=i*tiny
    w2=1-w1
    var=w1**2*var1 +w2**2*var2+2*w1*w2*rho*sigma1*sigma2
    if(var<portVar):
        portVar=var
        finalW1=w1
    #print(vol)
print("min vol=",sp.sqrt(portVar), "w1=",finalW1) 



Name     : c9_06_solution_2stock_negative_perfect_corr.py   Book     : Python for Finance (2nd ed.)   Publisher: Packt Publishing Ltd.    Author   : <NAME>   Date     : 6/6/2017   email    : <EMAIL>              <EMAIL> # assign a big number #print(vol)