Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
commodityspreadoption.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2019 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/exercise.hpp>
20#include <ql/shared_ptr.hpp>
24
25namespace QuantExt {
26
27CommoditySpreadOption::CommoditySpreadOption(const QuantLib::ext::shared_ptr<CommodityCashFlow>& longAssetFlow,
28 const QuantLib::ext::shared_ptr<CommodityCashFlow>& shortAssetFlow,
29 const ext::shared_ptr<Exercise>& exercise, const Real quantity,
30 const Real strikePrice, QuantLib::Option::Type type,
31 const QuantLib::Date& paymentDate,
32 const QuantLib::ext::shared_ptr<FxIndex>& longAssetFxIndex,
33 const QuantLib::ext::shared_ptr<FxIndex>& shortAssetFxIndex,
34 Settlement::Type delivery, Settlement::Method settlementMethod)
35 : Option(ext::shared_ptr<Payoff>(), exercise), longAssetFlow_(longAssetFlow), shortAssetFlow_(shortAssetFlow),
36 quantity_(quantity), strikePrice_(strikePrice), type_(type), paymentDate_(paymentDate),
37 longAssetFxIndex_(longAssetFxIndex), shortAssetFxIndex_(shortAssetFxIndex), settlementType_(delivery),
38 settlementMethod_(settlementMethod) {
39 registerWith(longAssetFlow_);
40 registerWith(shortAssetFlow_);
41 QL_REQUIRE(ext::dynamic_pointer_cast<CommodityIndexedCashFlow>(longAssetFlow_) ||
42 QuantLib::ext::dynamic_pointer_cast<CommodityIndexedAverageCashFlow>(longAssetFlow_),
43 "Expect commodity floating cashflows");
44 QL_REQUIRE(ext::dynamic_pointer_cast<CommodityIndexedCashFlow>(shortAssetFlow_) ||
45 QuantLib::ext::dynamic_pointer_cast<CommodityIndexedAverageCashFlow>(shortAssetFlow_),
46 "Expect commodity floating cashflows");
47 if (auto avgFlow = QuantLib::ext::dynamic_pointer_cast<CommodityIndexedAverageCashFlow>(longAssetFlow_)) {
48 QL_REQUIRE(exercise_->lastDate() >= avgFlow->indices().rbegin()->first,
49 "exercise Date hast to be after last observation date");
50 }
51 if (auto avgFlow = QuantLib::ext::dynamic_pointer_cast<CommodityIndexedAverageCashFlow>(shortAssetFlow_)) {
52 QL_REQUIRE(exercise_->lastDate() >= avgFlow->indices().rbegin()->first,
53 "exercise Date hast to be after last observation date");
54 }
55
57 registerWith(longAssetFxIndex_);
59 registerWith(shortAssetFxIndex_);
60 if (paymentDate_ == Date()) {
61 paymentDate_ = std::max(longAssetFlow_->date(), shortAssetFlow_->date());
62 }
63}
64
65bool CommoditySpreadOption::isExpired() const { return paymentDate_ < Settings::instance().evaluationDate(); }
66
68 return (strikePrice_ - longAssetFlow_->spread() + shortAssetFlow_->spread());
69}
70
71void CommoditySpreadOption::setupArguments(PricingEngine::arguments* args) const {
72 Option::setupArguments(args);
73
75
76 QL_REQUIRE(arguments != 0, "wrong argument type");
77 QL_REQUIRE(longAssetFlow_->gearing() > 0.0, "The gearing on an APO must be positive");
78
85 arguments->exercise = exercise_;
93}
94
96 : quantity(0.0), strikePrice(0.0), effectiveStrike(0.0), type(Option::Call), paymentDate(Date()),
97 longAssetFxIndex(nullptr), shortAssetFxIndex(nullptr), settlementType(Settlement::Physical),
98 settlementMethod(Settlement::PhysicalOTC) {}
99
101 QL_REQUIRE(longAssetFlow, "underlying not set");
102 QL_REQUIRE(shortAssetFlow, "underlying not set");
103 QL_REQUIRE(exercise, "exercise not set");
104 QuantLib::Settlement::checkTypeAndMethodConsistency(settlementType, settlementMethod);
105}
106
107
108
109} // namespace QuantExt
Arguments for commodity spread option calculation
QuantLib::ext::shared_ptr< CommodityCashFlow > longAssetFlow
QuantLib::ext::shared_ptr< FxIndex > longAssetFxIndex
QuantLib::ext::shared_ptr< CommodityCashFlow > shortAssetFlow
QuantLib::ext::shared_ptr< FxIndex > shortAssetFxIndex
QuantLib::Settlement::Type settlementType_
void setupArguments(PricingEngine::arguments *) const override
const QuantLib::ext::shared_ptr< CommodityCashFlow > & underlyingShortAssetFlow() const
const QuantLib::ext::shared_ptr< FxIndex > & shortAssetFxIndex() const
const QuantLib::ext::shared_ptr< FxIndex > & longAssetFxIndex() const
QuantLib::Settlement::Method settlementMethod_
QuantLib::ext::shared_ptr< CommodityCashFlow > longAssetFlow_
CommoditySpreadOption(const QuantLib::ext::shared_ptr< CommodityCashFlow > &longAssetCashflow, const QuantLib::ext::shared_ptr< CommodityCashFlow > &shortAssetCashflow, const ext::shared_ptr< Exercise > &exercise, const Real quantity, const Real strikePrice, Option::Type type, const QuantLib::Date &paymentDate=Date(), const QuantLib::ext::shared_ptr< FxIndex > &longAssetFxIndex=nullptr, const QuantLib::ext::shared_ptr< FxIndex > &shortAssetFxIndex=nullptr, Settlement::Type delivery=Settlement::Physical, Settlement::Method settlementMethod=Settlement::PhysicalOTC)
const QuantLib::ext::shared_ptr< CommodityCashFlow > & underlyingLongAssetFlow() const
QuantLib::ext::shared_ptr< CommodityCashFlow > shortAssetFlow_
QuantLib::ext::shared_ptr< FxIndex > longAssetFxIndex_
QuantLib::ext::shared_ptr< FxIndex > shortAssetFxIndex_
Cash flow dependent on the average commodity spot price or future's settlement price over a period....
Cash flow dependent on a single commodity spot price or future's settlement price.