QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
fftvanillaengine.cpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4Copyright (C) 2010 Adrian O' Neill
5
6This file is part of QuantLib, a free-software/open-source library
7for financial quantitative analysts and developers - http://quantlib.org/
8
9QuantLib is free software: you can redistribute it and/or modify it
10under the terms of the QuantLib license. You should have received a
11copy 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
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the license for more details.
18*/
19
20#include <ql/experimental/variancegamma/fftvanillaengine.hpp>
21#include <ql/exercise.hpp>
22#include <ql/termstructures/volatility/equityfx/blackconstantvol.hpp>
23#include <complex>
24
25namespace QuantLib {
26
28 const ext::shared_ptr<GeneralizedBlackScholesProcess>& process, Real logStrikeSpacing)
29 : FFTEngine(process, logStrikeSpacing)
30 {
31 }
32
33 std::unique_ptr<FFTEngine> FFTVanillaEngine::clone() const
34 {
35 ext::shared_ptr<GeneralizedBlackScholesProcess> process =
36 ext::dynamic_pointer_cast<GeneralizedBlackScholesProcess>(process_);
37 return std::unique_ptr<FFTEngine>(new FFTVanillaEngine(process, lambda_));
38 }
39
41 {
42 ext::shared_ptr<GeneralizedBlackScholesProcess> process =
43 ext::dynamic_pointer_cast<GeneralizedBlackScholesProcess>(process_);
44
46 process->dividendYield()->discount(d);
48 process->riskFreeRate()->discount(d);
49
50 DayCounter rfdc = process->riskFreeRate()->dayCounter();
51 t_ = rfdc.yearFraction(process->riskFreeRate()->referenceDate(), d);
52
53 ext::shared_ptr<BlackConstantVol> constVol = ext::dynamic_pointer_cast<BlackConstantVol>
54 (*(process->blackVolatility()));
55 QL_REQUIRE(constVol, "Constant volatility required");
56 Real vol = constVol->blackVol(0.0, 0.0);
57 var_ = vol*vol;
58 }
59
60 std::complex<Real> FFTVanillaEngine::complexFourierTransform(std::complex<Real> u) const
61 {
62 std::complex<Real> i1(0, 1);
63
64 Real s = process_->x0();
65
66 std::complex<Real> phi = std::exp(i1 * u * (std::log(s) - (var_ * t_) / 2.0)
67 - (var_ * u * u * t_) / 2.0);
68 phi = phi * std::pow(dividendDiscount_/ riskFreeDiscount_, i1 * u);
69 return phi;
70 }
71
73 {
74 ext::shared_ptr<GeneralizedBlackScholesProcess> process =
75 ext::dynamic_pointer_cast<GeneralizedBlackScholesProcess>(process_);
76 return process->riskFreeRate()->discount(d);
77 }
78
80 {
81 ext::shared_ptr<GeneralizedBlackScholesProcess> process =
82 ext::dynamic_pointer_cast<GeneralizedBlackScholesProcess>(process_);
83 return process->dividendYield()->discount(d);
84 }
85
86}
Concrete date class.
Definition: date.hpp:125
day counter class
Definition: daycounter.hpp:44
Time yearFraction(const Date &, const Date &, const Date &refPeriodStart=Date(), const Date &refPeriodEnd=Date()) const
Returns the period between two dates as a fraction of year.
Definition: daycounter.hpp:128
Base class for FFT pricing engines for European vanilla options.
Definition: fftengine.hpp:48
ext::shared_ptr< StochasticProcess1D > process_
Definition: fftengine.hpp:64
FFT Pricing engine vanilla options under a Black Scholes process.
void precalculateExpiry(Date d) override
std::complex< Real > complexFourierTransform(std::complex< Real > u) const override
std::unique_ptr< FFTEngine > clone() const override
FFTVanillaEngine(const ext::shared_ptr< GeneralizedBlackScholesProcess > &process, Real logStrikeSpacing=0.001)
Real dividendYield(Date d) const override
Real discountFactor(Date d) const override
QL_REAL Real
real number
Definition: types.hpp:50
Definition: any.hpp:35