Keller and Putten in their 2012 paper, “Generalized Momentum and FAA”, went on to combine multiple momentum ranking factors to form portfolios rebalanced monthly. I won’t go in to detail about their strategy as you can find a good commentary at Turnkey Analyst.

Here I took apart each ranking factors and constructed portfolios to see their individual performance. I thought this may be a good way to visualize the performance of each factor alone.

There are four portfolios, rebalanced monthly.

1. Relative Momentum- holds top n performing funds

2. Absolute Momentum- holds funds with positive momentum

3. Volatility Momentum- holds the n lowest volatility funds

4. Correlation Momentum- holds the n lowest average correlation fund; average of all pairwise correlation

Performance

</pre> ############################################################ #Flexible Asset Allocation (Keller & Putten, 2012) # ############################################################ rm(list=ls()) con = gzcon(url('http://www.systematicportfolio.com/sit.gz', 'rb')) source(con) close(con) load.packages("TTR,PerformanceAnalytics,quantmod,lattice") ####################################################### #Get and Prep Data ####################################################### setwd("C:/Users/michaelguan326/Dropbox/Code Space/R/blog research/FAA") data <- new.env() #tickers<-spl("VTI,IEF,TLT,DBC,VNQ,GLD") tickers<-spl("VTSMX,FDIVX,VEIEX,VFISX,VBMFX,QRAAX,VGSIX") getSymbols(tickers, src = 'yahoo', from = '1980-01-01', env = data, auto.assign = T) for(i in ls(data)) data[[i]] = adjustOHLC(data[[i]], use.Adjusted=T) bt.prep(data, align='remove.na', dates='1990::2013') #Helper #Rank Helper Function rank.mom<-function(x){ if(ncol(x) == 1){ r<-x r[1,1] <- 1 }else{ r <- as.xts(t(apply(-x, 1, rank, na.last = "keep"))) } return(r) } ####################################################### #Run Strategies ####################################################### source("C:/Users/michaelguan326/Dropbox/Code Space/R/blog research/FAA/FAA-mom.R") source("C:/Users/michaelguan326/Dropbox/Code Space/R/blog research/FAA/FAA-abs-mom.R") source("C:/Users/michaelguan326/Dropbox/Code Space/R/blog research/FAA/FAA-vol.R") source("C:/Users/michaelguan326/Dropbox/Code Space/R/blog research/FAA/FAA-cor.R") source("C:/Users/michaelguan326/Dropbox/Code Space/R/blog research/FAA/FAA-bench.R") models<-list() top<-3 lookback<-80 #run models models$mom<-mom.bt(data,top,lookback) #relative momentum factor models$abs.mom<-abs.mom.bt(data,lookback) #absolute momentum factor models$vol<-vol.bt(data,top,lookback) #volatility momentum factor models$cor<-cor.bt(data,top,lookback) #volatility factor models$faber<-timing.strategy.local(data,'months',ma.len=200) #faber models$ew<-equal.weight.bt(data) #equal weight benchmark #report plotbt.custom.report.part1(models) plotbt.transition.map(models) plotbt.strategy.sidebyside(models) <pre>

The source codes can be downloaded in my DB folder, can’t guarantee they are error free. Please leave comment of email me if you should find any mistakes.

Thanks for reading,

Mike

Nice job, i like this code structure. I will debug your code to see if find any mistakes. Can i have your email?

Hey tstudent, I inboxed you my email. Cheers

Hi Mike,

Really impressive work. I particularly like how you investigated the individual factors before jumping into FAA. I am currently researching this method and that is how I came across your work. Thank you for your insights and for sharing the code. I have a question about the code and I was wondering if you could send me your email address so I that I can send you the details of my question (there is too much screen output to put here).

Again, thank you for your work in this area. Very much appreciated!

-Gerald

After making the following change in line 24 ( trying to test performance between year 2000-2012 )

bt.prep(data, align=’remove.na’, dates=’2000::2012′)

, it gives out the following errors , how to correct this ?

#FAA model

> models$faa<-faa.bt(data,top,lookback,

+ weight.mom=c(1,0.5,0.5),cash = "VFISX")

Error in .xts(e, .index(e1), .indexCLASS = indexClass(e1), .indexFORMAT = indexFormat(e1), :

index length must match number of observations

In addition: Warning messages:

1: In min(j, na.rm = TRUE) :

no non-missing arguments to min; returning Inf

2: In max(j, na.rm = TRUE) :

no non-missing arguments to max; returning -Inf

After chaning the tickers to a different goup as following

tickers #FAA model

> models$faa<-faa.bt(data,top,lookback,

+ weight.mom=c(1,0.5,0.5),cash = "VFISX")

Error in `[<-.default`(`*tmp*`, i, cash, value = 0.333333333333333) :

subscript out of bounds