Coverage Report

Created: 2026-02-03 07:02

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/quantlib/ql/experimental/credit/riskyassetswap.hpp
Line
Count
Source
1
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3
/*
4
 Copyright (C) 2008, 2009 Roland Lichters
5
6
 This file is part of QuantLib, a free-software/open-source library
7
 for financial quantitative analysts and developers - http://quantlib.org/
8
9
 QuantLib is free software: you can redistribute it and/or modify it
10
 under the terms of the QuantLib license.  You should have received a
11
 copy of the license along with this program; if not, please email
12
 <quantlib-dev@lists.sf.net>. The license is also available online at
13
 <https://www.quantlib.org/license.shtml>.
14
15
 This program is distributed in the hope that it will be useful, but WITHOUT
16
 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17
 FOR A PARTICULAR PURPOSE.  See the license for more details.
18
*/
19
20
/*! \file riskyassetswap.hpp
21
    \brief Risky asset-swap instrument
22
*/
23
24
#ifndef quantlib_risky_asset_swap_hpp
25
#define quantlib_risky_asset_swap_hpp
26
27
#include <ql/instrument.hpp>
28
#include <ql/termstructures/defaulttermstructure.hpp>
29
#include <ql/termstructures/yieldtermstructure.hpp>
30
#include <ql/termstructures/credit/defaultprobabilityhelpers.hpp>
31
#include <ql/time/schedule.hpp>
32
33
namespace QuantLib {
34
35
    //! Risky asset-swap instrument
36
    class RiskyAssetSwap : public Instrument {
37
      public:
38
        RiskyAssetSwap(bool fixedPayer,
39
                       Real nominal,
40
                       Schedule fixedSchedule,
41
                       Schedule floatSchedule,
42
                       DayCounter fixedDayCounter,
43
                       DayCounter floatDayCounter,
44
                       Rate spread,
45
                       Rate recoveryRate_,
46
                       Handle<YieldTermStructure> yieldTS,
47
                       Handle<DefaultProbabilityTermStructure> defaultTS,
48
                       Rate coupon = Null<Rate>());
49
50
        Real fairSpread ();
51
52
        Real floatAnnuity() const;
53
54
0
        Real nominal() const { return nominal_; }
55
0
        Rate spread() const { return spread_; }
56
0
        bool fixedPayer() const { return fixedPayer_; }
57
58
      private:
59
        void setupExpired() const override;
60
        bool isExpired() const override;
61
        void performCalculations() const override;
62
63
        Real fixedAnnuity() const;
64
        Real parCoupon() const;
65
        Real recoveryValue() const;
66
        Real riskyBondPrice() const;
67
68
        // calculated values
69
        mutable Real fixedAnnuity_;
70
        mutable Real floatAnnuity_;
71
        mutable Real parCoupon_;
72
        mutable Real recoveryValue_;
73
        mutable Real riskyBondPrice_;
74
75
        // input
76
        bool fixedPayer_;
77
        Real nominal_;
78
        Schedule fixedSchedule_, floatSchedule_;
79
        DayCounter fixedDayCounter_, floatDayCounter_;
80
        Rate spread_;
81
        Rate recoveryRate_;
82
        Handle<YieldTermStructure> yieldTS_;
83
        Handle<DefaultProbabilityTermStructure> defaultTS_;
84
        mutable Real coupon_;
85
    };
86
87
88
    // risky-asset-swap helper for probability-curve bootstrap
89
    class AssetSwapHelper : public DefaultProbabilityHelper {
90
      public:
91
        AssetSwapHelper(const Handle<Quote>& spread,
92
                        const Period& tenor,
93
                        Natural settlementDays,
94
                        Calendar calendar,
95
                        const Period& fixedPeriod,
96
                        BusinessDayConvention fixedConvention,
97
                        DayCounter fixedDayCount,
98
                        const Period& floatPeriod,
99
                        BusinessDayConvention floatConvention,
100
                        DayCounter floatDayCount,
101
                        Real recoveryRate,
102
                        const RelinkableHandle<YieldTermStructure>& yieldTS,
103
                        const Period& integrationStepSize = Period());
104
        Real impliedQuote() const override;
105
        void setTermStructure(DefaultProbabilityTermStructure*) override;
106
107
      private:
108
        void update() override;
109
        void initializeDates();
110
111
        Period tenor_;
112
        Natural settlementDays_;
113
        Calendar calendar_;
114
        BusinessDayConvention fixedConvention_;
115
        Period fixedPeriod_;
116
        DayCounter fixedDayCount_;
117
        BusinessDayConvention floatConvention_;
118
        Period floatPeriod_;
119
        DayCounter floatDayCount_;
120
        Real recoveryRate_;
121
        RelinkableHandle<YieldTermStructure> yieldTS_;
122
        Period integrationStepSize_;
123
124
        Date evaluationDate_;
125
        ext::shared_ptr<RiskyAssetSwap> asw_;
126
        RelinkableHandle<DefaultProbabilityTermStructure> probability_;
127
    };
128
129
}
130
131
#endif
132