QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
onestepoptionlets.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/onestep/onestepoptionlets.hpp>
23#include <ql/models/marketmodels/utilities.hpp>
24#include <ql/payoff.hpp>
25#include <utility>
26
27namespace QuantLib {
28
29 OneStepOptionlets::OneStepOptionlets(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 : MultiProductOneStep(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 std::fill(numberCashFlowsThisStep.begin(),
44 numberCashFlowsThisStep.end(), 0);
45 for (Size i=0; i<payoffs_.size(); ++i) {
46 Rate liborRate = currentState.forwardRate(i);
47 Real payoff = (*payoffs_[i])(liborRate);
48 if (payoff>0.0) {
49 numberCashFlowsThisStep[i] = 1;
50 genCashFlows[i][0].timeIndex = i;
51 genCashFlows[i][0].amount = payoff*accruals_[i];
52 }
53 }
54
55 return true;
56 }
57
58 std::unique_ptr<MarketModelMultiProduct>
60 return std::unique_ptr<MarketModelMultiProduct>(new OneStepOptionlets(*this));
61 }
62
63}
Curve state for market-model simulations
Definition: curvestate.hpp:41
virtual Rate forwardRate(Size i) const =0
Single-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
OneStepOptionlets(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_
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.