1 /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 
3 /*
4  Copyright (C) 2006, 2007 Ferdinando Ametrano
5  Copyright (C) 2006, 2007 Mark Joshi
6  Copyright (C) 2007 StatPro Italia srl
7 
8  This file is part of QuantLib, a free-software/open-source library
9  for financial quantitative analysts and developers - http://quantlib.org/
10 
11  QuantLib is free software: you can redistribute it and/or modify it
12  under the terms of the QuantLib license.  You should have received a
13  copy of the license along with this program; if not, please email
14  <quantlib-dev@lists.sf.net>. The license is also available online at
15  <http://quantlib.org/license.shtml>.
16 
17  This program is distributed in the hope that it will be useful, but WITHOUT
18  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19  FOR A PARTICULAR PURPOSE.  See the license for more details.
20 */
21 
22 
23 #ifndef quantlib_marketmodel_hpp
24 #define quantlib_marketmodel_hpp
25 
26 #include <ql/math/matrix.hpp>
27 #include <ql/utilities/null.hpp>
28 #include <ql/patterns/observable.hpp>
29 #include <vector>
30 
31 namespace QuantLib {
32 
33     class EvolutionDescription;
34 
35     //! base class for market models
36     /*! For each time step, generates the pseudo-square root of the covariance
37         matrix for that time step.
38     */
39     class MarketModel {
40       public:
~MarketModel()41         virtual ~MarketModel() {}
42         virtual const std::vector<Rate>& initialRates() const = 0;
43         virtual const std::vector<Spread>& displacements() const = 0;
44         virtual const EvolutionDescription& evolution() const = 0;
45         virtual Size numberOfRates() const = 0;
46         virtual Size numberOfFactors() const = 0;
47         virtual Size numberOfSteps() const = 0;
48         virtual const Matrix& pseudoRoot(Size i) const = 0;
49         virtual const Matrix& covariance(Size i) const;
50         virtual const Matrix& totalCovariance(Size endIndex) const;
51         std::vector<Volatility> timeDependentVolatility(Size i) const;
52     private:
53         mutable std::vector<Matrix> covariance_, totalCovariance_;
54     };
55 
56     //! base class for market-model factories
57     class MarketModelFactory : public Observable {
58       public:
~MarketModelFactory()59         virtual ~MarketModelFactory() {}
60         virtual ext::shared_ptr<MarketModel> create(
61                                               const EvolutionDescription&,
62                                               Size numberOfFactors) const = 0;
63     };
64 
65 
66 }
67 
68 #endif
69