/src/quantlib/ql/quotes/impliedstddevquote.cpp
Line | Count | Source |
1 | | /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | |
3 | | /* |
4 | | Copyright (C) 2006, 2007, 2008 Ferdinando Ametrano |
5 | | Copyright (C) 2006 François du Vignaud |
6 | | |
7 | | This file is part of QuantLib, a free-software/open-source library |
8 | | for financial quantitative analysts and developers - http://quantlib.org/ |
9 | | |
10 | | QuantLib is free software: you can redistribute it and/or modify it |
11 | | under the terms of the QuantLib license. You should have received a |
12 | | copy of the license along with this program; if not, please email |
13 | | <quantlib-dev@lists.sf.net>. The license is also available online at |
14 | | <https://www.quantlib.org/license.shtml>. |
15 | | |
16 | | This program is distributed in the hope that it will be useful, but WITHOUT |
17 | | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
18 | | FOR A PARTICULAR PURPOSE. See the license for more details. |
19 | | */ |
20 | | |
21 | | #include <ql/pricingengines/blackformula.hpp> |
22 | | #include <ql/quotes/impliedstddevquote.hpp> |
23 | | #include <utility> |
24 | | |
25 | | namespace QuantLib { |
26 | | |
27 | | ImpliedStdDevQuote::ImpliedStdDevQuote(Option::Type optionType, |
28 | | Handle<Quote> forward, |
29 | | Handle<Quote> price, |
30 | | Real strike, |
31 | | Real guess, |
32 | | Real accuracy, |
33 | | Natural maxIter) |
34 | 0 | : impliedStdev_(guess), optionType_(optionType), strike_(strike), accuracy_(accuracy), |
35 | 0 | maxIter_(maxIter), forward_(std::move(forward)), price_(std::move(price)) { |
36 | 0 | registerWith(forward_); |
37 | 0 | registerWith(price_); |
38 | 0 | } Unexecuted instantiation: QuantLib::ImpliedStdDevQuote::ImpliedStdDevQuote(QuantLib::Option::Type, QuantLib::Handle<QuantLib::Quote>, QuantLib::Handle<QuantLib::Quote>, double, double, double, unsigned int) Unexecuted instantiation: QuantLib::ImpliedStdDevQuote::ImpliedStdDevQuote(QuantLib::Option::Type, QuantLib::Handle<QuantLib::Quote>, QuantLib::Handle<QuantLib::Quote>, double, double, double, unsigned int) |
39 | | |
40 | 0 | Real ImpliedStdDevQuote::value() const { |
41 | 0 | calculate(); |
42 | 0 | return impliedStdev_; |
43 | 0 | } |
44 | | |
45 | 0 | bool ImpliedStdDevQuote::isValid() const { |
46 | 0 | return !price_.empty() && !forward_.empty() && |
47 | 0 | price_->isValid() && forward_->isValid(); |
48 | 0 | } |
49 | | |
50 | 0 | void ImpliedStdDevQuote::performCalculations() const { |
51 | 0 | static const Real discount = 1.0; |
52 | 0 | static const Real displacement = 0.0; |
53 | 0 | Real blackPrice = price_->value(); |
54 | 0 | try { |
55 | 0 | impliedStdev_ = blackFormulaImpliedStdDev(optionType_, strike_, |
56 | 0 | forward_->value(), |
57 | 0 | blackPrice, |
58 | 0 | discount, displacement, |
59 | 0 | impliedStdev_, |
60 | 0 | accuracy_, maxIter_); |
61 | 0 | } catch(Error&) { |
62 | 0 | impliedStdev_ = 0.0; |
63 | 0 | } |
64 | 0 | } |
65 | | } |