Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
commodityswaption.hpp
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/*! \file portfolio/builders/commodityswaption.hpp
20\brief Engine builder for commodity swaptions
21\ingroup builders
22*/
23
24#pragma once
25
26#include <boost/make_shared.hpp>
30
31namespace ore {
32namespace data {
33
34//! Engine builder for Commodity Swaptions
35/*! Pricing engines are cached by currency and underlying name
36\ingroup builders
37*/
38class CommoditySwaptionEngineBuilder : public CachingPricingEngineBuilder<string, const Currency&, const string&> {
39public:
40 explicit CommoditySwaptionEngineBuilder(const std::string& engine)
41 : CachingEngineBuilder("Black", engine, {"CommoditySwaption"}) {}
42
43protected:
44 std::string keyImpl(const Currency& ccy, const string& name) override { return ccy.code() + ":" + name; }
45};
46
47//! Analytical Approximation Engine builder for Commodity Swaptions
48/*! Pricing engines are cached by currency and underlying name
49\ingroup builders
50*/
52public:
54
55protected:
56 QuantLib::ext::shared_ptr<QuantLib::PricingEngine> engineImpl(const Currency& ccy, const string& name) override {
57 Handle<QuantLib::BlackVolTermStructure> vol =
58 market_->commodityVolatility(name, configuration(MarketContext::pricing));
59 Handle<YieldTermStructure> yts = market_->discountCurve(ccy.code(), configuration(MarketContext::pricing));
60 Real beta = parseReal(engineParameter("beta"));
61 QL_REQUIRE(beta >= 0.0, "CommoditySwaptionAnalyticalEngineBuilder: beta must be non-negative");
62 return QuantLib::ext::make_shared<QuantExt::CommoditySwaptionEngine>(yts, vol, beta);
63 }
64};
65//! Monte Carlo Engine builder for Commodity Swaptions
66/*! Pricing engines are cached by currency and underlying name
67\ingroup builders
68*/
70public:
72
73protected:
74 QuantLib::ext::shared_ptr<QuantLib::PricingEngine> engineImpl(const Currency& ccy, const string& name) override {
75 Handle<QuantLib::BlackVolTermStructure> vol =
76 market_->commodityVolatility(name, configuration(MarketContext::pricing));
77 Handle<YieldTermStructure> yts = market_->discountCurve(ccy.code(), configuration(MarketContext::pricing));
78 Real beta = parseReal(engineParameter("beta"));
79 QL_REQUIRE(beta >= 0.0, "CommoditySwaptionAnalyticalEngineBuilder: beta must be non-negative");
80 Size samples = parseInteger(engineParameter("samples"));
81 long seed = parseInteger(engineParameter("seed"));
82 return QuantLib::ext::make_shared<QuantExt::CommoditySwaptionMonteCarloEngine>(yts, vol, samples, beta, seed);
83 }
84
85private:
86};
87
88} // namespace data
89} // namespace ore
Abstract template engine builder class.
Abstract template EngineBuilder class that can cache engines and coupon pricers.
Analytical Approximation Engine builder for Commodity Swaptions.
QuantLib::ext::shared_ptr< QuantLib::PricingEngine > engineImpl(const Currency &ccy, const string &name) override
Engine builder for Commodity Swaptions.
CommoditySwaptionEngineBuilder(const std::string &engine)
std::string keyImpl(const Currency &ccy, const string &name) override
Monte Carlo Engine builder for Commodity Swaptions.
QuantLib::ext::shared_ptr< QuantLib::PricingEngine > engineImpl(const Currency &ccy, const string &name) override
QuantLib::ext::shared_ptr< Market > market_
const string & engine() const
Return the engine name.
std::string engineParameter(const std::string &p, const std::vector< std::string > &qualifiers={}, const bool mandatory=true, const std::string &defaultValue="") const
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
Integer parseInteger(const string &s)
Convert text to QuantLib::Integer.
Definition: parsers.cpp:136
@ data
Definition: log.hpp:77
Serializable Credit Default Swap.
Definition: namespaces.docs:23
string name