23#ifndef quantlib_fdm_affine_model_swap_inner_value_hpp
24#define quantlib_fdm_affine_model_swap_inner_value_hpp
39 template <
class ModelType>
43 ext::shared_ptr<ModelType> fwdModel,
44 const ext::shared_ptr<FixedVsFloatingSwap>&
swap,
45 std::map<Time, Date> exerciseDates,
46 ext::shared_ptr<FdmMesher> mesher,
60 const ext::shared_ptr<IborIndex>
index_;
61 const ext::shared_ptr<FixedVsFloatingSwap>
swap_;
67 template <
class ModelType>
69 ext::shared_ptr<ModelType> disModel,
70 ext::shared_ptr<ModelType> fwdModel,
71 const ext::shared_ptr<FixedVsFloatingSwap>&
swap,
72 std::map<Time, Date> exerciseDates,
73 ext::shared_ptr<FdmMesher> mesher,
75 : disModel_(
std::move(disModel)), fwdModel_(
std::move(fwdModel)), index_(
swap->iborIndex()),
78 swap->fixedSchedule(),
80 swap->fixedDayCount(),
81 swap->floatingSchedule(),
82 swap->iborIndex()->clone(fwdTs_),
84 swap->floatingDayCount(),
85 swap->paymentConvention())),
88 template <
class ModelType>
inline
92 const Date& iterExerciseDate = exerciseDates_.find(
t)->second;
94 const Array disRate(getState(disModel_,
t, iter));
95 const Array fwdRate(getState(fwdModel_,
t, iter));
97 if (disTs_.empty() || iterExerciseDate != disTs_->referenceDate()) {
100 = disModel_->termStructure();
102 disTs_.linkTo(ext::shared_ptr<YieldTermStructure>(
104 discount->calendar(), discount->dayCounter(),
105 iterExerciseDate, discount->referenceDate(),
110 fwdTs_.linkTo(ext::shared_ptr<YieldTermStructure>(
112 fwd->calendar(), fwd->dayCounter(),
113 iterExerciseDate, fwd->referenceDate(),
118 ext::dynamic_pointer_cast<FdmAffineModelTermStructure>(
119 disTs_.currentLink())->setVariable(disRate);
120 ext::dynamic_pointer_cast<FdmAffineModelTermStructure>(
121 fwdTs_.currentLink())->setVariable(fwdRate);
125 for (
Size j = 0; j < 2; j++) {
126 for (
const auto& i : swap_->leg(j)) {
128 ext::dynamic_pointer_cast<Coupon>(i)->accrualStartDate() >= iterExerciseDate ?
129 Real(i->amount() * disTs_->discount(i->date())) :
138 return std::max(0.0, npv);
141 template <
class ModelType>
inline
144 return innerValue(iter,
t);
1-D array used in linear algebra.
Real innerValue(const FdmLinearOpIterator &iter, Time t) override
const ext::shared_ptr< ModelType > disModel_
const ext::shared_ptr< IborIndex > index_
Array getState(const ext::shared_ptr< ModelType > &model, Time t, const FdmLinearOpIterator &iter) const
Real avgInnerValue(const FdmLinearOpIterator &iter, Time t) override
const std::map< Time, Date > exerciseDates_
RelinkableHandle< YieldTermStructure > fwdTs_
const ext::shared_ptr< FdmMesher > mesher_
const ext::shared_ptr< FixedVsFloatingSwap > swap_
const ext::shared_ptr< ModelType > fwdModel_
RelinkableHandle< YieldTermStructure > disTs_
FdmAffineModelSwapInnerValue(ext::shared_ptr< ModelType > disModel, ext::shared_ptr< ModelType > fwdModel, const ext::shared_ptr< FixedVsFloatingSwap > &swap, std::map< Time, Date > exerciseDates, ext::shared_ptr< FdmMesher > mesher, Size direction)
Shared handle to an observable.
Relinkable handle to an observable.
Plain-vanilla swap: fix vs ibor leg.
Coupon accruing over a fixed period.
layer of abstraction to calculate the inner value
const ext::shared_ptr< FdmMesher > mesher_
Real Time
continuous quantity with 1-year units
std::size_t Size
size of a container
base class for Inter-Bank-Offered-Rate indexes
void swap(Array &v, Array &w) noexcept
Simple fixed-rate vs Libor swap.