Coverage Report

Created: 2025-08-28 06:30

/src/quantlib/ql/experimental/credit/riskyassetswapoption.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) 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
 <http://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
#include <ql/event.hpp>
21
#include <ql/experimental/credit/riskyassetswapoption.hpp>
22
#include <ql/math/distributions/normaldistribution.hpp>
23
#include <utility>
24
25
namespace QuantLib {
26
27
    RiskyAssetSwapOption::RiskyAssetSwapOption(ext::shared_ptr<RiskyAssetSwap> asw,
28
                                               const Date& expiry,
29
                                               Rate marketSpread,
30
                                               Volatility spreadVolatility)
31
0
    : asw_(std::move(asw)), expiry_(expiry), marketSpread_(marketSpread),
32
0
      spreadVolatility_(spreadVolatility) {}
Unexecuted instantiation: QuantLib::RiskyAssetSwapOption::RiskyAssetSwapOption(boost::shared_ptr<QuantLib::RiskyAssetSwap>, QuantLib::Date const&, double, double)
Unexecuted instantiation: QuantLib::RiskyAssetSwapOption::RiskyAssetSwapOption(boost::shared_ptr<QuantLib::RiskyAssetSwap>, QuantLib::Date const&, double, double)
33
34
0
    bool RiskyAssetSwapOption::isExpired() const {
35
0
        return detail::simple_event(expiry_).hasOccurred();
36
0
    }
37
38
39
0
    void RiskyAssetSwapOption::performCalculations() const {
40
0
        Real w;
41
0
        if (asw_->fixedPayer()) // strike receiver = asw call = spread put
42
0
            w = -1.0;
43
0
        else
44
0
            w = 1.0;
45
46
0
        Date today = Settings::instance().evaluationDate();
47
0
        Time expiryTime = Actual365Fixed().yearFraction(today, expiry_);
48
0
        Real stdDev = spreadVolatility_ * std::sqrt(expiryTime);
49
0
        Real d = (asw_->spread() - marketSpread_) / stdDev;
50
0
        Real A0 = asw_->nominal() * asw_->floatAnnuity();
51
52
0
        NPV_ = A0 * stdDev * (w*d * CumulativeNormalDistribution()(w*d)
53
0
                              + NormalDistribution()(d));
54
0
    }
55
56
}