Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
discountingcommodityforwardengine.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2018 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/event.hpp>
20
22
23using namespace std;
24using namespace QuantLib;
25
26namespace QuantExt {
27
28DiscountingCommodityForwardEngine::DiscountingCommodityForwardEngine(const Handle<YieldTermStructure>& discountCurve,
29 boost::optional<bool> includeSettlementDateFlows,
30 const Date& npvDate)
31 : discountCurve_(discountCurve), includeSettlementDateFlows_(includeSettlementDateFlows),
32 npvDate_(npvDate) {
33
34 registerWith(discountCurve_);
35}
36
38
39 const auto& index = arguments_.index;
40 Date npvDate = npvDate_;
41 if (npvDate == Null<Date>()) {
42 const auto& priceCurve = index->priceCurve();
43 QL_REQUIRE(!priceCurve.empty(), "DiscountingCommodityForwardEngine: need a non-empty price curve.");
44 npvDate = priceCurve->referenceDate();
45 }
46
47 const Date& maturity = arguments_.maturityDate;
48 Date paymentDate = maturity;
49 if (!arguments_.physicallySettled && arguments_.paymentDate != Date()) {
50 paymentDate = arguments_.paymentDate;
51 }
52
53 results_.value = 0.0;
54 if (!detail::simple_event(paymentDate).hasOccurred(Date(), includeSettlementDateFlows_)) {
55
56 Real buySell = arguments_.position == Position::Long ? 1.0 : -1.0;
57 Real forwardPrice = index->fixing(maturity);
58 Real discountPaymentDate = discountCurve_->discount(paymentDate);
59 auto value = arguments_.quantity * buySell * (forwardPrice - arguments_.strike) * discountPaymentDate /
60 discountCurve_->discount(npvDate);
61 if(arguments_.fxIndex && (arguments_.fixingDate!=Date()) && (arguments_.payCcy!=arguments_.currency)){ // NDF
62 auto fxRate = arguments_.fxIndex->fixing(arguments_.fixingDate);
63 value*=fxRate;
64 results_.additionalResults["productCurrency"] = arguments_.currency;
65 results_.additionalResults["settlementCurrency"] = arguments_.payCcy;
66 results_.additionalResults["fxRate"] = fxRate;
67 }
68 results_.value = value;
69 results_.additionalResults["forwardPrice"] = forwardPrice;
70 results_.additionalResults["currentNotional"] = forwardPrice * arguments_.quantity;
71 results_.additionalResults["discountPaymentDate"] = discountPaymentDate;
72 }
73}
74
75} // namespace QuantExt
const Instrument::results * results_
Definition: cdsoption.cpp:81
DiscountingCommodityForwardEngine(const QuantLib::Handle< QuantLib::YieldTermStructure > &discountCurve, boost::optional< bool > includeSettlementDateFlows=boost::none, const QuantLib::Date &npvDate=QuantLib::Date())
QuantLib::Handle< QuantLib::YieldTermStructure > discountCurve_
Engine to value a commodity forward contract.
Swap::arguments * arguments_