1 /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 
3 /*
4  Copyright (C) 2006 Ferdinando Ametrano
5  Copyright (C) 2006 Mark Joshi
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 #ifndef quantlib_forward_rate_pc_evolver_hpp
22 #define quantlib_forward_rate_pc_evolver_hpp
23 
24 #include <ql/models/marketmodels/evolver.hpp>
25 #include <ql/models/marketmodels/curvestates/lmmcurvestate.hpp>
26 #include <ql/models/marketmodels/driftcomputation/lmmdriftcalculator.hpp>
27 
28 namespace QuantLib {
29 
30     class MarketModel;
31     class BrownianGenerator;
32     class BrownianGeneratorFactory;
33 
34     //! Predictor-Corrector
35     class LogNormalFwdRatePc : public MarketModelEvolver {
36       public:
37         LogNormalFwdRatePc(const ext::shared_ptr<MarketModel>&,
38                            const BrownianGeneratorFactory&,
39                            const std::vector<Size>& numeraires,
40                            Size initialStep = 0);
41         //! \name MarketModel interface
42         //@{
43         const std::vector<Size>& numeraires() const;
44         Real startNewPath();
45         Real advanceStep();
46         Size currentStep() const;
47         const CurveState& currentState() const;
48         void setInitialState(const CurveState&);
49         //@}
50       private:
51         void setForwards(const std::vector<Real>& forwards);
52         // inputs
53         ext::shared_ptr<MarketModel> marketModel_;
54         std::vector<Size> numeraires_;
55         Size initialStep_;
56         ext::shared_ptr<BrownianGenerator> generator_;
57         // fixed variables
58         std::vector<std::vector<Real> > fixedDrifts_;
59          // working variables
60         Size numberOfRates_, numberOfFactors_;
61         LMMCurveState curveState_;
62         Size currentStep_;
63         std::vector<Rate> forwards_, displacements_, logForwards_, initialLogForwards_;
64         std::vector<Real> drifts1_, drifts2_, initialDrifts_;
65         std::vector<Real> brownians_, correlatedBrownians_;
66         std::vector<Size> alive_;
67         // helper classes
68         std::vector<LMMDriftCalculator> calculators_;
69     };
70 
71 }
72 
73 #endif
74