/*@@@@@@@@@@@@@@@@@@@@@@ DownOut.h @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
 Random Option Pricing
 Summer 2002
 Authors: A. Korobchevsky
          S. Ferrando
 Ryerson University ALL RIGHTS RESERVED
 
 Purpose: Implements the European Down and Out (barrier) option 

 Instance variables:
	   above - flag which is true if the user is above the barier
	       N - number of timesteps
          H - value of barrier
 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/

#ifndef DOWN_OUT_H__
#define DOWN_OUT_H__

struct DownOut : Derivative
{ 
  /*************************** print **********************************
   * Function: print
   * Purpose: Display contents of the European Strike object
   * Param: fp - output file stream
   * Returns: output stream
   ********************************************************************/
  void print(FILE* fp)
  { fprintf(fp, "Derivative: Down Out, barrier = %f, strike = %f, above = %d\n, H, K, above");
  }




  /*********************** DownOut *****************************
   * Function: DownOut
   * Purpose: Constructor
   * Param: Strike value, value of the barrier
   * Returns: N/A
   ********************************************************************/
  DownOut(double K, double H = 99)
  { this->K = K;
    this->H = H;  
  }




  /*********************** init ***************************************
   * Function: init
   * Purpose: Initialises sum_St utility parameter
   * Param: N/A
   * Returns: N/A
   * Note: Empty for path independent derivatives
   ********************************************************************/
  void init()
  { above = true;
  }




  /********************* payOff ****************************************
   * Function: payOff
   * Purpose: Returns the option payoff
   * Param: Final stock price
   * Returns: option payoff
   * Precondiion: Underlying and derivative parameter must be initialized
   * Note: Call only after all timesteps are completed
   ********************************************************************/
  double payOff(double St)
  { return St - K > 0 && above ? St - K : 0;
  }




  /*********************** update *************************************
   * Function: update
   * Purpose: Updates the sum values between timesteps
   * Param: Stock value at any given point
   * Returns: N/A
   * Note: Empty for path independent derivatives
   ********************************************************************/
  void update(double St)
  { if (St < H) above = false; 
    // cout << "H = " << H << ", above = " << above << endl; 
  }




  private:
    double H;
    double K;
    bool above;
};

#endif
