QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
multistepinversefloater.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) 2006 Giorgio Facchinetti
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 MultiStepInverseFloater::MultiStepInverseFloater(const std::vector<Time>& rateTimes,
28 std::vector<Real> fixedAccruals,
29 const std::vector<Real>& floatingAccruals,
30 const std::vector<Real>& fixedStrikes,
31 const std::vector<Real>& fixedMultipliers,
32 const std::vector<Real>& floatingSpreads,
33 const std::vector<Time>& paymentTimes,
34 bool payer)
35 : MultiProductMultiStep(rateTimes), fixedAccruals_(std::move(fixedAccruals)),
36 floatingAccruals_(floatingAccruals), fixedStrikes_(fixedStrikes),
37 fixedMultipliers_(fixedMultipliers), floatingSpreads_(floatingSpreads),
38 paymentTimes_(paymentTimes), multiplier_(payer ? -1.0 : 1.0),
39 lastIndex_(rateTimes.size() - 1) {
40 checkIncreasingTimes(paymentTimes);
41 QL_REQUIRE(fixedAccruals_.size() == lastIndex_," Incorrect number of fixedAccruals given, should be " << lastIndex_ << " not " << fixedAccruals_.size() );
42 QL_REQUIRE(floatingAccruals.size() == lastIndex_," Incorrect number of floatingAccruals given, should be " << lastIndex_ << " not " << floatingAccruals.size() );
43 QL_REQUIRE(fixedStrikes.size() == lastIndex_," Incorrect number of fixedStrikes given, should be " << lastIndex_ << " not " << fixedStrikes.size() );
44 QL_REQUIRE(fixedMultipliers.size() == lastIndex_," Incorrect number of fixedMultipliers given, should be " << lastIndex_ << " not " << fixedMultipliers.size() );
45 QL_REQUIRE(floatingSpreads.size() == lastIndex_," Incorrect number of floatingSpreads given, should be " << lastIndex_ << " not " << floatingSpreads.size() );
46 QL_REQUIRE(paymentTimes.size() == lastIndex_," Incorrect number of paymentTimes given, should be " << lastIndex_ << " not " << paymentTimes.size() );
47 }
48
50 const CurveState& currentState,
51 std::vector<Size>& numberCashFlowsThisStep,
52 std::vector<std::vector<MarketModelMultiProduct::CashFlow> >&
53 genCashFlows)
54 {
55 Rate liborRate = currentState.forwardRate(currentIndex_);
56 Real inverseFloatingCoupon = std::max((fixedStrikes_[currentIndex_] - fixedMultipliers_[currentIndex_]*liborRate),0.0)*fixedAccruals_[currentIndex_] ;
58
59 genCashFlows[0][0].timeIndex = currentIndex_;
60 genCashFlows[0][0].amount =multiplier_*(inverseFloatingCoupon - floatingCoupon);
61
62 numberCashFlowsThisStep[0] = 1;
64
65 return (currentIndex_ == lastIndex_);
66 }
67
68 std::unique_ptr<MarketModelMultiProduct>
70 {
71 return std::unique_ptr<MarketModelMultiProduct>(new MultiStepInverseFloater(*this));
72 }
73
74}
75
Curve state for market-model simulations
Definition: curvestate.hpp:41
virtual Rate forwardRate(Size i) const =0
Multiple-step market-model product.
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
MultiStepInverseFloater(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)
#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
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.