// fut.cc // // Binomial futures option pricing model: implementation // #include #include "fut.h" #define MAX(a,b) (((a) > (b)) ? (a) : (b)) fut::fut(double ttm,int npers,double r,double sigma) { nper = npers; tinc = ttm/(double) nper; r1per = exp(r * tinc); disc = 1.0/r1per; disctm = exp(-r * ttm); up = 1.0 + sigma * sqrt(tinc); down = 1.0 - sigma * sqrt(tinc); prcup = 0.5*disc; prcdn = 0.5*disc;} valhedge fut::eurcall(double f0,double X) { int i,j; double futprice; valhedge x1; // initialize terminal payoffs // i is the number of up moves over the whole life for(i=0;i<=nper;i++) { futprice = f0 * pow(up,(double) i) * pow(down,(double) (nper-i)); val[i] = MAX(futprice - X,0);} // compute prices back through the tree // j+1 is the number of periods from the end // i is the number of up moves from the start for(j=0;j