[R-sig-finance] function to calc Fama-French 3 factor model

Dirk Eddelbuettel edd at debian.org
Fri Sep 2 03:04:11 CEST 2005

On 1 September 2005 at 11:24, Andrew West wrote:
| Hello,
| I have written a function that downloads data from
| Yahoo and Ken French's website to automatically
| calculate a regular beta, a robust beta, and the betas
| for the Fama-French 3-factor model, then using these
| factor estimates to estimate various costs of equity
| for the company. After pasting in the function, one
| calls it by typing:
| getffBeta("CSX") -for example to look at CSX

Very nice, thanks for contributing that!

| The function doesn't work however for companies whose
| stock history doesn't go back to Jan 1991. I haven't
| been able to figure out how to automatically set the
| starts of the time series to adjust to short histories
| in a get.hist.quote data download, mostly because I
| cannot figure out how to connect dates from the
| get.hist.quote data to the dating of ts objects. The

I would use the zoo class as the container, and possibly (if you stick to the
montly resolution) use the zooreg class from the zoo package. There is ample
documentation in the zoo package, have a look and don't hesitate to ask here
if you need help.

| code also assumes a C: drive exists.

Naa, for that you want tempfile() which will also keep it portable and
cross-platform.  Moreover, you probably want to cache the Fama/French file to
not have to download it for each equity.
| I am quite a novice programmer, and know that the code
| is pretty poor, but may be still be worthwhile to
| someone. Any improvements offered for the function's
| code would be appreciated. It follows here:

And you may want to use a real R/S-aware editor such as ESS for Emacs (which
is happy on Windoze too) to get auto-indentation. And a lot more in the case
of ESS.

Time permitting, I may have a stab at your function. I can't promise that I
get to it, though.

Regards, Dirk

Statistics: The (futile) attempt to offer certainty about uncertainty.
         -- Roger Koenker, 'Dictionary of Received Ideas of Statistics'

More information about the R-sig-finance mailing list