- Joined
- 9/23/10
- Messages
- 1
- Points
- 11
I am currently programming up a binomial tree to price both euro and american options. I am stuck and cannot figure out how to alter the european code to allow for early exercise of the option. I've looked at many other examples and tried many things and can't get it to work. Here's my european put code, any help would be awesome I've been stuck for hours.
if (indicator1 == 'd')
{
if (indicator2 == 'a')
{
nper = npers;
tinc = ttm/nper;
sqrtt = sqrt(tinc);
up = exp(sigma*sqrtt);
down = exp(-sigma*sqrtt);
R = exp(r*tinc);
prup = (R-down)/(up-down);
prdn = 1-prup;
int i,j;
for(i=0;i<=nper;i++)
{
Sprice = S0*pow(up,(double) i)*pow(down,(double) (nper-i));
val = MAX(X-Sprice,0);
}
for(j=0;j<nper;j++)><nper;i++)
{
for(i=0;i<nper-j;i++) <nper-j;i++)>
{
val = (prdn * val + prup * val[i+1])/R;
}
}
return(val[0]);
}</nper-j;i++)></nper;j++)>
if (indicator1 == 'd')
{
if (indicator2 == 'a')
{
nper = npers;
tinc = ttm/nper;
sqrtt = sqrt(tinc);
up = exp(sigma*sqrtt);
down = exp(-sigma*sqrtt);
R = exp(r*tinc);
prup = (R-down)/(up-down);
prdn = 1-prup;
int i,j;
for(i=0;i<=nper;i++)
{
Sprice = S0*pow(up,(double) i)*pow(down,(double) (nper-i));
val = MAX(X-Sprice,0);
}
for(j=0;j<nper;j++)><nper;i++)
{
for(i=0;i<nper-j;i++) <nper-j;i++)>
{
val = (prdn * val + prup * val[i+1])/R;
}
}
return(val[0]);
}</nper-j;i++)></nper;j++)>