americanfudge.h

00001 #ifndef stringify_defined
00002 #define stringify_defined
00003 #include <iostream>
00004 #include <sstream>
00005 #include <string>
00006 #include <stdexcept>
00007 
00008 inline std::string stringify(
00009                  const char *funcname,
00010                  const char* _file,
00011                  const char *_error_msg,
00012                  int _line,
00013                  int _erno)
00014 {
00015   std::ostringstream o;
00016   o << _error_msg 
00017     <<  " in function " 
00018     << funcname 
00019     << " at line " 
00020     << _line << 
00021     " of file " 
00022     << _file;
00023 
00024   return o.str();
00025 }
00026 #endif
00027 
00028 #ifndef AMERICANFUDGE_H
00029 #define AMERICANFUDGE_H
00030 
00031 #if defined( WIN32) && !defined(__NT__)
00032 #define __NT__
00033 #endif
00034 
00035 #if defined( __NT__) && !defined(WIN32)
00036 #define WIN32
00037 #endif
00038 
00039 #if defined(ALLSTATIC) && defined(AMERICANFUDGEDLL)
00040 #error ALLSTATIC and AMERICANFUDGEDLL are mutually exclusive
00041 #endif
00042 
00043 #if defined(ALLSTATIC) || defined(AMERICANFUDGESTATIC)
00044 #undef  AMERICANFUDGEPTR
00045 #define AMERICANFUDGEPTR 
00046 #define AMERICANFUDGEFNC
00047 #elif !defined(AMERICANFUDGEPTR)
00048    #ifdef  __NT__
00049       #ifdef AMERICANFUDGEDLL
00050          #define AMERICANFUDGEPTR __declspec(dllexport)
00051          #define AMERICANFUDGEFNC __declspec(dllexport)
00052       #else
00053          #define AMERICANFUDGEPTR __declspec(dllimport)
00054          #define AMERICANFUDGEFNC __declspec(dllimport)
00055       #endif
00056    #else
00057       #define AMERICANFUDGEFNC
00058       #define AMERICANFUDGEPTR
00059    #endif
00060 #endif
00061 
00062 #ifdef __GNUC__
00063   #ifdef  AMERICANFUDGEFNC
00064     #undef AMERICANFUDGEFNC
00065   #endif
00066   #define AMERICANFUDGEFNC
00067 #endif
00068 
00069 #ifdef WIN32
00070 #define STDCALL __stdcall
00071 #else
00072 #define STDCALL
00073 #endif
00074 
00075 #ifdef WIN32
00076 #pragma warning(disable : 4251) //4251=needs to have dll-interface
00077 #endif
00078 
00079 #include "simpleoption.h"
00080 
00081 using namespace std;
00082 
00084 class AMERICANFUDGEPTR american_option_fudge: public european_option_pair {
00085   protected:
00086     //key attributes
00087 
00088     //functional attributes
00089 
00090     //derived attributes
00091       mutable double _call_fudge;
00092       mutable double _d_call_fudge_ds;
00093       mutable double _d_call_fudge_dt;
00094       mutable double _put_fudge;
00095       mutable double _d_put_fudge_ds;
00096       mutable double _d_put_fudge_dt;
00097 
00098     //static data for error handling
00099       static const char *_error_msg;
00100       static int _erno;
00101 
00102   public:
00103     //static functions for getting error messages
00104       static const char *get_error_msg() { return _error_msg;}
00105       static int get_erno() { return _erno;}
00106 virtual const char *get_class_name() { return "american_option_fudge";}
00107 
00108     static int check_attributes(
00109       double S,
00110       double K,
00111       double Tau,
00112       double Alpha,
00113       double R,
00114       double Sigma);
00115 
00116     void set_null() {
00117       european_option_pair::set_null();
00118       _call_fudge = 0;
00119       _d_call_fudge_ds = 0;
00120       _d_call_fudge_dt = 0;
00121       _put_fudge = 0;
00122       _d_put_fudge_ds = 0;
00123       _d_put_fudge_dt = 0;
00124     }
00125 
00126     virtual void init_calc_derived_attributes() const;
00127 
00128     void init( const american_option_fudge& rhs) {
00129       _S = rhs._S;
00130       _K = rhs._K;
00131       _tau = rhs._tau;
00132       _alpha = rhs._alpha;
00133       _r = rhs._r;
00134       _sigma = rhs._sigma;
00135       _C = rhs._C;
00136       _P = rhs._P;
00137       _dC_dS = rhs._dC_dS;
00138       _dP_dS = rhs._dP_dS;
00139       _d2C_dS2 = rhs._d2C_dS2;
00140       _d2P_dS2 = rhs._d2P_dS2;
00141       _dC_dtau = rhs._dC_dtau;
00142       _dP_dtau = rhs._dP_dtau;
00143       _dC_dsigma = rhs._dC_dsigma;
00144       _dP_dsigma = rhs._dP_dsigma;
00145       _calc_call = rhs._calc_call;
00146       _calc_put = rhs._calc_put;
00147       _input_call_price = rhs._input_call_price;
00148       _input_put_price = rhs._input_put_price;
00149       _C_implied_sigma = rhs._C_implied_sigma;
00150       _P_implied_sigma = rhs._P_implied_sigma;
00151       _mu = rhs._mu;
00152       _sqrt_tau = rhs._sqrt_tau;
00153       _sigma_sqrt_tau = rhs._sigma_sqrt_tau;
00154       _log_S_K = rhs._log_S_K;
00155       _Zk = rhs._Zk;
00156       _dZk_dtau = rhs._dZk_dtau;
00157       _h = rhs._h;
00158       _dh_dtau = rhs._dh_dtau;
00159       _N_h = rhs._N_h;
00160       _N_Zk = rhs._N_Zk;
00161       _exp_alpha_r_t = rhs._exp_alpha_r_t;
00162       _exp_r_t = rhs._exp_r_t;
00163       _S_exp_alpha_r_t = rhs._S_exp_alpha_r_t;
00164       _K_exp_r_t = rhs._K_exp_r_t;
00165       _d3C_dS2_dtau = rhs._d3C_dS2_dtau;
00166       _d3P_dS2_dtau = rhs._d3P_dS2_dtau;
00167       _dh_dsigma = rhs._dh_dsigma;
00168       _dZ_dsigma = rhs._dZ_dsigma;
00169       _d2C_dsigma2 = rhs._d2C_dsigma2;
00170       _d2P_dsigma2 = rhs._d2P_dsigma2;
00171       _dC_dtau = rhs._dC_dtau;
00172       _dP_dtau = rhs._dP_dtau;
00173       _d2C_dtau2 = rhs._d2C_dtau2;
00174       _d2P_dtau2 = rhs._d2P_dtau2;
00175       _d2C_dS_dtau = rhs._d2C_dS_dtau;
00176       _d2P_dS_dtau = rhs._d2P_dS_dtau;
00177       _P_h = rhs._P_h;
00178       _call_fudge = rhs._call_fudge;
00179       _d_call_fudge_ds = rhs._d_call_fudge_ds;
00180       _d_call_fudge_dt = rhs._d_call_fudge_dt;
00181       _put_fudge = rhs._put_fudge;
00182       _d_put_fudge_ds = rhs._d_put_fudge_ds;
00183       _d_put_fudge_dt = rhs._d_put_fudge_dt;
00184     }
00185 
00186     american_option_fudge& operator = ( const american_option_fudge& rhs) {
00187         init( rhs);
00188         return *this;
00189     }
00190 
00191     american_option_fudge( const american_option_fudge& rhs) { 
00192         init( rhs);
00193     }
00194 
00195     void init(
00196       double S,
00197       double K,
00198       double Tau,
00199       double Alpha = 0,
00200       double R = 0.05,
00201       double Sigma = 0.2)
00202     {
00203       const char* funcname = "american_option_fudge::init";
00204 
00205       check_attributes(
00206         S,
00207         K,
00208         Tau,
00209         Alpha,
00210         R,
00211         Sigma);
00212 
00213       if (_erno) {
00214         cerr << _error_msg << std::endl;
00215         throw std::domain_error( stringify(
00216           funcname,
00217           __FILE__,
00218           _error_msg,
00219           __LINE__,
00220           _erno   ));
00221       }
00222 
00223       //copy all_key attributes
00224       _S = S;
00225       _K = K;
00226       _tau = Tau;
00227 
00228       //copy all_functional attributes
00229       _alpha = Alpha;
00230       _r = R;
00231       _sigma = Sigma;
00232 
00233       init_calc_derived_attributes();
00234     }
00235 
00236     american_option_fudge(
00237       double S = 0,
00238       double K = 0,
00239       double Tau = 0,
00240       double Alpha = 0,
00241       double R = 0.05,
00242       double Sigma = 0.2)
00243     {
00244       set_null();
00245 
00246       init(
00247         S,
00248         K,
00249         Tau,
00250         Alpha,
00251         R,
00252         Sigma);
00253     }
00254 
00255     void deinit() { set_null();}
00256 
00257     virtual ~american_option_fudge() { deinit();}
00258 
00259     //data access functions
00260 
00261     double get_call_fudge() const { return _call_fudge;}
00262     double get_d_call_fudge_ds() const { return _d_call_fudge_ds;}
00263     double get_d_call_fudge_dt() const { return _d_call_fudge_dt;}
00264     double get_put_fudge() const { return _put_fudge;}
00265     double get_d_put_fudge_ds() const { return _d_put_fudge_ds;}
00266     double get_d_put_fudge_dt() const { return _d_put_fudge_dt;}
00267 
00268     void init_simple_attributes( const american_option_fudge& rhs) {
00269        _call_fudge = rhs._call_fudge;
00270        _d_call_fudge_ds = rhs._d_call_fudge_ds;
00271        _d_call_fudge_dt = rhs._d_call_fudge_dt;
00272        _put_fudge = rhs._put_fudge;
00273        _d_put_fudge_ds = rhs._d_put_fudge_ds;
00274        _d_put_fudge_dt = rhs._d_put_fudge_dt;
00275     }
00276 
00277     virtual double call_intrinsic_value() const;
00278     virtual double put_intrinsic_value() const;
00279     friend AMERICANFUDGEFNC ostream& STDCALL operator << (ostream& os, const american_option_fudge& rhs);
00280 };
00281 
00282 
00283 #endif

Generated on Fri Jan 7 12:36:18 2011 for public_options by  doxygen 1.5.1