00001 #pragma once
00002 #ifndef binomialtree_h
00003 #define binomialtree_h
00004
00005 #include "../common/types.h"
00006 #include "../PartA/MonteCarlo1/PayOff.h"
00007 #include "../PartB/yieldCurve.h"
00008 #include "../PartC/asset.h"
00009 #include "../common/utils.h"
00010 #include <iostream>
00011 #include <valarray>
00012 using namespace std;
00013
00014 #define BT_DEFAULT_SO 100
00015 #define BT_DEFAULT_RATE 0.05
00016 #define BT_DEFAULT_SIGMA 0.30
00017 #define BT_DEFAULT_MATURITY 1
00018 #define BT_DEFAULT_STEPS 10
00019
00020 class binomialTree {
00021 public:
00022 friend ostream& operator << (ostream &os, const binomialTree& bt);
00023 friend ostream& operator << (ostream &os, const binomialTree* bt) {
00024 return os << *bt;
00025 };
00026
00028 binomialTree(void);
00029
00032 binomialTree(Real So, Real r, Real sigma, Real T, Natural n);
00033 binomialTree(Real So, Real r, Real sigma, Real T, Natural n, Real u, Real d);
00034 binomialTree(const asset& theAsset, yieldCurve& yc, Real T, Natural n);
00035 binomialTree(const binomialTree &rhs);
00036 binomialTree &operator=(const binomialTree &rhs);
00037 virtual ~binomialTree(void);
00038
00039 const valarray<Real>* getStockProcess(Natural step);
00040
00041 const valarray<Real>* getClaimProcess(Natural step);
00042
00043 Real getPrice();
00044
00045 void runEngineConvertibleBond(PayOff thePayoff,
00046 Real ConversionRatio,
00047 Real CallPrice,
00048 Real PutPrice);
00049
00050 void runEngineCall(PayOff thePayoff);
00051
00052
00053
00054
00055 protected:
00056 Real getSo() const {return _So;};
00057 Real getRate(Natural timestep) const {
00058 return (timestep < _n ? _discountFactor[timestep] : 0);
00059 };
00060 Real getSigma() const {return _sigma;};
00061 Real getMaturity() const {return _maturity;};
00062 Natural getSteps() const {return _n;};
00063 void constructStockProcess();
00064 void setClaimVariables(Real constantRate);
00065 void setClaimVariables(yieldCurve& yc);
00066 private:
00067 Real _So;
00068 Real _sigma;
00069 Real _maturity;
00070 Natural _n;
00071 Real _dt;
00072 Real _u;
00073 Real _d;
00074
00075 valarray<valarray <Real> > _stockProcess;
00076
00077 valarray<valarray <Real> > _claimProcess;
00078
00079 valarray<Real> _discountFactor;
00080
00082 valarray<Real> _q;
00083
00084 void
00085 copyObj(const binomialTree &rhs);
00086 };
00087
00088 #endif