1 /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 3 /* 4 Copyright (C) 2009 Mark Joshi 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 #include <ql/models/marketmodels/products/pathwise/pathwiseproductcashrebate.hpp> 21 #include <ql/models/marketmodels/curvestate.hpp> 22 #include <ql/models/marketmodels/utilities.hpp> 23 #include <ql/auto_ptr.hpp> 24 25 namespace QuantLib 26 { 27 28 alreadyDeflated() const29 bool MarketModelPathwiseCashRebate::alreadyDeflated() const 30 { 31 return false; 32 } 33 MarketModelPathwiseCashRebate(const EvolutionDescription & evolution,const std::vector<Time> & paymentTimes,const Matrix & amounts,Size numberOfProducts)34 MarketModelPathwiseCashRebate::MarketModelPathwiseCashRebate( 35 const EvolutionDescription& evolution, 36 const std::vector<Time>& paymentTimes, 37 const Matrix& amounts, 38 Size numberOfProducts) 39 : evolution_(evolution), paymentTimes_(paymentTimes), 40 amounts_(amounts), numberOfProducts_(numberOfProducts) 41 { 42 43 checkIncreasingTimes(paymentTimes); 44 45 QL_REQUIRE(amounts_.rows() == numberOfProducts_, 46 "the number of rows in the matrix must equal " 47 "the number of products"); 48 QL_REQUIRE(amounts_.columns() == paymentTimes_.size(), 49 "the number of columns in the matrix must equal " 50 "the number of payment times"); 51 QL_REQUIRE(evolution_.evolutionTimes().size() == paymentTimes_.size(), 52 "the number of evolution times must equal " 53 "the number of payment times"); 54 } 55 56 57 std::vector<Time> possibleCashFlowTimes() const58 MarketModelPathwiseCashRebate::possibleCashFlowTimes() const 59 { 60 return paymentTimes_; 61 } 62 numberOfProducts() const63 Size MarketModelPathwiseCashRebate::numberOfProducts() const 64 { 65 return numberOfProducts_; 66 } 67 maxNumberOfCashFlowsPerProductPerStep() const68 Size MarketModelPathwiseCashRebate::maxNumberOfCashFlowsPerProductPerStep() const 69 { 70 return 1; 71 } 72 reset()73 void MarketModelPathwiseCashRebate::reset() 74 { 75 currentIndex_=0; 76 } 77 78 std::vector<Size> suggestedNumeraires() const79 MarketModelPathwiseCashRebate::suggestedNumeraires() const 80 { 81 QL_FAIL("not implemented (yet?)"); 82 } 83 evolution() const84 const EvolutionDescription& MarketModelPathwiseCashRebate::evolution() const 85 { 86 return evolution_; 87 } 88 89 nextTimeStep(const CurveState &,std::vector<Size> & numberCashFlowsThisStep,std::vector<std::vector<MarketModelPathwiseMultiProduct::CashFlow>> & cashFlowsGenerated)90 bool MarketModelPathwiseCashRebate::nextTimeStep( 91 const CurveState&, 92 std::vector<Size>& numberCashFlowsThisStep, 93 std::vector<std::vector<MarketModelPathwiseMultiProduct::CashFlow> >& cashFlowsGenerated) 94 { 95 for (Size i=0; i<numberOfProducts_; ++i) 96 { 97 numberCashFlowsThisStep[i] = 1; 98 cashFlowsGenerated[i][0].timeIndex = currentIndex_; 99 cashFlowsGenerated[i][0].amount[0] = amounts_[i][currentIndex_]; 100 101 for (Size k=1; k <= evolution_.numberOfRates(); ++k) 102 cashFlowsGenerated[i][0].amount[k] = 0.0; 103 104 } 105 ++currentIndex_; 106 return true; 107 } 108 109 QL_UNIQUE_OR_AUTO_PTR<MarketModelPathwiseMultiProduct> clone() const110 MarketModelPathwiseCashRebate::clone() const 111 { 112 return QL_UNIQUE_OR_AUTO_PTR<MarketModelPathwiseMultiProduct>( 113 new MarketModelPathwiseCashRebate(*this)); 114 } 115 116 } 117