# Commands that generated the results of Section 2.1 of # "The Portfolio Probe User's Manual" # # These commands demonstrate the static random portfolio method # of performance measurement # # This depends on functions listed in 'pprobe_functions01.R' # The data are created in 'pprobe_R_data01.txt' # # The functions that create the graphs are in 'pprobe_graphFun01.R' # If you want hardcopies of the graphs, then you need to start a # graphics device (like 'pdf') and do 'dev.off()' after the graphs # are created. # things to CHANGE, possibly PP_LOC <- ".." # initial setup if(!exists("us.pricemat")) attach(paste(PP_LOC, "us.pricemat.rda", sep="/")) if(!exists("us.macdmat")) attach(paste(PP_LOC, "us.macdmat.rda", sep="/")) # create the starting portfolio init.20.w10 <- trade.optimizer(us.pricemat[251,], expected.return=us.macdmat[251,], port.size=20, max.weight=.1, gross.value=1e6, long.only=TRUE, do.warn=c(novar=FALSE, utility.switch=FALSE)) # These optimizations do not involve a variance for simplicity # Real optimizations almost certainly will, see the file # 'pprobe_R_varCache.txt' for a method of dealing with # large variance matrices # do the series of optimizations for 200% turnover ser.20.w10.t200 <- pp.serial.opt(init.20.w10, pricemat=us.pricemat[-1:-251,], alphamat=us.macdmat, frac.turnover=2/252, max.weight=.1, port.size=20, do.warn=c(novar=FALSE, utility.switch=FALSE), keep.port=TRUE) # do the series of optimizations for 400% turnover ser.20.w10.t400 <- pp.serial.opt(init.20.w10, pricemat=us.pricemat[-1:-251,], alphamat=us.macdmat, frac.turnover=4/252, max.weight=.1, port.size=20, do.warn=c(novar=FALSE, utility.switch=FALSE), keep.port=TRUE) # generate random portfolios that obey constraints at start of period rp251.20.w10 <- random.portfolio(1000, us.pricemat[251,], expected.return=us.macdmat[251,], port.size=20, max.weight=.1, gross.value=1e6, long.only=TRUE) # calculate returns of random portfolios for 2007 rp251.20.w10.ret07 <- pp.simpret(valuation(rp251.20.w10, us.pricemat[c(251, nrow(us.pricemat)-252),], collapse=TRUE)) # calculate return of optimal portfolios for 2007 serret200.07 <- ser.20.w10.t200$value[251]/ser.20.w10.t200$value[1] - 1 serret400.07 <- ser.20.w10.t400$value[251]/ser.20.w10.t400$value[1] - 1 # calculate returns of random portfolios for 2007-2008 rp251.20.w10.ret0708 <- pp.simpret(valuation(rp251.20.w10, us.pricemat[c(251, nrow(us.pricemat)),], collapse=TRUE)) # calculate return of optimal portfolios for 2007-2008 serret200.0708 <- ser.20.w10.t200$value[504]/ser.20.w10.t200$value[1] - 1 serret400.0708 <- ser.20.w10.t400$value[504]/ser.20.w10.t400$value[1] - 1 # create the graphs P.simpm07(NULL) P.simpm0708(NULL) # calculate percentiles round(100 * mean(rp251.20.w10.ret07 < serret200.07)) round(100 * mean(rp251.20.w10.ret07 < serret400.07)) round(100 * mean(rp251.20.w10.ret0708 < serret200.0708)) round(100 * mean(rp251.20.w10.ret0708 < serret400.0708))