QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
equityfxvolsurface.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) 2007 Ferdinando Ametrano
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
21
22namespace QuantLib {
23
25 const DayCounter& dc)
26 : BlackVolSurface(bdc, dc) {}
27
29 const Calendar& cal,
31 const DayCounter& dc)
32 : BlackVolSurface(refDate, cal, bdc, dc) {}
33
35 const Calendar& cal,
37 const DayCounter& dc)
38 : BlackVolSurface(settlDays, cal, bdc, dc) {}
39
41 const Date& date2,
42 bool extrapolate) const {
43 QL_REQUIRE(date1<date2, "wrong dates");
44 Time t1 = timeFromReference(date1);
45 Time t2 = timeFromReference(date2);
46 return atmForwardVol(t1, t2, extrapolate);
47 }
48
50 Time time2,
51 bool extrapolate) const {
52 Real fwdVariance = atmForwardVariance(time1, time2, extrapolate);
53 Time t = time2-time1;
54 return std::sqrt(fwdVariance/t);
55 }
56
58 const Date& date2,
59 bool extrapolate) const {
60 QL_REQUIRE(date1<date2, "wrong dates");
61 Time t1 = timeFromReference(date1);
62 Time t2 = timeFromReference(date2);
63 return atmForwardVariance(t1, t2, extrapolate);
64 }
65
67 Time time2,
68 bool extrapolate) const {
69 QL_REQUIRE(time1<time2, "wrong times");
70 Real var1 = atmVariance(time1, extrapolate);
71 Real var2 = atmVariance(time2, extrapolate);
72 QL_ENSURE(var1<var2, "non-increasing variances");
73 return var2-var1;
74 }
75
77 auto* v1 = dynamic_cast<Visitor<EquityFXVolSurface>*>(&v);
78 if (v1 != nullptr)
79 v1->visit(*this);
80 else
81 QL_FAIL("not a EquityFXVolSurface term structure visitor");
82 }
83
84}
degenerate base class for the Acyclic Visitor pattern
Definition: visitor.hpp:33
Real atmVariance(const Period &optionTenor, bool extrapolate=false) const
spot at-the-money variance
Black volatility (smile) surface.
calendar class
Definition: calendar.hpp:61
Concrete date class.
Definition: date.hpp:125
day counter class
Definition: daycounter.hpp:44
Real atmForwardVariance(const Date &date1, const Date &date2, bool extrapolate=false) const
forward (at-the-money) variance
void accept(AcyclicVisitor &) override
EquityFXVolSurface(BusinessDayConvention bdc=Following, const DayCounter &dc=DayCounter())
default constructor
Volatility atmForwardVol(const Date &date1, const Date &date2, bool extrapolate=false) const
forward (at-the-money) volatility
Time timeFromReference(const Date &date) const
date/time conversion
Visitor for a specific class
Definition: visitor.hpp:40
virtual void visit(T &)=0
const DefaultType & t
Equity/FX vol (smile) surface.
#define QL_ENSURE(condition, message)
throw an error if the given post-condition is not verified
Definition: errors.hpp:130
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
#define QL_FAIL(message)
throw an error (possibly with file and line information)
Definition: errors.hpp:92
BusinessDayConvention
Business Day conventions.
Real Time
continuous quantity with 1-year units
Definition: types.hpp:62
QL_REAL Real
real number
Definition: types.hpp:50
unsigned QL_INTEGER Natural
positive integer
Definition: types.hpp:43
Real Volatility
volatility
Definition: types.hpp:78
Definition: any.hpp:35
ext::shared_ptr< BlackVolTermStructure > v