[Numpy-discussion] Is there a function to calculate ecnomic beta coefficient in numpy given two time series data.
Thu Jun 19 18:08:22 CDT 2008
On Thu, Jun 19, 2008 at 17:48, Vineet Jain (gmail) <firstname.lastname@example.org> 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 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 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])
"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
More information about the Numpy-discussion