Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
fdblackscholesbase.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2020 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/fdblackscholesbase.hpp
20 \brief black scholes fd model base class for n underlyings (fx, equity or commodity)
21 \ingroup models
22*/
23
24#pragma once
25
27
30
31#include <ql/indexes/interestrateindex.hpp>
32#include <ql/methods/finitedifferences/meshers/fdmmesher.hpp>
33#include <ql/methods/finitedifferences/solvers/fdmbackwardsolver.hpp>
34#include <ql/processes/blackscholesprocess.hpp>
35#include <ql/timegrid.hpp>
36
37namespace ore {
38namespace data {
39
40/* At the moment this is the FD Black Scholes model class, restricted to one underlying. TODOs:
41 - extend to several underlyings,
42 - cover both black scholes and local vol models
43 - refactor with BlackScholesBase, there is quite a bit of code duplication */
45public:
46 /* For the constructor arguments see BlackScholesBase (the corresponding MC model class), except
47 - we don't have a regressionOrder and paths parameter here.
48 - instead we have a stateGridPoints parameter and additional fd specific parameters
49 - if staticMesher is true, the mesh will be held constant after its initial construction, this
50 is important to get stable sensitivities
51 */
53 const Size stateGridPoints, 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 std::set<std::string>& payCcys_, 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 const std::string& calibration, const std::map<std::string, std::vector<Real>>& calibrationStrikes = {},
62 const Real mesherEpsilon = 1E-4, const Real mesherScaling = 1.5, const Real mesherConcentration = 0.1,
63 const Size mesherMaxConcentratingPoints = 9999, const bool staticMesher = false);
64
65 // ctor for single underlying
66 FdBlackScholesBase(const Size stateGridPoints, const std::string& currency, const Handle<YieldTermStructure>& curve,
67 const std::string& index, const std::string& indexCurrency,
68 const Handle<BlackScholesModelWrapper>& model, const std::set<Date>& simulationDates,
69 const IborFallbackConfig& iborFallbackConfig, const std::string& calibration,
70 const std::vector<Real>& calibrationStrikes = {}, const Real mesherEpsilon = 1E-4,
71 const Real mesherScaling = 1.5, const Real mesherConcentration = 0.1,
72 const Size mesherMaxConcentratingPoints = 9999, const bool staticMesher = false);
73
74 // Model interface implementation
75 Type type() const override { return Type::FD; }
76 const Date& referenceDate() const override;
77 RandomVariable npv(const RandomVariable& amount, const Date& obsdate, const Filter& filter,
78 const boost::optional<long>& memSlot, const RandomVariable& addRegressor1,
79 const RandomVariable& addRegressor2) const override;
80 RandomVariable fwdCompAvg(const bool isAvg, const std::string& index, const Date& obsdate, const Date& start,
81 const Date& end, const Real spread, const Real gearing, const Integer lookback,
82 const Natural rateCutoff, const Natural fixingDays, const bool includeSpread,
83 const Real cap, const Real floor, const bool nakedOption,
84 const bool localCapFloor) const override;
85 void releaseMemory() override;
86 Real extractT0Result(const RandomVariable& result) const override;
87
88 // override to handle cases where we use a quanto-adjusted pde
89 const std::string& baseCcy() const override;
90 RandomVariable pay(const RandomVariable& amount, const Date& obsdate, const Date& paydate,
91 const std::string& currency) const override;
92
93protected:
94 // ModelImpl interface implementation (except initiModelState, this is done in the derived classes)
95 void performCalculations() const override;
96 RandomVariable getIndexValue(const Size indexNo, const Date& d, const Date& fwd = Null<Date>()) const override;
97 RandomVariable getIrIndexValue(const Size indexNo, const Date& d, const Date& fwd = Null<Date>()) const override;
98 RandomVariable getInfIndexValue(const Size indexNo, const Date& d, const Date& fwd = Null<Date>()) const override;
99 RandomVariable getDiscount(const Size idx, const Date& s, const Date& t) const override;
100 RandomVariable getNumeraire(const Date& s) const override;
101 Real getFxSpot(const Size idx) const override;
102 RandomVariable getFutureBarrierProb(const std::string& index, const Date& obsdate1, const Date& obsdate2,
103 const RandomVariable& barrier, const bool above) const override;
104
105 // helper function that constructs the correlation matrix
106 Matrix getCorrelation() const;
107
108 // input parameters
109 const std::vector<Handle<YieldTermStructure>> curves_;
110 const std::vector<Handle<Quote>> fxSpots_;
111 const std::set<std::string> payCcys_;
112 const Handle<BlackScholesModelWrapper> model_;
113 const std::map<std::pair<std::string, std::string>, Handle<QuantExt::CorrelationTermStructure>> correlations_;
114 const std::vector<Date> simulationDates_;
115 const std::string calibration_;
116 const std::map<std::string, std::vector<Real>> calibrationStrikes_;
119 const bool staticMesher_;
120
121 // quanto adjustment parameters
125
126 // these are all initialised when the interface functions above are called
127 mutable std::vector<std::function<RandomVariable(const std::vector<const RandomVariable*>&)>> basisFns_;
128 mutable Date referenceDate_; // the model reference date
129 mutable std::set<Date> effectiveSimulationDates_; // the dates effectively simulated (including today)
130 mutable TimeGrid timeGrid_; // the (possibly refined) time grid for the FD solver
131 mutable std::vector<Size> positionInTimeGrid_; // for each effective simulation date the index in the time grid
132 mutable QuantLib::ext::shared_ptr<FdmMesher> mesher_; // the mesher for the FD solver
133 mutable QuantLib::ext::shared_ptr<FdmLinearOpComposite> operator_; // the operator
134 mutable QuantLib::ext::shared_ptr<FdmBackwardSolver> solver_; // the sovler
135 mutable RandomVariable underlyingValues_; // the discretised underlying
136};
137
138} // namespace data
139} // namespace ore
RandomVariable getInfIndexValue(const Size indexNo, const Date &d, const Date &fwd=Null< Date >()) const override
void performCalculations() const override
RandomVariable getFutureBarrierProb(const std::string &index, const Date &obsdate1, const Date &obsdate2, const RandomVariable &barrier, const bool above) const override
QuantLib::ext::shared_ptr< FdmLinearOpComposite > operator_
const std::vector< Date > simulationDates_
RandomVariable getIrIndexValue(const Size indexNo, const Date &d, const Date &fwd=Null< Date >()) const override
RandomVariable npv(const RandomVariable &amount, const Date &obsdate, const Filter &filter, const boost::optional< long > &memSlot, const RandomVariable &addRegressor1, const RandomVariable &addRegressor2) const override
Real getFxSpot(const Size idx) const override
std::vector< std::function< RandomVariable(const std::vector< const RandomVariable * > &)> > basisFns_
const Date & referenceDate() const override
const std::string & baseCcy() const override
RandomVariable getNumeraire(const Date &s) const override
const std::set< std::string > payCcys_
QuantLib::ext::shared_ptr< FdmBackwardSolver > solver_
Real extractT0Result(const RandomVariable &result) const override
QuantLib::ext::shared_ptr< FdmMesher > mesher_
const std::vector< Handle< Quote > > fxSpots_
RandomVariable pay(const RandomVariable &amount, const Date &obsdate, const Date &paydate, const std::string &currency) const override
const Handle< BlackScholesModelWrapper > model_
const std::map< std::string, std::vector< Real > > calibrationStrikes_
RandomVariable getDiscount(const Size idx, const Date &s, const Date &t) const override
RandomVariable 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_
RandomVariable fwdCompAvg(const bool isAvg, const std::string &index, 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 std::vector< Handle< YieldTermStructure > > curves_
std::vector< Size > positionInTimeGrid_
SafeStack< Filter > filter
@ data
Definition: log.hpp:77
basis implementation for a script engine model
Serializable Credit Default Swap.
Definition: namespaces.docs:23