Coverage Report

Created: 2026-03-11 06:44

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/quantlib/ql/models/shortrate/twofactormodel.cpp
Line
Count
Source
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
#include <ql/models/shortrate/twofactormodel.hpp>
22
#include <ql/processes/stochasticprocessarray.hpp>
23
24
namespace QuantLib {
25
26
    TwoFactorModel::TwoFactorModel(Size nArguments)
27
0
    : ShortRateModel(nArguments) {}
28
29
    ext::shared_ptr<Lattice>
30
0
    TwoFactorModel::tree(const TimeGrid& grid) const {
31
0
        ext::shared_ptr<ShortRateDynamics> dyn = dynamics();
32
33
0
        ext::shared_ptr<TrinomialTree> tree1(
34
0
                                    new TrinomialTree(dyn->xProcess(), grid));
35
0
        ext::shared_ptr<TrinomialTree> tree2(
36
0
                                    new TrinomialTree(dyn->yProcess(), grid));
37
38
0
        return ext::shared_ptr<Lattice>(
39
0
                        new TwoFactorModel::ShortRateTree(tree1, tree2, dyn));
40
0
    }
41
42
    TwoFactorModel::ShortRateTree::ShortRateTree(
43
                         const ext::shared_ptr<TrinomialTree>& tree1,
44
                         const ext::shared_ptr<TrinomialTree>& tree2,
45
                         const ext::shared_ptr<ShortRateDynamics>& dynamics)
46
0
    : TreeLattice2D<TwoFactorModel::ShortRateTree,TrinomialTree>(
47
0
                                       tree1, tree2, dynamics->correlation()),
48
0
      dynamics_(dynamics) {}
49
50
    ext::shared_ptr<StochasticProcess>
51
0
    TwoFactorModel::ShortRateDynamics::process() const {
52
0
        Matrix correlation(2,2);
53
0
        correlation[0][0] = correlation[1][1] = 1.0;
54
0
        correlation[0][1] = correlation[1][0] = correlation_;
55
0
        std::vector<ext::shared_ptr<StochasticProcess1D> > processes(2);
56
0
        processes[0] = xProcess_;
57
0
        processes[1] = yProcess_;
58
0
        return ext::shared_ptr<StochasticProcess>(
59
0
                           new StochasticProcessArray(processes,correlation));
60
0
    }
61
62
}