// crr.cc // // Simple binomial option pricing model: implementation // (following Cox, Ross, and Rubinstein) // #include #include #include "crr.h" #define MAX(a,b) (((a) > (b)) ? (a) : (b)) crr::crr(double ttm,int npers,double r,double sigma) { nper = npers; tinc = ttm/(double) nper; r1per = 1.0 + r * tinc; disc = 1.0/r1per; up = r1per + sigma * sqrt(tinc); down = r1per - sigma * sqrt(tinc); prup = disc * 0.5; prdn = disc * 0.5;} double crr::eurcall(double S0,double X) { int i,j; // initialize terminal payoffs // i is the number of up moves over the whole life for(i=0;i<=nper;i++) { Sprice = S0*pow(up,(double) i)*pow(down,(double) (nper-i)); val[i] = MAX(Sprice - 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=lower) && (Sprice<=upper)) ? 1.0 : 0.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