1 /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 
3 /*
4  Copyright (C) 2006 Ferdinando Ametrano
5  Copyright (C) 2006 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 #ifndef quantlib_forward_to_coterminal_adapter_hpp
23 #define quantlib_forward_to_coterminal_adapter_hpp
24 
25 #include <ql/models/marketmodels/marketmodel.hpp>
26 
27 namespace QuantLib {
28 
29     class EvolutionDescription;
30 
31     class FwdToCotSwapAdapter : public MarketModel {
32       public:
33         FwdToCotSwapAdapter(
34                           const ext::shared_ptr<MarketModel>& forwardModel);
35         //! \name MarketModel interface
36         //@{
37         const std::vector<Rate>& initialRates() const;
38         const std::vector<Spread>& displacements() const;
39         const EvolutionDescription& evolution() const;
40         Size numberOfRates() const;
41         Size numberOfFactors() const;
42         Size numberOfSteps() const;
43         const Matrix& pseudoRoot(Size i) const;
44         //@}
45       private:
46         ext::shared_ptr<MarketModel> fwdModel_;
47         Size numberOfFactors_, numberOfRates_, numberOfSteps_;
48         std::vector<Rate> initialRates_;
49         std::vector<Matrix> pseudoRoots_;
50     };
51 
52 
53     class FwdToCotSwapAdapterFactory : public MarketModelFactory,
54                                               public Observer {
55       public:
56         FwdToCotSwapAdapterFactory(
57               const ext::shared_ptr<MarketModelFactory>& forwardFactory);
58         ext::shared_ptr<MarketModel> create(const EvolutionDescription&,
59                                               Size numberOfFactors) const;
60         void update();
61       private:
62         ext::shared_ptr<MarketModelFactory> forwardFactory_;
63     };
64 
65 
66     // inline definitions
67 
68     inline const std::vector<Rate>&
initialRates() const69     FwdToCotSwapAdapter::initialRates() const {
70         return initialRates_;
71     }
72 
73     inline const std::vector<Spread>&
displacements() const74     FwdToCotSwapAdapter::displacements() const {
75         return fwdModel_->displacements();
76     }
77 
78     inline const EvolutionDescription&
evolution() const79     FwdToCotSwapAdapter::evolution() const {
80         return fwdModel_->evolution();
81     }
82 
numberOfRates() const83     inline Size FwdToCotSwapAdapter::numberOfRates() const {
84         return fwdModel_->numberOfRates();
85     }
86 
numberOfFactors() const87     inline Size FwdToCotSwapAdapter::numberOfFactors() const {
88         return fwdModel_->numberOfFactors();
89     }
90 
numberOfSteps() const91     inline Size FwdToCotSwapAdapter::numberOfSteps() const {
92         return fwdModel_->numberOfSteps();
93     }
94 
pseudoRoot(Size i) const95     inline const Matrix& FwdToCotSwapAdapter::pseudoRoot(Size i) const {
96         return pseudoRoots_[i];
97     }
98 
99 }
100 
101 #endif
102