Coverage Report

Created: 2025-08-28 06:30

/src/quantlib/ql/instruments/varianceswap.cpp
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) 2006 Warren Chou
5
 Copyright (C) 2007, 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
 <http://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
#include <ql/instruments/varianceswap.hpp>
22
#include <ql/event.hpp>
23
24
namespace QuantLib {
25
26
    VarianceSwap::VarianceSwap(
27
                          Position::Type position,
28
                          Real strike,
29
                          Real notional,
30
                          const Date& startDate,
31
                          const Date& maturityDate)
32
0
    : position_(position), strike_(strike), notional_(notional),
33
0
      startDate_(startDate), maturityDate_(maturityDate) {}
Unexecuted instantiation: QuantLib::VarianceSwap::VarianceSwap(QuantLib::Position::Type, double, double, QuantLib::Date const&, QuantLib::Date const&)
Unexecuted instantiation: QuantLib::VarianceSwap::VarianceSwap(QuantLib::Position::Type, double, double, QuantLib::Date const&, QuantLib::Date const&)
34
35
0
    Real VarianceSwap::variance() const {
36
0
        calculate();
37
0
        QL_REQUIRE(variance_ != Null<Real>(), "result not available");
38
0
        return variance_;
39
0
    }
40
41
0
    void VarianceSwap::setupExpired() const {
42
0
        Instrument::setupExpired();
43
0
        variance_ = Null<Real>();
44
0
    }
45
46
0
    void VarianceSwap::setupArguments(PricingEngine::arguments* args) const {
47
0
        auto* arguments = dynamic_cast<VarianceSwap::arguments*>(args);
48
0
        QL_REQUIRE(arguments != nullptr, "wrong argument type");
49
50
0
        arguments->position = position_;
51
0
        arguments->strike = strike_;
52
0
        arguments->notional = notional_;
53
0
        arguments->startDate = startDate_;
54
0
        arguments->maturityDate = maturityDate_;
55
0
    }
56
57
0
    void VarianceSwap::fetchResults(const PricingEngine::results* r) const {
58
0
        Instrument::fetchResults(r);
59
0
        const auto* results = dynamic_cast<const VarianceSwap::results*>(r);
60
0
        variance_ = results->variance;
61
0
    }
62
63
0
    void VarianceSwap::arguments::validate() const {
64
0
        QL_REQUIRE(strike != Null<Real>(), "no strike given");
65
0
        QL_REQUIRE(strike > 0.0, "negative or null strike given");
66
0
        QL_REQUIRE(notional != Null<Real>(), "no notional given");
67
0
        QL_REQUIRE(notional > 0.0, "negative or null notional given");
68
0
        QL_REQUIRE(startDate != Date(), "null start date given");
69
0
        QL_REQUIRE(maturityDate != Date(), "null maturity date given");
70
0
    }
71
72
0
    bool VarianceSwap::isExpired() const {
73
0
        return detail::simple_event(maturityDate_).hasOccurred();
74
0
    }
75
76
}