QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
arithmeticoisratehelper.cpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2016 Stefano Fondi
5
6 This file is part of QuantLib, a free-software/open-source library
7 for financial quantitative analysts and developers - http://quantlib.org/
8
9 QuantLib is free software: you can redistribute it and/or modify it
10 under the terms of the QuantLib license. You should have received a
11 copy of the license along with this program; if not, please email
12 <quantlib-dev@lists.sf.net>. The license is also available online at
13 <http://quantlib.org/license.shtml>.
14
15 This program is distributed in the hope that it will be useful, but WITHOUT
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 FOR A PARTICULAR PURPOSE. See the license for more details.
18*/
19
20#include <ql/experimental/averageois/arithmeticoisratehelper.hpp>
21#include <ql/experimental/averageois/makearithmeticaverageois.hpp>
22#include <ql/pricingengines/swap/discountingswapengine.hpp>
23#include <ql/utilities/null_deleter.hpp>
24#include <utility>
25
26namespace QuantLib {
27
29 const Period& tenor, // swap maturity
30 Frequency fixedLegPaymentFrequency,
31 const Handle<Quote>& fixedRate,
32 ext::shared_ptr<OvernightIndex> overnightIndex,
33 Frequency overnightLegPaymentFrequency,
34 Handle<Quote> spread,
35 Real meanReversionSpeed,
36 Real volatility,
37 bool byApprox,
39 : RelativeDateRateHelper(fixedRate), settlementDays_(settlementDays), tenor_(tenor),
40 overnightIndex_(std::move(overnightIndex)), discountHandle_(std::move(discount)),
41 fixedLegPaymentFrequency_(fixedLegPaymentFrequency),
42 overnightLegPaymentFrequency_(overnightLegPaymentFrequency), spread_(std::move(spread)),
43 mrs_(meanReversionSpeed), vol_(volatility), byApprox_(byApprox) {
48 }
49
51
52 // dummy OvernightIndex with curve/swap arguments
53 // review here
54 ext::shared_ptr<IborIndex> clonedIborIndex =
56 ext::shared_ptr<OvernightIndex> clonedOvernightIndex =
57 ext::dynamic_pointer_cast<OvernightIndex>(clonedIborIndex);
58
59 swap_ = MakeArithmeticAverageOIS(tenor_, clonedOvernightIndex, 0.0)
65
66 earliestDate_ = swap_->startDate();
67 latestDate_ = swap_->maturityDate();
68 }
69
71 // do not set the relinkable handle as an observer -
72 // force recalculation when needed
73 bool observer = false;
74
75 ext::shared_ptr<YieldTermStructure> temp(t, null_deleter());
76 termStructureHandle_.linkTo(temp, observer);
77
78 if (discountHandle_.empty())
79 discountRelinkableHandle_.linkTo(temp, observer);
80 else
82
84 }
85
87 QL_REQUIRE(termStructure_ != nullptr, "term structure not set");
88 // we didn't register as observers - force calculation
89 swap_->recalculate();
90 //return swap_->fairRate();
91 // weak implementation... to be improved
92 static const Spread basisPoint = 1.0e-4;
93 Real floatingLegNPV = swap_->overnightLegNPV();
94 Spread spread = spread_.empty() ? 0.0 : spread_->value();
95 Real spreadNPV = swap_->overnightLegBPS() / basisPoint*spread;
96 Real totNPV = -(floatingLegNPV + spreadNPV);
97 Real result = totNPV / (swap_->fixedLegBPS() / basisPoint);
98 return result;
99 }
100
102 auto* v1 = dynamic_cast<Visitor<ArithmeticOISRateHelper>*>(&v);
103 if (v1 != nullptr)
104 v1->visit(*this);
105 else
107 }
108
109}
degenerate base class for the Acyclic Visitor pattern
Definition: visitor.hpp:33
ext::shared_ptr< OvernightIndex > overnightIndex_
RelinkableHandle< YieldTermStructure > discountRelinkableHandle_
void setTermStructure(YieldTermStructure *) override
RelinkableHandle< YieldTermStructure > termStructureHandle_
Handle< YieldTermStructure > discountHandle_
void accept(AcyclicVisitor &) override
ArithmeticOISRateHelper(Natural settlementDays, const Period &tenor, Frequency fixedLegPaymentFrequency, const Handle< Quote > &fixedRate, ext::shared_ptr< OvernightIndex > overnightIndex, Frequency overnightLegPaymentFrequency, Handle< Quote > spread, Real meanReversionSpeed=0.03, Real volatility=0.00, bool byApprox=false, Handle< YieldTermStructure > discountingCurve=Handle< YieldTermStructure >())
ext::shared_ptr< ArithmeticAverageOIS > swap_
virtual void accept(AcyclicVisitor &)
virtual void setTermStructure(TS *)
sets the term structure to be used for pricing
Shared handle to an observable.
Definition: handle.hpp:41
MakeArithmeticAverageOIS & withFixedLegPaymentFrequency(Frequency f)
MakeArithmeticAverageOIS & withArithmeticAverage(Real meanReversionSpeed=0.03, Real volatility=0.00, bool byApprox=false)
MakeArithmeticAverageOIS & withDiscountingTermStructure(const Handle< YieldTermStructure > &discountingTermStructure)
MakeArithmeticAverageOIS & withSettlementDays(Natural settlementDays)
MakeArithmeticAverageOIS & withOvernightLegPaymentFrequency(Frequency f)
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
Definition: observable.hpp:228
Bootstrap helper with date schedule relative to global evaluation date.
Visitor for a specific class
Definition: visitor.hpp:40
virtual void visit(T &)=0
Interest-rate term structure.
Frequency
Frequency of events.
Definition: frequency.hpp:37
QL_REAL Real
real number
Definition: types.hpp:50
unsigned QL_INTEGER Natural
positive integer
Definition: types.hpp:43
Real Spread
spreads on interest rates
Definition: types.hpp:74
Definition: any.hpp:35
STL namespace.