QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
cliquetoption.cpp
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 <http://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
24namespace QuantLib {
25
26 CliquetOption::CliquetOption(const ext::shared_ptr<PercentageStrikePayoff>& payoff,
27 const ext::shared_ptr<EuropeanExercise>& maturity,
28 std::vector<Date> resetDates)
29 : OneAssetOption(payoff, maturity), resetDates_(std::move(resetDates)) {}
30
33 // set accrued coupon, last fixing, caps, floors
34 auto* moreArgs = dynamic_cast<CliquetOption::arguments*>(args);
35 QL_REQUIRE(moreArgs != nullptr, "wrong engine type");
36 moreArgs->resetDates = resetDates_;
37 }
38
40 OneAssetOption::arguments::validate();
41
42 ext::shared_ptr<PercentageStrikePayoff> moneyness =
43 ext::dynamic_pointer_cast<PercentageStrikePayoff>(payoff);
44 QL_REQUIRE(moneyness,
45 "wrong payoff type");
46 QL_REQUIRE(moneyness->strike() > 0.0,
47 "negative or zero moneyness given");
48 QL_REQUIRE(accruedCoupon == Null<Real>() || accruedCoupon >= 0.0,
49 "negative accrued coupon");
50 QL_REQUIRE(localCap == Null<Real>() || localCap >= 0.0,
51 "negative local cap");
52 QL_REQUIRE(localFloor == Null<Real>() || localFloor >= 0.0,
53 "negative local floor");
54 QL_REQUIRE(globalCap == Null<Real>() || globalCap >= 0.0,
55 "negative global cap");
56 QL_REQUIRE(globalFloor == Null<Real>() || globalFloor >= 0.0,
57 "negative global floor");
58 QL_REQUIRE(!resetDates.empty(),
59 "no reset dates given");
60 for (Size i=0; i<resetDates.size(); ++i) {
61 QL_REQUIRE(exercise->lastDate() > resetDates[i],
62 "reset date greater or equal to maturity");
63 QL_REQUIRE(i == 0 || resetDates[i] > resetDates[i-1],
64 "unsorted reset dates");
65 }
66 }
67
68}
Arguments for cliquet option calculation
void setupArguments(PricingEngine::arguments *) const override
CliquetOption(const ext::shared_ptr< PercentageStrikePayoff > &, const ext::shared_ptr< EuropeanExercise > &maturity, std::vector< Date > resetDates)
std::vector< Date > resetDates_
virtual void setupArguments(PricingEngine::arguments *) const
Definition: instrument.cpp:45
template class providing a null value for a given type.
Definition: null.hpp:76
Base class for options on a single asset.
ext::shared_ptr< Payoff > payoff() const
Definition: option.hpp:45
ext::shared_ptr< Exercise > exercise() const
Definition: option.hpp:46
std::size_t Size
size of a container
Definition: types.hpp:58
Definition: any.hpp:35
STL namespace.