/src/quantlib/ql/instruments/vanillaswingoption.hpp
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) 2010 Klaus Spanderen |
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 vanillaswingoption.hpp |
21 | | \brief vanilla swing option class |
22 | | */ |
23 | | |
24 | | #ifndef quantlib_vanilla_swing_option_hpp |
25 | | #define quantlib_vanilla_swing_option_hpp |
26 | | |
27 | | #include <ql/exercise.hpp> |
28 | | #include <ql/time/daycounter.hpp> |
29 | | #include <ql/instruments/payoffs.hpp> |
30 | | #include <ql/instruments/oneassetoption.hpp> |
31 | | |
32 | | namespace QuantLib { |
33 | | |
34 | | //! Swing exercise |
35 | | /*! A Swing option can only be exercised at a set of fixed date times |
36 | | */ |
37 | | class SwingExercise : public BermudanExercise { |
38 | | public: |
39 | | explicit SwingExercise(const std::vector<Date>& dates, |
40 | | const std::vector<Size>& seconds = std::vector<Size>()); |
41 | | SwingExercise(const Date& from, const Date& to, Size stepSizeSecs); |
42 | | |
43 | | const std::vector<Size>& seconds() const; |
44 | | |
45 | | std::vector<Time> exerciseTimes(const DayCounter& dc, |
46 | | const Date& refDate) const; |
47 | | |
48 | | private: |
49 | | const std::vector<Size> seconds_; |
50 | | }; |
51 | | |
52 | | class VanillaForwardPayoff : public StrikedTypePayoff { |
53 | | public: |
54 | | VanillaForwardPayoff(Option::Type type, Real strike) |
55 | 0 | : StrikedTypePayoff(type, strike) {} |
56 | | |
57 | 0 | std::string name() const override { return "ForwardTypePayoff"; } |
58 | | Real operator()(Real price) const override; |
59 | | void accept(AcyclicVisitor&) override; |
60 | | }; |
61 | | |
62 | | //! base option class |
63 | | class VanillaSwingOption : public OneAssetOption { |
64 | | public: |
65 | | class arguments; |
66 | | VanillaSwingOption(const ext::shared_ptr<Payoff>& payoff, |
67 | | const ext::shared_ptr<SwingExercise>& ex, |
68 | | Size minExerciseRights, Size maxExerciseRights) |
69 | | : OneAssetOption(payoff, ex), |
70 | | minExerciseRights_(minExerciseRights), |
71 | 0 | maxExerciseRights_(maxExerciseRights) {} |
72 | | |
73 | | bool isExpired() const override; |
74 | | void setupArguments(PricingEngine::arguments*) const override; |
75 | | |
76 | | private: |
77 | | const Size minExerciseRights_, maxExerciseRights_; |
78 | | }; |
79 | | |
80 | | class VanillaSwingOption::arguments |
81 | | : public virtual PricingEngine::arguments { |
82 | | public: |
83 | 0 | arguments() = default; |
84 | | void validate() const override; |
85 | | |
86 | | Size minExerciseRights, maxExerciseRights; |
87 | | ext::shared_ptr<StrikedTypePayoff> payoff; |
88 | | ext::shared_ptr<SwingExercise> exercise; |
89 | | }; |
90 | | } |
91 | | |
92 | | #endif |