QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
fftengine.hpp
Go to the documentation of this file.
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/*! \file fftengine.hpp
21 \brief base class for FFT option pricing engines
22*/
23
24#ifndef quantlib_fft_engine_hpp
25#define quantlib_fft_engine_hpp
26
29#include <complex>
30
31namespace QuantLib {
32
33 //! Base class for FFT pricing engines for European vanilla options
34 /*! \ingroup vanillaengines
35
36 The FFT engine calculates the values of all options with the same expiry at the same time.
37 For that reason it is very inefficient to price options individually. When using this engine
38 you should collect all the options you wish to price in a list and call
39 the engine's precalculate method before calling the NPV method of the option.
40
41 References:
42 Carr, P. and D. B. Madan (1998),
43 "Option Valuation using the fast Fourier transform,"
44 Journal of Computational Finance, 2, 61-73.
45 */
46
47 class FFTEngine :
48 public VanillaOption::engine {
49 public:
50 FFTEngine(ext::shared_ptr<StochasticProcess1D> process, Real logStrikeSpacing);
51 void calculate() const override;
52 void update() override;
53
54 void precalculate(const std::vector<ext::shared_ptr<Instrument> >& optionList);
55 virtual std::unique_ptr<FFTEngine> clone() const = 0;
56 protected:
57 virtual void precalculateExpiry(Date d) = 0;
58 virtual std::complex<Real> complexFourierTransform(std::complex<Real> u) const = 0;
59 virtual Real discountFactor(Date d) const = 0;
60 virtual Real dividendYield(Date d) const = 0;
61 void calculateUncached(const ext::shared_ptr<StrikedTypePayoff>& payoff,
62 const ext::shared_ptr<Exercise>& exercise) const;
63
64 ext::shared_ptr<StochasticProcess1D> process_;
65 Real lambda_; // Log strike spacing
66
67 private:
68 typedef std::map<ext::shared_ptr<StrikedTypePayoff>, Real> PayoffResultMap;
69 typedef std::map<Date, PayoffResultMap> ResultMap;
71 };
72
73}
74
75
76#endif
77
Concrete date class.
Definition: date.hpp:125
Base class for FFT pricing engines for European vanilla options.
Definition: fftengine.hpp:48
virtual void precalculateExpiry(Date d)=0
void update() override
Definition: fftengine.cpp:58
void calculateUncached(const ext::shared_ptr< StrikedTypePayoff > &payoff, const ext::shared_ptr< Exercise > &exercise) const
Definition: fftengine.cpp:67
void calculate() const override
Definition: fftengine.cpp:34
ext::shared_ptr< StochasticProcess1D > process_
Definition: fftengine.hpp:64
void precalculate(const std::vector< ext::shared_ptr< Instrument > > &optionList)
Definition: fftengine.cpp:79
virtual Real dividendYield(Date d) const =0
std::map< ext::shared_ptr< StrikedTypePayoff >, Real > PayoffResultMap
Definition: fftengine.hpp:68
virtual std::complex< Real > complexFourierTransform(std::complex< Real > u) const =0
virtual Real discountFactor(Date d) const =0
ResultMap resultMap_
Definition: fftengine.hpp:70
virtual std::unique_ptr< FFTEngine > clone() const =0
std::map< Date, PayoffResultMap > ResultMap
Definition: fftengine.hpp:69
Date d
QL_REAL Real
real number
Definition: types.hpp:50
ext::shared_ptr< QuantLib::Payoff > payoff
Definition: any.hpp:35
stochastic processes
Vanilla option on a single asset.