Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
FdmBlackScholesOp Class Reference

#include <qle/methods/fdmblackscholesop.hpp>

+ Inheritance diagram for FdmBlackScholesOp:
+ Collaboration diagram for FdmBlackScholesOp:

Public Member Functions

 FdmBlackScholesOp (const ext::shared_ptr< FdmMesher > &mesher, const ext::shared_ptr< GeneralizedBlackScholesProcess > &process, Real strike=Null< Real >(), bool localVol=false, Real illegalLocalVolOverwrite=-Null< Real >(), Size direction=0, const ext::shared_ptr< FdmQuantoHelper > &quantoHelper=ext::shared_ptr< FdmQuantoHelper >(), const bool discounting=true, const bool ensureNonNegativeForwardVariance=false)
 
Size size () const override
 
void setTime (Time t1, Time t2) override
 
Array apply (const Array &r) const override
 
Array apply_mixed (const Array &r) const override
 
Array apply_direction (Size direction, const Array &r) const override
 
Array solve_splitting (Size direction, const Array &r, Real s) const override
 
Array preconditioner (const Array &r, Real s) const override
 
std::vector< QuantLib::SparseMatrix > toMatrixDecomp () const override
 

Private Attributes

const ext::shared_ptr< FdmMesher > mesher_
 
const ext::shared_ptr< YieldTermStructure > rTS_
 
const ext::shared_ptr< YieldTermStructure > qTS_
 
const ext::shared_ptr< BlackVolTermStructurevolTS_
 
const ext::shared_ptr< LocalVolTermStructure > localVol_
 
const Array x_
 
const FirstDerivativeOp dxMap_
 
const TripleBandLinearOp dxxMap_
 
TripleBandLinearOp mapT_
 
const Real strike_
 
const Real illegalLocalVolOverwrite_
 
const Size direction_
 
const ext::shared_ptr< FdmQuantoHelperquantoHelper_
 
const Real initialValue_
 
const bool discounting_
 
const bool ensureNonNegativeForwardVariance_
 

Detailed Description

Definition at line 47 of file fdmblackscholesop.hpp.

Constructor & Destructor Documentation

◆ FdmBlackScholesOp()

FdmBlackScholesOp ( const ext::shared_ptr< FdmMesher > &  mesher,
const ext::shared_ptr< GeneralizedBlackScholesProcess > &  process,
Real  strike = Null<Real>(),
bool  localVol = false,
Real  illegalLocalVolOverwrite = -Null<Real>(),
Size  direction = 0,
const ext::shared_ptr< FdmQuantoHelper > &  quantoHelper = ext::shared_ptr<FdmQuantoHelper>(),
const bool  discounting = true,
const bool  ensureNonNegativeForwardVariance = false 
)

Definition at line 30 of file fdmblackscholesop.cpp.

35 : mesher_(mesher), rTS_(bsProcess->riskFreeRate().currentLink()), qTS_(bsProcess->dividendYield().currentLink()),
36 volTS_(bsProcess->blackVolatility().currentLink()),
37 localVol_((localVol) ? bsProcess->localVolatility().currentLink() : ext::shared_ptr<LocalVolTermStructure>()),
38 x_((localVol) ? Array(Exp(mesher->locations(direction))) : Array()), dxMap_(FirstDerivativeOp(direction, mesher)),
39 dxxMap_(SecondDerivativeOp(direction, mesher)), mapT_(direction, mesher), strike_(strike),
40 illegalLocalVolOverwrite_(illegalLocalVolOverwrite), direction_(direction), quantoHelper_(quantoHelper),
41 initialValue_(bsProcess->x0()), discounting_(discounting),
42 ensureNonNegativeForwardVariance_(ensureNonNegativeForwardVariance) {}
const TripleBandLinearOp dxxMap_
const ext::shared_ptr< FdmQuantoHelper > quantoHelper_
const ext::shared_ptr< YieldTermStructure > qTS_
const FirstDerivativeOp dxMap_
const ext::shared_ptr< FdmMesher > mesher_
const ext::shared_ptr< YieldTermStructure > rTS_
const ext::shared_ptr< BlackVolTermStructure > volTS_
const ext::shared_ptr< LocalVolTermStructure > localVol_

Member Function Documentation

◆ size()

Size size ( ) const
override

Definition at line 98 of file fdmblackscholesop.cpp.

98{ return 1u; }

◆ setTime()

void setTime ( Time  t1,
Time  t2 
)
override

Definition at line 44 of file fdmblackscholesop.cpp.

