00001 #pragma once
00002 #ifndef rainbowoption_h
00003 #define rainbowoption_h
00004
00005 #include "../common/types.h"
00006 #include "../common/matrix.h"
00007 #include "../common/date.h"
00008 #include "..\PartB\yieldCurve.h"
00009 #include "..\PartE\volsurface.h"
00010 #include <valarray>
00011
00012 #include"../PartA/MonteCarlo1/MersenneTwister.h"
00013 #include"../PartA/MonteCarlo1/GaussianProcess.h"
00014 #include"../PartA/MonteCarlo1/PayOff.h"
00015 #include"../PartA/MonteCarlo1/Random.h"
00016 #include"../PartA/MonteCarlo1/Drift.h"
00017 #include"../PartA/MonteCarlo1/MCEngine.h"
00018 #include"../PartA/MonteCarlo1/PayOff.h"
00019
00020 #include "../PartA/BlackScholes/BlackScholes.h"
00021
00022 #define RO_DEFAULT_STRIKE 100
00023 #define RO_DEFAULT_VOL 0.15
00024 #define RO_DEFAULT_RATE 0.02
00025 #define RO_DEFAULT_MATURITY 1
00026 #define RO_DEFAULT_NB_ASSETS 2
00027 #define RO_DEFAULT_MULTIPLIER 1
00028
00029 #define RO_NPATHS 100000
00030 #define RO_SEED 100000000
00031
00032 #define EPSILON 0.00000001
00033 #define GREEKAPPROX 0.01
00034
00035 using namespace std;
00041 enum priceType {
00042 MonteCarlo,
00043 ClosedForm
00044 };
00045
00046 enum rainbowType {
00047 SpreadOptionMax,
00048 AssetsBasketMax,
00049 BestOf2AssetsCash,
00050 WorstOf2AssetsCash,
00051 BetterOf2Assets,
00052 WorseOf2Assets,
00053 Max2AssetsCall,
00054 Min2AssetsCall,
00055 Max2AssetsPut,
00056 Min2AssetsPut
00057 };
00058
00059 class RainbowOption
00060 {
00061 public:
00069 RainbowOption(void);
00070
00074 RainbowOption(rainbowType type,Date startDate,Real expiry,Real Strike,yieldCurve yc,valarray<volsurface> vols,valarray <Real> spots=valarray<Real>(RO_DEFAULT_STRIKE,RO_DEFAULT_NB_ASSETS),Real Multiplier=RO_DEFAULT_MULTIPLIER,Matrix Correl = IdentityMatrix(RO_DEFAULT_NB_ASSETS),valarray<Real> weights=valarray<Real>(1/(Real)RO_DEFAULT_NB_ASSETS,RO_DEFAULT_NB_ASSETS),bool outputMsgs=false);
00075
00080 RainbowOption(rainbowType type,Date start,Real exp,Real Strike,yieldCurve yc,valarray<volsurface> vols,Real Spot1,Real Spot2,Real Mult=RO_DEFAULT_MULTIPLIER,Real Correl12=0,Real weight1=0.5,Real weight2=0.5,bool outputMsgs=false);
00081 ~RainbowOption(void);
00082
00087 Real getPrice(priceType priceMethod=ClosedForm,LongNatural nPaths=RO_NPATHS);
00088
00090 Real getPartialDelta(Natural security,priceType priceMethod=ClosedForm);
00091
00093 Real getPartialGamma(Natural security,priceType priceMethod=ClosedForm);
00094
00096 Real getPartialVega(Natural security,priceType priceMethod=ClosedForm);
00097
00099 Real getDelta(priceType priceMethod=ClosedForm);
00100
00102 Real getGamma(priceType priceMethod=ClosedForm);
00103
00105 Real getVega(priceType priceMethod=ClosedForm);
00106
00108 Real getCorrelRisk(priceType priceMethod=ClosedForm);
00109
00111 Real getRho(priceType priceMethod=ClosedForm);
00112
00114 Real getTheta(priceType priceMethod=ClosedForm);
00115
00116 rainbowType getRainbowType(){return _type;}
00117 void setRainbowType(rainbowType newType){_type=newType;}
00118
00119 private:
00120
00121 Real PriceByMc_2SpreadOptionMax(LongNatural nPaths=RO_NPATHS);
00122 Real PriceByMc_2AssetsBasketMax(LongNatural nPaths=RO_NPATHS);
00123 Real PriceByMc_BestOf2AssetsCash(LongNatural nPaths=RO_NPATHS);
00124 Real PriceByMc_WorstOf2AssetsCash(LongNatural nPaths=RO_NPATHS);
00125 Real PriceByMc_BetterOf2Assets(LongNatural nPaths=RO_NPATHS);
00126 Real PriceByMc_WorseOf2Assets(LongNatural nPaths=RO_NPATHS);
00127 Real PriceByMc_Max2AssetsCall(LongNatural nPaths=RO_NPATHS);
00128 Real PriceByMc_Min2AssetsCall(LongNatural nPaths=RO_NPATHS);
00129 Real PriceByMc_Max2AssetsPut(LongNatural nPaths=RO_NPATHS);
00130 Real PriceByMc_Min2AssetsPut(LongNatural nPaths=RO_NPATHS);
00131
00132
00133
00134
00135 Real PriceByClosedForm_BestOf2_plusCash();
00136
00137 Real PriceByClosedForm_BetterOf2();
00138 Real PriceByClosedForm_WorseOf2();
00139 Real PriceByClosedForm_MaxOf2_call();
00140 Real PriceByClosedForm_MinOf2_call();
00141 Real PriceByClosedForm_MaxOf2_put();
00142 Real PriceByClosedForm_MinOf2_put();
00143
00144
00145
00146 private:
00147
00148 bool _outputMsgs;
00149
00150
00151 Date _startDate;
00152 Real _expiryInYears;
00153 Natural _NumberOfAssets;
00154 Real _Strike;
00155 valarray <Real> _spots;
00156 Real _Multiplier;
00157 valarray <Real> _weights;
00158 Matrix _CorrelationMatrix;
00159 valarray<Real> _volatilities;
00160 valarray<volsurface> _volatilitiesSurfaces;
00161 yieldCurve _yc;
00162
00163 rainbowType _type;
00164
00165
00166 void reassignVolsAtThemoney();
00167 void reassignVolsAtThestrike();
00168
00169
00170 PayOff _thePayOff;
00171 Real _DFTomaturity;
00172 valarray<Drift> _Drifts;
00173 Random *_pRandom;
00174 MCEngine _MCEngine;
00175 Real _gaussianSample;
00176 valarray<Real> _TerminalPoints;
00177 valarray<GaussianProcess> _pHazardRateProcesses;
00178
00179 void instanciateMCVariables();
00180 LongNatural _seed;
00181
00182
00183 Real sigmaA;
00184 void compute_sigmaA();
00185 Real rho1;
00186 void compute_rho1();
00187 Real rho2;
00188 void compute_rho2();
00189 Real d1;
00190 void compute_d1();
00191 Real d2;
00192 void compute_d2();
00193 Real d3;
00194 void compute_d3();
00195 Real d4;
00196 void compute_d4();
00197 Real A;
00198 void compute_A();
00199 Real B;
00200 void compute_B();
00201 Real C;
00202 void compute_C();
00203
00204 bool haveClosedFormVariablesBeenComputed;
00205 void compute_ClosedFormsParameters();
00206
00207
00208 };
00209 #endif
00210