Coverage Report

Created: 2026-01-25 06:59

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/quantlib/ql/instruments/assetswap.hpp
Line
Count
Source
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
        // results
74
        Spread fairSpread() const;
75
        Real floatingLegBPS() const;
76
        Real floatingLegNPV() const;
77
        Real fairCleanPrice() const;
78
        Real fairNonParRepayment() const;
79
        // inspectors
80
0
        bool parSwap() const { return parSwap_; }
81
0
        Spread spread() const { return spread_; }
82
0
        Real cleanPrice() const { return bondCleanPrice_; }
83
0
        Real nonParRepayment() const { return nonParRepayment_; }
84
0
        const ext::shared_ptr<Bond>& bond() const { return bond_; }
85
0
        bool payBondCoupon() const { return (payer_[0] == -1.0); }
86
0
        const Leg& bondLeg() const { return legs_[0]; }
87
0
        const Leg& floatingLeg() const { return legs_[1]; }
88
        // other
89
        void setupArguments(PricingEngine::arguments* args) const override;
90
        void fetchResults(const PricingEngine::results*) const override;
91
92
      private:
93
        void setupExpired() const override;
94
        ext::shared_ptr<Bond> bond_;
95
        Real bondCleanPrice_, nonParRepayment_;
96
        Spread spread_;
97
        bool parSwap_;
98
        Date upfrontDate_;
99
        // results
100
        mutable Spread fairSpread_;
101
        mutable Real fairCleanPrice_, fairNonParRepayment_;
102
    };
103
104
105
    //! %Arguments for asset swap calculation
106
    class AssetSwap::arguments : public Swap::arguments {
107
      public:
108
        arguments() = default;
109
        std::vector<Date> fixedResetDates;
110
        std::vector<Date> fixedPayDates;
111
        std::vector<Real> fixedCoupons;
112
        std::vector<Time> floatingAccrualTimes;
113
        std::vector<Date> floatingResetDates;
114
        std::vector<Date> floatingFixingDates;
115
        std::vector<Date> floatingPayDates;
116
        std::vector<Spread> floatingSpreads;
117
        void validate() const override;
118
    };
119
120
    //! %Results from simple swap calculation
121
    class AssetSwap::results : public Swap::results {
122
      public:
123
        Spread fairSpread;
124
        Real fairCleanPrice, fairNonParRepayment;
125
        void reset() override;
126
    };
127
128
}
129
130
#endif