Coverage Report

Created: 2025-09-04 07:11

/src/quantlib/ql/pricingengines/latticeshortratemodelengine.hpp
Line
Count
Source (jump to first uncovered line)
1
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3
/*
4
 Copyright (C) 2001, 2002, 2003 Sadruddin Rejeb
5
 Copyright (C) 2005 StatPro Italia srl
6
7
 This file is part of QuantLib, a free-software/open-source library
8
 for financial quantitative analysts and developers - http://quantlib.org/
9
10
 QuantLib is free software: you can redistribute it and/or modify it
11
 under the terms of the QuantLib license.  You should have received a
12
 copy of the license along with this program; if not, please email
13
 <quantlib-dev@lists.sf.net>. The license is also available online at
14
 <https://www.quantlib.org/license.shtml>.
15
16
 This program is distributed in the hope that it will be useful, but WITHOUT
17
 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18
 FOR A PARTICULAR PURPOSE.  See the license for more details.
19
*/
20
21
/*! \file latticeshortratemodelengine.hpp
22
    \brief Engine for a short-rate model specialized on a lattice
23
*/
24
25
#ifndef quantlib_short_rate_model_engine_hpp
26
#define quantlib_short_rate_model_engine_hpp
27
28
#include <ql/models/model.hpp>
29
#include <ql/pricingengines/genericmodelengine.hpp>
30
31
namespace QuantLib {
32
33
    //! Engine for a short-rate model specialized on a lattice
34
    /*! Derived engines only need to implement the <tt>calculate()</tt>
35
        method
36
    */
37
    template <class Arguments, class Results>
38
    class LatticeShortRateModelEngine
39
        : public GenericModelEngine<ShortRateModel, Arguments, Results> {
40
      public:
41
        LatticeShortRateModelEngine(
42
                               const ext::shared_ptr<ShortRateModel>& model,
43
                               Size timeSteps);
44
        LatticeShortRateModelEngine(
45
                               const Handle<ShortRateModel>& model,
46
                               Size timeSteps);
47
        LatticeShortRateModelEngine(
48
                               const ext::shared_ptr<ShortRateModel>& model,
49
                               const TimeGrid& timeGrid);
50
        void update() override;
51
52
      protected:
53
        TimeGrid timeGrid_;
54
        Size timeSteps_;
55
        ext::shared_ptr<Lattice> lattice_;
56
    };
57
58
    template <class Arguments, class Results>
59
    LatticeShortRateModelEngine<Arguments, Results>::LatticeShortRateModelEngine(
60
            const ext::shared_ptr<ShortRateModel>& model,
61
            Size timeSteps)
62
0
    : GenericModelEngine<ShortRateModel, Arguments, Results>(model),
63
0
      timeSteps_(timeSteps) {
64
0
        QL_REQUIRE(timeSteps>0,
65
0
                   "timeSteps must be positive, " << timeSteps <<
66
0
                   " not allowed");
67
0
    }
Unexecuted instantiation: QuantLib::LatticeShortRateModelEngine<QuantLib::CallableBond::arguments, QuantLib::CallableBond::results>::LatticeShortRateModelEngine(boost::shared_ptr<QuantLib::ShortRateModel> const&, unsigned long)
Unexecuted instantiation: QuantLib::LatticeShortRateModelEngine<QuantLib::CapFloor::arguments, QuantLib::Instrument::results>::LatticeShortRateModelEngine(boost::shared_ptr<QuantLib::ShortRateModel> const&, unsigned long)
Unexecuted instantiation: QuantLib::LatticeShortRateModelEngine<QuantLib::FixedVsFloatingSwap::arguments, QuantLib::FixedVsFloatingSwap::results>::LatticeShortRateModelEngine(boost::shared_ptr<QuantLib::ShortRateModel> const&, unsigned long)
Unexecuted instantiation: QuantLib::LatticeShortRateModelEngine<QuantLib::Swaption::arguments, QuantLib::Instrument::results>::LatticeShortRateModelEngine(boost::shared_ptr<QuantLib::ShortRateModel> const&, unsigned long)
68
69
    template <class Arguments, class Results>
70
    LatticeShortRateModelEngine<Arguments, Results>::LatticeShortRateModelEngine(
71
            const Handle<ShortRateModel>& model,
72
            Size timeSteps)
73
0
    : GenericModelEngine<ShortRateModel, Arguments, Results>(model),
74
0
      timeSteps_(timeSteps) {
75
0
        QL_REQUIRE(timeSteps>0,
76
0
                   "timeSteps must be positive, " << timeSteps <<
77
0
                   " not allowed");
78
0
    }
79
80
    template <class Arguments, class Results>
81
    LatticeShortRateModelEngine<Arguments, Results>::LatticeShortRateModelEngine(
82
            const ext::shared_ptr<ShortRateModel>& model,
83
            const TimeGrid& timeGrid)
84
0
    : GenericModelEngine<ShortRateModel, Arguments, Results>(model),
85
0
      timeGrid_(timeGrid), timeSteps_(0) {
86
0
        lattice_ = this->model_->tree(timeGrid);
87
0
    }
Unexecuted instantiation: QuantLib::LatticeShortRateModelEngine<QuantLib::CallableBond::arguments, QuantLib::CallableBond::results>::LatticeShortRateModelEngine(boost::shared_ptr<QuantLib::ShortRateModel> const&, QuantLib::TimeGrid const&)
Unexecuted instantiation: QuantLib::LatticeShortRateModelEngine<QuantLib::CapFloor::arguments, QuantLib::Instrument::results>::LatticeShortRateModelEngine(boost::shared_ptr<QuantLib::ShortRateModel> const&, QuantLib::TimeGrid const&)
Unexecuted instantiation: QuantLib::LatticeShortRateModelEngine<QuantLib::FixedVsFloatingSwap::arguments, QuantLib::FixedVsFloatingSwap::results>::LatticeShortRateModelEngine(boost::shared_ptr<QuantLib::ShortRateModel> const&, QuantLib::TimeGrid const&)
Unexecuted instantiation: QuantLib::LatticeShortRateModelEngine<QuantLib::Swaption::arguments, QuantLib::Instrument::results>::LatticeShortRateModelEngine(boost::shared_ptr<QuantLib::ShortRateModel> const&, QuantLib::TimeGrid const&)
88
89
    template <class Arguments, class Results>
90
    void LatticeShortRateModelEngine<Arguments, Results>::update()
91
0
    {
92
0
        if (!timeGrid_.empty())
93
0
            lattice_ = this->model_->tree(timeGrid_);
94
0
        GenericModelEngine<ShortRateModel, Arguments, Results>::update();
95
0
    }
Unexecuted instantiation: QuantLib::LatticeShortRateModelEngine<QuantLib::CallableBond::arguments, QuantLib::CallableBond::results>::update()
Unexecuted instantiation: QuantLib::LatticeShortRateModelEngine<QuantLib::CapFloor::arguments, QuantLib::Instrument::results>::update()
Unexecuted instantiation: QuantLib::LatticeShortRateModelEngine<QuantLib::FixedVsFloatingSwap::arguments, QuantLib::FixedVsFloatingSwap::results>::update()
Unexecuted instantiation: QuantLib::LatticeShortRateModelEngine<QuantLib::Swaption::arguments, QuantLib::Instrument::results>::update()
96
97
}
98
99
100
#endif