QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
discounter.cpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2006 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
20#include <ql/models/marketmodels/discounter.hpp>
21#include <ql/models/marketmodels/curvestate.hpp>
22#include <ql/models/marketmodels/utilities.hpp>
23#include <algorithm>
24
25namespace QuantLib {
26
28 Time paymentTime,
29 const std::vector<Time>& rateTimes) {
30 checkIncreasingTimes(rateTimes);
31 before_ = std::lower_bound(rateTimes.begin(), rateTimes.end(),
32 paymentTime) - rateTimes.begin();
33
34 // handle the case where the payment is in the last
35 // period or after the last period
36 if (before_ > rateTimes.size()-2)
37 before_ = rateTimes.size()-2;
38
39 beforeWeight_=1.0-(paymentTime-rateTimes[before_])/
40 (rateTimes[before_+1]-rateTimes[before_]);
41 }
42
44 Size numeraire) const {
45 Real preDF = curveState.discountRatio(before_,numeraire);
46 if (beforeWeight_==1.0)
47 return preDF;
48
49 Real postDF = curveState.discountRatio(before_+1,numeraire);
50 if (beforeWeight_==0.0)
51 return postDF;
52
53 return std::pow(preDF,beforeWeight_)*std::pow(postDF,1.-beforeWeight_);
54 }
55
56}
Curve state for market-model simulations
Definition: curvestate.hpp:41
virtual Real discountRatio(Size i, Size j) const =0
Real numeraireBonds(const CurveState &, Size numeraire) const
Definition: discounter.cpp:43
MarketModelDiscounter(Time paymentTime, const std::vector< Time > &rateTimes)
Definition: discounter.cpp:27
Real Time
continuous quantity with 1-year units
Definition: types.hpp:62
QL_REAL Real
real number
Definition: types.hpp:50
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