QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
twofactormodel.cpp
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
21#include <ql/models/shortrate/twofactormodel.hpp>
22#include <ql/processes/stochasticprocessarray.hpp>
23
24namespace QuantLib {
25
27 : ShortRateModel(nArguments) {}
28
29 ext::shared_ptr<Lattice>
30 TwoFactorModel::tree(const TimeGrid& grid) const {
31 ext::shared_ptr<ShortRateDynamics> dyn = dynamics();
32
33 ext::shared_ptr<TrinomialTree> tree1(
34 new TrinomialTree(dyn->xProcess(), grid));
35 ext::shared_ptr<TrinomialTree> tree2(
36 new TrinomialTree(dyn->yProcess(), grid));
37
38 return ext::shared_ptr<Lattice>(
39 new TwoFactorModel::ShortRateTree(tree1, tree2, dyn));
40 }
41
43 const ext::shared_ptr<TrinomialTree>& tree1,
44 const ext::shared_ptr<TrinomialTree>& tree2,
45 const ext::shared_ptr<ShortRateDynamics>& dynamics)
47 tree1, tree2, dynamics->correlation()),
48 dynamics_(dynamics) {}
49
50 ext::shared_ptr<StochasticProcess>
52 Matrix correlation(2,2);
53 correlation[0][0] = correlation[1][1] = 1.0;
54 correlation[0][1] = correlation[1][0] = correlation_;
55 std::vector<ext::shared_ptr<StochasticProcess1D> > processes(2);
56 processes[0] = xProcess_;
57 processes[1] = yProcess_;
58 return ext::shared_ptr<StochasticProcess>(
59 new StochasticProcessArray(processes,correlation));
60 }
61
62}
Matrix used in linear algebra.
Definition: matrix.hpp:41
Abstract short-rate model class.
Definition: model.hpp:141
Array of correlated 1-D stochastic processes
time grid class
Definition: timegrid.hpp:43
Two-dimensional tree-based lattice.
Definition: lattice2d.hpp:42
Recombining trinomial tree class.
ext::shared_ptr< StochasticProcess > process() const
Joint process of the two variables.
Recombining two-dimensional tree discretizing the state variable.
ShortRateTree(const ext::shared_ptr< TrinomialTree > &tree1, const ext::shared_ptr< TrinomialTree > &tree2, const ext::shared_ptr< ShortRateDynamics > &dynamics)
Plain tree build-up from short-rate dynamics.
Abstract base-class for two-factor models.
ext::shared_ptr< Lattice > tree(const TimeGrid &grid) const override
Returns a two-dimensional trinomial tree.
virtual ext::shared_ptr< ShortRateDynamics > dynamics() const =0
Returns the short-rate dynamics.
std::size_t Size
size of a container
Definition: types.hpp:58
Definition: any.hpp:35