Coverage Report

Created: 2025-12-08 06:13

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/quantlib/ql/instruments/vanillastorageoption.hpp
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 vanillastorageoption.hpp
21
    \brief vanilla storage option class
22
*/
23
24
#ifndef quantlib_vanilla_storage_option_hpp
25
#define quantlib_vanilla_storage_option_hpp
26
27
#include <ql/event.hpp>
28
#include <ql/exercise.hpp>
29
#include <ql/instruments/payoffs.hpp>
30
#include <ql/instruments/oneassetoption.hpp>
31
32
namespace QuantLib {
33
34
    //! base option class
35
    class VanillaStorageOption : public OneAssetOption {
36
      public:
37
          class arguments;
38
          VanillaStorageOption(const ext::shared_ptr<BermudanExercise>& ex,
39
                               Real capacity, Real load, Real changeRate)
40
        : OneAssetOption(ext::shared_ptr<Payoff>(new NullPayoff), ex),
41
          capacity_  (capacity),
42
          load_      (load),
43
0
          changeRate_(changeRate) {}
44
45
          bool isExpired() const override;
46
          void setupArguments(PricingEngine::arguments*) const override;
47
48
        private:
49
          const Real capacity_;
50
          const Real load_;
51
          const Real changeRate_;
52
    };
53
54
    class VanillaStorageOption::arguments
55
        : public virtual PricingEngine::arguments {
56
      public:
57
0
        arguments() = default;
58
0
        void validate() const override {
59
0
            QL_REQUIRE(payoff, "no payoff given");
60
0
            QL_REQUIRE(exercise, "no exercise given");
61
62
0
            QL_REQUIRE(capacity > 0.0 && changeRate > 0.0 && load >= 0.0,
63
0
                      "positive capacity, load and change rate required");
64
0
            QL_REQUIRE(load <= capacity && changeRate <= capacity,
65
0
                        "illegal values load of changeRate");
66
0
        }
67
68
        Real capacity;
69
        Real load;
70
        Real changeRate;
71
        ext::shared_ptr<NullPayoff> payoff;
72
        ext::shared_ptr<BermudanExercise> exercise;
73
    };
74
75
    inline void VanillaStorageOption::setupArguments(
76
0
                                PricingEngine::arguments* args) const {
77
0
        auto* arguments = dynamic_cast<VanillaStorageOption::arguments*>(args);
78
0
        QL_REQUIRE(arguments != nullptr, "wrong argument type");
79
80
0
        arguments->payoff
81
0
            = ext::dynamic_pointer_cast<NullPayoff>(payoff_);
82
0
        arguments->exercise
83
0
            = ext::dynamic_pointer_cast<BermudanExercise>(exercise_);
84
0
        arguments->capacity   = capacity_;
85
0
        arguments->load       = load_;
86
0
        arguments->changeRate = changeRate_;
87
0
    }
88
89
0
    inline bool VanillaStorageOption::isExpired() const {
90
0
        return detail::simple_event(exercise_->lastDate()).hasOccurred();
91
0
    }
92
}
93
94
#endif