Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
formulabasedcoupon.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2018 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/cashflows/formulabasedcoupon.hpp
20 \brief formula based coupon
21 \ingroup cashflows
22*/
23
24#pragma once
25
27
28#include <ql/cashflows/couponpricer.hpp>
29#include <ql/cashflows/floatingratecoupon.hpp>
30#include <ql/termstructures/volatility/equityfx/blackvoltermstructure.hpp>
31#include <ql/time/schedule.hpp>
32
34
35namespace QuantExt {
36using namespace QuantLib;
37
38//! formula based coupon class
40public:
41 FormulaBasedCoupon(const Currency& paymentCurrency, const Date& paymentDate, Real nominal, const Date& startDate,
42 const Date& endDate, Natural fixingDays, const QuantLib::ext::shared_ptr<FormulaBasedIndex>& index,
43 const Date& refPeriodStart = Date(), const Date& refPeriodEnd = Date(),
44 const DayCounter& dayCounter = DayCounter(), bool isInArrears = false);
45 //! \name Inspectors
46 //@{
47 const Currency& paymentCurrency() const { return paymentCurrency_; }
48 const QuantLib::ext::shared_ptr<FormulaBasedIndex>& formulaBasedIndex() const { return index_; }
49 //@}
50 //! \name Visitability
51 //@{
52 virtual void accept(AcyclicVisitor&) override;
53 //@}
54private:
55 const Currency paymentCurrency_;
56 QuantLib::ext::shared_ptr<FormulaBasedIndex> index_;
57};
58
59//! helper class building a sequence of formula based coupons
61public:
62 FormulaBasedLeg(const Currency& paymentCurrency, const Schedule& schedule,
63 const QuantLib::ext::shared_ptr<FormulaBasedIndex>& index);
64 FormulaBasedLeg& withNotionals(Real notional);
65 FormulaBasedLeg& withNotionals(const std::vector<Real>& notionals);
66 FormulaBasedLeg& withPaymentDayCounter(const DayCounter&);
67 FormulaBasedLeg& withPaymentAdjustment(BusinessDayConvention);
68 FormulaBasedLeg& withPaymentLag(Natural lag);
69 FormulaBasedLeg& withPaymentCalendar(const Calendar&);
70 FormulaBasedLeg& withFixingDays(Natural fixingDays);
71 FormulaBasedLeg& withFixingDays(const std::vector<Natural>& fixingDays);
72 FormulaBasedLeg& inArrears(bool flag = true);
73 FormulaBasedLeg& withZeroPayments(bool flag = true);
74 operator Leg() const;
75
76private:
78 Schedule schedule_;
79 QuantLib::ext::shared_ptr<FormulaBasedIndex> index_;
80 std::vector<Real> notionals_;
82 BusinessDayConvention paymentAdjustment_;
83 Natural paymentLag_;
85 std::vector<Natural> fixingDays_;
87};
88
89//! base pricer for formula based coupons
90class FormulaBasedCouponPricer : public FloatingRateCouponPricer {
91public:
92 // fx vols should be given for index currencies vs. payment currency pairs;
93 // correlations should be given for pairs of index names resp. (index name,"FX"), if not given
94 // they are assumed to be zero
96 const std::string& paymentCurrencyCode,
97 const std::map<std::string, Handle<BlackVolTermStructure>>& fxVolatilities,
98 const std::map<std::pair<std::string, std::string>, Handle<QuantExt::CorrelationTermStructure>>& correlation)
99 : paymentCurrencyCode_(paymentCurrencyCode), fxVolatilities_(fxVolatilities), correlation_(correlation) {
100 for (auto const& v : fxVolatilities)
101 registerWith(v.second);
102 for (auto const& c : correlation)
103 registerWith(c.second);
104 }
105
106protected:
107 const std::string paymentCurrencyCode_;
108 const std::map<std::string, Handle<BlackVolTermStructure>> fxVolatilities_;
109 std::map<std::pair<std::string, std::string>, Handle<QuantExt::CorrelationTermStructure>> correlation_;
110};
111
112} // namespace QuantExt
formula based coupon class
const QuantLib::ext::shared_ptr< FormulaBasedIndex > & formulaBasedIndex() const
const Currency & paymentCurrency() const
QuantLib::ext::shared_ptr< FormulaBasedIndex > index_
virtual void accept(AcyclicVisitor &) override
base pricer for formula based coupons
FormulaBasedCouponPricer(const std::string &paymentCurrencyCode, const std::map< std::string, Handle< BlackVolTermStructure > > &fxVolatilities, const std::map< std::pair< std::string, std::string >, Handle< QuantExt::CorrelationTermStructure > > &correlation)
const std::map< std::string, Handle< BlackVolTermStructure > > fxVolatilities_
std::map< std::pair< std::string, std::string >, Handle< QuantExt::CorrelationTermStructure > > correlation_
helper class building a sequence of formula based coupons
BusinessDayConvention paymentAdjustment_
FormulaBasedLeg & withPaymentCalendar(const Calendar &)
FormulaBasedLeg & inArrears(bool flag=true)
QuantLib::ext::shared_ptr< FormulaBasedIndex > index_
std::vector< Real > notionals_
FormulaBasedLeg & withPaymentDayCounter(const DayCounter &)
FormulaBasedLeg & withNotionals(Real notional)
FormulaBasedLeg & withPaymentLag(Natural lag)
std::vector< Natural > fixingDays_
FormulaBasedLeg & withFixingDays(Natural fixingDays)
FormulaBasedLeg & withZeroPayments(bool flag=true)
FormulaBasedLeg & withPaymentAdjustment(BusinessDayConvention)
Term structure of correlations.
formula based index