Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
oiccbasisswaphelper.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#include <ql/currencies/europe.hpp>
20#include <ql/pricingengines/swap/discountingswapengine.hpp>
21#include <ql/utilities/null_deleter.hpp>
24
25using QuantLib::ext::shared_ptr;
26
27using namespace QuantLib;
28
29namespace QuantExt {
30
31OICCBSHelper::OICCBSHelper(Natural settlementDays,
32 const Period& term, // swap maturity
33 const QuantLib::ext::shared_ptr<OvernightIndex>& payIndex, const Period& payTenor,
34 const QuantLib::ext::shared_ptr<OvernightIndex>& recIndex,
35 const Period& recTenor, // swap maturity
36 const Handle<Quote>& spreadQuote, const Handle<YieldTermStructure>& fixedDiscountCurve,
37 bool spreadQuoteOnPayLeg, bool fixedDiscountOnPayLeg)
38 : RelativeDateRateHelper(spreadQuote), settlementDays_(settlementDays), term_(term), payIndex_(payIndex),
39 payTenor_(payTenor), recIndex_(recIndex), recTenor_(recTenor), fixedDiscountCurve_(fixedDiscountCurve),
40 spreadQuoteOnPayLeg_(spreadQuoteOnPayLeg), fixedDiscountOnPayLeg_(fixedDiscountOnPayLeg) {
41
42 registerWith(payIndex_);
43 registerWith(recIndex_);
44 registerWith(fixedDiscountCurve_);
46}
47
49 Date asof = Settings::instance().evaluationDate();
50 Date settlementDate = payIndex_->fixingCalendar().advance(asof, settlementDays_, Days);
51 Schedule paySchedule = MakeSchedule().from(settlementDate).to(settlementDate + term_).withTenor(payTenor_);
52 Schedule recSchedule = MakeSchedule().from(settlementDate).to(settlementDate + term_).withTenor(recTenor_);
53 Currency payCurrency = EURCurrency(); // arbitrary here
54 Currency recCurrency = GBPCurrency(); // recCcy != payCcy, but FX=1
55 QuantLib::ext::shared_ptr<Quote> fx(new SimpleQuote(1.0));
56 swap_ = QuantLib::ext::shared_ptr<OvernightIndexedCrossCcyBasisSwap>(
57 new OvernightIndexedCrossCcyBasisSwap(10000.0, // arbitrary payNominal
58 payCurrency, paySchedule, payIndex_,
59 0.0, // zero pay spread
60 10000.0, // recNominal consistent with FX rate used
61 recCurrency, recSchedule, recIndex_,
62 0.0)); // target receive spread
64 QuantLib::ext::shared_ptr<PricingEngine> engine(new OvernightIndexedCrossCcyBasisSwapEngine(
65 fixedDiscountCurve_, payCurrency, termStructureHandle_, recCurrency, Handle<Quote>(fx)));
66 swap_->setPricingEngine(engine);
67 } else {
68 QuantLib::ext::shared_ptr<PricingEngine> engine(new OvernightIndexedCrossCcyBasisSwapEngine(
69 termStructureHandle_, payCurrency, fixedDiscountCurve_, recCurrency, Handle<Quote>(fx)));
70 swap_->setPricingEngine(engine);
71 }
72
73 earliestDate_ = swap_->startDate();
74 latestDate_ = swap_->maturityDate();
75}
76
77void OICCBSHelper::setTermStructure(YieldTermStructure* t) {
78 // do not set the relinkable handle as an observer -
79 // force recalculation when needed
80 termStructureHandle_.linkTo(QuantLib::ext::shared_ptr<YieldTermStructure>(t, null_deleter()), false);
81 RelativeDateRateHelper::setTermStructure(t);
82}
83
85 QL_REQUIRE(termStructure_ != 0, "term structure not set");
86 // we didn't register as observers - force calculation
87 swap_->deepUpdate();
89 return swap_->fairPayLegSpread();
90 else
91 return swap_->fairRecLegSpread();
92}
93
94void OICCBSHelper::accept(AcyclicVisitor& v) {
95 Visitor<OICCBSHelper>* v1 = dynamic_cast<Visitor<OICCBSHelper>*>(&v);
96 if (v1 != 0)
97 v1->visit(*this);
98 else
99 RateHelper::accept(v);
100}
101} // namespace QuantExt
void setTermStructure(YieldTermStructure *) override
QuantLib::ext::shared_ptr< OvernightIndex > recIndex_
OICCBSHelper(Natural settlementDays, const Period &term, const QuantLib::ext::shared_ptr< OvernightIndex > &payIndex, const Period &payTenor, const QuantLib::ext::shared_ptr< OvernightIndex > &recIndex, const Period &recTenor, const Handle< Quote > &spreadQuote, const Handle< YieldTermStructure > &fixedDiscountCurve, bool spreadQuoteOnPayLeg, bool fixedDiscountOnPayLeg)
RelinkableHandle< YieldTermStructure > termStructureHandle_
void accept(AcyclicVisitor &) override
QuantLib::ext::shared_ptr< OvernightIndexedCrossCcyBasisSwap > swap_
Real impliedQuote() const override
QuantLib::ext::shared_ptr< OvernightIndex > payIndex_
Handle< YieldTermStructure > fixedDiscountCurve_
Basis swap: compounded overnight rate in ccy 1 vs. compounded overnight rate in ccy 2.
RelativeDateBootstrapHelper< YieldTermStructure > RelativeDateRateHelper
Overnight Indexed Cross Currency Basis Swap Engine.
Overnight Indexed Cross Currency Basis Swap helpers.