44 {
45 const Rate r = rTS_->forwardRate(t1, t2, Continuous).rate();
46 const Rate q = qTS_->forwardRate(t1, t2, Continuous).rate();
47 Rate discountRate = discounting_ ? r : 0.0;
48
49 if (localVol_) {
50 const ext::shared_ptr<FdmLinearOpLayout> layout = mesher_->layout();
51 const FdmLinearOpIterator endIter = layout->end();
52
53 Array v(layout->size());
54 for (FdmLinearOpIterator iter = layout->begin(); iter != endIter; ++iter) {
55 const Size i = iter.index();
56
57 if (illegalLocalVolOverwrite_ < 0.0) {
58 v[i] = squared(localVol_->localVol(0.5 * (t1 + t2), x_[i], true));
59 } else {
60 try {
61 v[i] = squared(localVol_->localVol(0.5 * (t1 + t2), x_[i], true));
62 } catch (Error&) {
63 v[i] = squared(illegalLocalVolOverwrite_);
64 }
65 }
66 }
67
68 if (quantoHelper_) {
69 mapT_.axpyb(r - q - 0.5 * v - quantoHelper_->quantoAdjustment(Sqrt(v), t1, t2), dxMap_,
70 dxxMap_.mult(0.5 * v), Array(1, -discountRate));
71 } else {
72 mapT_.axpyb(r - q - 0.5 * v, dxMap_, dxxMap_.mult(0.5 * v), Array(1, -discountRate));
73 }
74 } else {
75 Real k1, k2;
76 if (strike_ == Null<Real>()) {
77 k1 = initialValue_ * qTS_->discount(t1) / rTS_->discount(t1);
78 k2 = initialValue_ * qTS_->discount(t2) / rTS_->discount(t2);
79 } else {
80 k1 = k2 = strike_;
81 }
82 Real v = ((close_enough(t2, 0.0) ? 0.0 : volTS_->blackVariance(t2, k2)) -
83 (close_enough(t1, 0.0) ? 0.0 : volTS_->blackVariance(t1, k1))) /
84 (t2 - t1);
86 v = std::max(v, 0.0);
87
88 if (quantoHelper_) {
89 mapT_.axpyb(Array(1, r - q - 0.5 * v) - quantoHelper_->quantoAdjustment(Array(1, std::sqrt(v)), t1, t2),
90 dxMap_, dxxMap_.mult(0.5 * Array(mesher_->layout()->size(), v)), Array(1, -discountRate));
91 } else {
92 mapT_.axpyb(Array(1, r - q - 0.5 * v), dxMap_, dxxMap_.mult(0.5 * Array(mesher_->layout()->size(), v)),
93 Array(1, -discountRate));
94 }
95 }
96}
Filter close_enough(const RandomVariable &x, const RandomVariable &y)
+ Here is the call graph for this function:

◆ apply()

Array apply ( const Array &  r) const
override

Definition at line 100 of file fdmblackscholesop.cpp.

100{ return mapT_.apply(u); }

◆ apply_mixed()

Array apply_mixed ( const Array &  r) const
override

Definition at line 111 of file fdmblackscholesop.cpp.

111 {
112 Array retVal(r.size(), 0.0);
113 return retVal;
114}

◆ apply_direction()

Array apply_direction ( Size  direction,
const Array &  r 
) const
override

Definition at line 102 of file fdmblackscholesop.cpp.

102 {
103 if (direction == direction_)
104 return mapT_.apply(r);
105 else {
106 Array retVal(r.size(), 0.0);
107 return retVal;
108 }
109}

◆ solve_splitting()

Array solve_splitting ( Size  direction,
const Array &  r,
Real  s 
) const
override

Definition at line 116 of file fdmblackscholesop.cpp.

116 {
117 if (direction == direction_)
118 return mapT_.solve_splitting(r, dt, 1.0);
119 else {
120 Array retVal(r);
121 return retVal;
122 }
123}
+ Here is the caller graph for this function:

◆ preconditioner()

Array preconditioner ( const Array &  r,
Real  s 
) const
override

Definition at line 125 of file fdmblackscholesop.cpp.

125 {
126 return solve_splitting(direction_, r, dt);
127}
Array solve_splitting(Size direction, const Array &r, Real s) const override
+ Here is the call graph for this function:

◆ toMatrixDecomp()

std::vector< QuantLib::SparseMatrix > toMatrixDecomp ( ) const
override

Definition at line 130 of file fdmblackscholesop.cpp.

130 {
131 std::vector<QuantLib::SparseMatrix> retVal(1, mapT_.toMatrix());
132 return retVal;
133}

Member Data Documentation

◆ mesher_

const ext::shared_ptr<FdmMesher> mesher_
private

Definition at line 68 of file fdmblackscholesop.hpp.

◆ rTS_

const ext::shared_ptr<YieldTermStructure> rTS_
private

Definition at line 69 of file fdmblackscholesop.hpp.

◆ qTS_

const ext::shared_ptr<YieldTermStructure> qTS_
private

Definition at line 69 of file fdmblackscholesop.hpp.

◆ volTS_

const ext::shared_ptr<BlackVolTermStructure> volTS_
private

Definition at line 70 of file fdmblackscholesop.hpp.

◆ localVol_

const ext::shared_ptr<LocalVolTermStructure> localVol_
private

Definition at line 71 of file fdmblackscholesop.hpp.

◆ x_

const Array x_
private

Definition at line 72 of file fdmblackscholesop.hpp.

◆ dxMap_

const FirstDerivativeOp dxMap_
private

Definition at line 73 of file fdmblackscholesop.hpp.

◆ dxxMap_

const TripleBandLinearOp dxxMap_
private

Definition at line 74 of file fdmblackscholesop.hpp.

◆ mapT_

TripleBandLinearOp mapT_
private

Definition at line 75 of file fdmblackscholesop.hpp.

◆ strike_

const Real strike_
private

Definition at line 76 of file fdmblackscholesop.hpp.

◆ illegalLocalVolOverwrite_

const Real illegalLocalVolOverwrite_
private

Definition at line 77 of file fdmblackscholesop.hpp.

◆ direction_

const Size direction_
private

Definition at line 78 of file fdmblackscholesop.hpp.

◆ quantoHelper_

const ext::shared_ptr<FdmQuantoHelper> quantoHelper_
private

Definition at line 79 of file fdmblackscholesop.hpp.

◆ initialValue_

const Real initialValue_
private

Definition at line 80 of file fdmblackscholesop.hpp.

◆ discounting_

const bool discounting_
private

Definition at line 81 of file fdmblackscholesop.hpp.

◆ ensureNonNegativeForwardVariance_

const bool ensureNonNegativeForwardVariance_
private

Definition at line 82 of file fdmblackscholesop.hpp.