Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
crossccyswap.cpp
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
20
21namespace QuantExt {
22
23CrossCcySwap::CrossCcySwap(const Leg& firstLeg, const Currency& firstLegCcy, const Leg& secondLeg,
24 const Currency& secondLegCcy)
25 : Swap(firstLeg, secondLeg) {
26 currencies_.resize(2);
27 currencies_[0] = firstLegCcy;
28 currencies_[1] = secondLegCcy;
29}
30
31CrossCcySwap::CrossCcySwap(const std::vector<Leg>& legs, const std::vector<bool>& payer,
32 const std::vector<Currency>& currencies)
33 : Swap(legs, payer), currencies_(currencies) {
34 QL_REQUIRE(payer.size() == currencies_.size(), "Size mismatch "
35 "between payer ("
36 << payer.size() << ") and currencies (" << currencies_.size()
37 << ")");
38}
39
41 : Swap(legs), currencies_(legs), inCcyLegNPV_(legs, 0.0), inCcyLegBPS_(legs, 0.0), npvDateDiscounts_(legs, 0.0) {}
42
43void CrossCcySwap::setupArguments(PricingEngine::arguments* args) const {
44
45 Swap::setupArguments(args);
46
48 QL_REQUIRE(arguments, "The arguments are not of type "
49 "cross currency swap");
50
52}
53
54void CrossCcySwap::fetchResults(const PricingEngine::results* r) const {
55
56 Swap::fetchResults(r);
57
58 const CrossCcySwap::results* results = dynamic_cast<const CrossCcySwap::results*>(r);
59 QL_REQUIRE(results, "The results are not of type "
60 "cross currency swap");
61
62 if (!results->inCcyLegNPV.empty()) {
63 QL_REQUIRE(results->inCcyLegNPV.size() == inCcyLegNPV_.size(),
64 "Wrong number of in currency leg NPVs returned by engine");
66 } else {
67 std::fill(inCcyLegNPV_.begin(), inCcyLegNPV_.end(), Null<Real>());
68 }
69
70 if (!results->inCcyLegBPS.empty()) {
71 QL_REQUIRE(results->inCcyLegBPS.size() == inCcyLegBPS_.size(),
72 "Wrong number of in currency leg BPSs returned by engine");
74 } else {
75 std::fill(inCcyLegBPS_.begin(), inCcyLegBPS_.end(), Null<Real>());
76 }
77
78 if (!results->npvDateDiscounts.empty()) {
79 QL_REQUIRE(results->npvDateDiscounts.size() == npvDateDiscounts_.size(),
80 "Wrong number of npv date discounts returned by engine");
82 } else {
83 std::fill(npvDateDiscounts_.begin(), npvDateDiscounts_.end(), Null<DiscountFactor>());
84 }
85}
86
88 Swap::setupExpired();
89 std::fill(inCcyLegBPS_.begin(), inCcyLegBPS_.end(), 0.0);
90 std::fill(inCcyLegNPV_.begin(), inCcyLegNPV_.end(), 0.0);
91 std::fill(npvDateDiscounts_.begin(), npvDateDiscounts_.end(), 0.0);
92}
93
95 Swap::arguments::validate();
96 QL_REQUIRE(legs.size() == currencies.size(), "Number of legs is not equal to number of currencies");
97}
98
100 Swap::results::reset();
101 inCcyLegNPV.clear();
102 inCcyLegBPS.clear();
103 npvDateDiscounts.clear();
104}
105} // namespace QuantExt
std::vector< Currency > currencies
void validate() const override
std::vector< DiscountFactor > npvDateDiscounts
std::vector< Real > inCcyLegNPV
std::vector< Real > inCcyLegBPS
std::vector< Real > inCcyLegNPV_
CrossCcySwap(const Leg &firstLeg, const Currency &firstLegCcy, const Leg &secondLeg, const Currency &secondLegCcy)
First leg is paid and the second is received.
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_
Swap instrument with legs involving two currencies.