Coverage Report

Created: 2026-02-03 07:02

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/quantlib/ql/instruments/varianceswap.hpp
Line
Count
Source
1
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3
/*
4
 Copyright (C) 2006 Warren Chou
5
 Copyright (C) 2008 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 varianceswap.hpp
22
    \brief Variance swap
23
*/
24
25
#ifndef quantlib_variance_swap_hpp
26
#define quantlib_variance_swap_hpp
27
28
#include <ql/processes/blackscholesprocess.hpp>
29
#include <ql/instruments/payoffs.hpp>
30
#include <ql/option.hpp>
31
#include <ql/position.hpp>
32
33
namespace QuantLib {
34
35
    //! Variance swap
36
    /*! \warning This class does not manage seasoned variance swaps.
37
38
        \ingroup instruments
39
    */
40
    class VarianceSwap : public Instrument {
41
      public:
42
        class arguments;
43
        class results;
44
        class engine;
45
        VarianceSwap(Position::Type position,
46
                     Real strike,
47
                     Real notional,
48
                     const Date& startDate,
49
                     const Date& maturityDate);
50
        //! \name Instrument interface
51
        //@{
52
        bool isExpired() const override;
53
        //@}
54
        //! \name Additional interface
55
        //@{
56
        // inspectors
57
        Real strike() const;
58
        Position::Type position() const;
59
        Date startDate() const;
60
        Date maturityDate() const;
61
        Real notional() const;
62
        // results
63
        Real variance() const;
64
        //@}
65
        // other
66
        void setupArguments(PricingEngine::arguments* args) const override;
67
        void fetchResults(const PricingEngine::results*) const override;
68
69
      protected:
70
        void setupExpired() const override;
71
        // data members
72
        Position::Type position_;
73
        Real strike_;
74
        Real notional_;
75
        Date startDate_, maturityDate_;
76
        // results
77
        mutable Real variance_;
78
    };
79
80
81
    //! %Arguments for forward fair-variance calculation
82
    class VarianceSwap::arguments : public virtual PricingEngine::arguments {
83
      public:
84
0
        arguments() : strike(Null<Real>()), notional(Null<Real>()) {}
85
        void validate() const override;
86
        Position::Type position;
87
        Real strike;
88
        Real notional;
89
        Date startDate;
90
        Date maturityDate;
91
    };
92
93
94
    //! %Results from variance-swap calculation
95
    class VarianceSwap::results : public Instrument::results {
96
      public:
97
        Real variance;
98
0
        void reset() override {
99
0
            Instrument::results::reset();
100
0
            variance = Null<Real>();
101
0
        }
102
    };
103
104
    //! base class for variance-swap engines
105
    class VarianceSwap::engine :
106
        public GenericEngine<VarianceSwap::arguments,
107
                             VarianceSwap::results> {};
108
109
110
    // inline definitions
111
112
0
    inline Date VarianceSwap::startDate() const {
113
0
        return startDate_;
114
0
    }
115
116
0
    inline Date VarianceSwap::maturityDate() const {
117
0
        return maturityDate_;
118
0
    }
119
120
0
    inline Real VarianceSwap::strike() const {
121
0
        return strike_;
122
0
    }
123
124
0
    inline Real VarianceSwap::notional() const {
125
0
        return notional_;
126
0
    }
127
128
0
    inline Position::Type VarianceSwap::position() const {
129
0
        return position_;
130
0
    }
131
132
}
133
134
135
#endif