28 const Date& referenceDate,
30 const ext::shared_ptr<IborIndex>& iborIdx)
const {
32 QL_REQUIRE(iborIdx !=
nullptr,
"no ibor index given");
37 return iborIdx->fixing(fixing);
42 Date valueDate = iborIdx->valueDate(fixing);
44 valueDate, iborIdx->tenor(), iborIdx->businessDayConvention(), iborIdx->
endOfMonth());
46 Real dcf = iborIdx->dayCounter().yearFraction(valueDate, endDate);
48 return (
zerobond(valueDate, referenceDate,
y, yts) -
49 zerobond(endDate, referenceDate,
y, yts)) /
50 (dcf *
zerobond(endDate, referenceDate,
y, yts));
55 const Date& referenceDate,
57 const ext::shared_ptr<SwapIndex>& swapIdx)
const {
59 QL_REQUIRE(swapIdx !=
nullptr,
"no swap index given");
64 return swapIdx->fixing(fixing);
67 swapIdx->iborIndex()->forwardingTermStructure();
69 swapIdx->discountingTermStructure();
74 ext::shared_ptr<VanillaSwap> underlying =
77 sched = underlying->fixedSchedule();
79 ext::shared_ptr<OvernightIndexedSwapIndex> oisIdx =
80 ext::dynamic_pointer_cast<OvernightIndexedSwapIndex>(swapIdx);
81 if (oisIdx !=
nullptr) {
84 floatSched = underlying->floatingSchedule();
97 underlying->paymentConvention()),
100 for (
Size i = 1; i < floatSched.
size(); i++) {
102 (
zerobond(floatSched[i - 1], referenceDate,
y, ytsf) /
103 zerobond(floatSched[i], referenceDate,
y, ytsf) -
106 floatSched[i], underlying->paymentConvention()),
107 referenceDate,
y, ytsd);
110 return floatleg / annuity;
115 const Date& referenceDate,
117 const ext::shared_ptr<SwapIndex>& swapIdx)
const {
119 QL_REQUIRE(swapIdx !=
nullptr,
"no swap index given");
124 swapIdx->discountingTermStructure();
127 ext::shared_ptr<VanillaSwap> underlying =
130 Schedule sched = underlying->fixedSchedule();
133 for (
unsigned int j = 1; j < sched.
size(); j++) {
135 sched.
date(j), underlying->paymentConvention()),
136 referenceDate,
y, ytsd) *
137 swapIdx->dayCounter().yearFraction(sched.
date(j - 1),
145 const Date &maturity,
const Rate strike,
const Date &referenceDate,
147 const Size yGridPoints,
const bool extrapolatePayoff,
148 const bool flatPayoffExtrapolation)
const {
158 Array yg =
yGrid(yStdDevs, yGridPoints, fixingTime, referenceTime,
y);
163 for (
Size i = 0; i < yg.
size(); i++) {
164 Real expValDsc =
zerobond(valueDate, expiry, yg[i], yts);
166 zerobond(maturity, expiry, yg[i], yts) / expValDsc;
168 std::max((type ==
Option::Call ? 1.0 : -1.0) * (discount - strike),
170 numeraire(fixingTime, yg[i], yts) * expValDsc;
178 for (
Size i = 0; i < z.
size() - 1; i++) {
180 0.0,
payoff.cCoefficients()[i],
payoff.bCoefficients()[i],
181 payoff.aCoefficients()[i], p[i], z[i], z[i], z[i + 1]);
183 if (extrapolatePayoff) {
184 if (flatPayoffExtrapolation) {
186 0.0, 0.0, 0.0, 0.0, p[z.
size() - 2], z[z.
size() - 2],
187 z[z.
size() - 1], 100.0);
196 z[z.
size() - 2], z[z.
size() - 1], 100.0);
199 0.0,
payoff.cCoefficients()[0],
payoff.bCoefficients()[0],
200 payoff.aCoefficients()[0], p[0], z[0], -100.0, z[0]);
204 return numeraire(referenceTime,
y, yts) * price;
211#ifdef GAUSS1D_ENABLE_NTL
212 const boost::math::ntl::RR aa = 4.0 * a, ba = 2.0 *
M_SQRT2 *
b,
215 const boost::math::ntl::RR res =
216 (0.125 * (3.0 * aa + 2.0 * ca + 4.0 * e) * std::erf(x1) -
217 1.0 / (4.0 *
M_SQRTPI) * std::exp(-x1 * x1) *
218 (2.0 * aa * x1 * x1 * x1 + 3.0 * aa * x1 +
219 2.0 * ba * (x1 * x1 + 1.0) + 2.0 * ca * x1 + 2.0 * da)) -
220 (0.125 * (3.0 * aa + 2.0 * ca + 4.0 * e) * std::erf(x0) -
221 1.0 / (4.0 *
M_SQRTPI) * std::exp(-x0 * x0) *
222 (2.0 * aa * x0 * x0 * x0 + 3.0 * aa * x0 +
223 2.0 * ba * (x0 * x0 + 1.0) + 2.0 * ca * x0 + 2.0 * da));
224 return NTL::to_double(res.value());
226 const Real aa = 4.0 * a, ba = 2.0 *
M_SQRT2 *
b, ca = 2.0 * c,
229 return (0.125 * (3.0 * aa + 2.0 * ca + 4.0 * e) * std::erf(x1) -
230 1.0 / (4.0 *
M_SQRTPI) * std::exp(-x1 * x1) *
231 (2.0 * aa * x1 * x1 * x1 + 3.0 * aa * x1 +
232 2.0 * ba * (x1 * x1 + 1.0) + 2.0 * ca * x1 + 2.0 * da)) -
233 (0.125 * (3.0 * aa + 2.0 * ca + 4.0 * e) * std::erf(x0) -
234 1.0 / (4.0 *
M_SQRTPI) * std::exp(-x0 * x0) *
235 (2.0 * aa * x0 * x0 * x0 + 3.0 * aa * x0 +
236 2.0 * ba * (x0 * x0 + 1.0) + 2.0 * ca * x0 + 2.0 * da));
244 a, -4.0 * a * h +
b, 6.0 * a * h * h - 3.0 *
b * h + c,
245 -4 * a * h * h * h + 3.0 *
b * h * h - 2.0 * c * h +
d,
246 a * h * h * h * h -
b * h * h * h + c * h * h -
d * h + e, x0, x1);
250 const Real stdDevs,
const int gridPoints,
const Real T,
const Real t,
const Real y)
const {
256 Array result(2 * gridPoints + 1, 0.0);
258 Real x_t, e_0_t, e_t_T, stdDev_0_t, stdDev_t_T;
264 stdDev_t_T = stdDev_0_T;
272 x_t =
y * stdDev_0_t + e_0_t;
276 Real h = stdDevs / ((
Real)gridPoints);
278 for (
int j = -gridPoints; j <= gridPoints; j++) {
279 result[j + gridPoints] =
280 (e_t_T + stdDev_t_T * ((
Real)j) * h - e_0_T) / stdDev_0_T;
1-D array used in linear algebra.
const_iterator end() const
Size size() const
dimension of the array
const_iterator begin() const
Date adjust(const Date &, BusinessDayConvention convention=Following) const
Cubic interpolation between discrete points.
static Date endOfMonth(const Date &d)
last day of the month to which the given date belongs
static Date advance(const Date &d, Integer units, TimeUnit)
static Real gaussianPolynomialIntegral(Real a, Real b, Real c, Real d, Real e, Real x0, Real x1)
static Real gaussianShiftedPolynomialIntegral(Real a, Real b, Real c, Real d, Real e, Real h, Real x0, Real x1)
ext::shared_ptr< VanillaSwap > underlyingSwap(const ext::shared_ptr< SwapIndex > &index, const Date &expiry, const Period &tenor) const
Real numeraire(Time t, Real y=0.0, const Handle< YieldTermStructure > &yts=Handle< YieldTermStructure >()) const
Real swapRate(const Date &fixing, const Period &tenor, const Date &referenceDate=Null< Date >(), Real y=0.0, const ext::shared_ptr< SwapIndex > &swapIdx=ext::shared_ptr< SwapIndex >()) const
Array yGrid(Real yStdDevs, int gridPoints, Real T=1.0, Real t=0, Real y=0) const
Real forwardRate(const Date &fixing, const Date &referenceDate=Null< Date >(), Real y=0.0, const ext::shared_ptr< IborIndex > &iborIdx=ext::shared_ptr< IborIndex >()) const
bool enforcesTodaysHistoricFixings_
Real zerobond(Time T, Time t=0.0, Real y=0.0, const Handle< YieldTermStructure > &yts=Handle< YieldTermStructure >()) const
Real zerobondOption(const Option::Type &type, const Date &expiry, const Date &valueDate, const Date &maturity, Rate strike, const Date &referenceDate=Null< Date >(), Real y=0.0, const Handle< YieldTermStructure > &yts=Handle< YieldTermStructure >(), Real yStdDevs=7.0, Size yGridPoints=64, bool extrapolatePayoff=true, bool flatPayoffExtrapolation=false) const
Real swapAnnuity(const Date &fixing, const Period &tenor, const Date &referenceDate=Null< Date >(), Real y=0.0, const ext::shared_ptr< SwapIndex > &swapIdx=ext::shared_ptr< SwapIndex >()) const
ext::shared_ptr< StochasticProcess1D > stateProcess_
Shared handle to an observable.
bool empty() const
checks if the contained shared pointer points to anything
virtual void calculate() const
template class providing a null value for a given type.
const Calendar & calendar() const
const std::vector< Date > & dates() const
const Date & date(Size i) const
const Handle< YieldTermStructure > & termStructure() const
cubic interpolation between discrete points
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
ext::function< Real(Real)> b
basic interface for one factor interest rate models
Real Time
continuous quantity with 1-year units
std::size_t Size
size of a container
ext::shared_ptr< QuantLib::Payoff > payoff