[R-SIG-Finance] Extract Fama and French coefficients at each t point in time on one asset

Ilya Kipnis ilya.kipnis at gmail.com
Tue Jan 20 01:29:56 CET 2015


I highly recommend you look into the xts package and its endpoints
functionality. That may solve a lot of your hassles. Furthermore, I also
recommend you use a list data structure and append to it at every iteration
before combining it into your output data frame and only writing it once.
Take note of the weights <- list(), weights[[i]] <- periodWeights, and
weights <- do.call(rbind, periodWeights) lines.

On Mon, Jan 19, 2015 at 7:24 PM, Alex Badoi <alex.badoi1 at gmail.com> wrote:

> Hello,
>
> My name is Alex B, Financial Economics student. I am using R to write my
> thesis i am in need of a bit of programming help. I have been using the
> program for just over a month so i'm still not familiar with all the
> functions and packages. I am trying to extract Fama and French coefficient
> data to CSV for further analysis and factor portfolio formation.
>
> I am using the package nlme with the following regression equation:
>
> fund.xcess ~ rmrf + smb + hml + rmw + cma
>
> What i am trying to do:
> I have a time series of daily asset prices from 2009 to 2015 and i am
> trying to estimate the regression coefficients at each period in time
> starting with 2010 and using the last year for my first estimate such that
> i have a time series of regression coefficients. The end result would
> ideally be a .csv file with coefficient estimates  rmrf , smb , hml, rmw
> and cma as columns and dates ranging from 2010 to 2015 as rows.
>
> Here is what i have so far:
>
> # Load data into R
> setwd("/Users/alexbadoi/Desktop/College/Postgrad/Master/Seminar Pc/R")
> ff_data = read.csv("ff5_bab_qmj.csv", header = TRUE, sep=",")
> library(nlme)
>
> # Assign Fama-French Factor Data
>
> rmrf <- ff_data[,2]/100
> rf <- ff_data[,7]/100
> smb <- ff_data[,3]/100
> hml <- ff_data[,4]/100
> rmw <- ff_data[,5]/100
> cma <- ff_data[,6]/100
>
> #perform regression
>
> i = nrow(ff_data)
>
> for(i in 58){
> fund <- ff_data[11,i+1]/100
> fund.xcess <- fund - rf
> ffgls <- gls(fund.xcess ~ rmrf + smb + hml + rmw + cma,
>              correlation=corARMA(p=1, q=1), method='ML')
>
> output <- data.frame(ffgls$coefficients)
>
> write.table(output, file="test123.csv", sep=",", dec=".", col.names=FALSE,
> append=TRUE)
> print(summary(ffgls))
> }
>
>
> My asset returns are at [,11].
> the ff5_bab_qmj.csv file contains Fama and French factor data, rf and
> returns of asset a
>
> Any help would be very much appreciated.
> Thank you in advance.
>
>         [[alternative HTML version deleted]]
>
> _______________________________________________
> R-SIG-Finance at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions
> should go.
>

	[[alternative HTML version deleted]]



More information about the R-SIG-Finance mailing list