29#pragma push_macro("BOOST_DISABLE_ASSERTS")
30#ifndef BOOST_DISABLE_ASSERTS
31#define BOOST_DISABLE_ASSERTS
33#include <boost/multi_array.hpp>
34#pragma pop_macro("BOOST_DISABLE_ASSERTS")
42 ext::shared_ptr<BrownianGeneratorFactory> brownianGeneratorFactory,
44 Size timeStepsPerYear,
46 Size calibrationPaths,
47 const std::vector<Date>& mandatoryDates,
48 const Real mixingFactor)
49 : localVol_(
std::move(localVol)), hestonModel_(
std::move(hestonModel)),
50 brownianGeneratorFactory_(
std::move(brownianGeneratorFactory)), endDate_(endDate),
51 nBins_(nBins), calibrationPaths_(calibrationPaths), mixingFactor_(mixingFactor) {
57 const Date refDate =
hestonModel_->process()->riskFreeRate()->referenceDate();
59 std::vector<Time> gridTimes;
60 gridTimes.reserve(mandatoryDates.size()+1);
61 for (
auto mandatoryDate : mandatoryDates) {
62 gridTimes.push_back(dc.
yearFraction(refDate, mandatoryDate));
66 timeGrid_ = ext::make_shared<TimeGrid>(gridTimes.begin(), gridTimes.end(),
67 std::max(
Size(2),
Size(gridTimes.back()*timeStepsPerYear)));
78 ext::shared_ptr<LocalVolTermStructure>
88 const ext::shared_ptr<Quote> spot
96 =
localVol_->localVol(0.0, spot->value())/std::sqrt(
v0);
100 std::vector<ext::shared_ptr<std::vector<Real> > >
106 vStrikes[i] = ext::make_shared<std::vector<Real> >(
nBins_);
109 vStrikes[i]->at(j) = spot->value() + (j - u)*dx;
112 std::fill(L->column_begin(0),L->column_end(0), lv0);
119 const ext::shared_ptr<HestonSLVProcess> slvProcess
122 std::vector<std::pair<Real, Real> > pairs(
130 typedef boost::multi_array<Real, 3> path_type;
133 const ext::shared_ptr<BrownianGenerator> brownianGenerator =
137 brownianGenerator->nextPath();
138 std::vector<Real> tmp(2);
139 for (
Size j=0; j < timeSteps; ++j) {
140 brownianGenerator->nextStep(tmp);
141 paths[i][j][0] = tmp[0];
142 paths[i][j][1] = tmp[1];
153 x0[0] = pairs[i].first;
154 x0[1] = pairs[i].second;
156 dw[0] = paths[i][
n-1][0];
157 dw[1] = paths[i][
n-1][1];
159 x0 = slvProcess->evolve(
t, x0, dt, dw);
161 pairs[i].first = x0[0];
162 pairs[i].second = x0[1];
165 std::sort(pairs.begin(), pairs.end());
169 const Size inc = k +
static_cast<unsigned long>(i < m);
173 for (
Size j=
s; j < e; ++j) {
174 sum+=pairs[j].second;
178 vStrikes[
n]->at(i) = 0.5*(pairs[e-1].first + pairs[
s].first);
1-D array used in linear algebra.
Time yearFraction(const Date &, const Date &, const Date &refPeriodStart=Date(), const Date &refPeriodEnd=Date()) const
Returns the period between two dates as a fraction of year.
Shared handle to an observable.
ext::shared_ptr< LocalVolTermStructure > leverageFunction() const
ext::shared_ptr< TimeGrid > timeGrid_
void performCalculations() const override
const ext::shared_ptr< BrownianGeneratorFactory > brownianGeneratorFactory_
const Size calibrationPaths_
const Handle< LocalVolTermStructure > localVol_
const Handle< HestonModel > hestonModel_
HestonSLVMCModel(Handle< LocalVolTermStructure > localVol, Handle< HestonModel > hestonModel, ext::shared_ptr< BrownianGeneratorFactory > brownianGeneratorFactory, const Date &endDate, Size timeStepsPerYear=365, Size nBins=201, Size calibrationPaths=(1<< 15), const std::vector< Date > &mandatoryDates=std::vector< Date >(), Real mixingFactor=1.0)
ext::shared_ptr< HestonProcess > hestonProcess() const
ext::shared_ptr< FixedLocalVolSurface > leverageFunction_
ext::shared_ptr< LocalVolTermStructure > localVol() const
virtual void calculate() const
Linear-interpolation factory and traits
Matrix used in linear algebra.
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
Local volatility surface based on fixed values plus interpolation.
Real Time
continuous quantity with 1-year units
Real Volatility
volatility
QL_INTEGER Integer
integer number
std::size_t Size
size of a container
Calibration of a Heston stochastic local volatility model based on MC.
Heston stochastic local volatility process.
functionals and combinators not included in the STL