| 1 | /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 | |
| 3 | /* |
| 4 | Copyright (C) 2007, 2009 StatPro Italia srl |
| 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 | /*! \file impliedvolatility.hpp |
| 21 | \brief Utilities for implied-volatility calculation |
| 22 | */ |
| 23 | |
| 24 | #ifndef quantlib_implied_volatility_hpp |
| 25 | #define quantlib_implied_volatility_hpp |
| 26 | |
| 27 | #include <ql/instrument.hpp> |
| 28 | #include <ql/quotes/simplequote.hpp> |
| 29 | #include <ql/processes/blackscholesprocess.hpp> |
| 30 | |
| 31 | namespace QuantLib { |
| 32 | |
| 33 | namespace detail { |
| 34 | |
| 35 | //! helper class for one-asset implied-volatility calculation |
| 36 | /*! The passed engine must be linked to the passed quote (see, |
| 37 | e.g., VanillaOption to see how this can be achieved.) |
| 38 | |
| 39 | \note this function is meant for developers of option |
| 40 | classes so that they can implement an |
| 41 | impliedVolatility() method. |
| 42 | */ |
| 43 | class ImpliedVolatilityHelper { |
| 44 | public: |
| 45 | static Volatility calculate(const Instrument& instrument, |
| 46 | const PricingEngine& engine, |
| 47 | SimpleQuote& volQuote, |
| 48 | Real targetValue, |
| 49 | Real accuracy, |
| 50 | Natural maxEvaluations, |
| 51 | Volatility minVol, |
| 52 | Volatility maxVol); |
| 53 | // utilities |
| 54 | |
| 55 | /*! The returned process is equal to the passed one, except |
| 56 | for the volatility which is flat and whose value is driven |
| 57 | by the passed quote. |
| 58 | */ |
| 59 | static ext::shared_ptr<GeneralizedBlackScholesProcess> clone( |
| 60 | const ext::shared_ptr<GeneralizedBlackScholesProcess>&, |
| 61 | const ext::shared_ptr<SimpleQuote>&); |
| 62 | }; |
| 63 | |
| 64 | } |
| 65 | |
| 66 | } |
| 67 | |
| 68 | #endif |
| 69 | |