Hello. I am new to the list thanks for accepting my question.
 
I am trying to run the attached code, directly from the book in the title. 
 
It simply calculates correlation of returns of the stock listed in the 
spreadsheets. could it be that the numPY library is not being recognized on my 
system for some reason? 
 
I installed the 32 bit version of python/numpy. This is to preserve 
compatibility with another application that will trigger the code. I am on 
Windows 7 64 bit Home Edition, however. 
 
Thanks for any suggestions.
 
-Dinesh
#!/usr/bin/python

import numpy
from pylab import *

bhp = numpy.loadtxt('BHP.csv', delimiter=',', usecols=(6,), unpack=True)

bhp_returns = numpy.diff(bhp) / bhp[ : -1]

vale = numpy.loadtxt('VALE.csv', delimiter=',', usecols=(6,), unpack=True)

vale_returns = numpy.diff(vale) / vale[ : -1]

covariance = numpy.cov(bhp_returns, vale_returns) 


print "Covariance diagonal", covariance.diagonal()
print "Covariance trace", covariance.trace()

print covariance/ (bhp_returns.std() * vale_returns.std())

print "Correlation coefficient", numpy.corrcoef(bhp_returns, vale_returns)

difference = bhp - vale
avg = numpy.mean(difference)
dev = numpy.std(difference)

print "Out of sync", numpy.abs(difference[-1] - avg) > 2 * dev

t = numpy.arange(len(bhp_returns))
plot(t, bhp_returns, lw=1)
plot(t, vale_returns, lw=2)
show()

Attachment: BHP.csv
Description: MS-Excel spreadsheet

Attachment: VALE.csv
Description: MS-Excel spreadsheet

_______________________________________________
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to