QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
latticeshortratemodelengine.hpp
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 <http://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
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
31namespace QuantLib {
32
34
37 template <class Arguments, class Results>
39 : public GenericModelEngine<ShortRateModel, Arguments, Results> {
40 public:
42 const ext::shared_ptr<ShortRateModel>& model,
43 Size timeSteps);
45 const Handle<ShortRateModel>& model,
46 Size timeSteps);
48 const ext::shared_ptr<ShortRateModel>& model,
49 const TimeGrid& timeGrid);
50 void update() override;
51
52 protected:
55 ext::shared_ptr<Lattice> lattice_;
56 };
57
58 template <class Arguments, class Results>
60 const ext::shared_ptr<ShortRateModel>& model,
61 Size timeSteps)
63 timeSteps_(timeSteps) {
64 QL_REQUIRE(timeSteps>0,
65 "timeSteps must be positive, " << timeSteps <<
66 " not allowed");
67 }
68
69 template <class Arguments, class Results>
71 const Handle<ShortRateModel>& model,
72 Size timeSteps)
74 timeSteps_(timeSteps) {
75 QL_REQUIRE(timeSteps>0,
76 "timeSteps must be positive, " << timeSteps <<
77 " not allowed");
78 }
79
80 template <class Arguments, class Results>
82 const ext::shared_ptr<ShortRateModel>& model,
83 const TimeGrid& timeGrid)
85 timeGrid_(timeGrid), timeSteps_(0) {
86 lattice_ = this->model_->tree(timeGrid);
87 }
88
89 template <class Arguments, class Results>
91 {
92 if (!timeGrid_.empty())
93 lattice_ = this->model_->tree(timeGrid_);
95 }
96
97}
98
99
100#endif
Base class for some pricing engine on a particular model.
Shared handle to an observable.
Definition: handle.hpp:41
Engine for a short-rate model specialized on a lattice.
LatticeShortRateModelEngine(const ext::shared_ptr< ShortRateModel > &model, Size timeSteps)
LatticeShortRateModelEngine(const ext::shared_ptr< ShortRateModel > &model, const TimeGrid &timeGrid)
LatticeShortRateModelEngine(const Handle< ShortRateModel > &model, Size timeSteps)
virtual void update()=0
Abstract short-rate model class.
Definition: model.hpp:141
time grid class
Definition: timegrid.hpp:43
std::size_t Size
size of a container
Definition: types.hpp:58
Definition: any.hpp:35