Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
scaledcoupon.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/scaledcoupon.hpp
20 \brief Coupon / Cashflow paying scaled amounts
21 \ingroup cashflows
22*/
23
24#pragma once
25
26#include <ql/cashflows/coupon.hpp>
27#include <ql/patterns/lazyobject.hpp>
28#include <ql/time/daycounter.hpp>
29#include <ql/time/schedule.hpp>
30
31namespace QuantExt {
32using namespace QuantLib;
33
34//! scalable cashflow
35/*! %CashFlow that returns the scaled results for an underlying cashflow
36 \ingroup cashflows
37*/
38class ScaledCashFlow : public CashFlow {
39public:
40 ScaledCashFlow(Real multiplier, QuantLib::ext::shared_ptr<CashFlow> underlying)
41 : multiplier_(multiplier), underlying_(underlying) {}
42
43 Date date() const override { return underlying_->date(); }
44 Real amount() const override { return underlying_->amount() * multiplier_; }
45
46private:
48 QuantLib::ext::shared_ptr<CashFlow> underlying_;
49};
50
51//! scalable coupon
52/*! %Coupon that returns the scaled results for an underlying coupon
53 \ingroup cashflows
54*/
55class ScaledCoupon : public Coupon, public Observer {
56public:
57 ScaledCoupon(Real multiplier, QuantLib::ext::shared_ptr<Coupon> underlyingCoupon)
58 : Coupon(underlyingCoupon->date(), underlyingCoupon->nominal(), underlyingCoupon->accrualStartDate(),
59 underlyingCoupon->accrualEndDate()),
61 registerWith(underlyingCoupon_);
62 };
63 //! \name Observer interface
64 void update() override { notifyObservers(); }
65 //! \name Cashflow interface
66 Rate amount() const override { return multiplier_ * underlyingCoupon_->amount(); }
67
68 //! \name Inspectors
69 Real accruedAmount(const Date& d) const override { return multiplier_ * underlyingCoupon_->accruedAmount(d); }
70 Rate nominal() const override { return multiplier_ * underlyingCoupon_->nominal(); }
71 Rate rate() const override { return underlyingCoupon_->rate(); }
72 DayCounter dayCounter() const override { return underlyingCoupon_->dayCounter(); }
73
74 const Real multiplier() const { return multiplier_; }
75 const QuantLib::ext::shared_ptr<Coupon> underlyingCoupon() const { return underlyingCoupon_; }
76
77private:
79 QuantLib::ext::shared_ptr<Coupon> underlyingCoupon_;
80};
81
82} // namespace QuantExt
scalable cashflow
Real amount() const override
QuantLib::ext::shared_ptr< CashFlow > underlying_
Date date() const override
ScaledCashFlow(Real multiplier, QuantLib::ext::shared_ptr< CashFlow > underlying)
const QuantLib::ext::shared_ptr< Coupon > underlyingCoupon() const
void update() override
Rate rate() const override
const Real multiplier() const
Rate nominal() const override
DayCounter dayCounter() const override
ScaledCoupon(Real multiplier, QuantLib::ext::shared_ptr< Coupon > underlyingCoupon)
Rate amount() const override
QuantLib::ext::shared_ptr< Coupon > underlyingCoupon_
Real accruedAmount(const Date &d) const override