#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <limits.h>
#include "option.h"
extern clock_t clock();
/* Computes European/American-style call/put options for a
 * multiplicative binomial tree valuation *
 * 
 */

int main(int argc, char **argv)
{
 double K, S,r,u,d;
 int    T,N;
 double result;
 double rst, rc;
 double t1,t2;
 double An,Adt,Ap,Adiscount;

 if (argc !=2 ) {
  fprintf(stderr,"%s horizon datafile-from-stdinput\n",argv[0]);
  return(1);
 }
 scanf("%lf",&K);
 scanf("%d",&T);
 scanf("%lf",&S);
 scanf("%lf",&r);
 scanf("%d",&N);
 scanf("%lf",&u);
 scanf("%lf",&d);
 N= atoi(argv[1]);

 
 An=(double)N; Adt= (double)T/ (double) N;
 Ap=(exp(r *Adt) -d)/ (u-d); Adiscount = exp(-r*Adt);
 fprintf(stdout, "K=%6.3f T=%6.3d S=%6.3f r=%6.3f N=%6.3d, u=%6.3f d=%6.3f dt=%6.3f p=%6.3f discount=%f\n", K,T,S,r,N,u,d,Adt,Ap,Adiscount); 
 fflush(stdout);

 t1=clock();
 result=option(K,T,S,r,N,u,d,&rst,&rc,EUROPEANCALL);
/*
*/
 t2=clock();
 fprintf(stdout,"EuropeanCallOption = %8.4f  (S= %f)  (Time = %f)\n",rc,rst,(t2-t1)/((double)CLOCKS_PER_SEC));
 fflush(stdout);

 t1=clock();
 result=option(K,T,S,r,N,u,d,&rst,&rc,EUROPEANPUT);
/*
*/
 t2=clock();
 fprintf(stdout,"EuropeanPutOption  = %8.4f  (S= %f)  (Time = %f)\n",rc,rst,(t2-t1)/((double)CLOCKS_PER_SEC));
 fflush(stdout);

 t1=clock();
 result=option(K,T,S,r,N,u,d,&rst,&rc,AMERICANCALL);
/*
*/
 t2=clock();
 fprintf(stdout,"AmericanCallOption = %8.4f  (S= %f)  (Time = %f)\n",rc,rst,(t2-t1)/((double)CLOCKS_PER_SEC));
 fflush(stdout);

 t1=clock();
 result=option(K,T,S,r,N,u,d,&rst,&rc,AMERICANPUT);
/*
*/
 t2=clock();
 fprintf(stdout,"AmericanPutOption  = %8.4f  (S= %f)  (Time = %f)\n",rc,rst,(t2-t1)/(
(double)CLOCKS_PER_SEC));
 fflush(stdout);


}
