Coverage Report

Created: 2026-06-08 06:47

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/quantlib/ql/experimental/inflation/yoyoptionlethelpers.cpp
Line
Count
Source
1
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3
/*
4
 Copyright (C) 2009 Chris Kenyon
5
6
 This file is part of QuantLib, a free-software/open-source library
7
 for financial quantitative analysts and developers - http://quantlib.org/
8
9
 QuantLib is free software: you can redistribute it and/or modify it
10
 under the terms of the QuantLib license.  You should have received a
11
 copy of the license along with this program; if not, please email
12
 <quantlib-dev@lists.sf.net>. The license is also available online at
13
 <https://www.quantlib.org/license.shtml>.
14
15
 This program is distributed in the hope that it will be useful, but WITHOUT
16
 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17
 FOR A PARTICULAR PURPOSE.  See the license for more details.
18
*/
19
20
#include <ql/experimental/inflation/yoyoptionlethelpers.hpp>
21
#include <ql/instruments/makeyoyinflationcapfloor.hpp>
22
#include <ql/utilities/null_deleter.hpp>
23
#include <utility>
24
25
namespace QuantLib {
26
27
    YoYOptionletHelper::YoYOptionletHelper(const Handle<Quote>& price,
28
                                           Real notional,
29
                                           YoYInflationCapFloor::Type capFloorType,
30
                                           Period& lag,
31
                                           DayCounter yoyDayCounter,
32
                                           Calendar paymentCalendar,
33
                                           Natural fixingDays,
34
                                           ext::shared_ptr<YoYInflationIndex> index,
35
                                           CPI::InterpolationType interpolation,
36
                                           Rate strike,
37
                                           Size n,
38
                                           ext::shared_ptr<YoYInflationCapFloorEngine> pricer)
39
0
    : BootstrapHelper<YoYOptionletVolatilitySurface>(price), notional_(notional),
40
0
      capFloorType_(capFloorType), lag_(lag), fixingDays_(fixingDays), index_(std::move(index)),
41
0
      strike_(strike), n_(n), yoyDayCounter_(std::move(yoyDayCounter)),
42
0
      calendar_(std::move(paymentCalendar)), pricer_(std::move(pricer)) {
43
44
        // build the instrument to reprice (only need do this once)
45
0
        yoyCapFloor_ =
46
0
            MakeYoYInflationCapFloor(capFloorType_, index_,
47
0
                                     n_, calendar_, lag_, interpolation)
48
0
            .withNominal(notional)
49
0
            .withFixingDays(fixingDays_)
50
0
            .withPaymentDayCounter(yoyDayCounter_)
51
0
            .withStrike(strike_);
52
53
        // dates already build in lag of index/instrument
54
        // these are the dates of the values of the index
55
        // that fix the capfloor
56
0
          earliestDate_ = ext::dynamic_pointer_cast<YoYInflationCoupon>(
57
0
              yoyCapFloor_->yoyLeg().front())->fixingDate();
58
0
          latestDate_ = ext::dynamic_pointer_cast<YoYInflationCoupon>(
59
0
              yoyCapFloor_->yoyLeg().back())->fixingDate();
60
61
        // each reprice is resetting the inflation surf in the
62
        // pricer... so set the pricer
63
0
        yoyCapFloor_->setPricingEngine(pricer_);
64
        // haven't yet set the vol (term structure = surface)
65
0
    }
66
67
68
0
    Real YoYOptionletHelper::impliedQuote() const {
69
0
        yoyCapFloor_->deepUpdate();
70
0
        return yoyCapFloor_->NPV();
71
0
    }
72
73
74
    void YoYOptionletHelper::setTermStructure(
75
0
                                           YoYOptionletVolatilitySurface* v) {
76
77
0
        BootstrapHelper<YoYOptionletVolatilitySurface>::setTermStructure(v);
78
        // set up a new yoyCapFloor
79
        // but this one does NOT own its inflation term structure
80
0
        const bool own = false;
81
        // create a handle to the new vol surface
82
0
        Handle<YoYOptionletVolatilitySurface> volSurf(
83
0
            ext::shared_ptr<YoYOptionletVolatilitySurface>(v, null_deleter()),
84
0
            own);
85
        // in this case all we need to do is reset the vol in the pricer
86
        // we must do it because the surface is a different one each time
87
        // i.e. the pointer (handle) changes, not just what it points to
88
0
        pricer_->setVolatility(volSurf);
89
0
    }
90
91
}
92