Coverage Report

Created: 2025-09-04 07:11

/src/quantlib/ql/instruments/assetswap.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) 2006, 2007 Chiara Fornarola
5
 Copyright (C) 2007, 2009, 2011 Ferdinando Ametrano
6
 Copyright (C) 2007, 2009 StatPro Italia srl
7
8
 This file is part of QuantLib, a free-software/open-source library
9
 for financial quantitative analysts and developers - http://quantlib.org/
10
11
 QuantLib is free software: you can redistribute it and/or modify it
12
 under the terms of the QuantLib license.  You should have received a
13
 copy of the license along with this program; if not, please email
14
 <quantlib-dev@lists.sf.net>. The license is also available online at
15
 <https://www.quantlib.org/license.shtml>.
16
17
 This program is distributed in the hope that it will be useful, but WITHOUT
18
 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19
 FOR A PARTICULAR PURPOSE.  See the license for more details.
20
*/
21
22
/*! \file assetswap.hpp
23
    \brief Bullet bond vs Libor swap
24
*/
25
26
#ifndef quantlib_asset_swap_hpp
27
#define quantlib_asset_swap_hpp
28
29
#include <ql/instruments/swap.hpp>
30
#include <ql/instruments/bond.hpp>
31
#include <ql/time/schedule.hpp>
32
#include <ql/time/daycounter.hpp>
33
34
namespace QuantLib {
35
36
    class IborIndex;
37
38
    //! Bullet bond vs %Libor swap
39
    /*! for mechanics of par asset swap and market asset swap, refer to
40
        "Introduction to Asset Swap", Lehman Brothers European Fixed
41
        Income Research - January 2000, D. O'Kane
42
43
        \ingroup instruments
44
45
        \warning bondCleanPrice must be the (forward) price at the
46
                 floatSchedule start date
47
48
        \bug fair prices are not calculated correctly when using
49
             indexed coupons.
50
    */
51
    class AssetSwap : public Swap {
52
      public:
53
        class arguments;
54
        class results;
55
56
        /*! If the passed iborIndex is an overnight rate such as
57
            SOFR, ESTR or SONIA, the floatSchedule argument is
58
            required and will be used to build overnight-indexed
59
            coupons.
60
        */
61
        AssetSwap(bool payBondCoupon,
62
                  ext::shared_ptr<Bond> bond,
63
                  Real bondCleanPrice,
64
                  const ext::shared_ptr<IborIndex>& iborIndex,
65
                  Spread spread,
66
                  Schedule floatSchedule = Schedule(),
67
                  const DayCounter& floatingDayCount = DayCounter(),
68
                  bool parAssetSwap = true,
69
                  Real gearing = 1.0,
70
                  Real nonParRepayment = Null<Real>(),
71
                  Date dealMaturity = Date());
72
73
        /*! \deprecated Use the other overload.
74
                        Deprecated in version 1.37.
75
        */
76
        [[deprecated("Use the other overload")]]
77
        AssetSwap(bool parAssetSwap,
78
                  ext::shared_ptr<Bond> bond,
79
                  Real bondCleanPrice,
80
                  Real nonParRepayment,
81
                  Real gearing,
82
                  const ext::shared_ptr<IborIndex>& iborIndex,
83
                  Spread spread = 0.0,
84
                  const DayCounter& floatingDayCount = DayCounter(),
85
                  Date dealMaturity = Date(),
86
                  bool payBondCoupon = false);
87
88
        // results
89
        Spread fairSpread() const;
90
        Real floatingLegBPS() const;
91
        Real floatingLegNPV() const;
92
        Real fairCleanPrice() const;
93
        Real fairNonParRepayment() const;
94
        // inspectors
95
0
        bool parSwap() const { return parSwap_; }
96
0
        Spread spread() const { return spread_; }
97
0
        Real cleanPrice() const { return bondCleanPrice_; }
98
0
        Real nonParRepayment() const { return nonParRepayment_; }
99
0
        const ext::shared_ptr<Bond>& bond() const { return bond_; }
100
0
        bool payBondCoupon() const { return (payer_[0] == -1.0); }
101
0
        const Leg& bondLeg() const { return legs_[0]; }
102
0
        const Leg& floatingLeg() const { return legs_[1]; }
103
        // other
104
        void setupArguments(PricingEngine::arguments* args) const override;
105
        void fetchResults(const PricingEngine::results*) const override;
106
107
      private:
108
        void setupExpired() const override;
109
        ext::shared_ptr<Bond> bond_;
110
        Real bondCleanPrice_, nonParRepayment_;
111
        Spread spread_;
112
        bool parSwap_;
113
        Date upfrontDate_;
114
        // results
115
        mutable Spread fairSpread_;
116
        mutable Real fairCleanPrice_, fairNonParRepayment_;
117
    };
118
119
120
    //! %Arguments for asset swap calculation
121
    class AssetSwap::arguments : public Swap::arguments {
122
      public:
123
        arguments() = default;
124
        std::vector<Date> fixedResetDates;
125
        std::vector<Date> fixedPayDates;
126
        std::vector<Real> fixedCoupons;
127
        std::vector<Time> floatingAccrualTimes;
128
        std::vector<Date> floatingResetDates;
129
        std::vector<Date> floatingFixingDates;
130
        std::vector<Date> floatingPayDates;
131
        std::vector<Spread> floatingSpreads;
132
        void validate() const override;
133
    };
134
135
    //! %Results from simple swap calculation
136
    class AssetSwap::results : public Swap::results {
137
      public:
138
        Spread fairSpread;
139
        Real fairCleanPrice, fairNonParRepayment;
140
        void reset() override;
141
    };
142
143
}
144
145
#endif