Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

VolatilityAndCorrelation.h

Go to the documentation of this file.
00001 /* WARANTY NOTICE AND COPYRIGHT
00002 This program is free software; you can redistribute it and/or
00003 modify it under the terms of the GNU General Public License
00004 as published by the Free Software Foundation; either version 2
00005 of the License, or (at your option) any later version.
00006 
00007 This program is distributed in the hope that it will be useful,
00008 but WITHOUT ANY WARRANTY; without even the implied warranty of
00009 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00010 GNU General Public License for more details.
00011 
00012 You should have received a copy of the GNU General Public License
00013 along with this program; if not, write to the Free Software
00014 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00015 
00016 Copyright (C) Michael J. Meyer
00017 
00018 matmjm@mindspring.com
00019 spyqqqdia@yahoo.com
00020 
00021 */
00022 
00023 
00024 
00025 
00026 #ifndef martingale_volatilityandcorrelation_h    
00027 #define martingale_volatilityandcorrelation_h
00028 
00029 #include "TypedefsMacros.h"
00030 #include "Matrix.h"
00031 #include <string>
00032 #include <iostream>
00033 
00034 MTGL_BEGIN_NAMESPACE(Martingale)
00035 
00036 
00037 
00047 /*******************************************************************************
00048  *
00049  *                    VOLATILITY SURFACE
00050  *
00051  ******************************************************************************/
00052 
00053 
00054 
00076 class VolSurface {
00077         
00078 protected:
00079         
00082         int volType;
00083         
00084         Real a,b,c,d;           // the parameters
00085 
00086         
00087 public:
00088         
00089                 
00095         static const int M=0, JR=1, CONST=2; 
00096         
00097         
00101         VolSurface
00102         (Real a_, Real b_, Real c_, Real d_, int type) :
00103         volType(type), a(a_), b(b_), c(c_), d(d_)
00104     {    }
00105         
00108         int getType() const { return volType; }
00109         
00110         
00113         static VolSurface* sample(int type);
00114         
00116         static string volSurfaceType(int type);
00117         
00118 
00119         
00122         virtual Real sigma(Real t, Real T) const = 0;
00123 
00124         
00129         virtual Real integral_sgsg(Real t, Real T_1, Real T_2) const = 0;
00130         
00131         
00136         Real integral_sgsg(Real s, Real t, Real T_1, Real T_2) const
00137     {  return integral_sgsg(t,T_1,T_2)-integral_sgsg(s,T_1,T_2); }
00138         
00139         
00140         
00149     void testVolSurfaceIntegrals(int N, Real precision);
00150         
00151         
00152                                         
00155         void setParameters(Real _a, Real _b, Real _c, Real _d)
00156         { a=_a; b=_b; c=_c; d=_d; }
00157         
00159         virtual std::ostream& printSelf(std::ostream& os) const = 0;
00160         
00161         
00164         string volSurfaceType();
00165         
00166 
00167 }; // end VolSurface
00168 
00169 
00170 
00171 
00172 // JAECKEL-REBONATO VOL SURFACE
00173 
00176 class JR_VolSurface : public VolSurface {
00177         
00178 public:
00179         
00180         JR_VolSurface
00181         (Real a, Real b, Real c, Real d) :
00182         VolSurface(a,b,c,d,JR)
00183     {    }
00184 
00185   
00186                 
00187 // VOLATILITIES, CORRELATIONS, COVARIATION INTEGRALS
00188         
00189         
00193    Real sigma(Real t, Real T) const;
00194 
00195   
00198    Real integral_sgsg(Real t, Real T_1, Real T_2) const;
00199    
00200    
00202         std::ostream& printSelf(std::ostream& os) const;
00203         
00205         static VolSurface* sample();
00206 
00207    
00208         
00209 }; // end JR_VolatilitySurface
00210 
00211 
00212 
00213 
00214 // OUR OWN VOL SURFACE
00215 
00219 class M_VolSurface : public VolSurface {
00220         
00221 public:
00222         
00223         M_VolSurface
00224         (Real a, Real b, Real c, Real d) :
00225         VolSurface(a,b,c,d,M)
00226     {    }
00227 
00228   
00229                 
00230 // VOLATILITIES, CORRELATIONS, COVARIATION INTEGRALS
00231         
00232         
00236    Real sigma(Real t, Real T) const { return g(1-t/T); }
00237 
00238   
00241    Real integral_sgsg(Real t, Real T_1, Real T_2) const;
00242    
00243     
00245         std::ostream& printSelf(std::ostream& os) const;
00246         
00248         static VolSurface* sample();
00249 
00250   
00251 private:
00252 
00253 // Exponential Integrals
00254     
00255     // integral of exp(s/D)ds 
00256     Real F(Real D, Real s) const;
00257     
00258     // integral of  s*exp(s/D)ds
00259     Real G(Real D, Real s) const;
00260 
00261     // integral of  s^2*exp(s/D)ds 
00262     Real H(Real D, Real s) const;
00263          
00267     Real g(Real x) const;
00268     
00269                 
00270                 
00271 }; // end M_VolatilitySurface
00272 
00273 
00274 
00275 // CONSTANT VOLATILITY SURFACE
00276 
00277 
00280 class CONST_VolSurface : public VolSurface {
00281         
00282 public:
00283         
00284         CONST_VolSurface(Real a, Real b, Real c, Real d) :
00285         VolSurface(a,b,c,d,CONST)
00286     {    }
00287                 
00288 // VOLATILITIES, CORRELATIONS, COVARIATION INTEGRALS
00289                 
00292    Real sigma(Real t, Real T) const { return 1; }
00293    
00296    Real integral_sgsg(Real t, Real T_1, Real T_2) const { return t; }
00297       
00299    std::ostream& printSelf(std::ostream& os) const;
00300         
00303    static VolSurface* sample(){ return new CONST_VolSurface(0.0,0.0,0.0,0.0); }
00304         
00305 }; // end CONST_VolSurface
00306 
00307 
00308 
00309 
00310 
00311 /*******************************************************************************
00312  *
00313  *                    CORRELATION
00314  *
00315  ******************************************************************************/
00316 
00329 class Correlations {
00330         
00331 protected:
00332         
00334         int n;
00335         
00338         int corrType;
00339         
00340         Real alpha, beta, r_oo;
00341         
00342         UTRRealMatrix correlationMatrix;
00343         
00344 public:
00345         
00347         static const int JR=0, CS=1;
00348         
00350         int getType() const { return corrType; }
00351         
00353         static string correlationType(int type);
00354         
00356         int getDimension() const { return n; }
00357         
00358         
00364         Correlations(int n, Real alpha, Real beta, Real r_oo, int correlationType);
00365         
00366         virtual ~Correlations(){ }
00367         
00368         
00371         static Correlations* sample(int n, int type);
00372         
00373                 
00376         virtual void setCorrelations() = 0;
00377                 
00380         Real& operator()(int i, int j);
00381         
00382         
00385         const UTRRealMatrix& getCorrelationMatrix() const
00386         { return correlationMatrix; }
00387         
00388                                 
00391         void setParameters(Real _alpha, Real _beta, Real _r_oo);
00392         
00395         virtual std::ostream& printSelf(std::ostream& os) const = 0;
00396         
00397         
00400         std::string correlationType();
00401         
00402         
00403 }; // end Correlations
00404 
00405 
00406 
00407 
00408 // JAECKEL-REBONATO CORRELATIONS
00409 
00413 class JR_Correlations : public Correlations {
00414         
00417         RealArray1D T;
00418         
00419 public:
00420         
00424         JR_Correlations(const RealArray1D& T, Real beta);       
00425         virtual ~JR_Correlations(){ }
00426 
00427            
00430     void setCorrelations();
00431         
00432     
00434         std::ostream& printSelf(std::ostream& os) const;
00435         
00440         static Correlations* sample(int n, Real delta=0.25);
00441 
00442 
00443 }; // end JR_Correlations
00444 
00445 
00446 
00447 
00448 
00449 // COFFEE-SHOENMAKERS CORRELATIONS
00450 
00453 class CS_Correlations : public Correlations {
00454 
00455         
00456 public:
00457         
00460         CS_Correlations(int n, Real alpha, Real beta, Real r_oo);
00461         virtual ~CS_Correlations(){ }
00462 
00463            
00466     void setCorrelations();
00467         
00468     
00470         std::ostream& printSelf(std::ostream& os) const;
00471         
00472         
00476         static Correlations* sample(int n);
00477         
00478         
00479 private:
00480         
00481         
00485     Real f(Real x) const;
00486 
00487 
00488 }; // end CS_Correlations
00489 
00490 
00491 
00492 
00493 MTGL_END_NAMESPACE(Martingale)
00494 
00495 #endif

Generated on Mon Sep 22 02:16:32 2003 for Libor-Library by doxygen1.3-rc3