http://quantlib.414.s1.nabble.com/Re-QuantLib-svn-SF-net-SVN-quantlib-17823-trunk-QuantLib-ql-tp9009.html
Sorry, it breaks backwards compatibility. We'll have to think how to
>
> Modified Paths:
> --------------
> trunk/QuantLib/ql/experimental/inflation/
> piecewiseyoyoptionletvolatility.hpp
> trunk/QuantLib/ql/termstructures/credit/probabilitytraits.hpp
> trunk/QuantLib/ql/termstructures/inflation/
> piecewiseyoyinflationcurve.hpp
> trunk/QuantLib/ql/termstructures/inflation/
> piecewisezeroinflationcurve.hpp
> trunk/QuantLib/ql/termstructures/iterativebootstrap.hpp
> trunk/QuantLib/ql/termstructures/localbootstrap.hpp
> trunk/QuantLib/ql/termstructures/yield/bootstraptraits.hpp
>
> Modified: trunk/QuantLib/ql/experimental/inflation/
> piecewiseyoyoptionletvolatility.hpp
> ===================================================================
> --- trunk/QuantLib/ql/experimental/inflation/
> piecewiseyoyoptionletvolatility.hpp 2011-06-29 17:50:59 UTC (rev
> 17822)
> +++ trunk/QuantLib/ql/experimental/inflation/
> piecewiseyoyoptionletvolatility.hpp 2011-06-29 18:01:02 UTC (rev
> 17823)
> @@ -2,6 +2,7 @@
>
> /*
> Copyright (C) 2009 Chris Kenyon
> + Copyright (C) 2011 Ferdinando Ametrano
>
> This file is part of QuantLib, a free-software/open-source library
> for financial quantitative analysts and developers -
http://quantlib.org/> @@ -46,19 +47,34 @@
> // assumptions on early options
> // that are _not_ quoted
> }
> - static Volatility initialGuess() {return 0.005;}
> - static Volatility guess(const YoYOptionletVolatilitySurface*,
> - const Date &) {
> +
> + template <class C>
> + static Volatility guess(Size i,
> + const C* c,
> + bool validData) {
> + if (validData) // previous iteration value
> + return c->data()[i];
> +
> + if (i==1) // first pillar
> + return 0.005;
> +
> + // could/should extrapolate
> return 0.002;
> }
> - static Volatility minValueAfter(Size n,
> - const
> std::vector<Volatility> &v) {
> - return std::max(0.0, v[n-1] - 0.02); // vol cannot be
> negative
> +
> + template <class C>
> + static Volatility minValueAfter(Size i,
> + const C* c,
> + bool validData) {
> + return std::max(0.0, c->data()[i-1] - 0.02); // vol
> cannot be negative
> }
> - static Volatility maxValueAfter(Size n,
> - const
> std::vector<Volatility> &v) {
> - return v[n-1] + 0.02;
> + template <class C>
> + static Volatility maxValueAfter(Size i,
> + const C* c,
> + bool validData) {
> + return c->data()[i-1] + 0.02;
> }
> +
> static void updateGuess(std::vector<Volatility> &vols,
> Volatility level,
> Size i) {
> @@ -198,4 +214,3 @@
> }
>
> #endif
> -
>
> Modified: trunk/QuantLib/ql/termstructures/credit/
> probabilitytraits.hpp
> ===================================================================
> --- trunk/QuantLib/ql/termstructures/credit/probabilitytraits.hpp
> 2011-06-29 17:50:59 UTC (rev 17822)
> +++ trunk/QuantLib/ql/termstructures/credit/probabilitytraits.hpp
> 2011-06-29 18:01:02 UTC (rev 17823)
> @@ -5,7 +5,7 @@
> Copyright (C) 2008 Chris Kenyon
> Copyright (C) 2008 Roland Lichters
> Copyright (C) 2008 StatPro Italia srl
> - Copyright (C) 2009 Ferdinando Ametrano
> + Copyright (C) 2009, 2011 Ferdinando Ametrano
>
> This file is part of QuantLib, a free-software/open-source library
> for financial quantitative analysts and developers -
http://quantlib.org/> @@ -56,24 +56,37 @@
> static Real initialValue(const
> DefaultProbabilityTermStructure*) {
> return 1.0;
> }
> - // initial guess
> - static Real initialGuess() {
> - return 1.0/(1.0+detail::avgHazardRate*0.25);
> - }
> - // further guesses
> - static Real guess(const DefaultProbabilityTermStructure* c,
> - const Date& d) {
> +
> + // guesses
> + template <class C>
> + static Real guess(Size i,
> + const C* c,
> + bool validData) {
> + if (validData) // previous iteration value
> + return c->data()[i];
> +
> + if (i==1) // first pillar
> + return 1.0/(1.0+detail::avgHazardRate*0.25);
> +
> + // extrapolate
> + Date d = c->dates()[i];
> return c->survivalProbability(d,true);
> }
> +
> // possible constraints based on previous values
> - static Real minValueAfter(Size,
> - const std::vector<Real>&) {
> + template <class C>
> + static Real minValueAfter(Size i,
> + const C* c,
> + bool validData) {
> return QL_EPSILON;
> }
> + template <class C>
> static Real maxValueAfter(Size i,
> - const std::vector<Real>& data) {
> - return data[i-1];
> + const C* c,
> + bool validData) {
> + return c->data()[i-1];
> }
> +
> // update with new guess
> static void updateGuess(std::vector<Real>& data,
> Probability p,
> @@ -101,24 +114,39 @@
> static Real initialValue(const
> DefaultProbabilityTermStructure*) {
> return detail::avgHazardRate;
> }
> - // initial guess
> - static Real initialGuess() { return detail::avgHazardRate; }
> - // further guesses
> - static Real guess(const DefaultProbabilityTermStructure* c,
> - const Date& d) {
> +
> + // guesses
> + template <class C>
> + static Real guess(Size i,
> + const C* c,
> + bool validData) {
> + if (validData) // previous iteration value
> + return c->data()[i];
> +
> + if (i==1) // first pillar
> + return detail::avgHazardRate;
> +
> + // extrapolate
> + Date d = c->dates()[i];
> return c->hazardRate(d, true);
> }
> +
> // possible constraints based on previous values
> - static Real minValueAfter(Size,
> - const std::vector<Real>&) {
> + template <class C>
> + static Real minValueAfter(Size i,
> + const C* c,
> + bool validData) {
> return QL_EPSILON;
> }
> - static Real maxValueAfter(Size,
> - const std::vector<Real>&) {
> + template <class C>
> + static Real maxValueAfter(Size i,
> + const C* c,
> + bool validData) {
> // no constraints.
> // We choose as max a value very unlikely to be exceeded.
> return 200.0;
> }
> +
> // update with new guess
> static void updateGuess(std::vector<Real>& data,
> Real rate,
> @@ -148,24 +176,39 @@
> static Real initialValue(const
> DefaultProbabilityTermStructure*) {
> return detail::avgHazardRate;
> }
> - // initial guess
> - static Real initialGuess() { return detail::avgHazardRate; }
> - // further guesses
> - static Real guess(const DefaultProbabilityTermStructure* c,
> - const Date& d) {
> +
> + // guesses
> + template <class C>
> + static Real guess(Size i,
> + const C* c,
> + bool validData) {
> + if (validData) // previous iteration value
> + return c->data()[i];
> +
> + if (i==1) // first pillar
> + return detail::avgHazardRate;
> +
> + // extrapolate
> + Date d = c->dates()[i];
> return c->defaultDensity(d, true);
> }
> +
> // possible constraints based on previous values
> - static Real minValueAfter(Size,
> - const std::vector<Real>&) {
> + template <class C>
> + static Real minValueAfter(Size i,
> + const C* c,
> + bool validData) {
> return QL_EPSILON;
> }
> - static Real maxValueAfter(Size,
> - const std::vector<Real>&) {
> + template <class C>
> + static Real maxValueAfter(Size i,
> + const C* c,
> + bool validData) {
> // no constraints.
> // We choose as max a value very unlikely to be exceeded.
> return 3.0;
> }
> +
> // update with new guess
> static void updateGuess(std::vector<Real>& data,
> Real density,
> @@ -180,5 +223,4 @@
>
> }
>
> -
> #endif
>
> Modified: trunk/QuantLib/ql/termstructures/inflation/
> piecewiseyoyinflationcurve.hpp
> ===================================================================
> --- trunk/QuantLib/ql/termstructures/inflation/
> piecewiseyoyinflationcurve.hpp 2011-06-29 17:50:59 UTC (rev 17822)
> +++ trunk/QuantLib/ql/termstructures/inflation/
> piecewiseyoyinflationcurve.hpp 2011-06-29 18:01:02 UTC (rev 17823)
> @@ -3,6 +3,7 @@
> /*
> Copyright (C) 2007 Chris Kenyon
> Copyright (C) 2007, 2008 StatPro Italia srl
> + Copyright (C) 2011 Ferdinando Ametrano
>
> This file is part of QuantLib, a free-software/open-source library
> for financial quantitative analysts and developers -
http://quantlib.org/> @@ -49,18 +50,36 @@
> static Rate initialValue(const YoYInflationTermStructure* t) {
> return t->baseRate();
> }
> - static Rate initialGuess() { return 0.02; }
> - // further guesses
> - static Rate guess(const YoYInflationTermStructure*, const
> Date&) {
> +
> + // guesses
> + template <class C>
> + static Rate guess(Size i,
> + const C* c,
> + bool validData) {
> + if (validData) // previous iteration value
> + return c->data()[i];
> +
> + if (i==1) // first pillar
> + return 0.02; // initial guess at flat inflation
> +
> + // could/should extrapolate
> return 0.02; // initial guess at flat inflation
> }
> +
> // possible constraints based on previous values
> - static Rate minValueAfter(Size, const std::vector<Rate>&) {
> + template <class C>
> + static Rate minValueAfter(Size i,
> + const C* c,
> + bool validData) {
> return -0.3 + QL_EPSILON;
> }
> - static Rate maxValueAfter(Size, const std::vector<Rate>&) {
> + template <class C>
> + static Rate maxValueAfter(Size i,
> + const C* c,
> + bool validData) {
> return 0.5 - QL_EPSILON;
> }
> +
> // update with new guess
> static void updateGuess(std::vector<Rate>& data,
> Rate level,
>
> Modified: trunk/QuantLib/ql/termstructures/inflation/
> piecewisezeroinflationcurve.hpp
> ===================================================================
> --- trunk/QuantLib/ql/termstructures/inflation/
> piecewisezeroinflationcurve.hpp 2011-06-29 17:50:59 UTC (rev 17822)
> +++ trunk/QuantLib/ql/termstructures/inflation/
> piecewisezeroinflationcurve.hpp 2011-06-29 18:01:02 UTC (rev 17823)
> @@ -3,6 +3,7 @@
> /*
> Copyright (C) 2007 Chris Kenyon
> Copyright (C) 2007, 2008 StatPro Italia srl
> + Copyright (C) 2011 Ferdinando Ametrano
>
> This file is part of QuantLib, a free-software/open-source library
> for financial quantitative analysts and developers -
http://quantlib.org/> @@ -49,18 +50,36 @@
> static Rate initialValue(const ZeroInflationTermStructure*
> t) {
> return t->baseRate();
> }
> - static Rate initialGuess() { return 0.02; }
> - // further guesses
> - static Rate guess(const ZeroInflationTermStructure*, const
> Date&) {
> +
> + // guesses
> + template <class C>
> + static Rate guess(Size i,
> + const C* c,
> + bool validData) {
> + if (validData) // previous iteration value
> + return c->data()[i];
> +
> + if (i==1) // first pillar
> + return 0.02;
> +
> + // could/should extrapolate
> return 0.02; // initial guess at flat inflation
> }
> +
> // possible constraints based on previous values
> - static Real minValueAfter(Size, const std::vector<Rate>&) {
> + template <class C>
> + static Real minValueAfter(Size i,
> + const C* c,
> + bool validData) {
> return -0.1 + QL_EPSILON;
> }
> - static Real maxValueAfter(Size, const std::vector<Rate>&) {
> + template <class C>
> + static Real maxValueAfter(Size i,
> + const C* c,
> + bool validData) {
> return 0.3 - QL_EPSILON;
> }
> +
> // update with new guess
> static void updateGuess(std::vector<Rate>& data,
> Rate level,
> @@ -195,4 +214,3 @@
> }
>
> #endif
> -
>
> Modified: trunk/QuantLib/ql/termstructures/iterativebootstrap.hpp
> ===================================================================
> --- trunk/QuantLib/ql/termstructures/iterativebootstrap.hpp
> 2011-06-29 17:50:59 UTC (rev 17822)
> +++ trunk/QuantLib/ql/termstructures/iterativebootstrap.hpp
> 2011-06-29 18:01:02 UTC (rev 17823)
> @@ -114,7 +114,7 @@
> ts_->data_[0] = Traits::initialValue(ts_);
> // reasonable numbers needed for the starting
> interpolation
> for (Size i=1; i<alive_+1; ++i)
> - ts_->data_[i] = Traits::initialGuess();
> + ts_->data_[i] = Traits::guess(1, ts_, false);
> }
> initialized_ = true;
> }
> @@ -149,21 +149,18 @@
>
> bool validData = validCurve_ || iteration>0;
>
> - // bracket root
> - Real min = Traits::minValueAfter(i, ts_->data_);
> - Real max = Traits::maxValueAfter(i, ts_->data_);
> + // bracket root and calculate guess
> + Real min = Traits::minValueAfter(i, ts_, validData);
> + Real max = Traits::maxValueAfter(i, ts_, validData);
> + Real guess = Traits::guess(i, ts_, validData);
> + // adjust guess if needed
> + if (guess>=max)
> + guess = max - (max-min)/5.0;
> + else if (guess<=min)
> + guess = min + (max-min)/5.0;
>
> - // calculate guess and extend interpolation if needed
> - Real guess = 0.0;
> - if (validData) {
> - guess = ts_->data_[i]; // previous iteration
> value
> - } else {
> - if (i==1) // special first pillar case
> - guess = Traits::initialGuess();
> - else // most traits extrapolate (using only
> - // the curve bootstrapped so far)
> - guess = Traits::guess(ts_, ts_->dates_[i]);
> -
> + // extend interpolation if needed
> + if (!validData) {
> try { // extend interpolation a point at a time
> // including the pillar to be boostrapped
> ts_->interpolation_ = ts_-
> >interpolator_.interpolate(
> @@ -182,11 +179,6 @@
> ts_->interpolation_.update();
> }
> }
> - // adjust guess if needed
> - if (guess>=max)
> - guess = max - (max-min)/5.0;
> - else if (guess<=min)
> - guess = min + (max-min)/5.0;
>
> // the actual instrument used for the current pillar
> boost::shared_ptr<typename Traits::helper>
> instrument =
>
> Modified: trunk/QuantLib/ql/termstructures/localbootstrap.hpp
> ===================================================================
> --- trunk/QuantLib/ql/termstructures/localbootstrap.hpp 2011-06-29
> 17:50:59 UTC (rev 17822)
> +++ trunk/QuantLib/ql/termstructures/localbootstrap.hpp 2011-06-29
> 18:01:02 UTC (rev 17823)
> @@ -222,7 +222,7 @@
>
> if (iInst >= localisation_) {
> startArray[localisation_-dataAdjust] =
> - Traits::guess(ts_, ts_->dates_[iInst]);
> + Traits::guess(iInst, ts_, false); // ?
> } else {
> startArray[localisation_-dataAdjust] = ts_->data_[0];
> }
>
> Modified: trunk/QuantLib/ql/termstructures/yield/bootstraptraits.hpp
> ===================================================================
> --- trunk/QuantLib/ql/termstructures/yield/bootstraptraits.hpp
> 2011-06-29 17:50:59 UTC (rev 17822)
> +++ trunk/QuantLib/ql/termstructures/yield/bootstraptraits.hpp
> 2011-06-29 18:01:02 UTC (rev 17823)
> @@ -2,6 +2,7 @@
>
> /*
> Copyright (C) 2005, 2007 StatPro Italia srl
> + Copyright (C) 2011 Ferdinando Ametrano
> Copyright (C) 2007 Chris Kenyon
>
> This file is part of QuantLib, a free-software/open-source library
> @@ -46,6 +47,7 @@
> };
> // helper class
> typedef BootstrapHelper<YieldTermStructure> helper;
> +
> // start of curve data
> static Date initialDate(const YieldTermStructure* c) {
> return c->referenceDate();
> @@ -54,31 +56,44 @@
> static DiscountFactor initialValue(const
> YieldTermStructure*) {
> return 1.0;
> }
> - // initial guess
> - static DiscountFactor initialGuess() {
> - return 1.0/(1.0+detail::avgRate*0.25);
> - }
> - // further guesses
> - static DiscountFactor guess(const YieldTermStructure* c,
> - const Date& d) {
> +
> + // guesses
> + template <class C>
> + static DiscountFactor guess(Size i,
> + const C* c,
> + bool validData) {
> + if (validData) // previous iteration value
> + return c->data()[i];
> +
> + if (i==1) // first pillar
> + return 1.0/(1.0+detail::avgRate*0.25);
> +
> + // extrapolate
> + Date d = c->dates()[i];
> return c->discount(d,true);
> }
> +
> // possible constraints based on previous values
> - static DiscountFactor minValueAfter(Size,
> - const
> std::vector<Real>&) {
> + template <class C>
> + static DiscountFactor minValueAfter(Size i,
> + const C* c,
> + bool validData) {
> return QL_EPSILON;
> }
> + template <class C>
> static DiscountFactor maxValueAfter(Size i,
> - const
> std::vector<Real>& data) {
> + const C* c,
> + bool validData) {
> #if defined(QL_NEGATIVE_RATES)
> // discount are not required to be decreasing--all bets
> are off.
> // We choose as max a value very unlikely to be exceeded.
> return 1.1;
> #else
> // discounts cannot increase
> - return data[i-1];
> + return c->data()[i-1];
> #endif
> }
> +
> // update with new guess
> static void updateGuess(std::vector<DiscountFactor>& data,
> DiscountFactor discount,
> @@ -107,16 +122,29 @@
> static Rate initialValue(const YieldTermStructure*) {
> return detail::avgRate;
> }
> - // initial guess
> - static Rate initialGuess() { return detail::avgRate; }
> - // further guesses
> - static Rate guess(const YieldTermStructure* c,
> - const Date& d) {
> +
> + // guesses
> + template <class C>
> + static Rate guess(Size i,
> + const C* c,
> + bool validData) {
> + if (validData) // previous iteration value
> + return c->data()[i];
> +
> + if (i==1) // first pillar
> + return detail::avgRate;
> +
> + // extrapolate
> + Date d = c->dates()[i];
> return c->zeroRate(d, c->dayCounter(),
> Continuous, Annual, true);
> }
> +
> // possible constraints based on previous values
> - static Rate minValueAfter(Size, const std::vector<Real>&) {
> + template <class C>
> + static Rate minValueAfter(Size i,
> + const C* c,
> + bool validData) {
> #if defined(QL_NEGATIVE_RATES)
> // no constraints.
> // We choose as min a value very unlikely to be exceeded.
> @@ -125,11 +153,15 @@
> return QL_EPSILON;
> #endif
> }
> - static Rate maxValueAfter(Size, const std::vector<Real>&) {
> + template <class C>
> + static Rate maxValueAfter(Size i,
> + const C* c,
> + bool validData) {
> // no constraints.
> // We choose as max a value very unlikely to be exceeded.
> return detail::maxRate;
> }
> +
> // update with new guess
> static void updateGuess(std::vector<Rate>& data,
> Rate rate,
> @@ -160,16 +192,29 @@
> static Rate initialValue(const YieldTermStructure*) {
> return detail::avgRate;
> }
> - // initial guess
> - static Rate initialGuess() { return detail::avgRate; }
> - // further guesses
> - static Rate guess(const YieldTermStructure* c,
> - const Date& d) {
> +
> + // guesses
> + template <class C>
> + static Rate guess(Size i,
> + const C* c,
> + bool validData) {
> + if (validData) // previous iteration value
> + return c->data()[i];
> +
> + if (i==1) // first pillar
> + return detail::avgRate;
> +
> + // extrapolate
> + Date d = c->dates()[i];
> return c->forwardRate(d, d, c->dayCounter(),
> Continuous, Annual, true);
> }
> +
> // possible constraints based on previous values
> - static Rate minValueAfter(Size, const std::vector<Real>&) {
> + template <class C>
> + static Rate minValueAfter(Size i,
> + const C* c,
> + bool validData) {
> #if defined(QL_NEGATIVE_RATES)
> // no constraints.
> // We choose as min a value very unlikely to be exceeded.
> @@ -178,11 +223,15 @@
> return QL_EPSILON;
> #endif
> }
> - static Rate maxValueAfter(Size, const std::vector<Real>&) {
> + template <class C>
> + static Rate maxValueAfter(Size i,
> + const C* c,
> + bool validData) {
> // no constraints.
> // We choose as max a value very unlikely to be exceeded.
> return detail::maxRate;
> }
> +
> // update with new guess
> static void updateGuess(std::vector<Rate>& data,
> Rate forward,
>
>
> This was sent by the SourceForge.net collaborative development
> platform, the world's largest Open Source development site.
>
> ------------------------------------------------------------------------------
> All of the data generated in your IT infrastructure is seriously
> valuable.
> Why? It contains a definitive record of application performance,
> security
> threats, fraudulent activity, and more. Splunk takes this data and
> makes
> sense of it. IT sense. And common sense.
>
http://p.sf.net/sfu/splunk-d2d-c2> _______________________________________________
> QuantLib-cvs mailing list
>
[hidden email]
>
https://lists.sourceforge.net/lists/listinfo/quantlib-cvsthreats, fraudulent activity, and more. Splunk takes this data and makes
sense of it. IT sense. And common sense.