QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
fdg2swaptionengine.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) 2011 Klaus Spanderen
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
20#include <ql/exercise.hpp>
31
32namespace QuantLib {
33
35 const ext::shared_ptr<G2>& model,
36 Size tGrid, Size xGrid, Size yGrid,
37 Size dampingSteps, Real invEps,
38 const FdmSchemeDesc& schemeDesc)
40 tGrid_(tGrid),
41 xGrid_(xGrid),
42 yGrid_(yGrid),
43 dampingSteps_(dampingSteps),
44 invEps_(invEps),
45 schemeDesc_(schemeDesc) {
46 }
47
49 QL_REQUIRE(!model_.empty(), "no model specified");
50
51 // 1. Term structure
52 const Handle<YieldTermStructure> ts = model_->termStructure();
53
54 // 2. Mesher
55 const DayCounter dc = ts->dayCounter();
56 const Date referenceDate = ts->referenceDate();
57 const Time maturity = dc.yearFraction(referenceDate,
58 arguments_.exercise->lastDate());
59
60 const ext::shared_ptr<OrnsteinUhlenbeckProcess> process1(
61 new OrnsteinUhlenbeckProcess(model_->a(), model_->sigma()));
62
63 const ext::shared_ptr<OrnsteinUhlenbeckProcess> process2(
64 new OrnsteinUhlenbeckProcess(model_->b(), model_->eta()));
65
66 const ext::shared_ptr<Fdm1dMesher> xMesher(
67 new FdmSimpleProcess1dMesher(xGrid_,process1,maturity,1,invEps_));
68
69 const ext::shared_ptr<Fdm1dMesher> yMesher(
70 new FdmSimpleProcess1dMesher(yGrid_,process2,maturity,1,invEps_));
71
72 const ext::shared_ptr<FdmMesher> mesher(
73 new FdmMesherComposite(xMesher, yMesher));
74
75 // 3. Inner Value Calculator
76 const std::vector<Date>& exerciseDates = arguments_.exercise->dates();
77 std::map<Time, Date> t2d;
78
79 for (auto exerciseDate : exerciseDates) {
80 const Time t = dc.yearFraction(referenceDate, exerciseDate);
81 QL_REQUIRE(t >= 0, "exercise dates must not contain past date");
82
83 t2d[t] = exerciseDate;
84 }
85
86 const Handle<YieldTermStructure> disTs = model_->termStructure();
88 = arguments_.swap->iborIndex()->forwardingTermStructure();
89
90 QL_REQUIRE(fwdTs->dayCounter() == disTs->dayCounter(),
91 "day counter of forward and discount curve must match");
92 QL_REQUIRE(fwdTs->referenceDate() == disTs->referenceDate(),
93 "reference date of forward and discount curve must match");
94
95 const ext::shared_ptr<G2> fwdModel(
96 new G2(fwdTs, model_->a(), model_->sigma(),
97 model_->b(), model_->eta(), model_->rho()));
98
99 const ext::shared_ptr<FdmInnerValueCalculator> calculator(
101 model_.currentLink(), fwdModel,
102 arguments_.swap, t2d, mesher, 0));
103
104 // 4. Step conditions
105 const ext::shared_ptr<FdmStepConditionComposite> conditions =
107 DividendSchedule(), arguments_.exercise,
108 mesher, calculator, referenceDate, dc);
109
110 // 5. Boundary conditions
111 const FdmBoundaryConditionSet boundaries;
112
113 // 6. Solver
114 FdmSolverDesc solverDesc = { mesher, boundaries, conditions,
115 calculator, maturity,
117
118 FdmG2Solver solver(model_, solverDesc, schemeDesc_);
119
120 results_.value = solver.valueAt(0.0, 0.0);
121 }
122}
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
void calculate() const override
FdG2SwaptionEngine(const ext::shared_ptr< G2 > &model, Size tGrid=100, Size xGrid=50, Size yGrid=50, Size dampingSteps=0, Real invEps=1e-5, const FdmSchemeDesc &schemeDesc=FdmSchemeDesc::Hundsdorfer())
Real valueAt(Real x, Real y) const
Definition: fdmg2solver.cpp:48
static ext::shared_ptr< FdmStepConditionComposite > vanillaComposite(const DividendSchedule &schedule, const ext::shared_ptr< Exercise > &exercise, const ext::shared_ptr< FdmMesher > &mesher, const ext::shared_ptr< FdmInnerValueCalculator > &calculator, const Date &refDate, const DayCounter &dayCounter)
Two-additive-factor gaussian model class.
Definition: g2.hpp:56
Base class for some pricing engine on a particular model.
Shared handle to an observable.
Definition: handle.hpp:41
bool empty() const
checks if the contained shared pointer points to anything
Definition: handle.hpp:191
const ext::shared_ptr< T > & currentLink() const
dereferencing
Definition: handle.hpp:173
Ornstein-Uhlenbeck process class.
Swaption class
Definition: swaption.hpp:88
const DefaultType & t
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
Option exercise classes and payoff function.
finite differences swaption engine
memory layout of a fdm linear operator
FdmMesher which is a composite of Fdm1dMesher.
One-dimensional grid mesher.
composite of fdm step conditions
Real Time
continuous quantity with 1-year units
Definition: types.hpp:62
QL_REAL Real
real number
Definition: types.hpp:50
std::size_t Size
size of a container
Definition: types.hpp:58
base class for Inter-Bank-Offered-Rate indexes
Definition: any.hpp:35
std::vector< ext::shared_ptr< Dividend > > DividendSchedule
OperatorTraits< FdmLinearOp >::bc_set FdmBoundaryConditionSet
Ornstein-Uhlenbeck process.