Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
lgm.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2016 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#include <iostream>
20#include <ql/experimental/math/piecewiseintegral.hpp>
21#include <qle/models/lgm.hpp>
23
24namespace QuantExt {
25
26LinearGaussMarkovModel::LinearGaussMarkovModel(const QuantLib::ext::shared_ptr<IrLgm1fParametrization>& parametrization,
27 const Measure measure, const Discretization discretization,
28 const bool evaluateBankAccount,
29 const QuantLib::ext::shared_ptr<Integrator>& integrator)
30 : parametrization_(parametrization), measure_(measure), discretization_(discretization),
31 evaluateBankAccount_(evaluateBankAccount) {
32 QL_REQUIRE(parametrization_ != nullptr, "HwModel: parametrization is null");
33 stateProcess_ = QuantLib::ext::make_shared<IrLgm1fStateProcess>(parametrization_);
34 arguments_.resize(2);
35 arguments_[0] = parametrization_->parameter(0);
36 arguments_[1] = parametrization_->parameter(1);
37 registerWith(parametrization_->termStructure());
38
39 std::vector<Time> allTimes;
40 for (Size i = 0; i < 2; ++i)
41 allTimes.insert(allTimes.end(), parametrization_->parameterTimes(i).begin(),
42 parametrization_->parameterTimes(i).end());
43
44 integrator_ = QuantLib::ext::make_shared<PiecewiseIntegral>(integrator, allTimes, true);
45}
46
47Real LinearGaussMarkovModel::bankAccountNumeraire(const Time t, const Real x, const Real y,
48 const Handle<YieldTermStructure> discountCurve) const {
49 QL_REQUIRE(t >= 0.0, "t (" << t << ") >= 0 required in LGM::bankAccountNumeraire");
50 Real Ht = parametrization_->H(t);
51 Real zeta0 = parametrization_->zeta(t);
52 Real zeta2 = parametrization_->zetan(2, t, integrator_);
53 Real Vt = 0.5 * (Ht * Ht * zeta0 + zeta2);
54 return std::exp(Ht * x - y + Vt) /
55 (discountCurve.empty() ? parametrization_->termStructure()->discount(t) : discountCurve->discount(t));
56}
57
58Size LinearGaussMarkovModel::n() const { return 1; }
59Size LinearGaussMarkovModel::m() const { return 1; }
63}
64
65} // namespace QuantExt
Size m() const override
Definition: lgm.cpp:59
Size n() const override
Definition: lgm.cpp:58
Size n_aux() const override
Definition: lgm.cpp:60
QuantLib::ext::shared_ptr< IrLgm1fParametrization > parametrization_
Definition: lgm.hpp:155
QuantLib::ext::shared_ptr< StochasticProcess1D > stateProcess_
Definition: lgm.hpp:160
Discretization discretization_
Definition: lgm.hpp:158
Size m_aux() const override
Definition: lgm.cpp:61
QuantLib::ext::shared_ptr< Integrator > integrator_
Definition: lgm.hpp:156
LinearGaussMarkovModel(const QuantLib::ext::shared_ptr< IrLgm1fParametrization > &parametrization, const Measure measure=Measure::LGM, const Discretization=Discretization::Euler, const bool evaluateBankAccount=true, const QuantLib::ext::shared_ptr< Integrator > &integrator=QuantLib::ext::make_shared< SimpsonIntegral >(1.0E-8, 100))
Definition: lgm.cpp:26
Real bankAccountNumeraire(const Time t, const Real x, const Real y, const Handle< YieldTermStructure > discountCurve=Handle< YieldTermStructure >()) const
Definition: lgm.cpp:47
std::vector< QuantLib::ext::shared_ptr< Parameter > > arguments_
ir LGM 1f model state process
lgm model class