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 
7  This file is part of QuantLib, a free-software/open-source library
8  for financial quantitative analysts and developers - http://quantlib.org/
9 
10  QuantLib is free software: you can redistribute it and/or modify it
11  under the terms of the QuantLib license.  You should have received a
12  copy of the license along with this program; if not, please email
13  <quantlib-dev@lists.sf.net>. The license is also available online at
14  <http://quantlib.org/license.shtml>.
15 
16  This program is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18  FOR A PARTICULAR PURPOSE.  See the license for more details.
19 */
20 
21 
22 #ifndef quantlib_lmmcurvestate_hpp
23 #define quantlib_lmmcurvestate_hpp
24 
25 #include <ql/models/marketmodels/curvestate.hpp>
26 
27 namespace QuantLib {
28 
29     //! %Curve state for %Libor market models
30     /*! This class stores the state of the yield curve associated to the
31         fixed calendar times within the simulation.
32         This is the workhorse discounting object associated to the rate times
33         of the simulation. It's important to pass the rates via an object like
34         this to the product rather than directly to make it easier to switch
35         to other engines such as a coterminal swap rate engine.
36         Many products will not need expired rates and others will only require
37         the first rate.
38     */
39     class LMMCurveState : public CurveState {
40     /* There will n+1 rate times expressing payment and reset times
41         of forward rates.
42 
43                 |-----|-----|-----|-----|-----|      (size = 6)
44                 t0    t1    t2    t3    t4    t5     rateTimes
45                 f0    f1    f2    f3    f4           forwardRates
46                 d0    d1    d2    d3    d4    d5     discountBonds
47                 d0/d0 d1/d0 d2/d0 d3/d0 d4/d0 d5/d0  discountRatios
48                 sr0   sr1   sr2   sr3   sr4          cotSwaps
49     */
50       public:
51         explicit LMMCurveState(const std::vector<Time>& rateTimes);
52         //! \name Modifiers
53         //@{
54         void setOnForwardRates(const std::vector<Rate>& fwdRates,
55                                Size firstValidIndex = 0);
56 
57         void setOnDiscountRatios(const std::vector<DiscountFactor>& discRatios,
58                                  Size firstValidIndex = 0);
59         //@}
60 
61         //! \name Inspectors
62         //@{
63         Real discountRatio(Size i,
64                           Size j) const;
65         Rate forwardRate(Size i) const;
66 
67         Rate coterminalSwapRate(Size i) const;
68         Rate coterminalSwapAnnuity(Size numeraire,
69                                    Size i) const;
70 
71         Rate cmSwapRate(Size i,
72                         Size spanningForwards) const;
73         Rate cmSwapAnnuity(Size numeraire,
74                            Size i,
75                            Size spanningForwards) const;
76         const std::vector<Rate>& forwardRates() const;
77         const std::vector<Rate>& coterminalSwapRates() const;
78         const std::vector<Rate>& cmSwapRates(Size spanningForwards) const;
79         //@}
80         #if defined(QL_USE_STD_UNIQUE_PTR)
81         std::unique_ptr<CurveState> clone() const;
82         #else
83         std::auto_ptr<CurveState> clone() const;
84         #endif
85 
86       private:
87         Size first_;
88         std::vector<DiscountFactor> discRatios_;
89         std::vector<Rate> forwardRates_;
90         mutable std::vector<Rate> cmSwapRates_;
91         mutable std::vector<Real> cmSwapAnnuities_;
92         mutable std::vector<Rate> cotSwapRates_;
93         mutable std::vector<Real> cotAnnuities_;
94 
95         mutable Size firstCotAnnuityComped_;
96     };
97 
98 }
99 
100 #endif
101