QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
fftvariancegammaengine.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/fftvariancegammaengine.hpp>
21#include <ql/exercise.hpp>
22
23namespace QuantLib {
24
26 const ext::shared_ptr<VarianceGammaProcess>& process, Real logStrikeSpacing)
27 : FFTEngine(process, logStrikeSpacing)
28 {
29 }
30
31 std::unique_ptr<FFTEngine> FFTVarianceGammaEngine::clone() const
32 {
33 ext::shared_ptr<VarianceGammaProcess> process =
34 ext::dynamic_pointer_cast<VarianceGammaProcess>(process_);
35 return std::unique_ptr<FFTEngine>(new FFTVarianceGammaEngine(process, lambda_));
36 }
37
39 {
40 ext::shared_ptr<VarianceGammaProcess> process =
41 ext::dynamic_pointer_cast<VarianceGammaProcess>(process_);
42
44 process->dividendYield()->discount(d);
46 process->riskFreeRate()->discount(d);
47
48 DayCounter rfdc = process->riskFreeRate()->dayCounter();
49 t_ = rfdc.yearFraction(process->riskFreeRate()->referenceDate(), d);
50
51 sigma_ = process->sigma();
52 nu_ = process->nu();
53 theta_ = process->theta();
54 }
55
56 std::complex<Real> FFTVarianceGammaEngine::complexFourierTransform(std::complex<Real> u) const
57 {
58 Real s = process_->x0();
59
60 std::complex<Real> i1(0, 1);
61
62 Real omega = std::log(1.0 - theta_ * nu_ - sigma_*sigma_ * nu_ / 2.0) / nu_;
63 std::complex<Real> phi = std::exp(i1 * u * (std::log(s) + omega * t_))
64 * std::pow(dividendDiscount_/ riskFreeDiscount_, i1 * u);
65 phi = phi * (std::pow((1.0 - i1 * theta_ * nu_ * u + sigma_*sigma_ * nu_ * u*u / 2.0), (-t_ / nu_)));
66
67 return phi;
68 }
69
71 {
72 ext::shared_ptr<VarianceGammaProcess> process =
73 ext::dynamic_pointer_cast<VarianceGammaProcess>(process_);
74 return process->riskFreeRate()->discount(d);
75 }
76
78 {
79 ext::shared_ptr<VarianceGammaProcess> process =
80 ext::dynamic_pointer_cast<VarianceGammaProcess>(process_);
81 return process->dividendYield()->discount(d);
82 }
83
84}
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 engine for vanilla options under a Variance Gamma process.
std::complex< Real > complexFourierTransform(std::complex< Real > u) const override
std::unique_ptr< FFTEngine > clone() const override
FFTVarianceGammaEngine(const ext::shared_ptr< VarianceGammaProcess > &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