Coverage Report

Created: 2025-08-28 06:30

/src/quantlib/ql/experimental/varianceoption/varianceoption.hpp
Line
Count
Source (jump to first uncovered line)
1
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3
/*
4
 Copyright (C) 2008 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
/*! \file varianceoption.hpp
21
    \brief Variance option
22
*/
23
24
#ifndef quantlib_variance_option_hpp
25
#define quantlib_variance_option_hpp
26
27
#include <ql/processes/blackscholesprocess.hpp>
28
#include <ql/instruments/payoffs.hpp>
29
#include <ql/option.hpp>
30
#include <ql/position.hpp>
31
32
namespace QuantLib {
33
34
    //! Variance option
35
    /*! \warning This class does not manage seasoned variance options.
36
37
        \ingroup instruments
38
    */
39
    class VarianceOption : public Instrument {
40
      public:
41
        class arguments;
42
        class results;
43
        class engine;
44
        VarianceOption(ext::shared_ptr<Payoff> payoff,
45
                       Real notional,
46
                       const Date& startDate,
47
                       const Date& maturityDate);
48
        //! \name Instrument interface
49
        //@{
50
        bool isExpired() const override;
51
        //@}
52
        //! \name Inspectors
53
        //@{
54
        Date startDate() const;
55
        Date maturityDate() const;
56
        Real notional() const;
57
        ext::shared_ptr<Payoff> payoff() const;
58
        //@}
59
        void setupArguments(PricingEngine::arguments* args) const override;
60
61
      protected:
62
        // data members
63
        ext::shared_ptr<Payoff> payoff_;
64
        Real notional_;
65
        Date startDate_, maturityDate_;
66
    };
67
68
69
    //! %Arguments for forward fair-variance calculation
70
    class VarianceOption::arguments : public virtual PricingEngine::arguments {
71
      public:
72
0
        arguments() : notional(Null<Real>()) {}
73
        void validate() const override;
74
        ext::shared_ptr<Payoff> payoff;
75
        Real notional;
76
        Date startDate;
77
        Date maturityDate;
78
    };
79
80
81
    //! %Results from variance-option calculation
82
    class VarianceOption::results : public Instrument::results {};
83
84
    //! base class for variance-option engines
85
    class VarianceOption::engine :
86
        public GenericEngine<VarianceOption::arguments,
87
                             VarianceOption::results> {};
88
89
90
    // inline definitions
91
92
0
    inline Date VarianceOption::startDate() const {
93
0
        return startDate_;
94
0
    }
95
96
0
    inline Date VarianceOption::maturityDate() const {
97
0
        return maturityDate_;
98
0
    }
99
100
0
    inline Real VarianceOption::notional() const {
101
0
        return notional_;
102
0
    }
103
104
0
    inline ext::shared_ptr<Payoff> VarianceOption::payoff() const {
105
0
        return payoff_;
106
0
    }
107
108
}
109
110
111
#endif