Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
oiccbasisswapengine.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
19/*! \file qle/pricingengines/oiccbasisswapengine.hpp
20 \brief Overnight Indexed Cross Currency Basis Swap Engine
21 \ingroup
22*/
23
24#include <ql/cashflows/cashflows.hpp>
25#include <ql/utilities/dataformatters.hpp>
27
28using namespace QuantLib;
29
30namespace QuantExt {
31
33 const Currency& ccy1,
34 const Handle<YieldTermStructure>& ts2,
35 const Currency& ccy2,
36 const Handle<Quote>& fx)
37 : ts1_(ts1), ccy1_(ccy1), ts2_(ts2), ccy2_(ccy2), fx_(fx) {
38 registerWith(ts1_);
39 registerWith(ts2_);
40 registerWith(fx_);
41}
42
44 results_.value = 0.0;
45 results_.errorEstimate = Null<Real>();
46
47 QL_REQUIRE(!fx_.empty(), "fx handle not set");
48 QL_REQUIRE(!ts1_.empty(), "ts1 handle not set");
49 QL_REQUIRE(!ts2_.empty(), "ts2 handle not set");
50
51 QL_REQUIRE(ts1_->referenceDate() == ts2_->referenceDate(), "reference dates do not match");
52
53 Date npvDate = Settings::instance().evaluationDate();
54
55 results_.valuationDate = npvDate;
56
57 results_.legNPV.resize(arguments_.legs.size());
58 results_.legBPS.resize(arguments_.legs.size());
59
60 bool includeRefDateFlows = Settings::instance().includeReferenceDateEvents();
61
62 for (Size i = 0; i < arguments_.legs.size(); ++i) {
63 try {
64 Handle<YieldTermStructure> yts;
65 Real fx;
66 if (arguments_.currency[i] == ccy1_) {
67 yts = ts1_;
68 fx = 1.0;
69 } else {
70 yts = ts2_;
71 fx = fx_->value();
72 }
73 results_.legNPV[i] = fx * arguments_.payer[i] *
74 CashFlows::npv(arguments_.legs[i], **yts, includeRefDateFlows, npvDate, npvDate);
75 results_.legBPS[i] = fx * arguments_.payer[i] *
76 CashFlows::bps(arguments_.legs[i], **yts, includeRefDateFlows, npvDate, npvDate);
77 } catch (std::exception& e) {
78 QL_FAIL(io::ordinal(i + 1) << " leg: " << e.what());
79 }
80 results_.value += results_.legNPV[i];
81 }
82
83 static Spread basisPoint = 1.0e-4;
84 results_.fairPayLegSpread = arguments_.paySpread - results_.value / (results_.legBPS[0] / basisPoint);
85 results_.fairRecLegSpread = arguments_.recSpread - results_.value / (results_.legBPS[1] / basisPoint);
86}
87} // namespace QuantExt
const Instrument::results * results_
Definition: cdsoption.cpp:81
OvernightIndexedCrossCcyBasisSwapEngine(const Handle< YieldTermStructure > &ts1, const Currency &ccy1, const Handle< YieldTermStructure > &ts2, const Currency &ccy2, const Handle< Quote > &fx)
Overnight Indexed Cross Currency Basis Swap Engine.
Swap::arguments * arguments_