1 /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 3 /* 4 Copyright (C) 2005, 2006 Klaus Spanderen 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/legacy/libormarketmodels/lmfixedvolmodel.hpp> 21 22 namespace QuantLib { 23 LmFixedVolatilityModel(const Array & volatilities,const std::vector<Time> & startTimes)24 LmFixedVolatilityModel::LmFixedVolatilityModel( 25 const Array& volatilities, 26 const std::vector<Time>& startTimes) 27 : LmVolatilityModel(startTimes.size(), 0), 28 volatilities_ (volatilities), 29 startTimes_ (startTimes) { 30 QL_REQUIRE(startTimes_.size()>1, "too few dates"); 31 QL_REQUIRE(volatilities_.size() == startTimes_.size(), 32 "volatility array and fixing time array have to have " 33 "the same size"); 34 for (Size i = 1; i < startTimes_.size(); i++) { 35 QL_REQUIRE(startTimes_[i] > startTimes_[i-1], 36 "invalid time (" << startTimes_[i] << ", vs " 37 << startTimes_[i-1] << ")"); 38 } 39 } 40 volatility(Time t,const Array &) const41 Disposable<Array> LmFixedVolatilityModel::volatility( 42 Time t, const Array&) const { 43 QL_REQUIRE(t >= startTimes_.front() && t <= startTimes_.back(), 44 "invalid time given for volatility model"); 45 46 const Size ti = std::upper_bound(startTimes_.begin(), 47 startTimes_.end()-1, t) 48 - startTimes_.begin()-1; 49 50 Array tmp(size_, 0.0); 51 52 for (Size i=ti; i<size_; ++i) { 53 tmp[i] = volatilities_[i-ti]; 54 } 55 56 return tmp; 57 } 58 volatility(Size i,Time t,const Array &) const59 Volatility LmFixedVolatilityModel::volatility( 60 Size i, Time t, const Array&) const { 61 QL_REQUIRE(t >= startTimes_.front() && t <= startTimes_.back(), 62 "invalid time given for volatility model"); 63 64 const Size ti = std::upper_bound(startTimes_.begin(), 65 startTimes_.end()-1, t) 66 - startTimes_.begin()-1; 67 68 return volatilities_[i-ti]; 69 } 70 generateArguments()71 void LmFixedVolatilityModel::generateArguments() {} 72 } 73 74