Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
paymentdiscountingengine.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
19#include <ql/cashflows/cashflows.hpp>
21
22namespace QuantExt {
23
24PaymentDiscountingEngine::PaymentDiscountingEngine(const Handle<YieldTermStructure>& discountCurve,
25 const Handle<Quote>& spotFX,
26 boost::optional<bool> includeSettlementDateFlows,
27 const Date& settlementDate, const Date& npvDate)
28 : discountCurve_(discountCurve), spotFX_(spotFX), includeSettlementDateFlows_(includeSettlementDateFlows),
29 settlementDate_(settlementDate), npvDate_(npvDate) {
30 QL_REQUIRE(!discountCurve_.empty(), "empty discount curve");
31 registerWith(discountCurve_);
32 if (!spotFX.empty())
33 registerWith(spotFX);
34}
35
37 QL_REQUIRE(!discountCurve_.empty(), "discounting term structure handle is empty");
38
39 results_.value = 0.0;
40 results_.errorEstimate = Null<Real>();
41
42 Date refDate = discountCurve_->referenceDate();
43
44 Date settlementDate = settlementDate_;
45 if (settlementDate_ == Date()) {
46 settlementDate = refDate;
47 } else {
48 QL_REQUIRE(settlementDate >= refDate, "settlement date (" << settlementDate
49 << ") before discount curve reference date ("
50 << refDate << ")");
51 }
52
53 Date valuationDate = npvDate_;
54 if (npvDate_ == Date()) {
55 valuationDate = refDate;
56 } else {
57 QL_REQUIRE(npvDate_ >= refDate,
58 "npv date (" << npvDate_ << ") before discount curve reference date (" << refDate << ")");
59 }
60
61 bool includeRefDateFlows =
62 includeSettlementDateFlows_ ? *includeSettlementDateFlows_ : Settings::instance().includeReferenceDateEvents();
63
64 Real NPV = 0.0;
65 if (!arguments_.cashflow->hasOccurred(settlementDate, includeRefDateFlows))
66 NPV = arguments_.cashflow->amount() * discountCurve_->discount(arguments_.cashflow->date());
67
68 if (!spotFX_.empty())
69 NPV *= spotFX_->value();
70
71 results_.value = NPV / discountCurve_->discount(valuationDate);
72
73} // calculate
74} // namespace QuantExt
const Instrument::results * results_
Definition: cdsoption.cpp:81
Handle< YieldTermStructure > discountCurve_
const Handle< Quote > & spotFX() const
boost::optional< bool > includeSettlementDateFlows_
PaymentDiscountingEngine(const Handle< YieldTermStructure > &discountCurve, const Handle< Quote > &spotFX=Handle< Quote >(), boost::optional< bool > includeSettlementDateFlows=boost::none, const Date &settlementDate=Date(), const Date &npvDate=Date())
Single payment discounting engine.
Swap::arguments * arguments_