Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
cdsoptionhelper.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2017 Quaternion Risk Management Ltd
3 All rights reserved.
4
5 This file is part of ORE, a free-software/open-source library
6 for transparent pricing and risk analysis - http://opensourcerisk.org
7
8 ORE is free software: you can redistribute it and/or modify it
9 under the terms of the Modified BSD License. You should have received a
10 copy of the license along with this program.
11 The license is also available online at <http://opensourcerisk.org>
12
13 This program is distributed on the basis that it will form a useful
14 contribution to risk analytics and model standardisation, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17*/
18
21
22#include <ql/pricingengines/credit/midpointcdsengine.hpp>
23#include <ql/exercise.hpp>
24#include <ql/quotes/simplequote.hpp>
25#include <ql/termstructures/volatility/equityfx/blackconstantvol.hpp>
26#include <ql/time/schedule.hpp>
27
28#include <boost/make_shared.hpp>
29
30namespace QuantExt {
31
32CdsOptionHelper::CdsOptionHelper(const Date& exerciseDate, const Handle<Quote>& volatility, const Protection::Side side,
33 const Schedule& schedule, const BusinessDayConvention paymentConvention,
34 const DayCounter& dayCounter,
35 const Handle<DefaultProbabilityTermStructure>& probability, const Real recoveryRate,
36 const Handle<YieldTermStructure>& termStructure, const Rate spread, const Rate upfront,
37 const bool settlesAccrual,
38 const CreditDefaultSwap::ProtectionPaymentTime protectionPaymentTime,
39 const Date protectionStart, const Date upfrontDate,
40 const QuantLib::ext::shared_ptr<Claim>& claim,
41 const BlackCalibrationHelper::CalibrationErrorType errorType)
42 : BlackCalibrationHelper(volatility, errorType), termStructure_(termStructure),
43 blackVol_(QuantLib::ext::make_shared<SimpleQuote>(0.0)) {
44
45 QuantLib::ext::shared_ptr<PricingEngine> cdsEngine =
46 QuantLib::ext::make_shared<QuantExt::MidPointCdsEngine>(probability, recoveryRate, termStructure);
47
48 QuantLib::ext::shared_ptr<CreditDefaultSwap> tmp;
49 if (upfront == Null<Real>())
50 tmp = QuantLib::ext::shared_ptr<CreditDefaultSwap>(
51 new CreditDefaultSwap(side, 1.0, 0.02, schedule, paymentConvention, dayCounter, settlesAccrual,
52 protectionPaymentTime, protectionStart, claim));
53 else
54 tmp = QuantLib::ext::shared_ptr<CreditDefaultSwap>(
55 new CreditDefaultSwap(side, 1.0, upfront, 0.02, schedule, paymentConvention, dayCounter, settlesAccrual,
56 protectionPaymentTime, protectionStart, upfrontDate, claim));
57 tmp->setPricingEngine(cdsEngine);
58
59 Real strike = spread == Null<Real>() ? tmp->fairSpreadClean() : spread;
60 if (upfront == Null<Real>())
61 cds_ = QuantLib::ext::shared_ptr<CreditDefaultSwap>(
62 new CreditDefaultSwap(side, 1.0, strike, schedule, paymentConvention, dayCounter, settlesAccrual,
63 protectionPaymentTime, protectionStart, claim));
64 else
65 cds_ = QuantLib::ext::shared_ptr<CreditDefaultSwap>(
66 new CreditDefaultSwap(side, 1.0, upfront, strike, schedule, paymentConvention, dayCounter, settlesAccrual,
67 protectionPaymentTime, protectionStart, upfrontDate, claim));
68
69 cds_->setPricingEngine(cdsEngine);
70
71 QuantLib::ext::shared_ptr<Exercise> exercise = QuantLib::ext::make_shared<EuropeanExercise>(exerciseDate);
72
73 option_ = QuantLib::ext::make_shared<CdsOption>(cds_, exercise, true);
74 Handle<BlackVolTermStructure> h(
75 QuantLib::ext::make_shared<BlackConstantVol>(0, NullCalendar(), Handle<Quote>(blackVol_), Actual365Fixed()));
76
77 blackEngine_ = QuantLib::ext::make_shared<BlackCdsOptionEngine>(
78 probability, recoveryRate, termStructure, Handle<CreditVolCurve>(QuantLib::ext::make_shared<CreditVolCurveWrapper>(h)));
79}
80
82 calculate();
83 option_->setPricingEngine(engine_);
84 return option_->NPV();
85}
86
87Real CdsOptionHelper::blackPrice(Volatility sigma) const {
88 calculate();
89 blackVol_->setValue(sigma);
90 option_->setPricingEngine(blackEngine_);
91 Real value = option_->NPV();
92 option_->setPricingEngine(engine_);
93 return value;
94}
95
96} // namespace QuantExt
Black credit default swap option engine.
QuantLib::ext::shared_ptr< PricingEngine > engine_
Definition: cdsoption.cpp:78
cds option calibration helper
QuantLib::ext::shared_ptr< QuantExt::CdsOption > option_
QuantLib::ext::shared_ptr< CreditDefaultSwap > cds_
virtual Real blackPrice(Volatility volatility) const override
QuantLib::ext::shared_ptr< PricingEngine > blackEngine_
virtual Real modelValue() const override
QuantLib::ext::shared_ptr< SimpleQuote > blackVol_
CdsOptionHelper(const Date &exerciseDate, const Handle< Quote > &volatility, const Protection::Side side, const Schedule &schedule, const BusinessDayConvention paymentConvention, const DayCounter &dayCounter, const Handle< DefaultProbabilityTermStructure > &probability, const Real recoveryRate, const Handle< YieldTermStructure > &termStructure, const Rate spread=Null< Rate >(), const Rate upfront=Null< Rate >(), const bool settlesAccrual=true, const CreditDefaultSwap::ProtectionPaymentTime proteectionPaymentTime=CreditDefaultSwap::ProtectionPaymentTime::atDefault, const Date protectionStart=Date(), const Date upfrontDate=Date(), const QuantLib::ext::shared_ptr< Claim > &claim=QuantLib::ext::shared_ptr< Claim >(), const BlackCalibrationHelper::CalibrationErrorType errorType=BlackCalibrationHelper::RelativePriceError)