QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
vanillastorageoption.hpp
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 <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
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
32namespace QuantLib {
33
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 changeRate_(changeRate) {}
44
45 bool isExpired() const override;
46 void setupArguments(PricingEngine::arguments*) const override;
47
48 private:
50 const Real load_;
52 };
53
55 : public virtual PricingEngine::arguments {
56 public:
57 arguments() = default;
58 void validate() const override {
59 QL_REQUIRE(payoff, "no payoff given");
60 QL_REQUIRE(exercise, "no exercise given");
61
62 QL_REQUIRE(capacity > 0.0 && changeRate > 0.0 && load >= 0.0,
63 "positive capacity, load and change rate required");
64 QL_REQUIRE(load <= capacity && changeRate <= capacity,
65 "illegal values load of changeRate");
66 }
67
71 ext::shared_ptr<NullPayoff> payoff;
72 ext::shared_ptr<BermudanExercise> exercise;
73 };
74
76 PricingEngine::arguments* args) const {
77 auto* arguments = dynamic_cast<VanillaStorageOption::arguments*>(args);
78 QL_REQUIRE(arguments != nullptr, "wrong argument type");
79
81 = ext::dynamic_pointer_cast<NullPayoff>(payoff_);
83 = ext::dynamic_pointer_cast<BermudanExercise>(exercise_);
87 }
88
89 inline bool VanillaStorageOption::isExpired() const {
90 return detail::simple_event(exercise_->lastDate()).hasOccurred();
91 }
92}
93
94#endif
virtual bool hasOccurred(const Date &refDate=Date(), ext::optional< bool > includeRefDate=ext::nullopt) const
returns true if an event has already occurred before a date
Definition: event.cpp:28
Dummy payoff class.
Definition: payoffs.hpp:36
Base class for options on a single asset.
ext::shared_ptr< Payoff > payoff_
Definition: option.hpp:49
ext::shared_ptr< Exercise > exercise_
Definition: option.hpp:50
Abstract base class for option payoffs.
Definition: payoff.hpp:36
ext::shared_ptr< BermudanExercise > exercise
void setupArguments(PricingEngine::arguments *) const override
bool isExpired() const override
returns whether the instrument might have value greater than zero.
VanillaStorageOption(const ext::shared_ptr< BermudanExercise > &ex, Real capacity, Real load, Real changeRate)
QL_REAL Real
real number
Definition: types.hpp:50
Definition: any.hpp:35