QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.38
Loading...
Searching...
No Matches
arithmeticoisratehelper.cpp
Go to the documentation of this file.
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
24#include <utility>
25
26namespace QuantLib {
27
29
31 const Period& tenor, // swap maturity
32 Frequency fixedLegPaymentFrequency,
33 const Handle<Quote>& fixedRate,
34 ext::shared_ptr<OvernightIndex> overnightIndex,
35 Frequency overnightLegPaymentFrequency,
36 Handle<Quote> spread,
37 Real meanReversionSpeed,
38 Real volatility,
39 bool byApprox,
41 : RelativeDateRateHelper(fixedRate), settlementDays_(settlementDays), tenor_(tenor),
42 overnightIndex_(std::move(overnightIndex)), discountHandle_(std::move(discount)),
43 fixedLegPaymentFrequency_(fixedLegPaymentFrequency),
44 overnightLegPaymentFrequency_(overnightLegPaymentFrequency), spread_(std::move(spread)),
45 mrs_(meanReversionSpeed), vol_(volatility), byApprox_(byApprox) {
50 }
51
53
54 // dummy OvernightIndex with curve/swap arguments
55 // review here
56 ext::shared_ptr<IborIndex> clonedIborIndex =
58 ext::shared_ptr<OvernightIndex> clonedOvernightIndex =
59 ext::dynamic_pointer_cast<OvernightIndex>(clonedIborIndex);
60
61 swap_ = MakeArithmeticAverageOIS(tenor_, clonedOvernightIndex, 0.0)
67
68 earliestDate_ = swap_->startDate();
69 latestDate_ = swap_->maturityDate();
70 }
71
73 // do not set the relinkable handle as an observer -
74 // force recalculation when needed
75 bool observer = false;
76
77 ext::shared_ptr<YieldTermStructure> temp(t, null_deleter());
78 termStructureHandle_.linkTo(temp, observer);
79
80 if (discountHandle_.empty())
81 discountRelinkableHandle_.linkTo(temp, observer);
82 else
84
86 }
87
89 QL_REQUIRE(termStructure_ != nullptr, "term structure not set");
90 // we didn't register as observers - force calculation
91 swap_->recalculate();
92 //return swap_->fairRate();
93 // weak implementation... to be improved
94 static const Spread basisPoint = 1.0e-4;
95 Real floatingLegNPV = swap_->overnightLegNPV();
96 Spread spread = spread_.empty() ? 0.0 : spread_->value();
97 Real spreadNPV = swap_->overnightLegBPS() / basisPoint*spread;
98 Real totNPV = -(floatingLegNPV + spreadNPV);
99 Real result = totNPV / (swap_->fixedLegBPS() / basisPoint);
100 return result;
101 }
102
104 auto* v1 = dynamic_cast<Visitor<ArithmeticOISRateHelper>*>(&v);
105 if (v1 != nullptr)
106 v1->visit(*this);
107 else
109 }
110
112
113}
Arithmetic Average Overnight Indexed Swap rate helpers.
ext::shared_ptr< SimpleQuote > vol_
Definition: cdsoption.cpp:62
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
ext::shared_ptr< ArithmeticAverageOIS > swap_
QL_DEPRECATED_DISABLE_WARNING 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 >())
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:226
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.
const DefaultType & t
discounting swap engine
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
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
Helper class to instantiate overnight indexed swaps.
Definition: any.hpp:37
STL namespace.
empty deleter for shared_ptr
ext::shared_ptr< BlackVolTermStructure > v
#define QL_DEPRECATED_DISABLE_WARNING
Definition: qldefines.hpp:216
#define QL_DEPRECATED_ENABLE_WARNING
Definition: qldefines.hpp:217