Ralph Vince - Portfolio Mathematics

(Brent) #1

394 THE HANDBOOK OF PORTFOLIO MATHEMATICS


//n things taken q at a time where q>=n
//we really cannot use this as we get OutOfMemoryError
early on
//because we try to save the whole array. Instead, use
nPqi()
protected double[][] nPq(int nopermutations, int q){
double hprpermutation[][]=new
double[nopermutations][q];
for(int column=0;column<q;column++){ // go
through column x column
for(int pn=0;pn<nopermutations;pn++){ // go
through permutation x permutation
if(column==0){
hprpermutation[pn][column] = hpr[pn %
N];
}else{
hprpermutation[pn][column] =
hpr[(pn/(int)(Math.pow((double)N,(double)column))) % N];
}
}
}
return hprpermutation;
}

//n things taken q at a time where q>=n to return the
i’th item
protected double[] nPqi(int q, long pn){
double hprpermutation[]=new double[q];
intx=0;
for(int column=0;column<q;column++){ // go through
column x column
if(column==0){
x = (int)(pn % NL);
}else{
x=
(int)((pn/(long)(Math.pow((double)N,(double)column))) %
NL);
}
hprpermutation[q-1-column] = hpr[x];
}
return hprpermutation;
}

protected void control(){
int counter=1;
Free download pdf