[Numpy-discussion] Question on lstsq and correlation coeff
Keith Goodman
kwgoodman@gmail....
Wed Feb 25 18:48:08 CST 2009
On Wed, Feb 25, 2009 at 3:21 PM, Anthony Kong
<Anthony.Kong@macquarie.com> 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.
More information about the Numpy-discussion
mailing list