Home > Backtesting, Portfolio Construction, R > 7Twelve Back-test

7Twelve Back-test

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)

plot1

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.

About these ads
  1. joe
    August 15, 2013 at 10:17 am

    Classic trend analysis of a series of lowe highs and lower lowes with macd and RSI readings that were also in a declining trend on a weekly and monthly time scale would have saved you from the 2009 draw down. We are showing similar alerts now in 2013…just need price confirmation.

  2. August 15, 2013 at 12:43 pm

    So it’s another application of aggressive diversification. Would it help to add some alpha strategy on top of it?

  3. Peter Sandersen
    September 13, 2013 at 6:13 pm

    Interesting, thanks for sharing. Consider some more active forecasting to determine whether to be in or out of any one ETF. A rolling ARMA model, or a Dynamic Binary Model to forecast the direction. Have a look at Alexios Ghalanos excellent new DBM package at http://www.unstarched.net/2013/09/12/direction-of-change-forecasting-using-a-dynamic-binary-model/

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 245 other followers

%d bloggers like this: