Site icon R-bloggers

7Twelve Back-test

[This article was first published on Systematic Investor » R, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

I recently came across the The 7Twelve Portfolio strategy. I like the catchy name and the strategy report, “An Introduction to 7Twelve.” Following is some additional info about the The 7Twelve Portfolio strategy that I found useful:

Today I want to show how to back-test the The 7Twelve Portfolio strategy using the Systematic Investor Toolbox.

Let’s start by loading historical data

###############################################################################
# Load Systematic Investor Toolbox (SIT)
# http://systematicinvestor.wordpress.com/systematic-investor-toolbox/
###############################################################################
setInternet2(TRUE)
con = gzcon(url('http://www.systematicportfolio.com/sit.gz', 'rb'))
    source(con)
close(con)
   
    #*****************************************************************
    # Load historical data
    #******************************************************************
    load.packages('quantmod')  

    tickers = spl('VFINX,VIMSX,NAESX,VDMIX,VEIEX,VGSIX,FNARX,QRAAX,VBMFX,VIPSX,OIBAX,BIL') 
	
    data <- new.env()
    getSymbols(tickers, src = 'yahoo', from = '1970-01-01', env = data, auto.assign = T)

    #--------------------------------   
    # BIL     30-May-2007 
    # load 3-Month Treasury Bill from FRED
    TB3M = quantmod::getSymbols('DTB3', src='FRED', auto.assign = FALSE)		
    TB3M[] = ifna.prev(TB3M)	
    TB3M = processTBill(TB3M, timetomaturity = 1/4, 261)	
    #--------------------------------       	

    # extend	
    data$BIL = extend.data(data$BIL, TB3M, scale=T)	
	
    for(i in ls(data)) data[[i]] = adjustOHLC(data[[i]], use.Adjusted=T)		
				
    bt.prep(data, align='remove.na')

Next, let’s make the The 7Twelve Portfolio strategy with annual/ quarterly and monthly rebalancing.

    #*****************************************************************
    # Code Strategies
    #****************************************************************** 
    models = list()
	
    # Vanguard 500 Index Investor (VFINX)
    data$weight[] = NA
        data$weight$VFINX[] = 1
    models$VFINX  = bt.run.share(data, clean.signal=F) 
		
    #*****************************************************************
    # Code Strategies
    #****************************************************************** 	
    obj = portfolio.allocation.helper(data$prices, periodicity = 'years',
        min.risk.fns = list(EW=equal.weight.portfolio)
    ) 	
    models$year = create.strategies(obj, data)$models$EW

    obj = portfolio.allocation.helper(data$prices, periodicity = 'quarters',
        min.risk.fns = list(EW=equal.weight.portfolio)
    ) 	
    models$quarter = create.strategies(obj, data)$models$EW
		
    obj = portfolio.allocation.helper(data$prices, periodicity = 'months',
        min.risk.fns = list(EW=equal.weight.portfolio)
    ) 	
    models$month = create.strategies(obj, data)$models$EW
	
    #*****************************************************************
    # Create Report
    #****************************************************************** 
    strategy.performance.snapshoot(models, T)

The strategy does better than the Vanguard 500 Index benchmark, but still suffers a huge draw-down in 2008-2009 period.

How would you make it a better strategy? Please share your ideas.

To view the complete source code for this example, please have a look at the bt.7twelve.strategy.test() function in bt.test.r at github.


To leave a comment for the author, please follow the link and comment on their blog: Systematic Investor » R.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.