QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
writerextensibleoption.cpp
Go to the documentation of this file.
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2011 Master IMAFA - Polytech'Nice Sophia - Université de Nice Sophia Antipolis
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#include <ql/event.hpp>
22#include <utility>
23
24namespace QuantLib {
25
27 const ext::shared_ptr<PlainVanillaPayoff>& payoff1,
28 const ext::shared_ptr<Exercise>& exercise1,
29 const ext::shared_ptr<PlainVanillaPayoff>& payoff2,
30 ext::shared_ptr<Exercise> exercise2)
31 : OneAssetOption(payoff1, exercise1), payoff2_(payoff2), exercise2_(std::move(exercise2)) {}
32
34 PricingEngine::arguments* args) const {
36
37 auto* otherArguments = dynamic_cast<WriterExtensibleOption::arguments*>(args);
38 QL_REQUIRE(otherArguments != nullptr, "wrong arguments type");
39
40 otherArguments->payoff2 = payoff2_;
41 otherArguments->exercise2 = exercise2_;
42 }
43
45 return detail::simple_event(exercise2_->lastDate()).hasOccurred();
46 }
47
49 OneAssetOption::arguments::validate();
50 QL_REQUIRE(payoff2, "no second payoff given");
51 QL_REQUIRE(exercise2, "no second exercise given");
52 QL_REQUIRE(exercise2->lastDate() > exercise->lastDate(),
53 "second exercise date is not later than the first");
54 }
55
56}
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
virtual void setupArguments(PricingEngine::arguments *) const
Definition: instrument.cpp:45
Base class for options on a single asset.
ext::shared_ptr< Exercise > exercise
Definition: option.hpp:65
Additional arguments for writer-extensible option.
WriterExtensibleOption(const ext::shared_ptr< PlainVanillaPayoff > &payoff1, const ext::shared_ptr< Exercise > &exercise1, const ext::shared_ptr< PlainVanillaPayoff > &payoff2, ext::shared_ptr< Exercise > exercise2)
void setupArguments(PricingEngine::arguments *) const override
bool isExpired() const override
returns whether the instrument might have value greater than zero.
ext::shared_ptr< Exercise > exercise2_
ext::shared_ptr< StrikedTypePayoff > payoff2_
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
Base class for events associated with a given date.
Definition: any.hpp:35
STL namespace.
Writer-extensible option.