Why not under a dedicated folder /instruments/inflation/ ?
M. > -----Original Message----- > From: [hidden email] > [mailto:[hidden email]] On Behalf > Of [hidden email] > Sent: 31 October 2007 17:09 > To: [hidden email] > Subject: [QuantLib-svn] SF.net SVN: quantlib: > [13271]trunk/QuantLib/ql/instruments > > > Revision: 13271 > > http://quantlib.svn.sourceforge.net/quantlib/?rev=13271&view=rev > Author: lballabio > Date: 2007-10-31 09:09:04 -0700 (Wed, 31 Oct 2007) > > Log Message: > ----------- > Added inflation swaps (thanks to Chris Kenyon) > > Modified Paths: > -------------- > trunk/QuantLib/ql/instruments/Makefile.am > trunk/QuantLib/ql/instruments/all.hpp > > Added Paths: > ----------- > trunk/QuantLib/ql/instruments/inflationswap.cpp > trunk/QuantLib/ql/instruments/inflationswap.hpp > trunk/QuantLib/ql/instruments/yyiis.cpp > trunk/QuantLib/ql/instruments/yyiis.hpp > trunk/QuantLib/ql/instruments/zciis.cpp > trunk/QuantLib/ql/instruments/zciis.hpp > > Modified: trunk/QuantLib/ql/instruments/Makefile.am > =================================================================== > --- trunk/QuantLib/ql/instruments/Makefile.am 2007-10-31 > 15:09:00 UTC (rev 13270) > +++ trunk/QuantLib/ql/instruments/Makefile.am 2007-10-31 > 16:09:04 UTC (rev 13271) > @@ -23,6 +23,7 @@ > forward.hpp \ > forwardrateagreement.hpp \ > forwardvanillaoption.hpp \ > + inflationswap.hpp \ > lookbackoption.hpp \ > makecapfloor.hpp \ > makecms.hpp \ > @@ -40,7 +41,9 @@ > swaption.hpp \ > vanillaoption.hpp \ > vanillaswap.hpp \ > - varianceswap.hpp > + varianceswap.hpp \ > + yyiis.hpp \ > + zciis.hpp > > libInstruments_la_SOURCES = \ > asianoption.cpp \ > @@ -57,6 +60,7 @@ > forward.cpp \ > forwardrateagreement.cpp \ > forwardvanillaoption.cpp \ > + inflationswap.cpp \ > lookbackoption.cpp \ > makecapfloor.cpp \ > makecms.cpp \ > @@ -74,7 +78,9 @@ > swaption.cpp \ > vanillaoption.cpp \ > vanillaswap.cpp \ > - varianceswap.cpp > + varianceswap.cpp \ > + yyiis.cpp \ > + zciis.cpp > > libInstruments_la_LIBADD = \ > bonds/libBonds.la > > Modified: trunk/QuantLib/ql/instruments/all.hpp > =================================================================== > --- trunk/QuantLib/ql/instruments/all.hpp 2007-10-31 > 15:09:00 UTC (rev 13270) > +++ trunk/QuantLib/ql/instruments/all.hpp 2007-10-31 > 16:09:04 UTC (rev 13271) > @@ -18,6 +18,7 @@ > #include <ql/instruments/forward.hpp> > #include <ql/instruments/forwardrateagreement.hpp> > #include <ql/instruments/forwardvanillaoption.hpp> > +#include <ql/instruments/inflationswap.hpp> > #include <ql/instruments/lookbackoption.hpp> > #include <ql/instruments/makecapfloor.hpp> > #include <ql/instruments/makecms.hpp> > @@ -36,5 +37,7 @@ > #include <ql/instruments/vanillaoption.hpp> > #include <ql/instruments/vanillaswap.hpp> > #include <ql/instruments/varianceswap.hpp> > +#include <ql/instruments/yyiis.hpp> > +#include <ql/instruments/zciis.hpp> > > #include <ql/instruments/bonds/all.hpp> > > Added: trunk/QuantLib/ql/instruments/inflationswap.cpp > =================================================================== > --- trunk/QuantLib/ql/instruments/inflationswap.cpp > (rev 0) > +++ trunk/QuantLib/ql/instruments/inflationswap.cpp > 2007-10-31 16:09:04 UTC (rev 13271) > @@ -0,0 +1,67 @@ > +/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; > c-basic-offset: 4 -*- */ > + > +/* > + Copyright (C) 2007 Chris Kenyon > + > + This file is part of QuantLib, a free-software/open-source library > + for financial quantitative analysts and developers - > http://quantlib.org/ > + > + QuantLib is free software: you can redistribute it and/or modify it > + under the terms of the QuantLib license. You should have received a > + copy of the license along with this program; if not, please email > + <[hidden email]>. The license is also available online at > + <http://quantlib.org/license.shtml>. > + > + This program is distributed in the hope that it will be > useful, but WITHOUT > + ANY WARRANTY; without even the implied warranty of > MERCHANTABILITY or FITNESS > + FOR A PARTICULAR PURPOSE. See the license for more details. > +*/ > + > +#include <ql/instruments/inflationswap.hpp> > + > +namespace QuantLib { > + > + InflationSwap::InflationSwap(const Date& start, const > Date& maturity, > + const Period& lag, const > Calendar& calendar, > + BusinessDayConvention convention, > + const DayCounter& dayCounter, > + const > Handle<YieldTermStructure>& yieldTS) > + : start_(start), maturity_(maturity), lag_(lag), > calendar_(calendar), > + bdc_(convention), dayCounter_(dayCounter), yieldTS_(yieldTS) { > + > + baseDate_ = calendar_.adjust(start_ - lag_, bdc_); > + maturity_ = calendar_.adjust(maturity_, bdc_); > + > + registerWith(yieldTS_); > + } > + > + Date InflationSwap::baseDate() const { > + return baseDate_; > + } > + > + Period InflationSwap::lag() const { > + return lag_; > + } > + > + Date InflationSwap::startDate() const { > + return start_; > + } > + > + Date InflationSwap::maturityDate() const { > + return maturity_; > + } > + > + Calendar InflationSwap::calendar() const { > + return calendar_; > + } > + > + BusinessDayConvention > InflationSwap::businessDayConvention() const { > + return bdc_; > + } > + > + DayCounter InflationSwap::dayCounter() const { > + return dayCounter_; > + } > + > +} > + > > > Property changes on: trunk/QuantLib/ql/instruments/inflationswap.cpp > ___________________________________________________________________ > Name: svn:eol-style > + native > > Added: trunk/QuantLib/ql/instruments/inflationswap.hpp > =================================================================== > --- trunk/QuantLib/ql/instruments/inflationswap.hpp > (rev 0) > +++ trunk/QuantLib/ql/instruments/inflationswap.hpp > 2007-10-31 16:09:04 UTC (rev 13271) > @@ -0,0 +1,75 @@ > +/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; > c-basic-offset: 4 -*- */ > + > +/* > + Copyright (C) 2007 Chris Kenyon > + > + This file is part of QuantLib, a free-software/open-source library > + for financial quantitative analysts and developers - > http://quantlib.org/ > + > + QuantLib is free software: you can redistribute it and/or modify it > + under the terms of the QuantLib license. You should have received a > + copy of the license along with this program; if not, please email > + <[hidden email]>. The license is also available online at > + <http://quantlib.org/license.shtml>. > + > + This program is distributed in the hope that it will be > useful, but WITHOUT > + ANY WARRANTY; without even the implied warranty of > MERCHANTABILITY or FITNESS > + FOR A PARTICULAR PURPOSE. See the license for more details. > +*/ > + > +/*! \file inflationswap.hpp > + \brief Abstract base class for inflation swaps > +*/ > + > +#ifndef quantlib_inflation_swap_hpp > +#define quantlib_inflation_swap_hpp > + > +#include <ql/instrument.hpp> > +#include <ql/termstructures/inflationtermstructure.hpp> > + > +namespace QuantLib { > + > + //! Abstract base class for inflation swaps. > + /*! Inflation swaps need two term structures: > + - nominal > + - inflation (either zero-coupon or year-on-year) > + > + \ingroup instruments > + */ > + class InflationSwap : public Instrument { > + public: > + //! the constructor sets common data members > + InflationSwap(const Date& start, const Date& maturity, > + const Period& lag, const Calendar& calendar, > + BusinessDayConvention convention, > + const DayCounter& dayCounter, > + const Handle<YieldTermStructure>& yieldTS); > + //! \name Inspectors > + /*! The inflation rate is taken relative to the base date, > + which is a lag period before the start date of the swap. > + */ > + //@{ > + Date baseDate() const; > + Period lag() const; > + Date startDate() const; > + Date maturityDate() const; > + Calendar calendar() const; > + BusinessDayConvention businessDayConvention() const; > + DayCounter dayCounter() const; > + //@} > + virtual Rate fairRate() const = 0; > + protected: > + Date start_; > + Date maturity_; > + Period lag_; > + Calendar calendar_; > + BusinessDayConvention bdc_; > + DayCounter dayCounter_; > + Handle<YieldTermStructure> yieldTS_; > + Date baseDate_; > + }; > + > +} > + > + > +#endif > > > Property changes on: trunk/QuantLib/ql/instruments/inflationswap.hpp > ___________________________________________________________________ > Name: svn:eol-style > + native > > Added: trunk/QuantLib/ql/instruments/yyiis.cpp > =================================================================== > --- trunk/QuantLib/ql/instruments/yyiis.cpp > (rev 0) > +++ trunk/QuantLib/ql/instruments/yyiis.cpp 2007-10-31 > 16:09:04 UTC (rev 13271) > @@ -0,0 +1,133 @@ > +/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; > c-basic-offset: 4 -*- */ > + > +/* > + Copyright (C) 2007 Chris Kenyon > + > + This file is part of QuantLib, a free-software/open-source library > + for financial quantitative analysts and developers - > http://quantlib.org/ > + > + QuantLib is free software: you can redistribute it and/or modify it > + under the terms of the QuantLib license. You should have received a > + copy of the license along with this program; if not, please email > + <[hidden email]>. The license is also available online at > + <http://quantlib.org/license.shtml>. > + > + This program is distributed in the hope that it will be > useful, but WITHOUT > + ANY WARRANTY; without even the implied warranty of > MERCHANTABILITY or FITNESS > + FOR A PARTICULAR PURPOSE. See the license for more details. > +*/ > + > +#include <ql/instruments/yyiis.hpp> > +#include <ql/time/schedule.hpp> > + > +namespace QuantLib { > + > + > + YearOnYearInflationSwap::YearOnYearInflationSwap( > + const Date& start, > + const Date& maturity, > + const Period& lag, > + Rate fixedRate, > + const Calendar& calendar, > + BusinessDayConvention convention, > + const DayCounter& dayCounter, > + const Handle<YieldTermStructure>& yieldTS, > + const Handle<YoYInflationTermStructure>& > inflationTS, > + bool allowAmbiguousPayments, > + const Period& ambiguousPaymentPeriod) > + : InflationSwap(start, maturity, lag, calendar, convention, > + dayCounter, yieldTS), > + fixedRate_(fixedRate), inflationTS_(inflationTS), > + allowAmbiguousPayments_(allowAmbiguousPayments), > + ambiguousPaymentPeriod_(ambiguousPaymentPeriod) { > + > + Schedule temp = MakeSchedule(start_, maturity_, > + Period(1,Years), > + calendar_, bdc_); > + paymentDates_.clear(); > + paymentDates_.reserve(temp.size()-1); > + > + // the first payment date is the _second_ date in > the schedule, > + // so we start from index 1 > + for (Size i=1; i<temp.size(); ++i) { > + if (!allowAmbiguousPayments_) { > + if (temp[i] > start_ + ambiguousPaymentPeriod_) { > + paymentDates_.push_back(temp[i]); > + } > + } else { > + paymentDates_.push_back(temp[i]); > + } > + } > + > + QL_REQUIRE(!paymentDates_.empty(), > + " no payments dates, start " << start_ > + << ", maturity: " << maturity_); > + } > + > + > + bool YearOnYearInflationSwap::isExpired() const { > + return yieldTS_->referenceDate() > maturity_; > + } > + > + > + Rate YearOnYearInflationSwap::fairRate() const { > + calculate(); > + return fairRate_; > + } > + > + > + Rate YearOnYearInflationSwap::fixedRate() const { > + return fixedRate_; > + } > + > + > + std::vector<Date> YearOnYearInflationSwap::paymentDates() const { > + return paymentDates_; > + } > + > + > + void YearOnYearInflationSwap::setupExpired() const { > + Instrument::setupExpired(); > + fairRate_ = Null<Rate>(); > + } > + > + > + void YearOnYearInflationSwap::performCalculations() const { > + // Rates for instruments always look at earlier > values paid later. > + Real nom = 0.0; > + Real inf1 = 0.0; > + Real inf2 = 0.0; > + Real frac; > + > + Date referenceDate = yieldTS_->referenceDate(); > + for (Size i=0; i<paymentDates_.size(); i++) { > + Date couponPayDate = paymentDates_[i]; > + if (couponPayDate >= referenceDate) { > + if (i==0) { > + frac = dayCounter_.yearFraction(referenceDate, > + couponPayDate); > + } else { > + if (referenceDate > paymentDates_[i-1]) > + frac = > dayCounter_.yearFraction(referenceDate, > + > couponPayDate); > + else > + frac = > dayCounter_.yearFraction(paymentDates_[i-1], > + > couponPayDate); > + } > + > + nom += frac * yieldTS_->discount(couponPayDate); > + inf1 += frac * inflationTS_->yoyRate( > + calendar().adjust(couponPayDate > - lag(), bdc_)); > + inf2 += frac * inflationTS_->yoyRate( > + calendar().adjust(couponPayDate > - lag(), bdc_)) * > + yieldTS_->discount(couponPayDate); > + } > + } > + > + NPV_ = nom*fixedRate_ - inf1; > + errorEstimate_ = 0.0; > + fairRate_ = inf2/nom; > + } > + > +} > + > > > Property changes on: trunk/QuantLib/ql/instruments/yyiis.cpp > ___________________________________________________________________ > Name: svn:eol-style > + native > > Added: trunk/QuantLib/ql/instruments/yyiis.hpp > =================================================================== > --- trunk/QuantLib/ql/instruments/yyiis.hpp > (rev 0) > +++ trunk/QuantLib/ql/instruments/yyiis.hpp 2007-10-31 > 16:09:04 UTC (rev 13271) > @@ -0,0 +1,90 @@ > +/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; > c-basic-offset: 4 -*- */ > + > +/* > + Copyright (C) 2007 Chris Kenyon > + > + This file is part of QuantLib, a free-software/open-source library > + for financial quantitative analysts and developers - > http://quantlib.org/ > + > + QuantLib is free software: you can redistribute it and/or modify it > + under the terms of the QuantLib license. You should have received a > + copy of the license along with this program; if not, please email > + <[hidden email]>. The license is also available online at > + <http://quantlib.org/license.shtml>. > + > + This program is distributed in the hope that it will be > useful, but WITHOUT > + ANY WARRANTY; without even the implied warranty of > MERCHANTABILITY or FITNESS > + FOR A PARTICULAR PURPOSE. See the license for more details. > +*/ > + > +/*! \file yyiis.hpp > + \brief Year-on-year inflation-indexed swap > +*/ > + > +#ifndef quantlib_yyiis_hpp > +#define quantlib_yyiis_hpp > + > +#include <ql/instruments/inflationswap.hpp> > + > +namespace QuantLib { > + > + //! Year-on-year inflation-indexed swap > + /*! \note The allowAmbiguousPayments parameter is to allow for > + payment arithmetic being ambiguous. If the maturity is > + in, say, 30.01 years according to the daycounter and > + roll rules does this mean that there is a payment in > + 0.01 years?. > + */ > + class YearOnYearInflationSwap : public InflationSwap { > + public: > + YearOnYearInflationSwap( > + const Date& start, > + const Date& maturity, > + const Period& lag, > + Rate fixedRate, > + const Calendar& calendar, > + BusinessDayConvention convention, > + const DayCounter& dayCounter, > + const Handle<YieldTermStructure>& yieldTS, > + const Handle<YoYInflationTermStructure>& > inflationTS, > + bool allowAmbiguousPayments = false, > + const Period& ambiguousPaymentPeriod = > Period(1, Months)); > + > + //! \name Instrument interface > + //@{ > + bool isExpired() const; > + //@} > + > + //! \name InflationSwap interface > + //@{ > + Rate fairRate() const; > + //@} > + > + //! \name Inspectors > + //@{ > + Rate fixedRate() const; > + std::vector<Date> paymentDates() const; > + //@} > + > + protected: > + //! \name Instrument interface > + //@{ > + void setupExpired() const; > + void performCalculations() const; > + //@} > + > + Rate fixedRate_; > + Handle<YoYInflationTermStructure> inflationTS_; > + > + bool allowAmbiguousPayments_; > + Period ambiguousPaymentPeriod_; > + std::vector<Date> paymentDates_; > + > + mutable Rate fairRate_; > + }; > + > +} > + > + > +#endif > + > > > Property changes on: trunk/QuantLib/ql/instruments/yyiis.hpp > ___________________________________________________________________ > Name: svn:eol-style > + native > > Added: trunk/QuantLib/ql/instruments/zciis.cpp > =================================================================== > --- trunk/QuantLib/ql/instruments/zciis.cpp > (rev 0) > +++ trunk/QuantLib/ql/instruments/zciis.cpp 2007-10-31 > 16:09:04 UTC (rev 13271) > @@ -0,0 +1,68 @@ > +/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; > c-basic-offset: 4 -*- */ > + > +/* > + Copyright (C) 2007 Chris Kenyon > + > + This file is part of QuantLib, a free-software/open-source library > + for financial quantitative analysts and developers - > http://quantlib.org/ > + > + QuantLib is free software: you can redistribute it and/or modify it > + under the terms of the QuantLib license. You should have received a > + copy of the license along with this program; if not, please email > + <[hidden email]>. The license is also available online at > + <http://quantlib.org/license.shtml>. > + > + This program is distributed in the hope that it will be > useful, but WITHOUT > + ANY WARRANTY; without even the implied warranty of > MERCHANTABILITY or FITNESS > + FOR A PARTICULAR PURPOSE. See the license for more details. > +*/ > + > +#include <ql/instruments/zciis.hpp> > + > +namespace QuantLib { > + > + ZeroCouponInflationSwap::ZeroCouponInflationSwap( > + const Date& start, > + const Date& maturity, > + const Period &lag, > + Rate fixedRate, > + const Calendar& calendar, > + BusinessDayConvention convention, > + const DayCounter& dayCounter, > + const Handle<YieldTermStructure>& yieldTS, > + const > Handle<ZeroInflationTermStructure>& inflationTS) > + : InflationSwap(start, maturity, lag, calendar, convention, > + dayCounter, yieldTS), > + fixedRate_(fixedRate), inflationTS_(inflationTS) { > + registerWith(inflationTS_); > + } > + > + > + bool ZeroCouponInflationSwap::isExpired() const { > + return yieldTS_->referenceDate() > maturity_; > + } > + > + > + Rate ZeroCouponInflationSwap::fairRate() const { > + return inflationTS_->zeroRate(maturity_ - lag_); > + } > + > + > + Rate ZeroCouponInflationSwap::fixedRate() const { > + return fixedRate_; > + } > + > + > + void ZeroCouponInflationSwap::performCalculations() const { > + > + // the observation lag is also taken into account in > fairRate(); > + // discount is relative to the payment date, not the > observation date. > + Real T = dayCounter_.yearFraction(inflationTS_->baseDate(), > + maturity_ - lag_); > + NPV_ = yieldTS_->discount(maturity_) * > + (std::pow(1.0 + fixedRate_, T) - std::pow(1.0 + > fairRate(), T)); > + errorEstimate_ = 0.0; > + } > + > +} > + > > > Property changes on: trunk/QuantLib/ql/instruments/zciis.cpp > ___________________________________________________________________ > Name: svn:eol-style > + native > > Added: trunk/QuantLib/ql/instruments/zciis.hpp > =================================================================== > --- trunk/QuantLib/ql/instruments/zciis.hpp > (rev 0) > +++ trunk/QuantLib/ql/instruments/zciis.hpp 2007-10-31 > 16:09:04 UTC (rev 13271) > @@ -0,0 +1,78 @@ > +/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; > c-basic-offset: 4 -*- */ > + > +/* > + Copyright (C) 2007 Chris Kenyon > + > + This file is part of QuantLib, a free-software/open-source library > + for financial quantitative analysts and developers - > http://quantlib.org/ > + > + QuantLib is free software: you can redistribute it and/or modify it > + under the terms of the QuantLib license. You should have received a > + copy of the license along with this program; if not, please email > + <[hidden email]>. The license is also available online at > + <http://quantlib.org/license.shtml>. > + > + This program is distributed in the hope that it will be > useful, but WITHOUT > + ANY WARRANTY; without even the implied warranty of > MERCHANTABILITY or FITNESS > + FOR A PARTICULAR PURPOSE. See the license for more details. > +*/ > + > +/*! \file zciis.hpp > + \brief Zero-coupon inflation-indexed swap > +*/ > + > +#ifndef quantlib_zciis_hpp > +#define quantlib_zciis_hpp > + > +#include <ql/instruments/inflationswap.hpp> > + > +namespace QuantLib { > + > + //! Zero-coupon inflation-indexed swap > + /*! A ZCIIS pays a fixed rate and receives the inflation rate at > + date \f$ d2 \f$ relative to inflation at date \f$ d1 \f$, > + where \f$ d1 \f$ is a lag period before start date > and \f$ d2 \f$ > + is a lag period before maturity. > + */ > + class ZeroCouponInflationSwap : public InflationSwap { > + public: > + ZeroCouponInflationSwap( > + const Date& start, > + const Date& maturity, > + const Period& lag, > + Rate fixedRate, > + const Calendar& calendar, > + BusinessDayConvention convention, > + const DayCounter& dayCounter, > + const Handle<YieldTermStructure>& yieldTS, > + const > Handle<ZeroInflationTermStructure>& inflationTS); > + > + //! \name Instrument interface > + //@{ > + bool isExpired() const; > + //@} > + > + //! \name InflationSwap interface > + //@{ > + Rate fairRate() const; > + //@} > + > + //! \name Inspectors > + //@{ > + Rate fixedRate() const; > + //@} > + > + protected: > + //! \name Instrument interface > + //@{ > + void performCalculations() const; > + //@} > + > + Rate fixedRate_; > + Handle<ZeroInflationTermStructure> inflationTS_; > + }; > + > +} > + > + > +#endif > > > Property changes on: trunk/QuantLib/ql/instruments/zciis.hpp > ___________________________________________________________________ > Name: svn:eol-style > + native > > > This was sent by the SourceForge.net collaborative > development platform, the world's largest Open Source > development site. > > -------------------------------------------------------------- > ----------- > This SF.net email is sponsored by: Splunk Inc. > Still grepping through log files to find problems? Stop. > Now Search log events and configuration files using AJAX and > a browser. > Download your FREE copy of Splunk now >> http://get.splunk.com/ > _______________________________________________ > QuantLib-cvs mailing list > [hidden email] > https://lists.sourceforge.net/lists/listinfo/quantlib-cvs > ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/ _______________________________________________ QuantLib-dev mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-dev |
On Wed, 2007-10-31 at 18:12 +0100, Bianchetti Marco wrote: > Why not under a dedicated folder /instruments/inflation/ ? I'm not particularly fond of deep folder structures. Especially when they're not clean-cut: if we added an inflation bond, would it go into inflation/ or into bonds/? Luigi -- The surest way to make a monkey of a man is to quote him. -- Robert Benchley ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/ _______________________________________________ QuantLib-dev mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-dev |
Free forum by Nabble | Edit this page |