QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
varianceswap.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) 2006 Warren Chou
5 Copyright (C) 2007, 2008 StatPro Italia srl
6
7 This file is part of QuantLib, a free-software/open-source library
8 for financial quantitative analysts and developers - http://quantlib.org/
9
10 QuantLib is free software: you can redistribute it and/or modify it
11 under the terms of the QuantLib license. You should have received a
12 copy of the license along with this program; if not, please email
13 <quantlib-dev@lists.sf.net>. The license is also available online at
14 <http://quantlib.org/license.shtml>.
15
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the license for more details.
19*/
20
22#include <ql/event.hpp>
23
24namespace QuantLib {
25
27 Position::Type position,
28 Real strike,
29 Real notional,
30 const Date& startDate,
31 const Date& maturityDate)
32 : position_(position), strike_(strike), notional_(notional),
33 startDate_(startDate), maturityDate_(maturityDate) {}
34
36 calculate();
37 QL_REQUIRE(variance_ != Null<Real>(), "result not available");
38 return variance_;
39 }
40
44 }
45
47 auto* arguments = dynamic_cast<VarianceSwap::arguments*>(args);
48 QL_REQUIRE(arguments != nullptr, "wrong argument type");
49
55 }
56
59 const auto* results = dynamic_cast<const VarianceSwap::results*>(r);
61 }
62
64 QL_REQUIRE(strike != Null<Real>(), "no strike given");
65 QL_REQUIRE(strike > 0.0, "negative or null strike given");
66 QL_REQUIRE(notional != Null<Real>(), "no notional given");
67 QL_REQUIRE(notional > 0.0, "negative or null notional given");
68 QL_REQUIRE(startDate != Date(), "null start date given");
69 QL_REQUIRE(maturityDate != Date(), "null maturity date given");
70 }
71
74 }
75
76}
Concrete date class.
Definition: date.hpp:125
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
void calculate() const override
Definition: instrument.hpp:129
virtual void fetchResults(const PricingEngine::results *) const
Definition: instrument.hpp:155
virtual void setupExpired() const
Definition: instrument.hpp:140
template class providing a null value for a given type.
Definition: null.hpp:76
Arguments for forward fair-variance calculation
void validate() const override
Results from variance-swap calculation
bool isExpired() const override
returns whether the instrument might have value greater than zero.
VarianceSwap(Position::Type position, Real strike, Real notional, const Date &startDate, const Date &maturityDate)
void setupArguments(PricingEngine::arguments *args) const override
Position::Type position_
void setupExpired() const override
void fetchResults(const PricingEngine::results *) const override
#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.
QL_REAL Real
real number
Definition: types.hpp:50
Definition: any.hpp:35
ext::shared_ptr< YieldTermStructure > r
Variance swap.