From 1e09506236476b51efe0a6f5e4f08844deecd0c4 Mon Sep 17 00:00:00 2001 From: Ferdinando Ametrano Date: Tue, 13 Apr 2010 09:23:54 +0000 Subject: [PATCH] merged branches/R01000x-branch into trunk, respecting ancestry --- ChangeLog.txt | 67 +++++++++++++ Contributors.txt | 8 +- News.txt | 97 +++++++------------ ql/cashflows/conundrumpricer.cpp | 1 + ql/cashflows/couponpricer.cpp | 1 + ql/cashflows/inflationcouponpricer.cpp | 1 + ql/cashflows/rangeaccrual.cpp | 1 + .../callablebonds/callablebond.cpp | 4 +- ql/experimental/coupons/subperiodcoupons.cpp | 1 + ql/instruments/creditdefaultswap.cpp | 2 +- ql/patterns/singleton.hpp | 28 ++++-- .../credit/defaultprobabilityhelpers.cpp | 2 +- ql/time/calendars/china.cpp | 11 ++- ql/time/calendars/china.hpp | 6 +- ql/time/calendars/hongkong.cpp | 16 ++- ql/time/calendars/hongkong.hpp | 4 +- ql/time/calendars/india.cpp | 23 ++++- ql/time/calendars/india.hpp | 6 +- ql/time/calendars/indonesia.cpp | 24 ++++- ql/time/calendars/indonesia.hpp | 15 +-- ql/time/calendars/singapore.cpp | 7 +- ql/time/calendars/singapore.hpp | 6 +- ql/time/calendars/southkorea.cpp | 8 +- ql/time/calendars/taiwan.cpp | 15 ++- ql/time/calendars/taiwan.hpp | 2 +- ql/time/calendars/turkey.cpp | 51 ++++++---- ql/time/calendars/turkey.hpp | 12 ++- test-suite/cashflows.cpp | 51 ++++++++++ test-suite/cashflows.hpp | 1 + test-suite/creditdefaultswap.cpp | 5 +- test-suite/defaultprobabilitycurves.cpp | 34 ++++--- 31 files changed, 365 insertions(+), 145 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index bb45f289903..c883eba126d 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,3 +1,70 @@ +2010-04-06 13:38 Luigi Ballabio + + * [r17236] ql/patterns/singleton.hpp: + + Fix: manage Singleton correctly in .Net (thanks to Nathan Abbott.) + +2010-03-08 08:59 Luigi Ballabio + + * [r17212] ql/experimental/callablebonds/callablebond.cpp: + + Bug fix: create exercise-date vector correctly. + + Previously, the actual exercise dates were stored after a number + of null dates. For most choices of day counter, this resulted in + negative exercise times that were simply discarded. For some + (e.g., ActualActual::Bond) it resulted in an exception instead. + +2010-03-08 08:57 Luigi Ballabio + + * [r17211] ql/time/calendars/china.cpp, ql/time/calendars/china.hpp, + ql/time/calendars/hongkong.cpp, ql/time/calendars/hongkong.hpp, + ql/time/calendars/india.cpp, ql/time/calendars/india.hpp, + ql/time/calendars/indonesia.cpp, ql/time/calendars/indonesia.hpp, + ql/time/calendars/singapore.cpp, ql/time/calendars/singapore.hpp, + ql/time/calendars/southkorea.cpp, ql/time/calendars/taiwan.cpp, + ql/time/calendars/taiwan.hpp, ql/time/calendars/turkey.cpp, + ql/time/calendars/turkey.hpp: + + Update: added 2010 moving holidays for Eastern calendars. + +2010-03-01 09:32 Luigi Ballabio + + * [r17180] ql/instruments/zerocouponinflationswap.cpp, + ql/instruments/zerocouponinflationswap.hpp: + + Bug fix: added missing method implementations. + +2010-03-01 09:32 Luigi Ballabio + + * [r17179] ql/cashflows/indexedcashflow.hpp: + + Bug fix: let an IndexedCashFlow observe its index. + + Previously, index changes would not be propagated to the cash flow + and thus to any observers of the latter. This affected zero-coupon + inflation swaps. + +2010-02-24 11:22 Luigi Ballabio + + * [r17170] Docs/Makefile.am: + + + +2010-02-24 11:10 Luigi Ballabio + + * [r17167] Docs/images/QL-small.jpg, Docs/images/QL-title.jpg, + Docs/images/QL.bmp, Docs/images/QL.jpg, Docs/images/favicon.ico, + Docs/quantlibheader.html, Docs/quantlibheaderonline.html: + + Replaced unlicensed font in logo. + +2010-02-23 15:08 Luigi Ballabio + + * [r17153] ChangeLog.txt: + + Updated ChangeLogs. + 2010-02-23 14:33 Luigi Ballabio * [r17148] ql/cashflows/cashflows.cpp, ql/cashflows/cashflows.hpp, diff --git a/Contributors.txt b/Contributors.txt index 5e7d395c3ac..307d25ed397 100644 --- a/Contributors.txt +++ b/Contributors.txt @@ -19,10 +19,10 @@ Robert Lopez, Andr Mariani, Slava Mazur, Enrico Michelotti, Radu Mondescu, Bart Mosley, Tiziano Müller, Bojan Nikolic, Jean Nkeng, Adrian O'Neill, Andrea Odetti, Mike Parker, Guillaume Pealat, Gilbert Peffer, Walter -Penschke, Adrien Pinatton, Gianni Piolanti, Mario Pucci, J. Erik -Radmall, Fabio Ramponi, Maria Cristina Recchioni, Dimitri Reiswich, -Sadruddin Rejeb, Alessandro Roveda, Mohamed Amine Sadaoui, Alpha Sanou -Toure, Tamas Sashalmi, Peter Schmitteckert, Ralph Schreyer, David +Penschke, Francesco Perissin, Adrien Pinatton, Gianni Piolanti, +Mario Pucci, J. Erik Radmall, Fabio Ramponi, Maria Cristina Recchioni, +Dimitri Reiswich, Sadruddin Rejeb, Alessandro Roveda, Mohamed Amine Sadaoui, +Alpha Sanou Toure, Tamas Sashalmi, Peter Schmitteckert, Ralph Schreyer, David Schwartz, Eugene Shevkoplyas, Enrico Sirola, Maxim Sokolov, Niels Elken Sĝnderby, Andreas Spengler, Roland Stamm, Marco Tarenghi, François du Vignaud, Charles Whitmore, Bernd Johannes Wuebben, Sun diff --git a/News.txt b/News.txt index 076c03b4bab..00bf88591c7 100644 --- a/News.txt +++ b/News.txt @@ -1,62 +1,39 @@ -Notable changes for QuantLib 1.0: - -PORTABILITY - -- Fixes for x64 Visual Studio compilation (thanks to Craig Miller.) - -- Enabled language extensions in Visual Studio projects. - -- Prevented make errors with older shells (thanks to Walter Eaves.) - -DATE/TIME - -- Changes to end-of-month adjustment. In a schedule, the Unadjusted - convention now supersedes a non-null calendar and causes dates to - roll on the unadjusted end of month (possibly a holiday.) - -- Added new date-generation rule for CDS (thanks to Jose Aparicio.) - -- Fix for CDS fair-upfront calculation (thanks to Jose Aparicio.) - Previously, fair-upfront calculation required a non-null upfront - to begin with. This is no longer the case. - -INSTRUMENTS - -- Fixed discounting of dividends on convertible-bond grid (thanks to - Benoit Houzelle and Samuel Lerouge.) - -CASH FLOWS - -- A number of CashFlows methods now return a meaningful result even - if the passed leg is empty. - -PROCESSES - -- Changed default discretization for Heston process. The new - default (giving a better performance) is quadratic exponential - with Martingale correction. - -TERM STRUCTURES - -- Removed ambiguous parRate member functions from YieldTermStructure - interface. - -EXAMPLES - -- Added market-model example. - -EXPERIMENTAL FOLDER - -The ql/experimental folder contains code which is still not fully -integrated with the library or even fully tested, but is released in -order to get user feedback. Experimental classes are considered -unstable; their interfaces might change in future releases. -New contributions for this release were: - -- Longstaff-Schwartz algorithm for basket products including coupon - payments (thanks to Andrea Odetti;) - -- added sparse incomplete LU preconditioner for 2D finite-difference - models (thanks to Ralph Schreyer.) +Changes for QuantLib 1.0.1: + +- Added moving holidays for 2010 to Eastern calendars. + +- The Singleton class should now work correctly when used on the .Net + platform (thanks to Nathan Abbott.) + +- Bug fix: let an IndexedCashFlow observe its index. + Previously, index changes would not be propagated to the cash flow + and thus to any observers of the latter. This affected zero-coupon + inflation swaps. + +- Bug fix: added missing method implementations to zero-coupon + inflation swaps. + A couple of methods were declared but not defined. + +- Bug fix: create exercise-date vector correctly for callable bonds. + Previously, the actual exercise dates were stored after a number + of null dates. For most choices of day counter, this resulted in + negative exercise times that were harmlessly discarded. For some + day counters (e.g., ActualActual::Bond) the null dates caused an + exception instead. + +- Bug fix: properly account for CDS protection-start date. + During bootstrap of the default-probability curve, the + protection-start date was taken into account when calculating the + coupon schedule of the underlying CDS but not when calculating its + value (a few days of protection could be lost.) + Also, sometimes the protection-start date was compared incorrectly + to the accrual-start date leading to false positives when checking + requirements. + +- Bug fix: coupon pricers now properly check for the result of the + dynamic_cast they perform. + Previously, setting a pricer to a coupon of the wrong type would + cause an access violation by dereferencing the null pointer + returned by the failed cast. diff --git a/ql/cashflows/conundrumpricer.cpp b/ql/cashflows/conundrumpricer.cpp index 717d5a3387f..baa4f87d957 100644 --- a/ql/cashflows/conundrumpricer.cpp +++ b/ql/cashflows/conundrumpricer.cpp @@ -78,6 +78,7 @@ namespace QuantLib { void HaganPricer::initialize(const FloatingRateCoupon& coupon){ coupon_ = dynamic_cast(&coupon); + QL_REQUIRE(coupon_, "CMS coupon needed"); gearing_ = coupon_->gearing(); spread_ = coupon_->spread(); diff --git a/ql/cashflows/couponpricer.cpp b/ql/cashflows/couponpricer.cpp index 72d35ec53b5..86cc0f26daf 100644 --- a/ql/cashflows/couponpricer.cpp +++ b/ql/cashflows/couponpricer.cpp @@ -37,6 +37,7 @@ namespace QuantLib { void BlackIborCouponPricer::initialize(const FloatingRateCoupon& coupon) { coupon_ = dynamic_cast(&coupon); + QL_REQUIRE(coupon_, "Libor coupon required"); gearing_ = coupon_->gearing(); spread_ = coupon_->spread(); Date paymentDate = coupon_->date(); diff --git a/ql/cashflows/inflationcouponpricer.cpp b/ql/cashflows/inflationcouponpricer.cpp index 00402834eb7..88c02746da5 100644 --- a/ql/cashflows/inflationcouponpricer.cpp +++ b/ql/cashflows/inflationcouponpricer.cpp @@ -116,6 +116,7 @@ namespace QuantLib { void YoYInflationCouponPricer::initialize(const InflationCoupon& coupon) { coupon_ = dynamic_cast(&coupon); + QL_REQUIRE(coupon_, "year-on-year inflation coupon needed"); gearing_ = coupon_->gearing(); spread_ = coupon_->spread(); paymentDate_ = coupon_->date(); diff --git a/ql/cashflows/rangeaccrual.cpp b/ql/cashflows/rangeaccrual.cpp index be39efa2b06..45816847b21 100644 --- a/ql/cashflows/rangeaccrual.cpp +++ b/ql/cashflows/rangeaccrual.cpp @@ -105,6 +105,7 @@ namespace QuantLib { void RangeAccrualPricer::initialize(const FloatingRateCoupon& coupon){ coupon_ = dynamic_cast(&coupon); + QL_REQUIRE(coupon_, "range-accrual coupon required"); gearing_ = coupon_->gearing(); spread_ = coupon_->spread(); diff --git a/ql/experimental/callablebonds/callablebond.cpp b/ql/experimental/callablebonds/callablebond.cpp index 72797adfadb..5bfa45192b7 100644 --- a/ql/experimental/callablebonds/callablebond.cpp +++ b/ql/experimental/callablebonds/callablebond.cpp @@ -187,9 +187,9 @@ namespace QuantLib { const Leg& cfs = cashflows(); arguments->couponDates.clear(); - arguments->couponDates = std::vector(cfs.size()-1); + arguments->couponDates.reserve(cfs.size()-1); arguments->couponAmounts.clear(); - arguments->couponAmounts = std::vector(cfs.size()-1); + arguments->couponAmounts.reserve(cfs.size()-1); for (Size i=0; ihasOccurred(settlement, false)) { diff --git a/ql/experimental/coupons/subperiodcoupons.cpp b/ql/experimental/coupons/subperiodcoupons.cpp index 016c01f79f3..8f3dabd697f 100644 --- a/ql/experimental/coupons/subperiodcoupons.cpp +++ b/ql/experimental/coupons/subperiodcoupons.cpp @@ -81,6 +81,7 @@ namespace QuantLib { void SubPeriodsPricer::initialize(const FloatingRateCoupon& coupon) { coupon_ = dynamic_cast(&coupon); + QL_REQUIRE(coupon_, "sub-periods coupon required"); gearing_ = coupon_->gearing(); spread_ = coupon_->spread(); diff --git a/ql/instruments/creditdefaultswap.cpp b/ql/instruments/creditdefaultswap.cpp index 43431122ef6..cddde9e119b 100644 --- a/ql/instruments/creditdefaultswap.cpp +++ b/ql/instruments/creditdefaultswap.cpp @@ -47,7 +47,7 @@ namespace QuantLib { paysAtDefaultTime_(paysAtDefaultTime), claim_(claim), protectionStart_(protectionStart == Null() ? schedule[0] : protectionStart) { - QL_REQUIRE(protectionStart_ >= schedule[0], + QL_REQUIRE(protectionStart_ <= schedule[0], "protection can not start after accrual"); leg_ = FixedRateLeg(schedule) .withNotionals(notional) diff --git a/ql/patterns/singleton.hpp b/ql/patterns/singleton.hpp index b322277df26..35c3f3dd01b 100644 --- a/ql/patterns/singleton.hpp +++ b/ql/patterns/singleton.hpp @@ -31,6 +31,19 @@ namespace QuantLib { + #if defined(QL_ENABLE_SESSIONS) + // definition must be provided by the user + Integer sessionId(); + #endif + + // this is required on VC++ (with a slightly different syntax depending + // on the compiler version) when CLR support is enabled + #if defined(QL_PATCH_MSVC71) + #pragma unmanaged + #elif defined(QL_PATCH_MSVC) + #pragma managed(push, off) + #endif + //! Basic support for the singleton pattern. /*! The typical use of this class is: \code @@ -58,17 +71,9 @@ namespace QuantLib { Singleton() {} }; - #if defined(QL_ENABLE_SESSIONS) - // definition must be provided by the user - Integer sessionId(); - #endif - // template definitions template - #if defined(QL_PATCH_MSVC) && defined(_MANAGED) - inline // this seems to be required when CLR support is enabled - #endif T& Singleton::instance() { static std::map > instances_; #if defined(QL_ENABLE_SESSIONS) @@ -82,6 +87,13 @@ namespace QuantLib { return *instance; } + // reverts the change above + #if defined(QL_PATCH_MSVC71) + #pragma managed + #elif defined(QL_PATCH_MSVC) + #pragma managed(pop) + #endif + } diff --git a/ql/termstructures/credit/defaultprobabilityhelpers.cpp b/ql/termstructures/credit/defaultprobabilityhelpers.cpp index 95887e168af..a3e24afc978 100644 --- a/ql/termstructures/credit/defaultprobabilityhelpers.cpp +++ b/ql/termstructures/credit/defaultprobabilityhelpers.cpp @@ -94,7 +94,7 @@ namespace QuantLib { } void CdsHelper::initializeDates() { - Date protectionStart_ = evaluationDate_ + settlementDays_; + protectionStart_ = evaluationDate_ + settlementDays_; Date startDate = calendar_.adjust(protectionStart_, paymentConvention_); Date endDate = evaluationDate_ + tenor_; diff --git a/ql/time/calendars/china.cpp b/ql/time/calendars/china.cpp index 81973f23a1c..23383291e3f 100644 --- a/ql/time/calendars/china.cpp +++ b/ql/time/calendars/china.cpp @@ -2,7 +2,7 @@ /* Copyright (C) 2004 FIMAT Group - Copyright (C) 2007, 2009 StatPro Italia srl + Copyright (C) 2007, 2009, 2010 StatPro Italia srl This file is part of QuantLib, a free-software/open-source library for financial quantitative analysts and developers - http://quantlib.org/ @@ -52,8 +52,7 @@ namespace QuantLib { || (y == 2006 && (d == 2 || d == 3) && m == January) || (y == 2007 && d <= 3 && m == January) || (y == 2007 && d == 31 && m == December) - || (y == 2008 && d == 1 && m == January) - || (y == 2009 && (d == 1 || d == 2) && m == January) + || (y == 2009 && d == 2 && m == January) // Chinese New Year || (y == 2004 && d >= 19 && d <= 28 && m == January) || (y == 2005 && d >= 7 && d <= 15 && m == February) @@ -62,23 +61,29 @@ namespace QuantLib { || (y == 2007 && d >= 17 && d <= 25 && m == February) || (y == 2008 && d >= 6 && d <= 12 && m == February) || (y == 2009 && d >= 26 && d <= 30 && m == January) + || (y == 2010 && d >= 15 && d <= 19 && m == January) // Ching Ming Festival || (y <= 2008 && d == 4 && m == April) || (y == 2009 && d == 6 && m == April) + || (y == 2010 && d == 5 && m == April) // Labor Day || (y <= 2007 && d >= 1 && d <= 7 && m == May) || (y == 2008 && d >= 1 && d <= 2 && m == May) || (y == 2009 && d == 1 && m == May) + || (y == 2010 && d == 3 && m == May) // Tuen Ng Festival || (y <= 2008 && d == 9 && m == June) || (y == 2009 && (d == 28 || d == 29) && m == May) + || (y == 2010 && d >= 14 && d <= 16 && m == June) // Mid-Autumn Festival || (y <= 2008 && d == 15 && m == September) + || (y == 2010 && d >= 22 && d <= 24 && m == September) // National Day || (y <= 2007 && d >= 1 && d <= 7 && m == October) || (y == 2008 && ((d >= 29 && m == September) || (d <= 3 && m == October))) || (y == 2009 && d >= 1 && d <= 8 && m == October) + || (y == 2010 && d >= 1 && d <= 7 && m == October) ) return false; return true; diff --git a/ql/time/calendars/china.hpp b/ql/time/calendars/china.hpp index 36997929221..8b5828c3d8c 100644 --- a/ql/time/calendars/china.hpp +++ b/ql/time/calendars/china.hpp @@ -2,7 +2,7 @@ /* Copyright (C) 2004 FIMAT Group - Copyright (C) 2008, 2009 StatPro Italia srl + Copyright (C) 2008, 2009, 2010 StatPro Italia srl This file is part of QuantLib, a free-software/open-source library for financial quantitative analysts and developers - http://quantlib.org/ @@ -41,7 +41,7 @@ namespace QuantLib { Other holidays for which no rule is given (data available for - 2004-2009 only): + 2004-2010 only):
  • Chinese New Year
  • Ching Ming Festival
  • @@ -49,7 +49,7 @@ namespace QuantLib {
  • Mid-Autumn Festival
- Data from + Data from \ingroup calendars */ diff --git a/ql/time/calendars/hongkong.cpp b/ql/time/calendars/hongkong.cpp index fa5707532ab..d73b0598ba6 100644 --- a/ql/time/calendars/hongkong.cpp +++ b/ql/time/calendars/hongkong.cpp @@ -2,7 +2,7 @@ /* Copyright (C) 2004 FIMAT Group - Copyright (C) 2007, 2009 StatPro Italia srl + Copyright (C) 2007, 2009, 2010 StatPro Italia srl This file is part of QuantLib, a free-software/open-source library for financial quantitative analysts and developers - http://quantlib.org/ @@ -154,6 +154,20 @@ namespace QuantLib { return false; } + if (y == 2010) { + if (// Lunar New Year + ((d == 15 || d == 16) && m == February) + // Ching Ming Festival + || (d == 6 && m == April) + // Buddha's birthday + || (d == 21 && m == May) + // Tuen NG festival + || (d == 16 && m == June) + // Mid-autumn festival + || (d == 23 && m == September)) + return false; + } + return true; } diff --git a/ql/time/calendars/hongkong.hpp b/ql/time/calendars/hongkong.hpp index 17e5da575d0..59ffe5c8c5b 100644 --- a/ql/time/calendars/hongkong.hpp +++ b/ql/time/calendars/hongkong.hpp @@ -2,7 +2,7 @@ /* Copyright (C) 2004 FIMAT Group - Copyright (C) 2007, 2009 StatPro Italia srl + Copyright (C) 2007, 2009, 2010 StatPro Italia srl This file is part of QuantLib, a free-software/open-source library for financial quantitative analysts and developers - http://quantlib.org/ @@ -46,7 +46,7 @@ namespace QuantLib { Other holidays for which no rule is given - (data available for 2004-2009 only:) + (data available for 2004-2010 only:)
  • Lunar New Year
  • Chinese New Year
  • diff --git a/ql/time/calendars/india.cpp b/ql/time/calendars/india.cpp index 63133f8bc60..98130cc52cc 100644 --- a/ql/time/calendars/india.cpp +++ b/ql/time/calendars/india.cpp @@ -1,7 +1,7 @@ /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* - Copyright (C) 2005, 2007, 2008, 2009 StatPro Italia srl + Copyright (C) 2005, 2007, 2008, 2009, 2010 StatPro Italia srl This file is part of QuantLib, a free-software/open-source library for financial quantitative analysts and developers - http://quantlib.org/ @@ -170,6 +170,27 @@ namespace QuantLib { return false; } + if (y == 2010) { + if (// New Year's Day + (d == 1 && m == January) + // Mahashivratri + || (d == 12 && m == February) + // Holi + || (d == 1 && m == March) + // Ram Navmi + || (d == 24 && m == March) + // Ramzan Id + || (d == 10 && m == September) + // Laxmi Puja + || (d == 5 && m == November) + // Bakri Id + || (d == 17 && m == November) + // Moharram + || (d == 17 && m == December) + ) + return false; + } + return true; } diff --git a/ql/time/calendars/india.hpp b/ql/time/calendars/india.hpp index fc14707e463..c32a9ac842e 100644 --- a/ql/time/calendars/india.hpp +++ b/ql/time/calendars/india.hpp @@ -1,7 +1,7 @@ /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* - Copyright (C) 2005, 2007, 2008, 2009 StatPro Italia srl + Copyright (C) 2005, 2007, 2008, 2009, 2010 StatPro Italia srl This file is part of QuantLib, a free-software/open-source library for financial quantitative analysts and developers - http://quantlib.org/ @@ -42,8 +42,8 @@ namespace QuantLib {
  • Christmas, December 25th
- Other holidays for which no rule is given (data available for - 2005-2009 only:) + Other holidays for which no rule is given + (data available for 2005-2010 only:)
  • Bakri Id
  • Moharram
  • diff --git a/ql/time/calendars/indonesia.cpp b/ql/time/calendars/indonesia.cpp index 8e2535255a4..7bf4816d764 100644 --- a/ql/time/calendars/indonesia.cpp +++ b/ql/time/calendars/indonesia.cpp @@ -1,7 +1,7 @@ /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* - Copyright (C) 2005, 2007, 2008, 2009 StatPro Italia srl + Copyright (C) 2005, 2007, 2008, 2009, 2010 StatPro Italia srl This file is part of QuantLib, a free-software/open-source library for financial quantitative analysts and developers - http://quantlib.org/ @@ -29,6 +29,7 @@ namespace QuantLib { switch (market) { case BEJ: case JSX: + case IDX: impl_ = bejImpl; break; default: @@ -171,6 +172,27 @@ namespace QuantLib { return false; } + if (y == 2010) { + if (// Birthday of the prophet Muhammad SAW + (d == 26 && m == February) + // Saka's New Year + || (d == 16 && m == March) + // Birth of Buddha + || (d == 28 && m == May) + // Ied Fitr + || (d >= 8 && d <= 14 && m == September) + // Ied Adha + || (d == 17 && m == November) + // Islamic New Year + || (d == 7 && m == December) + // Public Holiday + || (d == 24 && m == December) + // Trading holiday + || (d == 31 && m == December) + ) + return false; + } + return true; } diff --git a/ql/time/calendars/indonesia.hpp b/ql/time/calendars/indonesia.hpp index 9ff352392e4..e6fa38604d5 100644 --- a/ql/time/calendars/indonesia.hpp +++ b/ql/time/calendars/indonesia.hpp @@ -1,7 +1,7 @@ /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* - Copyright (C) 2005, 2007, 2008, 2009 StatPro Italia srl + Copyright (C) 2005, 2007, 2008, 2009, 2010 StatPro Italia srl This file is part of QuantLib, a free-software/open-source library for financial quantitative analysts and developers - http://quantlib.org/ @@ -29,8 +29,8 @@ namespace QuantLib { //! %Indonesian calendars - /*! Holidays for the Jakarta stock exchange - (data from ): + /*! Holidays for the Indonesia stock exchange + (data from ):
    • Saturdays
    • Sundays
    • @@ -42,7 +42,7 @@ namespace QuantLib {
    Other holidays for which no rule is given - (data available for 2005-2009 only:) + (data available for 2005-2010 only:)
    • Idul Adha
    • Ied Adha
    • @@ -67,10 +67,11 @@ namespace QuantLib { bool isBusinessDay(const Date&) const; }; public: - enum Market { BEJ, //!< Jakarta stock exchange - JSX //!< Jakarta stock exchange + enum Market { BEJ, //!< Jakarta stock exchange (merged into IDX) + JSX, //!< Jakarta stock exchange (merged into IDX) + IDX //!< Indonesia stock exchange }; - Indonesia(Market m = BEJ); + Indonesia(Market m = IDX); }; } diff --git a/ql/time/calendars/singapore.cpp b/ql/time/calendars/singapore.cpp index 43e0ffdbc11..0f7f39db266 100644 --- a/ql/time/calendars/singapore.cpp +++ b/ql/time/calendars/singapore.cpp @@ -2,7 +2,7 @@ /* Copyright (C) 2004 FIMAT Group - Copyright (C) 2007, 2008, 2009 StatPro Italia srl + Copyright (C) 2007, 2008, 2009, 2010 StatPro Italia srl This file is part of QuantLib, a free-software/open-source library for financial quantitative analysts and developers - http://quantlib.org/ @@ -55,6 +55,7 @@ namespace QuantLib { || ((d == 19 || d == 20) && m == February && y == 2007) || ((d == 7 || d == 8) && m == February && y == 2008) || ((d == 26 || d == 27) && m == January && y == 2009) + || ((d == 15 || d == 16) && m == January && y == 2010) // Hari Raya Haji || ((d == 1 || d == 2) && m == February && y == 2004) @@ -64,6 +65,7 @@ namespace QuantLib { || (d == 20 && m == December && y == 2007) || (d == 8 && m == December && y == 2008) || (d == 27 && m == November && y == 2009) + || (d == 17 && m == November && y == 2010) // Vesak Poya Day || (d == 2 && m == June && y == 2004) @@ -72,12 +74,14 @@ namespace QuantLib { || (d == 31 && m == May && y == 2007) || (d == 18 && m == May && y == 2008) || (d == 9 && m == May && y == 2009) + || (d == 28 && m == May && y == 2010) // Deepavali || (d == 11 && m == November && y == 2004) || (d == 8 && m == November && y == 2007) || (d == 28 && m == October && y == 2008) || (d == 16 && m == November && y == 2009) + || (d == 5 && m == November && y == 2010) // Diwali || (d == 1 && m == November && y == 2005) @@ -89,6 +93,7 @@ namespace QuantLib { || (d == 13 && m == October && y == 2007) || (d == 1 && m == October && y == 2008) || (d == 21 && m == September && y == 2009) + || (d == 10 && m == September && y == 2010) ) return false; return true; diff --git a/ql/time/calendars/singapore.hpp b/ql/time/calendars/singapore.hpp index a4c8b66453a..ab59be01bc7 100644 --- a/ql/time/calendars/singapore.hpp +++ b/ql/time/calendars/singapore.hpp @@ -2,7 +2,7 @@ /* Copyright (C) 2004 FIMAT Group - Copyright (C) 2007, 2008, 2009 StatPro Italia srl + Copyright (C) 2007, 2008, 2009, 2010 StatPro Italia srl This file is part of QuantLib, a free-software/open-source library for financial quantitative analysts and developers - http://quantlib.org/ @@ -31,7 +31,7 @@ namespace QuantLib { //! %Singapore calendars /*! Holidays for the Singapore exchange - (data from ): + (data from ):
      • Saturdays
      • Sundays
      • @@ -43,7 +43,7 @@ namespace QuantLib {
      Other holidays for which no rule is given - (data available for 2004-2008 only:) + (data available for 2004-2010 only:)
      • Chinese New Year
      • Hari Raya Haji
      • diff --git a/ql/time/calendars/southkorea.cpp b/ql/time/calendars/southkorea.cpp index 600f4478b52..f2c7b3872de 100644 --- a/ql/time/calendars/southkorea.cpp +++ b/ql/time/calendars/southkorea.cpp @@ -82,11 +82,12 @@ namespace QuantLib { || ((d == 6 || d == 7 || d == 8) && m == February && y == 2008) || ((d == 25 || d == 26 || d == 27) && m == January && y == 2009) || ((d == 13 || d == 14 || d == 15) && m == February && y == 2010) - // Election Day 2004 + // Election Days || (d == 15 && m == April && y == 2004) // National Assembly || (d == 31 && m == May && y == 2006) // Regional election || (d == 19 && m == December && y == 2007) // Presidency - || (d == 9 && m == April && y == 2008) + || (d == 9 && m == April && y == 2008) // National Assembly + || (d == 2 && m == June && y == 2010) // Local election // Buddha's birthday || (d == 26 && m == May && y == 2004) || (d == 15 && m == May && y == 2005) @@ -123,6 +124,9 @@ namespace QuantLib { || (d == 30 && m == December && y == 2005) || (d == 29 && m == December && y == 2006) || (d == 31 && m == December && y == 2007) + || (d == 31 && m == December && y == 2008) + || (d == 31 && m == December && y == 2009) + || (d == 31 && m == December && y == 2010) ) return false; diff --git a/ql/time/calendars/taiwan.cpp b/ql/time/calendars/taiwan.cpp index 7379058772c..e767fe1fc59 100644 --- a/ql/time/calendars/taiwan.cpp +++ b/ql/time/calendars/taiwan.cpp @@ -2,7 +2,7 @@ /* Copyright (C) 2004 FIMAT Group - Copyright (C) 2005, 2006, 2007, 2008, 2009 StatPro Italia srl + Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 StatPro Italia srl This file is part of QuantLib, a free-software/open-source library for financial quantitative analysts and developers - http://quantlib.org/ @@ -152,6 +152,19 @@ namespace QuantLib { return false; } + if (y == 2010) { + if (// Chinese Lunar New Year + (d >= 13 && d <= 21 && m == January) + // Tomb Sweeping Day + || (d == 5 && m == April) + // Dragon Boat Festival + || (d == 16 && m == May) + // Moon Festival + || (d == 22 && m == September) + ) + return false; + } + return true; } diff --git a/ql/time/calendars/taiwan.hpp b/ql/time/calendars/taiwan.hpp index 19d84db2d30..28c67dc08bb 100644 --- a/ql/time/calendars/taiwan.hpp +++ b/ql/time/calendars/taiwan.hpp @@ -42,7 +42,7 @@ namespace QuantLib {
      Other holidays for which no rule is given - (data available for 2002-2009 only:) + (data available for 2002-2010 only:)
      • Chinese Lunar New Year
      • Tomb Sweeping Day
      • diff --git a/ql/time/calendars/turkey.cpp b/ql/time/calendars/turkey.cpp index 2af4c32429f..7cf2a3753cf 100644 --- a/ql/time/calendars/turkey.cpp +++ b/ql/time/calendars/turkey.cpp @@ -2,6 +2,7 @@ /* Copyright (C) 2005 Sercan Atalik + Copyright (C) 2010 StatPro Italia srl This file is part of QuantLib, a free-software/open-source library for financial quantitative analysts and developers - http://quantlib.org/ @@ -52,39 +53,51 @@ namespace QuantLib { // Local Holidays if (y == 2004) { - // kurban + // Kurban if ((m == February && d <= 4) - // ramazan + // Ramadan || (m == November && d >= 14 && d <= 16)) return false; } else if (y == 2005) { - // kurban + // Kurban if ((m == January && d >= 19 && d <= 21) - // ramazan + // Ramadan || (m == November && d >= 2 && d <= 5)) return false; } else if (y == 2006) { - // kurban - if ((m == January && d >= 9 && d <= 13) - // ramazan + // Kurban + if ((m == January && d >= 10 && d <= 13) + // Ramadan || (m == October && d >= 23 && d <= 25) - // kurban - || (m == December && d >= 30)) + // Kurban + || (m == December && d == 31)) return false; } else if (y == 2007) { - // kurban - if ((m == January && d <= 4) - // ramazan - || (m == October && d >= 11 && d <= 14) - // kurban - || (m == December && d >= 19 && d <= 23)) + // Kurban + if ((m == January && d <= 3) + // Ramadan + || (m == October && d >= 12 && d <= 14) + // Kurban + || (m == December && d >= 20 && d <= 23)) return false; } else if (y == 2008) { - // ramazan - if ((m == September && d >= 29) + // Ramadan + if ((m == September && d == 30) || (m == October && d <= 2) - // kurban - || (m == December && d >= 7 && d <= 11)) + // Kurban + || (m == December && d >= 8 && d <= 11)) + return false; + } else if (y == 2009) { + // Ramadan + if ((m == September && d >= 20 && d <= 22) + // Kurban + || (m == November && d >= 27 && d <= 30)) + return false; + } else if (y == 2010) { + // Ramadan + if ((m == September && d >= 9 && d <= 11) + // Kurban + || (m == November && d >= 16 && d <= 19)) return false; } return true; diff --git a/ql/time/calendars/turkey.hpp b/ql/time/calendars/turkey.hpp index 53fdd1e3735..4897baeecf2 100644 --- a/ql/time/calendars/turkey.hpp +++ b/ql/time/calendars/turkey.hpp @@ -2,6 +2,7 @@ /* Copyright (C) 2005 Sercan Atalik + Copyright (C) 2010 StatPro Italia srl This file is part of QuantLib, a free-software/open-source library for financial quantitative analysts and developers - http://quantlib.org/ @@ -29,14 +30,17 @@ namespace QuantLib { //! Turkish calendar - /*! Holidays: + /*! Holidays for the Istanbul Stock Exchange: + (data from ):
        • Saturdays
        • Sundays
        • New Year's Day, January 1st
        • -
        • National Holidays (April 23rd, May 19th, August 30th, - October 29th
        • -
        • Local Holidays (Kurban, Ramadan; 2004 to 2009 only)
        • +
        • National Sovereignty and Children’s Day, April 23rd
        • +
        • Youth and Sports Day, May 19th
        • +
        • Victory Day, August 30th
        • +
        • Republic Day, October 29th
        • +
        • Local Holidays (Kurban, Ramadan; 2004 to 2010 only)
        \ingroup calendars diff --git a/test-suite/cashflows.cpp b/test-suite/cashflows.cpp index 135ab41f6ed..ba7cd2913ce 100644 --- a/test-suite/cashflows.cpp +++ b/test-suite/cashflows.cpp @@ -21,6 +21,12 @@ #include "utilities.hpp" #include #include +#include +#include +#include +#include +#include +#include #include using namespace QuantLib; @@ -161,10 +167,55 @@ void CashFlowsTest::testSettings() { } +void CashFlowsTest::testAccessViolation() { + BOOST_MESSAGE("Testing dynamic cast of coupon in Black pricer..."); + + SavedSettings backup; + + Date todaysDate(7, April, 2010); + Date settlementDate(9, April, 2010); + Settings::instance().evaluationDate() = todaysDate; + Calendar calendar = TARGET(); + + Handle rhTermStructure( + flatRate(settlementDate, 0.04875825, Actual365Fixed())); + + Volatility volatility = 0.10; + Handle vol; + vol = Handle( + boost::shared_ptr( + new ConstantOptionletVolatility( + 2, + calendar, + ModifiedFollowing, + volatility, + Actual365Fixed()))); + + boost::shared_ptr index3m (new USDLibor(3*Months, + rhTermStructure)); + + Date payDate(20, December, 2013); + Date startDate(20, September, 2013); + Date endDate(20, December, 2013); + Rate spread = 0.0115; + boost::shared_ptr pricer(new BlackIborCouponPricer(vol)); + boost::shared_ptr coupon( + new FloatingRateCoupon(payDate,100, startDate, endDate, 2, + index3m, 1.0 , spread / 100)); + coupon->setPricer(pricer); + + try { + // this caused an access violation in version 1.0 + Real amount = coupon->amount(); + } catch (Error&) { + // ok; proper exception thrown + } +} test_suite* CashFlowsTest::suite() { test_suite* suite = BOOST_TEST_SUITE("Cash flows tests"); suite->add(QUANTLIB_TEST_CASE(&CashFlowsTest::testSettings)); + suite->add(QUANTLIB_TEST_CASE(&CashFlowsTest::testAccessViolation)); return suite; } diff --git a/test-suite/cashflows.hpp b/test-suite/cashflows.hpp index 56652eef11f..5ea6f20cb5d 100644 --- a/test-suite/cashflows.hpp +++ b/test-suite/cashflows.hpp @@ -25,6 +25,7 @@ class CashFlowsTest { public: static void testSettings(); + static void testAccessViolation(); static boost::unit_test_framework::test_suite* suite(); }; diff --git a/test-suite/creditdefaultswap.cpp b/test-suite/creditdefaultswap.cpp index ab5f69f325b..fae07b9e40b 100644 --- a/test-suite/creditdefaultswap.cpp +++ b/test-suite/creditdefaultswap.cpp @@ -303,7 +303,9 @@ void CreditDefaultSwapTest::testImpliedHazardRate() { SavedSettings backup; // Initialize curves - Date today = Settings::instance().evaluationDate(); + Calendar calendar = TARGET(); + Date today = calendar.adjust(Date::todaysDate()); + Settings::instance().evaluationDate() = today; Rate h1 = 0.30, h2 = 0.40; DayCounter dayCounter = Actual365Fixed(); @@ -330,7 +332,6 @@ void CreditDefaultSwapTest::testImpliedHazardRate() { new FlatForward(today,0.03,Actual360()))); - Calendar calendar = TARGET(); Frequency frequency = Semiannual; BusinessDayConvention convention = ModifiedFollowing; diff --git a/test-suite/defaultprobabilitycurves.cpp b/test-suite/defaultprobabilitycurves.cpp index e422c47c3b4..e049b3ffcd1 100644 --- a/test-suite/defaultprobabilitycurves.cpp +++ b/test-suite/defaultprobabilitycurves.cpp @@ -145,10 +145,8 @@ namespace { Calendar calendar = TARGET(); Date today = Settings::instance().evaluationDate(); - Date startDate = today; - Date endDate = startDate; - Integer settlementDays = 0; + Integer settlementDays = 1; std::vector quote; quote.push_back(0.005); @@ -192,15 +190,21 @@ namespace { Real notional = 1.0; double tolerance = 1.0e-6; + // ensure apple-to-apple comparison + SavedSettings backup; + Settings::instance().includeTodaysCashFlows() = true; + for (Size i=0; i( new MidPointCdsEngine(piecewiseCurve, recoveryRate, discountCurve))); @@ -225,8 +229,6 @@ namespace { Calendar calendar = TARGET(); Date today = Settings::instance().evaluationDate(); - Date startDate = today; - Date endDate = startDate; Integer settlementDays = 0; @@ -279,15 +281,17 @@ namespace { Settings::instance().includeTodaysCashFlows() = true; for (Size i=0; i( new MidPointCdsEngine(piecewiseCurve, recoveryRate, discountCurve, true)));