QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
blackcdsoptionengine.cpp
Go to the documentation of this file.
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2008 Roland Stamm
5 Copyright (C) 2009 Jose Aparicio
6
7 This file is part of QuantLib, a free-software/open-source library
8 for financial quantitative analysts and developers - http://quantlib.org/
9
10 QuantLib is free software: you can redistribute it and/or modify it
11 under the terms of the QuantLib license. You should have received a
12 copy of the license along with this program; if not, please email
13 <quantlib-dev@lists.sf.net>. The license is also available online at
14 <http://quantlib.org/license.shtml>.
15
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the license for more details.
19*/
20
21#include <ql/exercise.hpp>
24#include <ql/quote.hpp>
26#include <utility>
27
28namespace QuantLib {
29
31 Real recoveryRate,
32 Handle<YieldTermStructure> termStructure,
33 Handle<Quote> volatility)
34 : probability_(std::move(probability)), recoveryRate_(recoveryRate),
35 termStructure_(std::move(termStructure)), volatility_(std::move(volatility)) {
36
40 }
41
43
44 Date maturityDate = arguments_.swap->coupons().front()->date();
45 Date exerciseDate = arguments_.exercise->date(0);
46 QL_REQUIRE(maturityDate > exerciseDate,
47 "Underlying CDS should start after option maturity");
48 Date settlement = termStructure_->referenceDate();
49
50 Rate spotFwdSpread = arguments_.swap->fairSpread();
51 Rate swapSpread = arguments_.swap->runningSpread();
52
53 DayCounter tSDc = termStructure_->dayCounter();
54
55 // The sense of the underlying/option has to be sent this way
56 // to the Black formula, no sign.
57 Real riskyAnnuity =
58 std::fabs(arguments_.swap->couponLegNPV() / swapSpread);
59 results_.riskyAnnuity = riskyAnnuity;
60
61 Time T = tSDc.yearFraction(settlement, exerciseDate);
62
63 Real stdDev = volatility_->value() * std::sqrt(T);
66
67 results_.value =
68 blackFormula(callPut, swapSpread, spotFwdSpread,
69 stdDev, riskyAnnuity);
70
71 // if a non knock-out payer option, add front end protection value
73 Real frontEndProtection =
74 Integer(callPut) * arguments_.swap->notional()
75 * (1.-recoveryRate_)
76 * probability_->defaultProbability(exerciseDate)
77 * termStructure_->discount(exerciseDate);
78 results_.value += frontEndProtection;
79 }
80 }
81
83 return termStructure_;
84 }
85
87 return volatility_;
88 }
89
90}
Black credit default swap option engine.
Black formula.
BlackCdsOptionEngine(Handle< DefaultProbabilityTermStructure >, Real recoveryRate, Handle< YieldTermStructure > termStructure, Handle< Quote > vol)
Handle< DefaultProbabilityTermStructure > probability_
Handle< YieldTermStructure > termStructure_
Handle< YieldTermStructure > termStructure()
ext::shared_ptr< CreditDefaultSwap > swap
Definition: cdsoption.hpp:94
Concrete date class.
Definition: date.hpp:125
day counter class
Definition: daycounter.hpp:44
Time yearFraction(const Date &, const Date &, const Date &refPeriodStart=Date(), const Date &refPeriodEnd=Date()) const
Returns the period between two dates as a fraction of year.
Definition: daycounter.hpp:128
Shared handle to an observable.
Definition: handle.hpp:41
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
Definition: observable.hpp:228
ext::shared_ptr< Exercise > exercise
Definition: option.hpp:65
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
Option exercise classes and payoff function.
Real Time
continuous quantity with 1-year units
Definition: types.hpp:62
QL_REAL Real
real number
Definition: types.hpp:50
QL_INTEGER Integer
integer number
Definition: types.hpp:35
Real Rate
interest rates
Definition: types.hpp:70
Definition: any.hpp:35
Real blackFormula(Option::Type optionType, Real strike, Real forward, Real stdDev, Real discount, Real displacement)
STL namespace.
purely virtual base class for market observables
Interest-rate term structure.