QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.38
Loading...
Searching...
No Matches
vectorbsmprocessextractor.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) 2024 Klaus Spanderen
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/*! \file vectorbsmprocessextractor.cpp
21*/
24
26
27namespace QuantLib::detail {
28
30 std::vector<ext::shared_ptr<GeneralizedBlackScholesProcess> > p)
31 : processes_(std::move(p)) {
32 }
33
35 const std::function<Real(
36 const ext::shared_ptr<GeneralizedBlackScholesProcess>&)>& f) const {
37
38 Array x(processes_.size());
39 std::transform(processes_.begin(), processes_.end(), x.begin(), f);
40
41 return x;
42 }
43
45 const Date& maturityDate) const {
46 const Array dr = extractProcesses(
47 [maturityDate](const auto& p) -> DiscountFactor {
48 return p->riskFreeRate()->discount(maturityDate);
49 }
50 );
51
53 std::equal(
54 dr.begin()+1, dr.end(), dr.begin(),
55 [](Real a, Real b) -> bool { return close_enough(a, b);}
56 ),
57 "interest rates need to be the same for all underlyings"
58 );
59
60 return dr[0];
61 }
62
64 return extractProcesses([](const auto& p) -> Real { return p->x0(); });
65 }
66
68 const Date& maturityDate) const {
69 return extractProcesses(
70 [maturityDate](const auto& p) -> DiscountFactor {
71 return p->dividendYield()->discount(maturityDate);
72 }
73 );
74 }
75
77 const Date& maturityDate) const {
78 return extractProcesses(
79 [maturityDate](const auto& p) -> Volatility {
80 return p->blackVolatility()->blackVariance(maturityDate, p->x0());
81 }
82 );
83 }
84
86 const Date& maturityDate) const {
87 return extractProcesses(
88 [maturityDate](const auto& p) -> Volatility {
89 const Time maturity = p->blackVolatility()->timeFromReference(maturityDate);
90 return p->blackVolatility()->blackVol(maturityDate, p->x0())*std::sqrt(maturity);
91 }
92 );
93 }
94
95}
96
1-D array used in linear algebra.
Definition: array.hpp:52
const_iterator end() const
Definition: array.hpp:499
const_iterator begin() const
Definition: array.hpp:491
Concrete date class.
Definition: date.hpp:125
Array getBlackStdDev(const Date &maturityDate) const
Array getDividendYieldDf(const Date &maturityDate) const
DiscountFactor getInterestRateDf(const Date &maturityDate) const
VectorBsmProcessExtractor(std::vector< ext::shared_ptr< GeneralizedBlackScholesProcess > > p)
Array extractProcesses(const std::function< Real(const ext::shared_ptr< GeneralizedBlackScholesProcess > &)> &f) const
Array getBlackVariance(const Date &maturityDate) const
const std::vector< ext::shared_ptr< GeneralizedBlackScholesProcess > > processes_
floating-point comparisons
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
std::function< Real(Real)> b
Real Time
continuous quantity with 1-year units
Definition: types.hpp:62
QL_REAL Real
real number
Definition: types.hpp:50
Real DiscountFactor
discount factor between dates
Definition: types.hpp:66
Real Volatility
volatility
Definition: types.hpp:78
functionals and combinators not included in the STL
STL namespace.
helper class to extract underlying, volatility etc from a vector of processes