1 /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 3 /* 4 Copyright (C) 2006 StatPro Italia srl 5 6 This file is part of QuantLib, a free-software/open-source library 7 for financial quantitative analysts and developers - http://quantlib.org/ 8 9 QuantLib is free software: you can redistribute it and/or modify it 10 under the terms of the QuantLib license. You should have received a 11 copy of the license along with this program; if not, please email 12 <quantlib-dev@lists.sf.net>. The license is also available online at 13 <http://quantlib.org/license.shtml>. 14 15 This program is distributed in the hope that it will be useful, but WITHOUT 16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 17 FOR A PARTICULAR PURPOSE. See the license for more details. 18 */ 19 20 #ifndef quantlib_market_model_composite_product_hpp 21 #define quantlib_market_model_composite_product_hpp 22 23 #include <ql/models/marketmodels/multiproduct.hpp> 24 #include <ql/models/marketmodels/evolutiondescription.hpp> 25 #include <ql/utilities/clone.hpp> 26 #include <valarray> 27 28 namespace QuantLib { 29 30 //! Composition of two or more market-model products 31 /*! Instances of this class build a market-model product by 32 composing one or more subproducts. 33 34 \pre All subproducts must have the same rate times. 35 */ 36 class MarketModelComposite : public MarketModelMultiProduct { 37 public: 38 MarketModelComposite(); 39 //! \name MarketModelMultiProduct interface 40 //@{ 41 const EvolutionDescription& evolution() const; 42 std::vector<Size> suggestedNumeraires() const; 43 std::vector<Time> possibleCashFlowTimes() const; 44 void reset(); 45 //@} 46 //! \name Composite facilities 47 //@{ 48 void add(const Clone<MarketModelMultiProduct>&, 49 Real multiplier = 1.0); 50 void subtract(const Clone<MarketModelMultiProduct>&, 51 Real multiplier = 1.0); 52 void finalize(); 53 Size size() const; 54 const MarketModelMultiProduct& item(Size i) const; 55 MarketModelMultiProduct& item(Size i); 56 Real multiplier(Size i) const; 57 //@} 58 protected: 59 // subproducts 60 struct SubProduct { 61 Clone<MarketModelMultiProduct> product; 62 Real multiplier; 63 std::vector<Size> numberOfCashflows; 64 std::vector<std::vector<CashFlow> > cashflows; 65 std::vector<Size> timeIndices; 66 bool done; 67 }; 68 std::vector<SubProduct> components_; 69 typedef std::vector<SubProduct>::iterator iterator; 70 typedef std::vector<SubProduct>::const_iterator const_iterator; 71 // common evolution data 72 std::vector<Time> rateTimes_; 73 std::vector<Time> evolutionTimes_; 74 EvolutionDescription evolution_; 75 // working variables 76 bool finalized_; 77 Size currentIndex_; 78 std::vector<Time> cashflowTimes_; 79 std::vector<std::vector<Time> > allEvolutionTimes_; 80 std::vector<std::valarray<bool> > isInSubset_; 81 }; 82 83 } 84 85 86 #endif 87