QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
integralcdoengine.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 // cast to fixed rate coupon?
50 e1 = arguments_.basket->expectedTrancheLoss(
51 ext::dynamic_pointer_cast<Coupon>(
52 arguments_.normalizedLeg[0])->accrualStartDate());
53 results_.expectedTrancheLoss.push_back(e1);// zero or realized losses?
54
55 for (auto& i : arguments_.normalizedLeg) {
56 if (i->hasOccurred(today)) {
57 // add includeSettlement date flows variable to engine.
58 results_.expectedTrancheLoss.push_back(0.);
59 continue;
60 }
61
62 const ext::shared_ptr<Coupon> coupon = ext::dynamic_pointer_cast<Coupon>(i);
63
64 Date d1 = coupon->accrualStartDate();
65 Date d2 = coupon->date();
66
67 Date d, d0 = d1;
68 Real e2;
69 do {
70 d = NullCalendar().advance(d0 > today ? d0 : today,
71 stepSize_);
72 if (d > d2) d = d2;
73
74 e2 = arguments_.basket->expectedTrancheLoss(d);
75
77 // ..check for e2 including past/realized losses
78 += (inceptionTrancheNotional - e2)
81 * discountCurve_->discount(d);
82
83 // TO DO: Addd default coupon accrual value here-----
84
85 if (e2 < e1) results_.error ++;
86
88 += (e2 - e1) * discountCurve_->discount(d);
89
90 d0 = d;
91 e1 = e2;
92 }
93 while (d < d2);
94 results_.expectedTrancheLoss.push_back(e2);
95 }
96
97 // add includeSettlement date flows variable to engine.
98 if (!arguments_.normalizedLeg[0]->hasOccurred(today))
100 = inceptionTrancheNotional * arguments_.upfrontRate
101 * discountCurve_->discount(
102 ext::dynamic_pointer_cast<Coupon>(
103 arguments_.normalizedLeg[0])->accrualStartDate());
104
109 }
110
114 // Fair spread GIVEN the upfront
115 Real fairSpread = 0.;
116 if (results_.premiumValue != 0.0) {
117 fairSpread =
120 }
121
122 results_.additionalResults["fairPremium"] = fairSpread;
123 results_.additionalResults["premiumLegNPV"] =
125 results_.additionalResults["protectionLegNPV"] =
127 }
128
129}
130
131#endif
Date advance(const Date &, Integer n, TimeUnit unit, BusinessDayConvention convention=Following, bool endOfMonth=false) const
Definition: calendar.cpp:130
Concrete date class.
Definition: date.hpp:125
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
std::map< std::string, ext::any > additionalResults
Definition: instrument.hpp:123
Handle< YieldTermStructure > discountCurve_
void calculate() const override
Calendar for reproducing theoretical calculations.
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
Date d
Coupon paying a fixed annual rate.
QL_REAL Real
real number
Definition: types.hpp:50
Definition: any.hpp:35
Interest-rate term structure.