1 /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 3 /* 4 Copyright (C) 2007 Chris Kenyon 5 Copyright (C) 2007, 2008 StatPro Italia srl 6 Copyright (C) 2011 Ferdinando Ametrano 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 /*! \file piecewisezeroinflationcurve.hpp 23 \brief Piecewise zero-inflation term structure 24 */ 25 26 #ifndef quantlib_piecewise_zero_inflation_curve_hpp 27 #define quantlib_piecewise_zero_inflation_curve_hpp 28 29 #include <ql/termstructures/iterativebootstrap.hpp> 30 #include <ql/termstructures/inflation/inflationtraits.hpp> 31 #include <ql/patterns/lazyobject.hpp> 32 33 namespace QuantLib { 34 35 //! Piecewise zero-inflation term structure 36 template <class Interpolator, 37 template <class> class Bootstrap = IterativeBootstrap, 38 class Traits = ZeroInflationTraits> 39 class PiecewiseZeroInflationCurve 40 : public InterpolatedZeroInflationCurve<Interpolator>, 41 public LazyObject { 42 private: 43 typedef InterpolatedZeroInflationCurve<Interpolator> base_curve; 44 typedef PiecewiseZeroInflationCurve<Interpolator,Bootstrap,Traits> 45 this_curve; 46 public: 47 typedef Traits traits_type; 48 typedef Interpolator interpolator_type; 49 50 //! \name Constructors 51 //@{ PiecewiseZeroInflationCurve(const Date & referenceDate,const Calendar & calendar,const DayCounter & dayCounter,const Period & lag,Frequency frequency,bool indexIsInterpolated,Rate baseZeroRate,const std::vector<ext::shared_ptr<typename Traits::helper>> & instruments,Real accuracy=1.0e-12,const Interpolator & i=Interpolator ())52 PiecewiseZeroInflationCurve( 53 const Date& referenceDate, 54 const Calendar& calendar, 55 const DayCounter& dayCounter, 56 const Period& lag, 57 Frequency frequency, 58 bool indexIsInterpolated, 59 Rate baseZeroRate, 60 const std::vector<ext::shared_ptr<typename Traits::helper> >& 61 instruments, 62 Real accuracy = 1.0e-12, 63 const Interpolator& i = Interpolator()) 64 : base_curve(referenceDate, calendar, dayCounter, 65 lag, frequency, indexIsInterpolated, baseZeroRate, i), 66 instruments_(instruments), accuracy_(accuracy) { 67 bootstrap_.setup(this); 68 } 69 70 /*! \deprecated Use the constructor not taking a yield 71 term structure. 72 Deprecated in version 1.19. 73 */ 74 QL_DEPRECATED PiecewiseZeroInflationCurve(const Date & referenceDate,const Calendar & calendar,const DayCounter & dayCounter,const Period & lag,Frequency frequency,bool indexIsInterpolated,Rate baseZeroRate,const Handle<YieldTermStructure> & nominalTS,const std::vector<ext::shared_ptr<typename Traits::helper>> & instruments,Real accuracy=1.0e-12,const Interpolator & i=Interpolator ())75 PiecewiseZeroInflationCurve( 76 const Date& referenceDate, 77 const Calendar& calendar, 78 const DayCounter& dayCounter, 79 const Period& lag, 80 Frequency frequency, 81 bool indexIsInterpolated, 82 Rate baseZeroRate, 83 const Handle<YieldTermStructure>& nominalTS, 84 const std::vector<ext::shared_ptr<typename Traits::helper> >& 85 instruments, 86 Real accuracy = 1.0e-12, 87 const Interpolator& i = Interpolator()) 88 : base_curve(referenceDate, calendar, dayCounter, 89 lag, frequency, indexIsInterpolated, baseZeroRate, 90 nominalTS, i), 91 instruments_(instruments), accuracy_(accuracy) { 92 bootstrap_.setup(this); 93 } 94 //@} 95 96 //! \name Inflation interface 97 //@{ 98 Date baseDate() const; 99 Date maxDate() const; 100 //@ 101 //! \name Inspectors 102 //@{ 103 const std::vector<Time>& times() const; 104 const std::vector<Date>& dates() const; 105 const std::vector<Real>& data() const; 106 std::vector<std::pair<Date, Real> > nodes() const; 107 //@} 108 //! \name Observer interface 109 //@{ 110 void update(); 111 //@} 112 private: 113 // methods 114 void performCalculations() const; 115 // data members 116 std::vector<ext::shared_ptr<typename Traits::helper> > instruments_; 117 Real accuracy_; 118 119 friend class Bootstrap<this_curve>; 120 friend class BootstrapError<this_curve>; 121 Bootstrap<this_curve> bootstrap_; 122 }; 123 124 125 // inline and template definitions 126 127 template <class I, template <class> class B, class T> baseDate() const128 inline Date PiecewiseZeroInflationCurve<I,B,T>::baseDate() const { 129 this->calculate(); 130 return base_curve::baseDate(); 131 } 132 133 template <class I, template <class> class B, class T> maxDate() const134 inline Date PiecewiseZeroInflationCurve<I,B,T>::maxDate() const { 135 this->calculate(); 136 return base_curve::maxDate(); 137 } 138 139 template <class I, template <class> class B, class T> times() const140 const std::vector<Time>& PiecewiseZeroInflationCurve<I,B,T>::times() const { 141 calculate(); 142 return base_curve::times(); 143 } 144 145 template <class I, template <class> class B, class T> dates() const146 const std::vector<Date>& PiecewiseZeroInflationCurve<I,B,T>::dates() const { 147 calculate(); 148 return base_curve::dates(); 149 } 150 151 template <class I, template <class> class B, class T> data() const152 const std::vector<Real>& PiecewiseZeroInflationCurve<I,B,T>::data() const { 153 calculate(); 154 return base_curve::rates(); 155 } 156 157 template <class I, template <class> class B, class T> 158 std::vector<std::pair<Date, Real> > nodes() const159 PiecewiseZeroInflationCurve<I,B,T>::nodes() const { 160 calculate(); 161 return base_curve::nodes(); 162 } 163 164 template <class I, template <class> class B, class T> performCalculations() const165 void PiecewiseZeroInflationCurve<I,B,T>::performCalculations() const { 166 bootstrap_.calculate(); 167 } 168 169 template <class I, template<class> class B, class T> update()170 void PiecewiseZeroInflationCurve<I,B,T>::update() { 171 base_curve::update(); 172 LazyObject::update(); 173 } 174 175 } 176 177 #endif 178