Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
capflooredcpileg.hpp
Go to the documentation of this file.
1/*
2Copyright (C) 2019 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
19/*! \file ored/portfolio/builders/capflooredyoyleg.hpp
20\brief builder that returns an engine to price capped floored yoy inflation legs
21\ingroup builders
22*/
23
24#pragma once
25
28#include <ql/cashflows/couponpricer.hpp>
29#include <ql/cashflows/cpicouponpricer.hpp>
30#include <ql/indexes/inflationindex.hpp>
32
33namespace ore {
34namespace data {
35//! CouponPricer Builder for Capped/Floored CPI Inflation Leg
36/*! The coupon pricers are cached by index name
37\ingroup builders
38*/
40public:
42 : CachingEngineBuilder("Black", "BlackAnalytic", {"CappedFlooredCpiLegCoupons"}) {}
43
44protected:
45 virtual string keyImpl(const string& indexName) override { return indexName; }
46 virtual QuantLib::ext::shared_ptr<QuantLib::InflationCouponPricer> engineImpl(const string& indexName) override {
47 Handle<QuantLib::CPIVolatilitySurface> vol =
48 market_->cpiInflationCapFloorVolatilitySurface(indexName, configuration(MarketContext::pricing));
49 Handle<ZeroInflationIndex> cpiIndex =
50 market_->zeroInflationIndex(indexName, configuration(MarketContext::pricing));
51 std::string ccyCode = cpiIndex->currency().code();
52 Handle<YieldTermStructure> discountCurve =
53 market_->discountCurve(ccyCode, configuration(MarketContext::pricing));
54
55 bool useLastFixingDate =
56 parseBool(engineParameter("useLastFixingDate", std::vector<std::string>(), false, "false"));
57
58 bool isLogNormal = QuantExt::ZeroInflation::isCPIVolSurfaceLogNormal(vol.currentLink());
59
60 if (isLogNormal) {
61 return QuantLib::ext::make_shared<QuantExt::BlackCPICouponPricer>(vol, discountCurve, useLastFixingDate);
62 } else {
63 return QuantLib::ext::make_shared<QuantExt::BachelierCPICouponPricer>(vol, discountCurve, useLastFixingDate);
64 }
65
66
67 }
68};
69
71public:
73 : CachingEngineBuilder("Black", "BlackAnalytic", {"CappedFlooredCpiLegCashFlows"}) {}
74
75protected:
76 virtual string keyImpl(const string& indexName) override { return indexName; }
77 virtual QuantLib::ext::shared_ptr<QuantExt::InflationCashFlowPricer> engineImpl(const string& indexName) override {
78 Handle<QuantLib::CPIVolatilitySurface> vol =
79 market_->cpiInflationCapFloorVolatilitySurface(indexName, configuration(MarketContext::pricing));
80 Handle<ZeroInflationIndex> cpiIndex =
81 market_->zeroInflationIndex(indexName, configuration(MarketContext::pricing));
82 std::string ccyCode = cpiIndex->currency().code();
83 Handle<YieldTermStructure> discountCurve =
84 market_->discountCurve(ccyCode, configuration(MarketContext::pricing));
85
86 bool useLastFixingDate =
87 parseBool(engineParameter("useLastFixingDate", std::vector<std::string>(), false, "false"));
88
89 bool isLogNormal = QuantExt::ZeroInflation::isCPIVolSurfaceLogNormal(vol.currentLink());
90
91 if (isLogNormal) {
92 return QuantLib::ext::make_shared<QuantExt::BlackCPICashFlowPricer>(vol, discountCurve, useLastFixingDate);
93 } else {
94 return QuantLib::ext::make_shared<QuantExt::BachelierCPICashFlowPricer>(vol, discountCurve, useLastFixingDate);
95 }
96 }
97};
98} // namespace data
99} // namespace ore
Abstract template engine builder class.
Abstract template EngineBuilder class that can cache engines and coupon pricers.
virtual QuantLib::ext::shared_ptr< QuantExt::InflationCashFlowPricer > engineImpl(const string &indexName) override
virtual string keyImpl(const string &indexName) override
CouponPricer Builder for Capped/Floored CPI Inflation Leg.
virtual QuantLib::ext::shared_ptr< QuantLib::InflationCouponPricer > engineImpl(const string &indexName) override
virtual string keyImpl(const string &indexName) override
QuantLib::ext::shared_ptr< Market > market_
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.
bool parseBool(const string &s)
Convert text to bool.
Definition: parsers.cpp:144
@ data
Definition: log.hpp:77
bool isCPIVolSurfaceLogNormal(const boost::shared_ptr< QuantLib::CPIVolatilitySurface > &surface)
Serializable Credit Default Swap.
Definition: namespaces.docs:23