| 1 | /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 | |
| 3 | /* |
| 4 | Copyright (C) 2003, 2004 Neil Firth |
| 5 | Copyright (C) 2003, 2004 Ferdinando Ametrano |
| 6 | Copyright (C) 2003, 2004, 2007 StatPro Italia srl |
| 7 | |
| 8 | This file is part of QuantLib, a free-software/open-source library |
| 9 | for financial quantitative analysts and developers - http://quantlib.org/ |
| 10 | |
| 11 | QuantLib is free software: you can redistribute it and/or modify it |
| 12 | under the terms of the QuantLib license. You should have received a |
| 13 | copy of the license along with this program; if not, please email |
| 14 | <quantlib-dev@lists.sf.net>. The license is also available online at |
| 15 | <http://quantlib.org/license.shtml>. |
| 16 | |
| 17 | This program is distributed in the hope that it will be useful, but WITHOUT |
| 18 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 19 | FOR A PARTICULAR PURPOSE. See the license for more details. |
| 20 | */ |
| 21 | |
| 22 | /*! \file barrieroption.hpp |
| 23 | \brief Barrier option on a single asset |
| 24 | */ |
| 25 | |
| 26 | #ifndef quantlib_barrier_option_hpp |
| 27 | #define quantlib_barrier_option_hpp |
| 28 | |
| 29 | #include <ql/instruments/oneassetoption.hpp> |
| 30 | #include <ql/instruments/barriertype.hpp> |
| 31 | #include <ql/instruments/payoffs.hpp> |
| 32 | #include <ql/instruments/dividendschedule.hpp> |
| 33 | |
| 34 | namespace QuantLib { |
| 35 | |
| 36 | class GeneralizedBlackScholesProcess; |
| 37 | |
| 38 | //! %Barrier option on a single asset. |
| 39 | /*! The analytic pricing engine will be used if none if passed. |
| 40 | |
| 41 | \ingroup instruments |
| 42 | */ |
| 43 | class BarrierOption : public OneAssetOption { |
| 44 | public: |
| 45 | class arguments; |
| 46 | class engine; |
| 47 | BarrierOption(Barrier::Type barrierType, |
| 48 | Real barrier, |
| 49 | Real rebate, |
| 50 | const ext::shared_ptr<StrikedTypePayoff>& payoff, |
| 51 | const ext::shared_ptr<Exercise>& exercise); |
| 52 | void setupArguments(PricingEngine::arguments*) const override; |
| 53 | |
| 54 | /*! \warning see VanillaOption for notes on implied-volatility |
| 55 | calculation. |
| 56 | */ |
| 57 | //@{ |
| 58 | Volatility impliedVolatility( |
| 59 | Real price, |
| 60 | const ext::shared_ptr<GeneralizedBlackScholesProcess>& process, |
| 61 | Real accuracy = 1.0e-4, |
| 62 | Size maxEvaluations = 100, |
| 63 | Volatility minVol = 1.0e-7, |
| 64 | Volatility maxVol = 4.0) const; |
| 65 | Volatility impliedVolatility( |
| 66 | Real price, |
| 67 | const ext::shared_ptr<GeneralizedBlackScholesProcess>& process, |
| 68 | const DividendSchedule& dividends, |
| 69 | Real accuracy = 1.0e-4, |
| 70 | Size maxEvaluations = 100, |
| 71 | Volatility minVol = 1.0e-7, |
| 72 | Volatility maxVol = 4.0) const; |
| 73 | //@} |
| 74 | protected: |
| 75 | // arguments |
| 76 | Barrier::Type barrierType_; |
| 77 | Real barrier_; |
| 78 | Real rebate_; |
| 79 | }; |
| 80 | |
| 81 | //! %Arguments for barrier option calculation |
| 82 | class BarrierOption::arguments : public OneAssetOption::arguments { |
| 83 | public: |
| 84 | arguments(); |
| 85 | Barrier::Type barrierType; |
| 86 | Real barrier; |
| 87 | Real rebate; |
| 88 | void validate() const override; |
| 89 | }; |
| 90 | |
| 91 | //! %Barrier-option %engine base class |
| 92 | class BarrierOption::engine |
| 93 | : public GenericEngine<BarrierOption::arguments, |
| 94 | BarrierOption::results> { |
| 95 | protected: |
| 96 | bool triggered(Real underlying) const; |
| 97 | }; |
| 98 | |
| 99 | } |
| 100 | |
| 101 | #endif |
| 102 | |