Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
commodityspreadoption.hpp
Go to the documentation of this file.
1/*
2Copyright (C) 2022 Quaternion Risk Management Ltd
3All rights reserved.
4
5This file is part of ORE, a free-software/open-source library
6for transparent pricing and risk analysis - http://opensourcerisk.org
7
8ORE is free software: you can redistribute it and/or modify it
9under the terms of the Modified BSD License. You should have received a
10copy of the license along with this program.
11The license is also available online at <http://opensourcerisk.org>
12
13This program is distributed on the basis that it will form a useful
14contribution to risk analytics and model standardisation, but WITHOUT
15ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17*/
18#pragma once
19
20#include <boost/make_shared.hpp>
26
27namespace ore::data{
28//! Base Engine builder for Commodity Spread Options
29/*! Pricing engines are cached by currency
30-
31\ingroup builders
32*/
33
34class CommoditySpreadOptionBaseEngineBuilder : public CachingPricingEngineBuilder<std::string, const Currency&, QuantLib::ext::shared_ptr<QuantExt::CommodityIndex> const&,
35 QuantLib::ext::shared_ptr<QuantExt::CommodityIndex> const&, std::string const&> {
36public:
37 CommoditySpreadOptionBaseEngineBuilder(const std::string& model, const std::string& engine,
38 const std::set<std::string>& tradeTypes)
40protected:
41 std::string keyImpl(const Currency&, QuantLib::ext::shared_ptr<QuantExt::CommodityIndex> const&, QuantLib::ext::shared_ptr<QuantExt::CommodityIndex> const&, std::string const& id) override {
42 return id;
43 }
44
45};
46
47
48//! Analytical Engine builder for Commodity Spread Options
49/*! Pricing engines are cached by currency
50-
51\ingroup builders
52
53*/
55public:
57 : CommoditySpreadOptionBaseEngineBuilder("BlackScholes", "CommoditySpreadOptionEngine", {"CommoditySpreadOption"}){}
58protected:
59
60 QuantLib::ext::shared_ptr<QuantLib::PricingEngine> engineImpl(const Currency& ccy, QuantLib::ext::shared_ptr<QuantExt::CommodityIndex> const& longIndex, QuantLib::ext::shared_ptr<QuantExt::CommodityIndex> const& shortIndex, string const& id) override{
61 Handle<YieldTermStructure> yts = market_->discountCurve(ccy.code(), configuration(MarketContext::pricing));
62 Handle<QuantLib::BlackVolTermStructure> volLong =
63 market_->commodityVolatility(longIndex->underlyingName(), configuration(MarketContext::pricing));
64 Handle<QuantLib::BlackVolTermStructure> volShort =
65 market_->commodityVolatility(shortIndex->underlyingName(), configuration(MarketContext::pricing));
66 Real beta = 0;
67 Handle<QuantExt::CorrelationTermStructure> rho{nullptr};
68 auto param = engineParameters_.find("beta");
69 if (param != engineParameters_.end())
70 beta = parseReal(param->second);
71 else {
72 ALOG("Missing engine parameter 'beta' for " << model() << " " << EngineBuilder::engine()
73 << ", using default value " << beta);
74 }
75 if(longIndex->underlyingName() == shortIndex->underlyingName()){ // calendar spread option
76 rho = Handle<QuantExt::CorrelationTermStructure>(QuantLib::ext::make_shared<QuantExt::FlatCorrelation>(0,QuantLib::NullCalendar(), 1.0, QuantLib::Actual365Fixed()));
77 }else {
78 rho = market_->correlationCurve("COMM-"+longIndex->underlyingName(), "COMM-"+shortIndex->underlyingName(),
80
81 }
82 return QuantLib::ext::make_shared<QuantExt::CommoditySpreadOptionAnalyticalEngine>(yts, volLong, volShort, rho, beta);
83 }
84};
85}
Abstract template engine builder class.
Abstract template EngineBuilder class that can cache engines and coupon pricers.
Base Engine builder for Commodity Spread Options.
CommoditySpreadOptionBaseEngineBuilder(const std::string &model, const std::string &engine, const std::set< std::string > &tradeTypes)
std::string keyImpl(const Currency &, QuantLib::ext::shared_ptr< QuantExt::CommodityIndex > const &, QuantLib::ext::shared_ptr< QuantExt::CommodityIndex > const &, std::string const &id) override
Analytical Engine builder for Commodity Spread Options.
QuantLib::ext::shared_ptr< QuantLib::PricingEngine > engineImpl(const Currency &ccy, QuantLib::ext::shared_ptr< QuantExt::CommodityIndex > const &longIndex, QuantLib::ext::shared_ptr< QuantExt::CommodityIndex > const &shortIndex, string const &id) override
QuantLib::ext::shared_ptr< Market > market_
const string & engine() const
Return the engine name.
const set< string > & tradeTypes() const
Return the possible trade types.
map< string, string > engineParameters_
const string & model() const
Return the model name.
const string & configuration(const MarketContext &key)
Return a configuration (or the default one if key not found)
Pricing Engine Factory.
Real parseReal(const string &s)
Convert text to Real.
Definition: parsers.cpp:112
#define ALOG(text)
Logging Macro (Level = Alert)
Definition: log.hpp:544