[Numpy-discussion] Is there a function to calculate ecnomic beta coefficient in numpy given two time series data.
Vineet Jain (gmail)
vinjvinj@gmail....
Thu Jun 19 18:18:50 CDT 2008
Thanks.
With your changes, I'm getting a beta of 0.23 which I think is still wrong.
I would have expected a value closer to 2.
Vineet
-----Original Message-----
From: numpy-discussion-bounces@scipy.org
[mailto:numpy-discussion-bounces@scipy.org] On Behalf Of Robert Kern
Sent: Thursday, June 19, 2008 7:08 PM
To: Discussion of Numerical Python
Subject: Re: [Numpy-discussion] Is there a function to calculate ecnomic
beta coefficient in numpy given two time series data.
On Thu, Jun 19, 2008 at 17:48, Vineet Jain (gmail) <vinjvinj@gmail.com>
wrote:
> I took the following code and applied it to aapl and qqqq time series (see
> attached file):
>
> import numpy as np
> lstsq = np.linalg.lstsq
> from numpy import float64, extract
>
> aapl_array = np.array([row[0] for row in stock_and_market_values])
> qqqq_array = np.array([row[1] for row in stock_and_market_values])
>
> A = np.ones((len(qqqq_array), 2), dtype=float64)
> A[:,0] = aapl_array
> result = lstsq(A, qqqq_array)
> print result
>
> The result is:
>
> (array([ 0.13851625, 29.57888955]), array([ 144.23291488]), 2, array([
> 639.591
> 08529, 0.94451427]))
>
> And the beta comes out to be 0.138 which is a low. It should be closer to
2.
> Any idea on what I'm doing wrong.
Beta is supposed to be calculated on returns, not prices.
aapl_ret = np.log(aapl_array[1:] / aapl_array[:-1])
qqqq_ret = np.log(qqqq_array[1:] / qqqq_array[:-1])
--
Robert Kern
"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
-- Umberto Eco
_______________________________________________
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion
More information about the Numpy-discussion
mailing list