Coverage Report

Created: 2025-08-28 06:30

/src/quantlib/ql/experimental/swaptions/irregularswap.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) 2000, 2001, 2002, 2003 RiskMap srl
5
 Copyright (C) 2003, 2004, 2005, 2006, 2007 StatPro Italia srl
6
 Copyright (C) 2006, 2008 Ferdinando Ametrano
7
 Copyright (C) 2010 Andre Miemiec
8
9
 This file is part of QuantLib, a free-software/open-source library
10
 for financial quantitative analysts and developers - http://quantlib.org/
11
12
 QuantLib is free software: you can redistribute it and/or modify it
13
 under the terms of the QuantLib license.  You should have received a
14
 copy of the license along with this program; if not, please email
15
 <quantlib-dev@lists.sf.net>. The license is also available online at
16
 <http://quantlib.org/license.shtml>.
17
18
 This program is distributed in the hope that it will be useful, but WITHOUT
19
 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
20
 FOR A PARTICULAR PURPOSE.  See the license for more details.
21
*/
22
23
/*! \file irregularswap.hpp
24
    \brief Irregular fixed-rate vs Libor swap
25
*/
26
27
#ifndef quantlib_irregular_swap_hpp
28
#define quantlib_irregular_swap_hpp
29
30
#include <ql/cashflows/fixedratecoupon.hpp>
31
#include <ql/cashflows/iborcoupon.hpp>
32
#include <ql/instruments/swap.hpp>
33
#include <ql/time/daycounter.hpp>
34
#include <ql/time/schedule.hpp>
35
36
namespace QuantLib {
37
38
    class IborIndex;
39
40
    //! Irregular swap: fixed vs floating leg
41
    class IrregularSwap : public Swap {
42
      public:
43
        class arguments;
44
        class results;
45
        class engine;
46
        IrregularSwap(
47
            Type type,
48
            const Leg& fixLeg,
49
            const Leg& floatLeg);
50
        //! \name Inspectors
51
        //@{
52
        Type type() const;
53
54
        const Leg& fixedLeg() const;
55
        const Leg& floatingLeg() const;
56
        //@}
57
58
        //! \name Results
59
        //@{
60
        Real fixedLegBPS() const;
61
        Real fixedLegNPV() const;
62
        Rate fairRate() const;
63
64
        Real floatingLegBPS() const;
65
        Real floatingLegNPV() const;
66
        Spread fairSpread() const;
67
        //@}
68
        // other
69
        void setupArguments(PricingEngine::arguments* args) const override;
70
        void fetchResults(const PricingEngine::results*) const override;
71
72
      private:
73
        void setupExpired() const override;
74
        Type type_;
75
76
        // results
77
        mutable Rate fairRate_;
78
        mutable Spread fairSpread_;
79
    };
80
81
82
    //! %Arguments for irregular-swap calculation
83
    class IrregularSwap::arguments : public Swap::arguments {
84
      public:
85
0
        arguments() = default;
86
        Type type = Receiver;
87
88
89
        std::vector<Date> fixedResetDates;
90
        std::vector<Date> fixedPayDates;
91
        std::vector<Real> fixedCoupons;
92
        std::vector<Real> fixedNominals;
93
94
        std::vector<Date> floatingResetDates;
95
        std::vector<Date> floatingFixingDates;
96
        std::vector<Date> floatingPayDates;
97
        std::vector<Time> floatingAccrualTimes;
98
        std::vector<Real> floatingNominals;
99
        std::vector<Spread> floatingSpreads;
100
        std::vector<Real> floatingCoupons;
101
102
        void validate() const override;
103
    };
104
105
    //! %Results from irregular-swap calculation
106
    class IrregularSwap::results : public Swap::results {
107
      public:
108
        Rate fairRate;
109
        Spread fairSpread;
110
        void reset() override;
111
    };
112
113
    class IrregularSwap::engine : public GenericEngine<IrregularSwap::arguments,
114
                                                       IrregularSwap::results> {};
115
116
117
    // inline definitions
118
119
0
    inline Swap::Type IrregularSwap::type() const {
120
0
        return type_;
121
0
    }
122
123
0
    inline const Leg& IrregularSwap::fixedLeg() const {
124
0
        return legs_[0];
125
0
    }
126
127
0
    inline const Leg& IrregularSwap::floatingLeg() const {
128
0
        return legs_[1];
129
0
    }
130
131
}
132
133
#endif