Coverage Report

Created: 2026-01-25 06:59

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/quantlib/ql/instruments/forwardvanillaoption.hpp
Line
Count
Source
1
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3
/*
4
 Copyright (C) 2002, 2003 Ferdinando Ametrano
5
 Copyright (C) 2007 StatPro Italia srl
6
7
 This file is part of QuantLib, a free-software/open-source library
8
 for financial quantitative analysts and developers - http://quantlib.org/
9
10
 QuantLib is free software: you can redistribute it and/or modify it
11
 under the terms of the QuantLib license.  You should have received a
12
 copy of the license along with this program; if not, please email
13
 <quantlib-dev@lists.sf.net>. The license is also available online at
14
 <https://www.quantlib.org/license.shtml>.
15
16
 This program is distributed in the hope that it will be useful, but WITHOUT
17
 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18
 FOR A PARTICULAR PURPOSE.  See the license for more details.
19
*/
20
21
/*! \file forwardvanillaoption.hpp
22
    \brief Forward version of a vanilla option
23
*/
24
25
#ifndef quantlib_forward_vanilla_option_hpp
26
#define quantlib_forward_vanilla_option_hpp
27
28
#include <ql/instruments/oneassetoption.hpp>
29
#include <ql/instruments/payoffs.hpp>
30
#include <ql/exercise.hpp>
31
#include <ql/settings.hpp>
32
33
namespace QuantLib {
34
35
    //! %Arguments for forward (strike-resetting) option calculation
36
    template <class ArgumentsType>
37
    class ForwardOptionArguments : public ArgumentsType {
38
      public:
39
0
        ForwardOptionArguments() : moneyness(Null<Real>()) {}
40
        void validate() const override;
41
        Real moneyness;
42
        Date resetDate;
43
    };
44
45
    //! %Forward version of a vanilla option
46
    /*! \ingroup instruments */
47
    class ForwardVanillaOption : public OneAssetOption {
48
      public:
49
        typedef ForwardOptionArguments<OneAssetOption::arguments> arguments;
50
        typedef OneAssetOption::results results;
51
        ForwardVanillaOption(Real moneyness,
52
                             const Date& resetDate,
53
                             const ext::shared_ptr<StrikedTypePayoff>& payoff,
54
                             const ext::shared_ptr<Exercise>& exercise);
55
        void setupArguments(PricingEngine::arguments*) const override;
56
        void fetchResults(const PricingEngine::results*) const override;
57
58
      private:
59
        // arguments
60
        Real moneyness_;
61
        Date resetDate_;
62
    };
63
64
65
    // template definitions
66
67
    template <class ArgumentsType>
68
0
    inline void ForwardOptionArguments<ArgumentsType>::validate() const {
69
0
        ArgumentsType::validate();
70
71
0
        QL_REQUIRE(moneyness != Null<Real>(), "null moneyness given");
72
0
        QL_REQUIRE(moneyness > 0.0, "negative or zero moneyness given");
73
74
0
        QL_REQUIRE(resetDate != Date(), "null reset date given");
75
0
        QL_REQUIRE(resetDate >= Settings::instance().evaluationDate(),
76
0
                   "reset date in the past");
77
0
        QL_REQUIRE(this->exercise->lastDate() > resetDate,
78
0
                   "reset date later or equal to maturity");
79
0
    }
80
81
82
}
83
84
85
#endif
86