QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
fdblackscholesrebateengine.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) 2008 Andreas Gaida
5 Copyright (C) 2008, 2009 Ralph Schreyer
6 Copyright (C) 2008 Klaus Spanderen
7
8 This file is part of QuantLib, a free-software/open-source library
9 for financial quantitative analysts and developers - http://quantlib.org/
10
11 QuantLib is free software: you can redistribute it and/or modify it
12 under the terms of the QuantLib license. You should have received a
13 copy of the license along with this program; if not, please email
14 <quantlib-dev@lists.sf.net>. The license is also available online at
15 <http://quantlib.org/license.shtml>.
16
17 This program is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 FOR A PARTICULAR PURPOSE. See the license for more details.
20*/
21
22#include <ql/exercise.hpp>
31#include <utility>
32
33namespace QuantLib {
34
36 ext::shared_ptr<GeneralizedBlackScholesProcess> process,
37 Size tGrid,
38 Size xGrid,
39 Size dampingSteps,
40 const FdmSchemeDesc& schemeDesc,
41 bool localVol,
42 Real illegalLocalVolOverwrite)
43 : process_(std::move(process)),
44 tGrid_(tGrid), xGrid_(xGrid), dampingSteps_(dampingSteps),
45 schemeDesc_(schemeDesc), localVol_(localVol),
46 illegalLocalVolOverwrite_(illegalLocalVolOverwrite) {
47
49 }
50
52 ext::shared_ptr<GeneralizedBlackScholesProcess> process,
53 DividendSchedule dividends,
54 Size tGrid,
55 Size xGrid,
56 Size dampingSteps,
57 const FdmSchemeDesc& schemeDesc,
58 bool localVol,
59 Real illegalLocalVolOverwrite)
60 : process_(std::move(process)), dividends_(std::move(dividends)),
61 tGrid_(tGrid), xGrid_(xGrid), dampingSteps_(dampingSteps),
62 schemeDesc_(schemeDesc), localVol_(localVol),
63 illegalLocalVolOverwrite_(illegalLocalVolOverwrite) {
64
66 }
67
69
70 // 1. Mesher
71 const ext::shared_ptr<StrikedTypePayoff> payoff =
72 ext::dynamic_pointer_cast<StrikedTypePayoff>(arguments_.payoff);
73 const Time maturity = process_->time(arguments_.exercise->lastDate());
74
75 Real xMin=Null<Real>();
76 Real xMax=Null<Real>();
79 xMin = std::log(arguments_.barrier);
80 }
83 xMax = std::log(arguments_.barrier);
84 }
85
86 const ext::shared_ptr<Fdm1dMesher> equityMesher(
88 xGrid_, process_, maturity, payoff->strike(),
89 xMin, xMax, 0.0001, 1.5,
90 std::make_pair(Null<Real>(), Null<Real>()),
91 dividends_));
92
93 const ext::shared_ptr<FdmMesher> mesher (
94 new FdmMesherComposite(equityMesher));
95
96 // 2. Calculator
97 const ext::shared_ptr<StrikedTypePayoff> rebatePayoff(
99 const ext::shared_ptr<FdmInnerValueCalculator> calculator(
100 new FdmLogInnerValue(rebatePayoff, mesher, 0));
101
102 // 3. Step conditions
103 QL_REQUIRE(arguments_.exercise->type() == Exercise::European,
104 "only european style option are supported");
105
106 const ext::shared_ptr<FdmStepConditionComposite> conditions =
108 dividends_, arguments_.exercise,
109 mesher, calculator,
110 process_->riskFreeRate()->referenceDate(),
111 process_->riskFreeRate()->dayCounter());
112
113 // 4. Boundary conditions
114 FdmBoundaryConditionSet boundaries;
117 boundaries.push_back(FdmBoundaryConditionSet::value_type(
120
121 }
124 boundaries.push_back(FdmBoundaryConditionSet::value_type(
127 }
128
129 // 5. Solver
130 FdmSolverDesc solverDesc = { mesher, boundaries, conditions, calculator,
131 maturity, tGrid_, dampingSteps_ };
132
133 const ext::shared_ptr<FdmBlackScholesSolver> solver(
136 payoff->strike(), solverDesc, schemeDesc_,
138
139 const Real spot = process_->x0();
140 results_.value = solver->valueAt(spot);
141 results_.delta = solver->deltaAt(spot);
142 results_.gamma = solver->gammaAt(spot);
143 results_.theta = solver->thetaAt(spot);
144 }
145}
Binary cash-or-nothing payoff.
Definition: payoffs.hpp:152
FdBlackScholesRebateEngine(ext::shared_ptr< GeneralizedBlackScholesProcess > process, Size tGrid=100, Size xGrid=100, Size dampingSteps=0, const FdmSchemeDesc &schemeDesc=FdmSchemeDesc::Douglas(), bool localVol=false, Real illegalLocalVolOverwrite=-Null< Real >())
ext::shared_ptr< GeneralizedBlackScholesProcess > process_
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)
Shared handle to an observable.
Definition: handle.hpp:41
template class providing a null value for a given type.
Definition: null.hpp:76
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
Definition: observable.hpp:228
#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 Black/Scholes barrier option rebate helper engine.
1-d mesher for the Black-Scholes process (in ln(S))
Dirichlet boundary conditions for differential operators.
layer of abstraction to calculate the inner value
memory layout of a fdm linear operator
FdmMesher which is a composite of Fdm1dMesher.
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
ext::shared_ptr< QuantLib::Payoff > payoff
Definition: any.hpp:35
std::vector< ext::shared_ptr< Dividend > > DividendSchedule
OperatorTraits< FdmLinearOp >::bc_set FdmBoundaryConditionSet
STL namespace.