QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
pathwiseproductswap.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) 2009 Mark Joshi
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
23
24namespace QuantLib
25{
26
27
29 {
30 return false;
31 }
32
33 MarketModelPathwiseSwap::MarketModelPathwiseSwap(const std::vector<Time>& rateTimes,
34 const std::vector<Real>& accruals,
35 const std::vector<Rate>& strikes,
36 Real multiplier)
37 : rateTimes_(rateTimes),
38 accruals_(accruals),
39 strikes_(strikes) ,
40 numberRates_(rateTimes.size()-1),
41 multiplier_(multiplier)
42 {
43 checkIncreasingTimes(rateTimes);
44 std::vector<Time> evolTimes(rateTimes_);
45 evolTimes.pop_back();
46
47 QL_REQUIRE(evolTimes.size()==numberRates_,
48 "rateTimes.size()<> numberOfRates+1");
49
50 if (strikes_.size() == 1)
51 strikes_ = std::vector<Rate>(numberRates_, strikes[0]);
52
53 if (accruals_.size() == 1)
54 accruals_ = std::vector<Rate>(numberRates_, accruals[0]);
55
57 "accruals.size() does not equal numberOfRates or 1");
58
59 QL_REQUIRE(strikes.size()==numberRates_,
60 "strikes.size() does not equal numberOfRates or 1" );
61
62 evolution_ = EvolutionDescription(rateTimes,evolTimes);
63
64 }
65
67 const CurveState& currentState,
68 std::vector<Size>& numberCashFlowsThisStep,
69 std::vector<std::vector<MarketModelPathwiseMultiProduct::CashFlow> >& cashFlowsGenerated)
70 {
71 Rate liborRate = currentState.forwardRate(currentIndex_);
72 cashFlowsGenerated[0][0].timeIndex = currentIndex_+1;
73
74 cashFlowsGenerated[0][0].amount[0] =
76
77 numberCashFlowsThisStep[0] = 1;
78
79 for (Size i=1; i <= numberRates_; ++i)
80 cashFlowsGenerated[0][0].amount[i] =0;
81
82 cashFlowsGenerated[0][0].amount[currentIndex_+1] = accruals_[currentIndex_]*multiplier_;
83
85 return (currentIndex_ == strikes_.size());
86 }
87
88 std::unique_ptr<MarketModelPathwiseMultiProduct>
90 {
91 return std::unique_ptr<MarketModelPathwiseMultiProduct>(new MarketModelPathwiseSwap(*this));
92 }
93
95 {
96 std::vector<Size> numeraires(numberRates_);
97 for (Size i=0; i < numberRates_; ++i)
98 numeraires[i] = i;
99
100 return numeraires;
101 }
102
104 {
105 return evolution_;
106 }
107
109 {
110 return rateTimes_; // note rateTimes_[0] is not used as a cash flow time but it is easier to keep track if we include it.
111 }
112
114 {
115 return 1;
116 }
117
119 {
120 return 1;
121
122 }
123
125 {
127 }
128
129}
130
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
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
Size maxNumberOfCashFlowsPerProductPerStep() const override
void reset() override
during simulation put product at start of path
MarketModelPathwiseSwap(const std::vector< Time > &rateTimes, const std::vector< Time > &accruals, const std::vector< Rate > &strikes, Real multiplier=1.0)
#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