[Numpy-discussion] Is there a function to calculate ecnomic beta coefficient in numpy given two time series data.
Vineet Jain (gmail)
Wed Jun 4 20:24:12 CDT 2008
[mailto:firstname.lastname@example.org] On Behalf Of Keith Goodman
Sent: Wednesday, June 04, 2008 9:04 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 Wed, Jun 4, 2008 at 5:39 PM, Vineet Jain (gmail) <email@example.com>
> Timeseries1 = daily or weekly close of stock a
> Timeseries2 = daily or weekly close of market index (spx, qqqq, etc)
> Beta of stock a is what I would like to compute as explained in this
> on Wikipedia:
> I'm trying to compute the beta of entire stock market (about 15,000
> instruments) one stock at a time and would like to use the spiders and
> to represent the overall market.
Unless you run out of memory (or if you want to handle missing returns
which may occur on different dates in each series) there is no need to
do it one stock at a time:
>> import numpy.matlib as mp
>> mrkt = mp.randn(250,1) # <----- 250 days of returns
>> stocks = mp.randn(250, 4) # <---- 4 stocks
>> beta, resids, rank, s = mp.linalg.lstsq(mrkt, stocks)
matrix([[-0.01701467, 0.11242168, 0.00207398, 0.03920687]])
And you can use mp.log to convert the price ratios to log returns.
It might also be useful to shuffle (mp.random.shuffle) the market
returns and repeat the beta calculation many times to estimate the
noise level of your beta estimates.
Numpy-discussion mailing list
More information about the Numpy-discussion