# Commands that generated the results of Section 2.4 of # "The Portfolio Probe User's Manual" # # These commands demonstrate the shadowing 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="/")) # 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 # Possibly OPTIONAL if 'pprobe_R_perfMeas_static.txt is done # 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, utility="maximum return", do.warn=c(novariance.optim=FALSE)) # 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) # 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 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 # End possibly OPTIONAL part # generate random series of trades randser.20.w10.t200 <- pp.serial.rand(200, 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)) randser.20.w10.t400 <- pp.serial.rand(200, 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)) # do plots P.matchpm.t200.07(NULL) P.matchpm.t200.0708(NULL) P.matchpm.t400.07(NULL) P.matchpm.t400.0708(NULL)