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

lballabio / QuantLib / 14936704017

09 May 2025 07:58PM UTC coverage: 73.327%. Remained the same
14936704017

push

github

web-flow
Remove dangling unreachable break clauses (#2219)

56238 of 76695 relevant lines covered (73.33%)

8685070.69 hits per line

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

0.0
/ql/experimental/processes/extendedblackscholesprocess.cpp
1
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2

3
/*
4
 Copyright (C) 2008 Frank Hövermann
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/experimental/processes/extendedblackscholesprocess.hpp>
21

22
namespace QuantLib {
23

24
    ExtendedBlackScholesMertonProcess::ExtendedBlackScholesMertonProcess(
×
25
                              const Handle<Quote>& x0,
26
                              const Handle<YieldTermStructure>& dividendTS,
27
                              const Handle<YieldTermStructure>& riskFreeTS,
28
                              const Handle<BlackVolTermStructure>& blackVolTS,
29
                              const ext::shared_ptr<discretization>& d,
30
                              Discretization evolDisc)
×
31
    : GeneralizedBlackScholesProcess(x0,dividendTS,riskFreeTS,blackVolTS,d),
32
      discretization_(evolDisc) {}
×
33

34
    Real ExtendedBlackScholesMertonProcess::drift(Time t, Real x) const {
×
35
        Real sigma = diffusion(t,x);
×
36
        // we could be more anticipatory if we know the right dt
37
        // for which the drift will be used
38
        Time t1 = t + 0.0001;
×
39
        return riskFreeRate()->forwardRate(t,t1,Continuous,NoFrequency,true).rate()
×
40
             - dividendYield()->forwardRate(t,t1,Continuous,NoFrequency,true).rate()
×
41
             - 0.5 * sigma * sigma;
×
42
    }
43

44
    Real ExtendedBlackScholesMertonProcess::diffusion(Time t, Real x) const {
×
45
        return blackVolatility()->blackVol(t, x, true);
×
46
    }
47

48
    Real ExtendedBlackScholesMertonProcess::evolve(Time t0, Real x0,
×
49
                                                   Time dt, Real dw) const {
50
        Real predictor, sigma0, sigma1;
51
        Time t1;
52
        Rate rate0, rate1;
53
        Real driftterm, diffusionterm, corrector;
54
        switch (discretization_) {
×
55
          case Milstein:
×
56
            // Milstein scheme
57
            return apply(x0, drift(t0, x0)*dt
×
58
                           + 0.5*std::pow(diffusion(t0, x0),2)*(dw*dw-1)*dt
×
59
                           + diffusion(t0,x0)*std::sqrt(dt)*dw);
×
60
          case Euler:
×
61
            // Usual Euler scheme
62
            return apply(expectation(t0,x0,dt), stdDeviation(t0,x0,dt)*dw);
×
63
          case PredictorCorrector:
×
64
            // Predictor-Corrector scheme with equal weighting
65
            predictor =
66
                apply(expectation(t0,x0,dt), stdDeviation(t0,x0,dt)*dw);
×
67
            t1 = t0 + 0.0001;
×
68
            sigma0 = diffusion(t0,x0);
×
69
            sigma1 = diffusion(t0+dt,predictor);
×
70
            rate0 =
×
71
                riskFreeRate()->forwardRate(t0,t1,Continuous,NoFrequency,true).rate()
×
72
              - dividendYield()->forwardRate(t0,t1,Continuous,NoFrequency,true).rate()
×
73
              - 0.5*std::pow(sigma0,2);
×
74
            rate1 =
×
75
                riskFreeRate()->forwardRate(t0+dt,t1+dt,Continuous,
×
76
                                            NoFrequency,true).rate()
77
              - dividendYield()->forwardRate(t0+dt,t1+dt,
×
78
                                             Continuous,NoFrequency,true).rate()
79
              - 0.5*std::pow(sigma1,2);
×
80
            driftterm = 0.5*rate1+0.5*rate0;
×
81
            diffusionterm = 0.5*(sigma1+sigma0);
×
82
            corrector =
83
                apply(x0,driftterm*dt+diffusionterm*std::sqrt(dt)*dw);
×
84
            return corrector;
×
85
          default:
×
86
            QL_FAIL("unknown discretization scheme");
×
87
        }
88
    }
89

90
}
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