QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
midpointcdoengine.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 Lichters
5 Copyright (C) 2009, 2014 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
22
23#ifndef QL_PATCH_SOLARIS
24
27
28namespace QuantLib {
29
32
36 results_.error = 0;
38 // todo Should be remaining when considering realized loses
39 results_.xMin = arguments_.basket->attachmentAmount();
40 results_.xMax = arguments_.basket->detachmentAmount();
42 const Real inceptionTrancheNotional =
43 arguments_.basket->trancheNotional();
44
45 // compute expected loss at the beginning of first relevant period
46 Real e1 = 0;
47 // todo add includeSettlement date flows variable to engine.
48 if (!arguments_.normalizedLeg[0]->hasOccurred(today))
49 // Notice that since there might be a gap between the end of
50 // acrrual and payment dates and today be in between
51 // the tranche loss on that date might not be contingent but
52 // realized:
53 e1 = arguments_.basket->expectedTrancheLoss(
54 ext::dynamic_pointer_cast<Coupon>(
55 arguments_.normalizedLeg[0])->accrualStartDate());
56 results_.expectedTrancheLoss.push_back(e1);
57 //'e1' should contain the existing loses.....? use remaining amounts?
58 for (auto& i : arguments_.normalizedLeg) {
59 if (i->hasOccurred(today)) {
60 results_.expectedTrancheLoss.push_back(0.);
61 continue;
62 }
63 ext::shared_ptr<Coupon> coupon = ext::dynamic_pointer_cast<Coupon>(i);
64 Date paymentDate = coupon->date();
65 Date startDate = std::max(coupon->accrualStartDate(),
66 discountCurve_->referenceDate());
67 Date endDate = coupon->accrualEndDate();
68 // we assume the loss within the period took place on this date:
69 Date defaultDate = startDate + (endDate-startDate)/2;
70
71 Real e2 = arguments_.basket->expectedTrancheLoss(endDate);
72 results_.expectedTrancheLoss.push_back(e2);
74 ((inceptionTrancheNotional - e2) / inceptionTrancheNotional)
75 * coupon->amount()
76 * discountCurve_->discount(paymentDate);
77 // default flows:
78 const Real discount = discountCurve_->discount(defaultDate);
79
80 /* Accrual removed till the argument flag is implemented
81 // pays accrued on defaults' date
82 results_.premiumValue += coupon->accruedAmount(defaultDate)
83 * discount * (e2 - e1) / inceptionTrancheNotional;
84 */
85 results_.protectionValue += discount * (e2 - e1);
86 /* use it in a future version for coherence with the integral engine
87 * arguments_.leverageFactor;
88 */
89 e1 = e2;
90 }
91
92 //\todo treat upfron tnow as in the new CDS (see March 2014)
93 // add includeSettlement date flows variable to engine ?
94 if (!arguments_.normalizedLeg[0]->hasOccurred(today))
96 = inceptionTrancheNotional * arguments_.upfrontRate
97 * discountCurve_->discount(
98 ext::dynamic_pointer_cast<Coupon>(
99 arguments_.normalizedLeg[0])->accrualStartDate());
100 /* use it in a future version for coherence with the integral engine
101 arguments_.leverageFactor * ;
102 */
107 }
111 // Fair spread GIVEN the upfront
112 Real fairSpread = 0.;
113 if (results_.premiumValue != 0.0) {
114 fairSpread =
117 }
118
119 results_.additionalResults["fairPremium"] = fairSpread;
120 results_.additionalResults["premiumLegNPV"] =
122 results_.additionalResults["protectionLegNPV"] =
124 }
125
126}
127
128#endif
Concrete date class.
Definition: date.hpp:125
std::map< std::string, ext::any > additionalResults
Definition: instrument.hpp:123
Handle< YieldTermStructure > discountCurve_
void calculate() const override
template class providing a null value for a given type.
Definition: null.hpp:76
DateProxy & evaluationDate()
the date at which pricing is to be performed.
Definition: settings.hpp:147
static Settings & instance()
access to the unique instance
Definition: singleton.hpp:104
ext::shared_ptr< Basket > basket
std::vector< Real > expectedTrancheLoss
Coupon paying a fixed annual rate.
QL_REAL Real
real number
Definition: types.hpp:50
Definition: any.hpp:35
Interest-rate term structure.