Coverage Report

Created: 2026-03-31 07:01

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/quantlib/ql/instruments/softbarrieroption.cpp
Line
Count
Source
1
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3
/*
4
 Copyright (C) 2025 William Day
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
#include <ql/exercise.hpp>
21
#include <ql/instruments/softbarrieroption.hpp>
22
#include <ql/instruments/impliedvolatility.hpp>
23
#include <ql/pricingengines/barrier/analyticsoftbarrierengine.hpp>
24
25
namespace QuantLib {
26
27
    SoftBarrierOption::SoftBarrierOption(
28
        Barrier::Type barrierType,
29
        Real barrier_lo,
30
        Real barrier_hi,
31
        const ext::shared_ptr<StrikedTypePayoff>& payoff,
32
        const ext::shared_ptr<Exercise>& exercise)
33
0
    : OneAssetOption(payoff, exercise),
34
0
      barrierType_(barrierType), barrier_lo_(barrier_lo),
35
0
      barrier_hi_(barrier_hi) {}
Unexecuted instantiation: QuantLib::SoftBarrierOption::SoftBarrierOption(QuantLib::Barrier::Type, double, double, boost::shared_ptr<QuantLib::StrikedTypePayoff> const&, boost::shared_ptr<QuantLib::Exercise> const&)
Unexecuted instantiation: QuantLib::SoftBarrierOption::SoftBarrierOption(QuantLib::Barrier::Type, double, double, boost::shared_ptr<QuantLib::StrikedTypePayoff> const&, boost::shared_ptr<QuantLib::Exercise> const&)
36
37
0
    void SoftBarrierOption::setupArguments(PricingEngine::arguments* args) const {
38
0
        OneAssetOption::setupArguments(args);
39
40
0
        auto* moreArgs = dynamic_cast<SoftBarrierOption::arguments*>(args);
41
0
        QL_REQUIRE(moreArgs != nullptr, "wrong argument type");
42
0
        moreArgs->barrierType = barrierType_;
43
0
        moreArgs->barrier_lo = barrier_lo_;
44
0
        moreArgs->barrier_hi = barrier_hi_;
45
0
    }
46
47
    Volatility SoftBarrierOption::impliedVolatility(      
48
             Real targetValue,
49
             const ext::shared_ptr<GeneralizedBlackScholesProcess>& process,
50
             Real accuracy,
51
             Size maxEvaluations,
52
             Volatility minVol,
53
0
             Volatility maxVol) const {
54
55
0
        QL_REQUIRE(!isExpired(), "option expired");
56
57
0
        ext::shared_ptr<SimpleQuote> volQuote(new SimpleQuote);
58
59
0
        ext::shared_ptr<GeneralizedBlackScholesProcess> newProcess =
60
0
            detail::ImpliedVolatilityHelper::clone(process, volQuote);
61
62
0
        std::unique_ptr<PricingEngine> engine;
63
0
        switch (exercise_->type()) {
64
0
            case Exercise::European:
65
0
              engine = std::make_unique<AnalyticSoftBarrierEngine>(newProcess);
66
0
              break;
67
0
          case Exercise::American:
68
0
          case Exercise::Bermudan:
69
0
            QL_FAIL("engine not available for non-European soft barrier option");
70
0
          default:
71
0
            QL_FAIL("unknown exercise type");
72
0
        }
73
74
0
        return detail::ImpliedVolatilityHelper::calculate(*this,
75
0
                                                          *engine,
76
0
                                                          *volQuote,
77
0
                                                          targetValue,
78
0
                                                          accuracy,
79
0
                                                          maxEvaluations,
80
0
                                                          minVol, maxVol);
81
0
    }
82
83
    SoftBarrierOption::arguments::arguments()
84
0
    : barrierType(Barrier::Type(-1)),
85
0
      barrier_lo(Null<Real>()), barrier_hi(Null<Real>()) {}
Unexecuted instantiation: QuantLib::SoftBarrierOption::arguments::arguments()
Unexecuted instantiation: QuantLib::SoftBarrierOption::arguments::arguments()
86
87
}