1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
#ifndef quantlib_spread_bootstrap_traits_hpp
#define quantlib_spread_bootstrap_traits_hpp
#include <ql/termstructures/yield/bootstraptraits.hpp>
#include <ql/termstructures/yield/spreaddiscountcurve.hpp>
namespace QuantLib::detail {
template <class Traits>
struct SpreadTraits;
//! Spread Discount-curve traits
template <>
struct SpreadTraits<Discount> : Discount {
// interpolated curve type
template <class Interpolator>
struct curve {
typedef InterpolatedSpreadDiscountCurve<Interpolator> type;
};
// guesses
template <class C>
static Real guess(Size i,
const C* c,
bool validData,
Size) // firstAliveHelper
{
if (validData) // previous iteration value
return c->data()[i];
if (i == 1) // first pillar
// Discount::guess() defaults to 5% initial guess, which would
// mean 5% rate difference for spreads. We instead default to
// guessing that there's no difference from the base curve.
return 1.0;
// flat rate extrapolation
Real r = -std::log(c->data()[i-1])/c->times()[i-1];
return std::exp(-r * c->times()[i]);
}
};
}
#endif
|