Coverage Report

Created: 2026-06-23 06:40

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/quantlib/ql/instruments/cliquetoption.cpp
Line
Count
Source
1
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3
/*
4
 Copyright (C) 2004, 2007 StatPro Italia srl
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/exercise.hpp>
21
#include <ql/instruments/cliquetoption.hpp>
22
#include <utility>
23
24
namespace QuantLib {
25
26
    CliquetOption::CliquetOption(const ext::shared_ptr<PercentageStrikePayoff>& payoff,
27
                                 const ext::shared_ptr<EuropeanExercise>& maturity,
28
                                 std::vector<Date> resetDates)
29
0
    : OneAssetOption(payoff, maturity), resetDates_(std::move(resetDates)) {}
Unexecuted instantiation: QuantLib::CliquetOption::CliquetOption(boost::shared_ptr<QuantLib::PercentageStrikePayoff> const&, boost::shared_ptr<QuantLib::EuropeanExercise> const&, std::__1::vector<QuantLib::Date, std::__1::allocator<QuantLib::Date> >)
Unexecuted instantiation: QuantLib::CliquetOption::CliquetOption(boost::shared_ptr<QuantLib::PercentageStrikePayoff> const&, boost::shared_ptr<QuantLib::EuropeanExercise> const&, std::__1::vector<QuantLib::Date, std::__1::allocator<QuantLib::Date> >)
30
31
0
    void CliquetOption::setupArguments(PricingEngine::arguments* args) const {
32
0
        OneAssetOption::setupArguments(args);
33
        // set accrued coupon, last fixing, caps, floors
34
0
        auto* moreArgs = dynamic_cast<CliquetOption::arguments*>(args);
35
0
        QL_REQUIRE(moreArgs != nullptr, "wrong engine type");
36
0
        moreArgs->resetDates = resetDates_;
37
0
    }
38
39
0
    void CliquetOption::arguments::validate() const {
40
0
        OneAssetOption::arguments::validate();
41
42
0
        ext::shared_ptr<PercentageStrikePayoff> moneyness =
43
0
            ext::dynamic_pointer_cast<PercentageStrikePayoff>(payoff);
44
0
        QL_REQUIRE(moneyness,
45
0
                   "wrong payoff type");
46
0
        QL_REQUIRE(moneyness->strike() > 0.0,
47
0
                   "negative or zero moneyness given");
48
0
        QL_REQUIRE(accruedCoupon == Null<Real>() || accruedCoupon >= 0.0,
49
0
                   "negative accrued coupon");
50
0
        QL_REQUIRE(localCap == Null<Real>() || localCap >= 0.0,
51
0
                   "negative local cap");
52
0
        QL_REQUIRE(localFloor == Null<Real>() || localFloor >= 0.0,
53
0
                   "negative local floor");
54
0
        QL_REQUIRE(globalCap == Null<Real>() || globalCap >= 0.0,
55
0
                   "negative global cap");
56
0
        QL_REQUIRE(globalFloor == Null<Real>() || globalFloor >= 0.0,
57
0
                   "negative global floor");
58
0
        QL_REQUIRE(!resetDates.empty(),
59
0
                   "no reset dates given");
60
0
        for (Size i=0; i<resetDates.size(); ++i) {
61
0
            QL_REQUIRE(exercise->lastDate() > resetDates[i],
62
0
                       "reset date greater or equal to maturity");
63
0
            QL_REQUIRE(i == 0 || resetDates[i] > resetDates[i-1],
64
0
                       "unsorted reset dates");
65
0
        }
66
0
    }
67
68
}