Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
commodityspreadoption.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2022 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/*! \file qle/instruments/commodityspreadoption.hpp
20 \brief Option class
21*/
22
23#pragma once
24#include <ql/exercise.hpp>
25#include <ql/instruments/swaption.hpp>
26#include <ql/option.hpp>
27#include <ql/termstructures/volatility/volatilitytype.hpp>
28#include <ql/termstructures/yieldtermstructure.hpp>
32
33namespace QuantExt {
34using namespace QuantLib;
35
36//! Commodity Spread Option
37/*! \ingroup instruments
38 */
39class CommoditySpreadOption : public Option {
40public:
41 class arguments;
42 class engine;
43 CommoditySpreadOption(const QuantLib::ext::shared_ptr<CommodityCashFlow>& longAssetCashflow,
44 const QuantLib::ext::shared_ptr<CommodityCashFlow>& shortAssetCashflow,
45 const ext::shared_ptr<Exercise>& exercise, const Real quantity, const Real strikePrice,
46 Option::Type type, const QuantLib::Date& paymentDate = Date(),
47 const QuantLib::ext::shared_ptr<FxIndex>& longAssetFxIndex = nullptr,
48 const QuantLib::ext::shared_ptr<FxIndex>& shortAssetFxIndex = nullptr,
49 Settlement::Type delivery = Settlement::Physical,
50 Settlement::Method settlementMethod = Settlement::PhysicalOTC);
51
52
53 //! \name Instrument interface
54 //@{
55 bool isExpired() const override;
56 void setupArguments(PricingEngine::arguments*) const override;
57 //@}
58
59 //! \name Inspectors
60 //@{
61 const QuantLib::ext::shared_ptr<CommodityCashFlow>& underlyingLongAssetFlow() const { return longAssetFlow_; }
62 const QuantLib::ext::shared_ptr<CommodityCashFlow>& underlyingShortAssetFlow() const { return shortAssetFlow_; }
63
64 const QuantLib::ext::shared_ptr<FxIndex>& longAssetFxIndex() const { return longAssetFxIndex_; }
65 const QuantLib::ext::shared_ptr<FxIndex>& shortAssetFxIndex() const { return shortAssetFxIndex_; }
66 Real effectiveStrike() const;
67 //@}
68
69 bool isCalendarSpread() const;
70
71private:
72 // arguments
73 QuantLib::ext::shared_ptr<CommodityCashFlow> longAssetFlow_;
74 QuantLib::ext::shared_ptr<CommodityCashFlow> shortAssetFlow_;
77 Option::Type type_;
79 QuantLib::ext::shared_ptr<FxIndex> longAssetFxIndex_;
80 QuantLib::ext::shared_ptr<FxIndex> shortAssetFxIndex_;
81 QuantLib::Settlement::Type settlementType_;
82 QuantLib::Settlement::Method settlementMethod_;
83};
84
85//! %Arguments for commodity spread option calculation
86class CommoditySpreadOption::arguments : public Option::arguments {
87public:
88 arguments();
89 QuantLib::ext::shared_ptr<CommodityCashFlow> longAssetFlow;
90 QuantLib::ext::shared_ptr<CommodityCashFlow> shortAssetFlow;
94 Option::Type type;
96 QuantLib::ext::shared_ptr<FxIndex> longAssetFxIndex;
97 QuantLib::ext::shared_ptr<FxIndex> shortAssetFxIndex;
101 Settlement::Type settlementType;
102 Settlement::Method settlementMethod;
103 void validate() const override;
104};
105
106//! base class for commodity spread option engines
108 : public GenericEngine<CommoditySpreadOption::arguments, CommoditySpreadOption::results> {};
109
110} // 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
base class for commodity spread option engines
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_
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_
Some data and logic shared among commodity cashflows.
Cash flow dependent on the average commodity spot price or future's settlement price over a period....
FX index class.