1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2008 StatPro Italia srl
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>
21#include <ql/experimental/varianceoption/varianceoption.hpp>
22#include <utility>
23
24namespace QuantLib {
25
26 VarianceOption::VarianceOption(ext::shared_ptr<Payoff> payoff,
27 Real notional,
28 const Date& startDate,
29 const Date& maturityDate)
30 : payoff_(std::move(payoff)), notional_(notional), startDate_(startDate),
31 maturityDate_(maturityDate) {}
32
33 void VarianceOption::setupArguments(PricingEngine::arguments* args) const {
34 auto* arguments = dynamic_cast<VarianceOption::arguments*>(args);
35 QL_REQUIRE(arguments != nullptr, "wrong argument type");
36
37 arguments->payoff = payoff_;
38 arguments->notional = notional_;
39 arguments->startDate = startDate_;
40 arguments->maturityDate = maturityDate_;
41 }
42
43 void VarianceOption::arguments::validate() const {
44 QL_REQUIRE(payoff, "no strike given");
45 QL_REQUIRE(notional != Null<Real>(), "no notional given");
46 QL_REQUIRE(notional > 0.0, "negative or null notional given");
47 QL_REQUIRE(startDate != Date(), "null start date given");
48 QL_REQUIRE(maturityDate != Date(), "null maturity date given");
49 }
50
51 bool VarianceOption::isExpired() const {
52 return detail::simple_event(maturityDate_).hasOccurred();
53 }
54
55}
56

source code of quantlib/ql/experimental/varianceoption/varianceoption.cpp