QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
pathwiseproductinversefloater.cpp
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) 2009 Mark Joshi
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
23#include <utility>
24
25namespace QuantLib
26{
27
28
30 {
31 return false;
32 }
33
35 const std::vector<Time>& rateTimes,
36 std::vector<Real> fixedAccruals,
37 const std::vector<Real>& floatingAccruals,
38 const std::vector<Real>& fixedStrikes,
39 const std::vector<Real>& fixedMultipliers,
40 const std::vector<Real>& floatingSpreads,
41 const std::vector<Time>& paymentTimes,
42 bool payer)
43 : rateTimes_(rateTimes), fixedAccruals_(std::move(fixedAccruals)),
44 floatingAccruals_(floatingAccruals), fixedStrikes_(fixedStrikes),
45 fixedMultipliers_(fixedMultipliers), floatingSpreads_(floatingSpreads),
46 paymentTimes_(paymentTimes), multiplier_(payer ? -1.0 : 1.0),
47 lastIndex_(rateTimes.size() - 1) {
48 checkIncreasingTimes(paymentTimes);
49 QL_REQUIRE(fixedAccruals_.size() == lastIndex_," Incorrect number of fixedAccruals given, should be " << lastIndex_ << " not " << fixedAccruals_.size() );
50 QL_REQUIRE(floatingAccruals.size() == lastIndex_," Incorrect number of floatingAccruals given, should be " << lastIndex_ << " not " << floatingAccruals.size() );
51 QL_REQUIRE(fixedStrikes.size() == lastIndex_," Incorrect number of fixedStrikes given, should be " << lastIndex_ << " not " << fixedStrikes.size() );
52 QL_REQUIRE(fixedMultipliers.size() == lastIndex_," Incorrect number of fixedMultipliers given, should be " << lastIndex_ << " not " << fixedMultipliers.size() );
53 QL_REQUIRE(floatingSpreads.size() == lastIndex_," Incorrect number of floatingSpreads given, should be " << lastIndex_ << " not " << floatingSpreads.size() );
54 QL_REQUIRE(paymentTimes.size() == lastIndex_," Incorrect number of paymentTimes given, should be " << lastIndex_ << " not " << paymentTimes.size() );
55
56 std::vector<Time> evolTimes(rateTimes);
57 evolTimes.pop_back();
58
59
60 evolution_ = EvolutionDescription(rateTimes,evolTimes);
61 }
62
64 const CurveState& currentState,
65 std::vector<Size>& numberCashFlowsThisStep,
66 std::vector<std::vector<MarketModelPathwiseMultiProduct::CashFlow> >& cashFlowsGenerated)
67 {
68 numberCashFlowsThisStep[0] =1 ;
69 for (Size i=1; i <= lastIndex_; ++i)
70 cashFlowsGenerated[0][0].amount[i] =0;
71
72 Rate liborRate = currentState.forwardRate(currentIndex_);
73 Real inverseFloatingCoupon = std::max((fixedStrikes_[currentIndex_] - fixedMultipliers_[currentIndex_]*liborRate),0.0)*fixedAccruals_[currentIndex_] ;
75 cashFlowsGenerated[0][0].timeIndex = currentIndex_;
76 cashFlowsGenerated[0][0].amount[0] =multiplier_*(inverseFloatingCoupon - floatingCoupon);
77
78
79
80 if (inverseFloatingCoupon > 0.0)
81 {
82
84
85
86 }
87 else
88 {
89
90 cashFlowsGenerated[0][0].amount[currentIndex_+1] =-multiplier_*floatingAccruals_[currentIndex_];
91
92 }
93
95
96 return (currentIndex_ == lastIndex_);
97
98
99 }
100
101 std::unique_ptr<MarketModelPathwiseMultiProduct>
103 {
104 return std::unique_ptr<MarketModelPathwiseMultiProduct>(new MarketModelPathwiseInverseFloater(*this));
105 }
106
108 {
109 std::vector<Size> numeraires(lastIndex_);
110 for (Size i=0; i < lastIndex_; ++i)
111 numeraires[i] = i;
112
113 return numeraires;
114 }
115
117 {
118 return evolution_;
119 }
120
122 {
123 return paymentTimes_;
124 }
125
127 {
128 return 1;
129 }
130
132 {
133 return 1;
134
135 }
136
138 {
140 }
141
142}
143
Curve state for market-model simulations
Definition: curvestate.hpp:41
virtual Rate forwardRate(Size i) const =0
Market-model evolution description.
std::vector< Size > suggestedNumeraires() const override
MarketModelPathwiseInverseFloater(const std::vector< Time > &rateTimes, std::vector< Real > fixedAccruals, const std::vector< Real > &floatingAccruals, const std::vector< Real > &fixedStrikes, const std::vector< Real > &fixedMultipliers, const std::vector< Real > &floatingSpreads, const std::vector< Time > &paymentTimes, bool payer=true)
bool nextTimeStep(const CurveState &currentState, std::vector< Size > &numberCashFlowsThisStep, std::vector< std::vector< MarketModelPathwiseMultiProduct::CashFlow > > &cashFlowsGenerated) override
return value indicates whether path is finished, TRUE means done
std::unique_ptr< MarketModelPathwiseMultiProduct > clone() const override
returns a newly-allocated copy of itself
std::vector< Time > possibleCashFlowTimes() const override
const EvolutionDescription & evolution() const override
void reset() override
during simulation put product at start of path
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
QL_REAL Real
real number
Definition: types.hpp:50
Real Rate
interest rates
Definition: types.hpp:70
std::size_t Size
size of a container
Definition: types.hpp:58
Definition: any.hpp:35
void checkIncreasingTimes(const std::vector< Time > &times)
check for strictly increasing times, first time greater than zero
Definition: utilities.cpp:92
STL namespace.