/src/quantlib/ql/experimental/finitedifferences/vanillavppoption.cpp
Line | Count | Source |
1 | | /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | |
3 | | /* |
4 | | Copyright (C) 2011 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 | | <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 | | /*! \file vanillavppoption.cpp |
21 | | */ |
22 | | |
23 | | |
24 | | #include <ql/event.hpp> |
25 | | #include <ql/instruments/basketoption.hpp> |
26 | | #include <ql/instruments/vanillaswingoption.hpp> |
27 | | #include <ql/experimental/finitedifferences/vanillavppoption.hpp> |
28 | | |
29 | | namespace QuantLib { |
30 | | namespace { |
31 | | |
32 | | class IdenticalPayoff : public Payoff { |
33 | | public: |
34 | 0 | std::string name() const override { return "IdenticalPayoff"; } |
35 | 0 | std::string description() const override { return name(); } |
36 | 0 | Real operator()(Real price) const override { return price; } |
37 | | }; |
38 | | } |
39 | | |
40 | | VanillaVPPOption::VanillaVPPOption( |
41 | | Real heatRate, |
42 | | Real pMin, Real pMax, |
43 | | Size tMinUp, Size tMinDown, |
44 | | Real startUpFuel, Real startUpFixCost, |
45 | | const ext::shared_ptr<SwingExercise>& exercise, |
46 | | Size nStarts, Size nRunningHours) |
47 | 0 | : MultiAssetOption(ext::shared_ptr<Payoff>(), exercise), |
48 | 0 | heatRate_(heatRate), |
49 | 0 | pMin_(pMin), pMax_(pMax), |
50 | 0 | tMinUp_(tMinUp), tMinDown_(tMinDown), |
51 | 0 | startUpFuel_(startUpFuel), |
52 | 0 | startUpFixCost_(startUpFixCost), |
53 | 0 | nStarts_(nStarts), |
54 | 0 | nRunningHours_(nRunningHours) { |
55 | 0 | Array weigths(2); |
56 | 0 | weigths[0] = 1.0; weigths[1] = -heatRate; |
57 | |
|
58 | 0 | payoff_ = ext::shared_ptr<Payoff>(new AverageBasketPayoff( |
59 | 0 | ext::shared_ptr<Payoff>(new IdenticalPayoff()), weigths)); |
60 | 0 | } Unexecuted instantiation: QuantLib::VanillaVPPOption::VanillaVPPOption(double, double, double, unsigned long, unsigned long, double, double, boost::shared_ptr<QuantLib::SwingExercise> const&, unsigned long, unsigned long) Unexecuted instantiation: QuantLib::VanillaVPPOption::VanillaVPPOption(double, double, double, unsigned long, unsigned long, double, double, boost::shared_ptr<QuantLib::SwingExercise> const&, unsigned long, unsigned long) |
61 | | |
62 | 0 | void VanillaVPPOption::arguments::validate() const { |
63 | 0 | QL_REQUIRE(exercise, "no exercise given"); |
64 | 0 | QL_REQUIRE(nStarts == Null<Size>() || nRunningHours == Null<Size>(), |
65 | 0 | "either a start limit or fuel limit is supported"); |
66 | 0 | } |
67 | | |
68 | | void VanillaVPPOption::setupArguments( |
69 | 0 | PricingEngine::arguments* args) const { |
70 | |
|
71 | 0 | MultiAssetOption::setupArguments(args); |
72 | |
|
73 | 0 | auto* arguments = dynamic_cast<VanillaVPPOption::arguments*>(args); |
74 | 0 | QL_REQUIRE(arguments != nullptr, "wrong argument type"); |
75 | | |
76 | 0 | arguments->heatRate = heatRate_; |
77 | 0 | arguments->pMin = pMin_; |
78 | 0 | arguments->pMax = pMax_; |
79 | 0 | arguments->tMinUp = tMinUp_; |
80 | 0 | arguments->tMinDown = tMinDown_; |
81 | 0 | arguments->startUpFuel = startUpFuel_; |
82 | 0 | arguments->startUpFixCost = startUpFixCost_; |
83 | 0 | arguments->nStarts = nStarts_; |
84 | 0 | arguments->nRunningHours = nRunningHours_; |
85 | 0 | } |
86 | | |
87 | 0 | bool VanillaVPPOption::isExpired() const { |
88 | 0 | return detail::simple_event(exercise_->lastDate()).hasOccurred(); |
89 | 0 | } |
90 | | } |
91 | | |