QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
multistepoptionlets.cpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2006 Ferdinando Ametrano
5 Copyright (C) 2006 Mark Joshi
6
7 This file is part of QuantLib, a free-software/open-source library
8 for financial quantitative analysts and developers - http://quantlib.org/
9
10 QuantLib is free software: you can redistribute it and/or modify it
11 under the terms of the QuantLib license. You should have received a
12 copy of the license along with this program; if not, please email
13 <quantlib-dev@lists.sf.net>. The license is also available online at
14 <http://quantlib.org/license.shtml>.
15
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the license for more details.
19*/
20
21#include <ql/models/marketmodels/curvestate.hpp>
22#include <ql/models/marketmodels/products/multistep/multistepoptionlets.hpp>
23#include <ql/models/marketmodels/utilities.hpp>
24#include <ql/payoff.hpp>
25#include <utility>
26
27namespace QuantLib {
28
29 MultiStepOptionlets::MultiStepOptionlets(const std::vector<Time>& rateTimes,
30 std::vector<Real> accruals,
31 const std::vector<Time>& paymentTimes,
32 std::vector<ext::shared_ptr<Payoff> > payoffs)
33 : MultiProductMultiStep(rateTimes), accruals_(std::move(accruals)), paymentTimes_(paymentTimes),
34 payoffs_(std::move(payoffs)) {
35 checkIncreasingTimes(paymentTimes);
36 }
37
39 const CurveState& currentState,
40 std::vector<Size>& numberCashFlowsThisStep,
41 std::vector<std::vector<MarketModelMultiProduct::CashFlow> >&
42 genCashFlows) {
43 Rate liborRate = currentState.forwardRate(currentIndex_);
44 genCashFlows[currentIndex_][0].timeIndex = currentIndex_;
45 genCashFlows[currentIndex_][0].amount =
46 (*payoffs_[currentIndex_])(liborRate) *
48 std::fill(numberCashFlowsThisStep.begin(),
49 numberCashFlowsThisStep.end(), 0);
50 numberCashFlowsThisStep[currentIndex_] = 1;
52 return (currentIndex_ == payoffs_.size());
53 }
54
55 std::unique_ptr<MarketModelMultiProduct>
57 return std::unique_ptr<MarketModelMultiProduct>(new MultiStepOptionlets(*this));
58 }
59
60}
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
MultiStepOptionlets(const std::vector< Time > &rateTimes, std::vector< Real > accruals, const std::vector< Time > &paymentTimes, std::vector< ext::shared_ptr< Payoff > >)
std::vector< ext::shared_ptr< Payoff > > payoffs_
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.