Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
blackscholescgbase.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2021 Quaternion Risk Management Ltd
3 All rights reserved.
4
5 This file is part of ORE, a free-software/open-source library
6 for transparent pricing and risk analysis - http://opensourcerisk.org
7
8 ORE is free software: you can redistribute it and/or modify it
9 under the terms of the Modified BSD License. You should have received a
10 copy of the license along with this program.
11 The license is also available online at <http://opensourcerisk.org>
12
13 This program is distributed on the basis that it will form a useful
14 contribution to risk analytics and model standardisation, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17*/
18
19/*! \file ored/scripting/models/blackscholescgbase.hpp
20 \brief black scholes model base class for n underlyings (fx, equity or commodity)
21 \ingroup utilities
22*/
23
24#pragma once
25
28
31
32#include <ql/indexes/interestrateindex.hpp>
33#include <ql/processes/blackscholesprocess.hpp>
34#include <ql/timegrid.hpp>
35
36namespace ore {
37namespace data {
38
39/* This class is the basis for the BlackScholes and LocalVol model implementations */
41public:
42 /* For the constructor arguments see ModelCGImpl, plus:
43 - eq, com processes are given with arbitrary riskFreeRate() and dividendYield(), these two curves only define
44 the forward curve drift for each asset
45 - the base ccy is the first ccy in the currency vector, the fx spots are given as for-base, the ccy curves define
46 the fx forwards
47 - fx processes must be given w.r.t. the base ccy and consistent with the given fx spots and curves, but we do not
48 require fx processes for all currencies (but they are required, if an fx index is evaluated in eval())
49 - correlations are for index pair names and must be constant; if not given for a pair, we assume zero correlation
50 - regressionOrder is the regression order used to compute conditional expectations in npv()
51 */
53 const Size paths, const std::vector<std::string>& currencies,
54 const std::vector<Handle<YieldTermStructure>>& curves, const std::vector<Handle<Quote>>& fxSpots,
55 const std::vector<std::pair<std::string, QuantLib::ext::shared_ptr<InterestRateIndex>>>& irIndices,
56 const std::vector<std::pair<std::string, QuantLib::ext::shared_ptr<ZeroInflationIndex>>>& infIndices,
57 const std::vector<std::string>& indices, const std::vector<std::string>& indexCurrencies,
58 const Handle<BlackScholesModelWrapper>& model,
59 const std::map<std::pair<std::string, std::string>, Handle<QuantExt::CorrelationTermStructure>>& correlations,
60 const std::set<Date>& simulationDates, const IborFallbackConfig& iborFallbackConfig);
61
62 // ctor for single underlying
63 BlackScholesCGBase(const Size paths, const std::string& currency, const Handle<YieldTermStructure>& curve,
64 const std::string& index, const std::string& indexCurrency,
65 const Handle<BlackScholesModelWrapper>& model, const std::set<Date>& simulationDates,
66 const IborFallbackConfig& iborFallbackConfig);
67
68 // Model interface implementation
69 Type type() const override { return Type::MC; }
70 const Date& referenceDate() const override;
71 std::size_t npv(const std::size_t amount, const Date& obsdate, const std::size_t filter,
72 const boost::optional<long>& memSlot, const std::size_t addRegressor1,
73 const std::size_t addRegressor2) const override;
74 std::size_t fwdCompAvg(const bool isAvg, const std::string& indexInput, const Date& obsdate, const Date& start,
75 const Date& end, const Real spread, const Real gearing, const Integer lookback,
76 const Natural rateCutoff, const Natural fixingDays, const bool includeSpread, const Real cap,
77 const Real floor, const bool nakedOption, const bool localCapFloor) const override;
78
79 // t0 market data functions from the ModelCG interface
80 Real getDirectFxSpotT0(const std::string& forCcy, const std::string& domCcy) const override;
81 Real getDirectDiscountT0(const Date& paydate, const std::string& currency) const override;
82
83protected:
84 // ModelImpl interface implementation
85 void performCalculations() const override;
86 std::size_t getIndexValue(const Size indexNo, const Date& d, const Date& fwd = Null<Date>()) const override;
87 std::size_t getIrIndexValue(const Size indexNo, const Date& d, const Date& fwd = Null<Date>()) const override;
88 std::size_t getInfIndexValue(const Size indexNo, const Date& d, const Date& fwd = Null<Date>()) const override;
89 std::size_t getDiscount(const Size idx, const Date& s, const Date& t) const override;
90 std::size_t getNumeraire(const Date& s) const override;
91 std::size_t getFxSpot(const Size idx) const override;
92
93 // input parameters
94 const std::vector<Handle<YieldTermStructure>> curves_;
95 const std::vector<Handle<Quote>> fxSpots_;
96 const Handle<BlackScholesModelWrapper> model_;
97 const std::map<std::pair<std::string, std::string>, Handle<QuantExt::CorrelationTermStructure>> correlations_;
98 const std::vector<Date> simulationDates_;
99
100 // updated in performCalculations()
101 mutable Date referenceDate_; // the model reference date
102 mutable std::set<Date> effectiveSimulationDates_; // the dates effectively simulated (including today)
103 mutable TimeGrid timeGrid_; // the (possibly refined) time grid for the simulation
104 mutable std::vector<Size> positionInTimeGrid_; // for each effective simulation date the index in the time grid
105
106 // updated in derived classes' performCalculations() whenever cg version changes
107 mutable std::map<Date, std::vector<std::size_t>> underlyingPaths_; // per simulation date index states
108 mutable std::size_t underlyingPathsCgVersion_ = 0;
109};
110
111} // namespace data
112} // namespace ore
void performCalculations() const override
std::map< Date, std::vector< std::size_t > > underlyingPaths_
const std::vector< Date > simulationDates_
std::size_t npv(const std::size_t amount, const Date &obsdate, const std::size_t filter, const boost::optional< long > &memSlot, const std::size_t addRegressor1, const std::size_t addRegressor2) const override
std::size_t getNumeraire(const Date &s) const override
std::size_t getFxSpot(const Size idx) const override
Real getDirectFxSpotT0(const std::string &forCcy, const std::string &domCcy) const override
std::size_t getInfIndexValue(const Size indexNo, const Date &d, const Date &fwd=Null< Date >()) const override
const Date & referenceDate() const override
Real getDirectDiscountT0(const Date &paydate, const std::string &currency) const override
std::size_t getIrIndexValue(const Size indexNo, const Date &d, const Date &fwd=Null< Date >()) const override
const std::vector< Handle< Quote > > fxSpots_
std::size_t fwdCompAvg(const bool isAvg, const std::string &indexInput, const Date &obsdate, const Date &start, const Date &end, const Real spread, const Real gearing, const Integer lookback, const Natural rateCutoff, const Natural fixingDays, const bool includeSpread, const Real cap, const Real floor, const bool nakedOption, const bool localCapFloor) const override
const Handle< BlackScholesModelWrapper > model_
std::size_t getDiscount(const Size idx, const Date &s, const Date &t) const override
std::size_t getIndexValue(const Size indexNo, const Date &d, const Date &fwd=Null< Date >()) const override
const std::map< std::pair< std::string, std::string >, Handle< QuantExt::CorrelationTermStructure > > correlations_
const std::vector< Handle< YieldTermStructure > > curves_
std::vector< Size > positionInTimeGrid_
SafeStack< Filter > filter
@ data
Definition: log.hpp:77
interface for model against which a script can be run
basis implementation for a script engine model
Serializable Credit Default Swap.
Definition: namespaces.docs:23