Main Page | Namespace List | Class Hierarchy | Class List | File List | Class Members | File Members

BlackScholes.h

Go to the documentation of this file.
00001 #ifndef BLACKSCHOLES_H
00002 #define BLACKSCHOLES_H
00003 
00004 #include "../../common/types.h"
00005 #include "../../common/Normals.h"
00006 #include <cmath>
00007 
00008 enum TypeOptionBS {
00009                 Call,           //Call type, payoff=(St-K)+
00010                 Put                     //Put type, payoff=(K-St)+
00011 };
00012 
00013 class OptionStrategy;
00014 
00015 class BlackScholes
00016 {
00017 public:
00027         BlackScholes(Real spot, Real volOrPrice, bool isVol, Real r, Real K, Real T,TypeOptionBS typeOption);
00028         BlackScholes();
00029         virtual ~BlackScholes();
00031         inline Real getPrice();
00033         Real getDelta();
00035         Real getGamma();
00037         Real getVega();
00039         Real getTheta();
00041         Real getRho();
00043         Real getVolatility() const;
00045         Real getStrike() const;
00047         Real getRate() const;
00049         Real getSpot() const;
00051         Real getMaturity() const;
00053         bool isCall() const;
00054 
00055 protected:
00057         friend OptionStrategy;
00058     void changeRate(Real newRate);
00059         void changeVol(Real newVol);
00060         void changeMaturity(Real newMat);
00061         void changeSpot(Real newSpot);
00062         void changeStrike(Real newVol);
00063 
00064 private:
00065         void recalcInformation();
00066         Real _spot,_vol,_r,_K,_T;
00067         Real d1,d2;
00068         Real _price;
00069         TypeOptionBS _type;
00070 };
00071 
00072 inline Real BlackScholes::getPrice()
00073 {
00074         switch (_type) {
00075                         case Call:
00076                         default:
00077                                 _price= _spot*CumulativeNormal(d1)-_K*exp(-_r*_T)*CumulativeNormal(d2);
00078                                 break;
00079                         case Put:
00080                                 _price= _K*exp(-_r*_T)*CumulativeNormal(-d2)-_spot*CumulativeNormal(-d1);
00081                                 break;
00082         }
00083         return _price;
00084 }
00085 
00086 #endif

Note: Generated nightly - reload for latest version
Generated on Thu Dec 22 23:12:35 2005 for terreneuve by doxygen 1.3.6