/src/quantlib/ql/quotes/futuresconvadjustmentquote.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | |
3 | | /* |
4 | | Copyright (C) 2006 Giorgio Facchinetti |
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 | | <https://www.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/models/shortrate/onefactormodels/hullwhite.hpp> |
21 | | #include <ql/quotes/futuresconvadjustmentquote.hpp> |
22 | | #include <ql/time/imm.hpp> |
23 | | #include <utility> |
24 | | |
25 | | namespace QuantLib { |
26 | | |
27 | | FuturesConvAdjustmentQuote::FuturesConvAdjustmentQuote(const ext::shared_ptr<IborIndex>& index, |
28 | | const Date& futuresDate, |
29 | | Handle<Quote> futuresQuote, |
30 | | Handle<Quote> volatility, |
31 | | Handle<Quote> meanReversion) |
32 | 0 | : dc_(index->dayCounter()), futuresDate_(futuresDate), |
33 | 0 | indexMaturityDate_(index->maturityDate(futuresDate_)), futuresQuote_(std::move(futuresQuote)), |
34 | 0 | volatility_(std::move(volatility)), meanReversion_(std::move(meanReversion)) { |
35 | |
|
36 | 0 | registerWith(futuresQuote_); |
37 | 0 | registerWith(volatility_); |
38 | 0 | registerWith(meanReversion_); |
39 | 0 | registerWith(Settings::instance().evaluationDate()); |
40 | 0 | } Unexecuted instantiation: QuantLib::FuturesConvAdjustmentQuote::FuturesConvAdjustmentQuote(boost::shared_ptr<QuantLib::IborIndex> const&, QuantLib::Date const&, QuantLib::Handle<QuantLib::Quote>, QuantLib::Handle<QuantLib::Quote>, QuantLib::Handle<QuantLib::Quote>) Unexecuted instantiation: QuantLib::FuturesConvAdjustmentQuote::FuturesConvAdjustmentQuote(boost::shared_ptr<QuantLib::IborIndex> const&, QuantLib::Date const&, QuantLib::Handle<QuantLib::Quote>, QuantLib::Handle<QuantLib::Quote>, QuantLib::Handle<QuantLib::Quote>) |
41 | | |
42 | | FuturesConvAdjustmentQuote::FuturesConvAdjustmentQuote(const ext::shared_ptr<IborIndex>& index, |
43 | | const std::string& immCode, |
44 | | Handle<Quote> futuresQuote, |
45 | | Handle<Quote> volatility, |
46 | | Handle<Quote> meanReversion) |
47 | 0 | : dc_(index->dayCounter()), futuresDate_(IMM::date(immCode)), |
48 | 0 | indexMaturityDate_(index->maturityDate(futuresDate_)), futuresQuote_(std::move(futuresQuote)), |
49 | 0 | volatility_(std::move(volatility)), meanReversion_(std::move(meanReversion)) { |
50 | |
|
51 | 0 | registerWith(futuresQuote_); |
52 | 0 | registerWith(volatility_); |
53 | 0 | registerWith(meanReversion_); |
54 | 0 | registerWith(Settings::instance().evaluationDate()); |
55 | 0 | } Unexecuted instantiation: QuantLib::FuturesConvAdjustmentQuote::FuturesConvAdjustmentQuote(boost::shared_ptr<QuantLib::IborIndex> const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, QuantLib::Handle<QuantLib::Quote>, QuantLib::Handle<QuantLib::Quote>, QuantLib::Handle<QuantLib::Quote>) Unexecuted instantiation: QuantLib::FuturesConvAdjustmentQuote::FuturesConvAdjustmentQuote(boost::shared_ptr<QuantLib::IborIndex> const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, QuantLib::Handle<QuantLib::Quote>, QuantLib::Handle<QuantLib::Quote>, QuantLib::Handle<QuantLib::Quote>) |
56 | | |
57 | 0 | Real FuturesConvAdjustmentQuote::value() const { |
58 | 0 | if (rate_ == Null<Real>()) { |
59 | 0 | Date settlementDate = Settings::instance().evaluationDate(); |
60 | 0 | Time startTime = dc_.yearFraction(settlementDate, futuresDate_); |
61 | 0 | Time indexMaturity = dc_.yearFraction(settlementDate, |
62 | 0 | indexMaturityDate_); |
63 | 0 | rate_ = HullWhite::convexityBias(futuresQuote_->value(), |
64 | 0 | startTime, |
65 | 0 | indexMaturity, |
66 | 0 | volatility_->value(), |
67 | 0 | meanReversion_->value()); |
68 | 0 | } |
69 | 0 | return rate_; |
70 | 0 | } |
71 | | |
72 | 0 | bool FuturesConvAdjustmentQuote::isValid() const { |
73 | 0 | return !futuresQuote_.empty() && !volatility_.empty() && |
74 | 0 | !meanReversion_.empty() && futuresQuote_->isValid() && |
75 | 0 | volatility_->isValid() && meanReversion_->isValid(); |
76 | 0 | } |
77 | | } |