[Numpy-discussion] Is there a function to calculate ecnomic beta coefficient in numpy given two time series data.
Vineet Jain (gmail)
Thu Jun 19 18:18:50 CDT 2008
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.
[mailto:firstname.lastname@example.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) <email@example.com>
> 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 for row in stock_and_market_values])
> qqqq_array = np.array([row 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([
> 08529, 0.94451427]))
> And the beta comes out to be 0.138 which is a low. It should be closer to
> 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])
"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
More information about the Numpy-discussion