On Wed, Feb 25, 2009 at 3:21 PM, Anthony Kong <[email protected]> wrote: > I trying to use scipy/numpy in a finanical context. I want to compute the > correlation coeff of two series (returns vs index returns). I tried two > appoarches > > Firstly, > > from scipy.linalg import lstsq > coeffs,a,b,c = lstsq(matrix, returns) # matrix contains index returns > > then I tried, > > import numpy as np > cov = np.cov(idx1, returns) > print cov.tolist() > stddev_x = np.std(returns, ddof=1) > stddev_y = np.std(idx1, ddof=1) > print "cor = %s" % (cov.tolist()[:-1] /(stddev_x * stddev_y)) > They differ from each other.
coeffs in coeffs,a,b,c = lstsq(matrix, returns) # matrix contains index returns is the beta of the stock with respect to the index, not the correlation. _______________________________________________ Numpy-discussion mailing list [email protected] http://projects.scipy.org/mailman/listinfo/numpy-discussion
