Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
depositengine.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2016 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
24DepositEngine::DepositEngine(const Handle<YieldTermStructure>& discountCurve,
25 boost::optional<bool> includeSettlementDateFlows, Date settlementDate, Date npvDate)
26 : discountCurve_(discountCurve), includeSettlementDateFlows_(includeSettlementDateFlows),
27 settlementDate_(settlementDate), npvDate_(npvDate) {
28 registerWith(discountCurve_);
29}
30
32 QL_REQUIRE(!discountCurve_.empty(), "discounting term structure handle is empty");
33
34 results_.value = 0.0;
35 results_.errorEstimate = Null<Real>();
36
37 Date refDate = discountCurve_->referenceDate();
38
39 Date settlementDate = settlementDate_;
40 if (settlementDate_ == Date()) {
41 settlementDate = refDate;
42 } else {
43 QL_REQUIRE(settlementDate >= refDate, "settlement date (" << settlementDate
44 << ") before "
45 "discount curve reference date ("
46 << refDate << ")");
47 }
48
49 Date valuationDate = npvDate_;
50 if (npvDate_ == Date()) {
51 valuationDate = refDate;
52 } else {
53 QL_REQUIRE(npvDate_ >= refDate, "npv date (" << npvDate_
54 << ") before "
55 "discount curve reference date ("
56 << refDate << ")");
57 }
58
59 bool includeRefDateFlows =
60 includeSettlementDateFlows_ ? *includeSettlementDateFlows_ : Settings::instance().includeReferenceDateEvents();
61
62 results_.value =
63 CashFlows::npv(arguments_.leg, **discountCurve_, includeRefDateFlows, settlementDate, valuationDate);
64
65 // calculate the fair rate of a hypothetical deposit instrument traded on the refDate with maturity as the original
66 // instrument; this is only possible if the maturity date is later than the start date of that new deposit
67 Date startDate = arguments_.index->valueDate(arguments_.index->fixingCalendar().adjust(refDate));
68 if (arguments_.maturityDate > startDate)
69 results_.fairRate =
70 (discountCurve_->discount(startDate) / discountCurve_->discount(arguments_.maturityDate) - 1.0) /
71 arguments_.index->dayCounter().yearFraction(startDate, arguments_.maturityDate);
72
73} // calculate
74} // namespace QuantExt
const Instrument::results * results_
Definition: cdsoption.cpp:81
Handle< YieldTermStructure > discountCurve_
boost::optional< bool > includeSettlementDateFlows_
void calculate() const override
DepositEngine(const Handle< YieldTermStructure > &discountCurve=Handle< YieldTermStructure >(), boost::optional< bool > includeSettlementDateFlows=boost::none, Date settlementDate=Date(), Date npvDate=Date())
deposit engine
Swap::arguments * arguments_