QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
multistepswaption.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) 2006 Giorgio Facchinetti
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
24
25namespace QuantLib {
26
27
28 MultiStepSwaption::MultiStepSwaption(const std::vector<Time>& rateTimes,
29 Size startIndex,
30 Size endIndex,
31 ext::shared_ptr<StrikedTypePayoff> & payOff)
32 : MultiProductMultiStep(rateTimes),
33 startIndex_(startIndex), endIndex_(endIndex), payoff_(payOff)
34 {
35 QL_REQUIRE(startIndex_ < endIndex_," start index must be before end index");
36
37 QL_REQUIRE(endIndex_ < rateTimes.size(), "end index be before the end of the rates.");
38 paymentTimes_.push_back(rateTimes[startIndex_]);
39
40 }
41
43 const CurveState& currentState,
44 std::vector<Size>& numberCashFlowsThisStep,
45 std::vector<std::vector<MarketModelMultiProduct::CashFlow> >&
46 genCashFlows)
47 {
49 {
50 genCashFlows[0][0].timeIndex = 0;
51
52
53 Rate swapRate = currentState.cmSwapRate(startIndex_,endIndex_-startIndex_);
55
56 genCashFlows[0][0].amount =
57 (*payoff_)(swapRate) * annuity;
58
59 numberCashFlowsThisStep[0] =genCashFlows[0][0].amount != 0.0 ? 1 : 0 ;
60
61 return true;
62 }
63 else
64 {
65 numberCashFlowsThisStep[0] =0;
67 return false;
68 }
69 }
70
71 std::unique_ptr<MarketModelMultiProduct>
73 return std::unique_ptr<MarketModelMultiProduct>(new MultiStepSwaption(*this));
74 }
75
76}
Curve state for market-model simulations
Definition: curvestate.hpp:41
virtual Rate cmSwapRate(Size i, Size spanningForwards) const =0
virtual Rate cmSwapAnnuity(Size numeraire, Size i, Size spanningForwards) const =0
Multiple-step market-model product.
std::vector< Time > paymentTimes_
std::unique_ptr< MarketModelMultiProduct > clone() const override
returns a newly-allocated copy of itself
bool nextTimeStep(const CurveState &currentState, std::vector< Size > &numberCashFlowsThisStep, std::vector< std::vector< CashFlow > > &cashFlowsGenerated) override
return value indicates whether path is finished, TRUE means done
MultiStepSwaption(const std::vector< Time > &rateTimes, Size startIndex, Size endIndex, ext::shared_ptr< StrikedTypePayoff > &)
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
const ext::shared_ptr< Payoff > payoff_
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
Payoffs for various options.