Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
crossccyswap.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2016 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 crossccyswap.hpp
20 \brief Swap instrument with legs involving two currencies
21
22 \ingroup instruments
23*/
24
25#ifndef quantext_cross_ccy_swap_hpp
26#define quantext_cross_ccy_swap_hpp
27
28#include <ql/currency.hpp>
29#include <ql/instruments/swap.hpp>
30
31namespace QuantExt {
32using namespace QuantLib;
33
34//! Cross currency swap
35/*! The first leg holds the pay currency cashflows and second leg holds
36 the receive currency cashflows.
37
38 \ingroup instruments
39*/
40class CrossCcySwap : public QuantLib::Swap {
41public:
42 class arguments;
43 class results;
44 class engine;
45 //! \name Constructors
46 //@{
47 //! First leg is paid and the second is received.
48 CrossCcySwap(const Leg& firstLeg, const Currency& firstLegCcy, const Leg& secondLeg, const Currency& secondLegCcy);
49 /*! Multi leg constructor. */
50 CrossCcySwap(const std::vector<Leg>& legs, const std::vector<bool>& payer, const std::vector<Currency>& currencies);
51 //@}
52 //! \name Instrument interface
53 //@{
54 void setupArguments(PricingEngine::arguments* args) const override;
55 void fetchResults(const PricingEngine::results*) const override;
56 //@}
57 //! \name Additional interface
58 //@{
59 const Currency& legCurrency(Size j) const {
60 QL_REQUIRE(j < legs_.size(), "leg# " << j << " doesn't exist!");
61 return currencies_[j];
62 }
63 Real inCcyLegBPS(Size j) const {
64 QL_REQUIRE(j < legs_.size(), "leg# " << j << " doesn't exist!");
65 calculate();
66 return inCcyLegBPS_[j];
67 }
68 Real inCcyLegNPV(Size j) const {
69 QL_REQUIRE(j < legs_.size(), "leg #" << j << " doesn't exist!");
70 calculate();
71 return inCcyLegNPV_[j];
72 }
73 DiscountFactor npvDateDiscounts(Size j) const {
74 QL_REQUIRE(j < legs_.size(), "leg #" << j << " doesn't exist!");
75 calculate();
76 return npvDateDiscounts_[j];
77 }
78 //@}
79protected:
80 //! \name Constructors
81 //@{
82 /*! This constructor can be used by derived classes that will
83 build their legs themselves.
84 */
85 CrossCcySwap(Size legs);
86 //@}
87 //! \name Instrument interface
88 //@{
89 void setupExpired() const override;
90 //@}
91
92 std::vector<Currency> currencies_;
93
94private:
95 mutable std::vector<Real> inCcyLegNPV_;
96 mutable std::vector<Real> inCcyLegBPS_;
97 mutable std::vector<DiscountFactor> npvDateDiscounts_;
98};
99
100//! \ingroup instruments
102public:
103 std::vector<Currency> currencies;
104 void validate() const override;
105};
106
107//! \ingroup instruments
109public:
110 std::vector<Real> inCcyLegNPV;
111 std::vector<Real> inCcyLegBPS;
112 std::vector<DiscountFactor> npvDateDiscounts;
113 void reset() override;
114};
115
116//! \ingroup instruments
117class CrossCcySwap::engine : public GenericEngine<CrossCcySwap::arguments, CrossCcySwap::results> {};
118} // namespace QuantExt
119
120#endif
std::vector< Currency > currencies
void validate() const override
std::vector< DiscountFactor > npvDateDiscounts
std::vector< Real > inCcyLegNPV
std::vector< Real > inCcyLegBPS
Cross currency swap.
std::vector< Real > inCcyLegNPV_
Real inCcyLegNPV(Size j) const
std::vector< DiscountFactor > npvDateDiscounts_
std::vector< Real > inCcyLegBPS_
void setupArguments(PricingEngine::arguments *args) const override
Real inCcyLegBPS(Size j) const
void setupExpired() const override
void fetchResults(const PricingEngine::results *) const override
DiscountFactor npvDateDiscounts(Size j) const
std::vector< Currency > currencies_
const Currency & legCurrency(Size j) const