## XFGpp (R 2.9.1)

XFGpp generates a P-P Plot for Backtesting of 1) basic simulation, mean adjustment, volatility updating and volatility updating and mean adjustment simulations as well as of 2) benchmark curve, spread curve, conservative approach and simultaneous simulation. All simulated data follow chapter 2.4 in XFG2.

Fri, June 29 2012 by Dedy Dwi Prastyo

`-`

Description: -

Description: -

```rm(list=ls(all=TRUE))
graphics.off()
XFGpp = function(MMPL,PL){
PP = matrix(0,ncol(PL)+1,3)
true = matrix(0,nrow(MMPL),ncol(PL))
for (i in 1:nrow(MMPL)){
k = 1
while (k < (ncol(PL))){
true[i,k] = c(MMPL[i,]>PL[i,k]) # true = 1 for any value of MMPL>PL
k = k + 1
}
}
tmp = apply(1-true,1,sum) # sum up all "true"s for each row
j=1
while (j < nrow(PL)) {
PP[(ncol(PL)-tmp[j]+2),2] = PP[(ncol(PL)-tmp[j]+2),2] + 1/nrow(PL)
j = j + 1
}
PP[1:50,]
PP[2:(ncol(PL)+1),1] = (1:ncol(PL))/ncol(PL)            # sequence
PP[2:(ncol(PL)+1),2] = cumsum(PP[2:(ncol(PL)+1),2])     # cum sum of empirical distribution of Loss
PP[2:(ncol(PL)+1),3] = (PP[2:(ncol(PL)+1),2]-PP[2:(ncol(PL)+1),1])^2/(ncol(PL)+1) # Mean Squared Deviation in each point
return(PP)
}
PP = XFGpp(MMPL,PL)
sum(PP[,3]) 	# Mean Squared Deviation
par(mfrow=c(2,2))
titl  = "Basic Simulation"
xlabel = "Uniform Distribution"
ylabel = "Empirical Distribution"
plot(PP[,1],PP[,1], type="l", col="blue3", lwd=3, ylab=ylabel, xlab=xlabel, main=titl, frame=T, axes=F)
axis(1,c(0,0.5,1))
axis(2,c(0,0.5,1))
lines(PP[,1],PP[,2],  col="red3", lwd=3)
PP = XFGpp(MMPL,PL)
sum(PP[,3]) 	# Mean Squared Deviation
titl  = "Mean Adjustment"
xlabel = "Uniform Distribution"
ylabel = "Empirical Distribution"
plot(PP[,1],PP[,1], type="l", col="blue3", lwd=3, ylab=ylabel, xlab=xlabel, main=titl, frame=T, axes=F)
axis(1,c(0,0.5,1))
axis(2,c(0,0.5,1))
lines(PP[,1],PP[,2],  col="red3", lwd=3)
PP = XFGpp(MMPL,PL)
sum(PP[,3]) 	# Mean Squared Deviation
titl  = "Volatility Updating"
xlabel = "Uniform Distribution"
ylabel = "Empirical Distribution"
plot(PP[,1],PP[,1], type="l", col="blue3", lwd=3, ylab=ylabel, xlab=xlabel, main=titl, frame=T, axes=F)
axis(1,c(0,0.5,1))
axis(2,c(0,0.5,1))
lines(PP[,1],PP[,2],  col="red3", lwd=3)
PP=XFGpp(MMPL,PL)
sum(PP[,3]) 	# Mean Squared Deviation
titl  = "Volatility Updating & Mean Adjustment"
xlabel = "Uniform Distribution"
ylabel = "Empirical Distribution"
plot(PP[,1],PP[,1], type="l", col="blue3", lwd=3, ylab=ylabel, xlab=xlabel, main=titl, frame=T, axes=F)
axis(1,c(0,0.5,1))
axis(2,c(0,0.5,1))
lines(PP[,1],PP[,2],  col="red3", lwd=3)
PP = XFGpp(MMPL,PL)
sum(PP[,3]) 	# Mean Squared Deviation
dev.new()
par(mfrow=c(2,2))
titl  = "Benchmark Curve"
xlabel = "Uniform Distribution"
ylabel = "Empirical Distribution"
plot(PP[,1],PP[,1], type="l", col="blue3", lwd=3, ylab=ylabel, xlab=xlabel, main=titl, frame=T, axes=F)
axis(1,c(0,0.5,1))
axis(2,c(0,0.5,1))
lines(PP[,1],PP[,2],  col="red3", lwd=3)
PP = XFGpp(MMPL,PL)
sum(PP[,3]) 	# Mean Squared Deviation
titl  = "Spread Curve"
xlabel = "Uniform Distribution"
ylabel = "Empirical Distribution"
plot(PP[,1],PP[,1], type="l", col="blue3", lwd=3, ylab=ylabel, xlab=xlabel, main=titl, frame=T, axes=F)
axis(1,c(0,0.5,1))
axis(2,c(0,0.5,1))
lines(PP[,1],PP[,2],  col="red3", lwd=3)
PP = XFGpp(MMPL,PL)
sum(PP[,3]) 	# Mean Squared Deviation
titl  = "Conservative Approach"
xlabel = "Uniform Distribution"
ylabel = "Empirical Distribution"
plot(PP[,1],PP[,1], type="l", col="blue3", lwd=3, ylab=ylabel, xlab=xlabel, main=titl, frame=T, axes=F)
axis(1,c(0,0.5,1))
axis(2,c(0,0.5,1))
lines(PP[,1],PP[,2],  col="red3", lwd=3)