Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
commodityforward.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
28CommodityForward::CommodityForward(const QuantLib::ext::shared_ptr<CommodityIndex>& index, const QuantLib::Currency& currency,
29 QuantLib::Position::Type position, QuantLib::Real quantity,
30 const QuantLib::Date& maturityDate, QuantLib::Real strike, bool physicallySettled,
31 const Date& paymentDate, const QuantLib::Currency& payCcy, const Date& fixingDate,
32 const QuantLib::ext::shared_ptr<QuantExt::FxIndex>& fxIndex)
33 : index_(index), currency_(currency), position_(position), quantity_(quantity), maturityDate_(maturityDate),
34 strike_(strike), physicallySettled_(physicallySettled), paymentDate_(paymentDate), payCcy_(payCcy),
35 fxIndex_(fxIndex), fixingDate_(fixingDate) {
36
37 QL_REQUIRE(quantity_ > 0, "Commodity forward quantity should be positive: " << quantity);
38 QL_REQUIRE(strike_ > 0 || close_enough(strike_, 0.0), "Commodity forward strike should be greater than or equal to 0: " << strike);
39
41 QL_REQUIRE(paymentDate_ == Date(), "CommodityForward: payment date (" << io::iso_date(paymentDate_) <<
42 ") should not be provided for physically settled commodity forwards.");
43 }
44
45 if (!physicallySettled_ && paymentDate_ != Date()) {
46 QL_REQUIRE(paymentDate_ >= maturityDate_, "CommodityForward: payment date (" << io::iso_date(paymentDate_) <<
47 ") for a cash settled commodity forward should be on or after the maturity date (" <<
48 io::iso_date(maturityDate_) << ").");
49 }
50
51 if (!physicallySettled_ && fixingDate_ != Date()) {
52 QL_REQUIRE(paymentDate_ >= fixingDate_,
53 "CommodityNonDeliverableForward: payment date ("
54 << io::iso_date(paymentDate_) << ") for a commodity NDF should be on or after the fixing date ("
55 << io::iso_date(fixingDate_) << ").");
56 }
57
58 registerWith(index_);
59}
60
62 if (physicallySettled_ || paymentDate_ == Date()) {
63 return detail::simple_event(maturityDate_).hasOccurred();
64 } else {
65 return detail::simple_event(paymentDate_).hasOccurred();
66 }
67}
68
70 auto* arguments = dynamic_cast<CommodityForward::arguments*>(args);
71 QL_REQUIRE(arguments != nullptr, "wrong argument type in CommodityForward");
72
84}
85
87 QL_REQUIRE(quantity > 0, "quantity should be positive: " << quantity);
88 QL_REQUIRE(strike > 0 || close_enough(strike, 0.0), "strike should be greater than or equal to 0: " << strike);
89}
90
91} // namespace QuantExt
QuantLib::ext::shared_ptr< FxIndex > fxIndex
QuantLib::ext::shared_ptr< CommodityIndex > index
CommodityForward(const QuantLib::ext::shared_ptr< CommodityIndex > &index, const QuantLib::Currency &currency, QuantLib::Position::Type position, QuantLib::Real quantity, const QuantLib::Date &maturityDate, QuantLib::Real strike, bool physicallySettled=true, const Date &paymentDate=Date(), const QuantLib::Currency &payCcy=Currency(), const Date &fixingDate=Date(), const QuantLib::ext::shared_ptr< QuantExt::FxIndex > &fxIndex=nullptr)
QuantLib::ext::shared_ptr< FxIndex > fxIndex_
bool isExpired() const override
QuantLib::Currency currency_
QuantLib::ext::shared_ptr< CommodityIndex > index_
void setupArguments(QuantLib::PricingEngine::arguments *) const override
QuantLib::Real quantity() const
QuantLib::Position::Type position_
QuantLib::Real strike() const
Instrument representing a commodity forward contract.
Filter close_enough(const RandomVariable &x, const RandomVariable &y)