• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

lballabio / QuantLib / 16721424135

04 Aug 2025 11:07AM UTC coverage: 73.862% (+0.03%) from 73.834%
16721424135

Pull #2271

github

web-flow
Merge e0d7c1c6e into 38cca0694
Pull Request #2271: Soft barrier implementation

146 of 169 new or added lines in 3 files covered. (86.39%)

12 existing lines in 1 file now uncovered.

56661 of 76712 relevant lines covered (73.86%)

17586185.78 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

48.39
/ql/instruments/softbarrieroption.cpp
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
 <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/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(
118✔
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)
118✔
33
    : OneAssetOption(payoff, exercise),
34
      barrierType_(barrierType), barrier_lo_(barrier_lo),
118✔
35
      barrier_hi_(barrier_hi) {}
236✔
36

37
    void SoftBarrierOption::setupArguments(PricingEngine::arguments* args) const {
118✔
38
        OneAssetOption::setupArguments(args);
118✔
39

40
        auto* moreArgs = dynamic_cast<SoftBarrierOption::arguments*>(args);
118✔
41
        QL_REQUIRE(moreArgs != nullptr, "wrong argument type");
118✔
42
        moreArgs->barrierType = barrierType_;
118✔
43
        moreArgs->barrier_lo = barrier_lo_;
118✔
44
        moreArgs->barrier_hi = barrier_hi_;
118✔
45
    }
118✔
46

NEW
47
    Volatility SoftBarrierOption::impliedVolatility(      
×
48
             Real targetValue,
49
             const ext::shared_ptr<GeneralizedBlackScholesProcess>& process,
50
             Real accuracy,
51
             Size maxEvaluations,
52
             Volatility minVol,
53
             Volatility maxVol) const {
54

NEW
55
        QL_REQUIRE(!isExpired(), "option expired");
×
56

NEW
57
        ext::shared_ptr<SimpleQuote> volQuote(new SimpleQuote);
×
58

59
        ext::shared_ptr<GeneralizedBlackScholesProcess> newProcess =
NEW
60
            detail::ImpliedVolatilityHelper::clone(process, volQuote);
×
61

NEW
62
        std::unique_ptr<PricingEngine> engine;
×
NEW
63
        switch (exercise_->type()) {
×
NEW
64
            case Exercise::European:
×
NEW
65
              engine = std::make_unique<AnalyticSoftBarrierEngine>(newProcess);
×
66
              break;
NEW
67
          case Exercise::American:
×
68
          case Exercise::Bermudan:
NEW
69
            QL_FAIL("engine not available for non-European soft barrier option");
×
NEW
70
          default:
×
NEW
71
            QL_FAIL("unknown exercise type");
×
72
        }
73

NEW
74
        return detail::ImpliedVolatilityHelper::calculate(*this,
×
75
                                                          *engine,
NEW
76
                                                          *volQuote,
×
77
                                                          targetValue,
78
                                                          accuracy,
79
                                                          maxEvaluations,
NEW
80
                                                          minVol, maxVol);
×
NEW
81
    }
×
82

83
    SoftBarrierOption::arguments::arguments()
118✔
84
    : barrierType(Barrier::Type(-1)),
118✔
85
      barrier_lo(Null<Real>()), barrier_hi(Null<Real>()) {}
118✔
86

87
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc