/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* Copyright (C) 2006 Banca Profilo S.p.A. Copyright (C) 2006 StatPro Italia srl This file is part of QuantLib, a free-software/open-source library for financial quantitative analysts and developers - http://quantlib.org/ QuantLib is free software: you can redistribute it and/or modify it under the terms of the QuantLib license. You should have received a copy of the license along with this program; if not, please email . The license is also available online at . This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the license for more details. */ #include namespace QuantLib { HullWhiteCapFloorPricer::HullWhiteCapFloorPricer( const CapFloor::arguments& args, const boost::shared_ptr& model, Time forwardMeasureTime) : args_(args), model_(model), forwardMeasureTime_(forwardMeasureTime) { endDiscount_ = model_->termStructure()->discount(forwardMeasureTime_); } Real HullWhiteCapFloorPricer::operator()(const Path& path) const { bool isCap = (args_.type == CapFloor::Cap); Real npv = 0.0; Time Tb = forwardMeasureTime_; Size pastFixings = 0; for (Size i = 0; idiscountBond(fixing, start, ri_1); DiscountFactor d2 = model_->discountBond(fixing, end, ri_1); currentLibor = (d1/d2-1)/tau; } Real accrualFactor = 1.0/model_->discountBond(end, Tb, ri_2); Rate strike = isCap? args_.capRates[i] : args_.floorRates[i]; Real payoff = isCap? std::max(currentLibor - strike, 0.0): std::max(strike - currentLibor, 0.0); npv += payoff * tau * args_.gearings[i] * args_.nominals[i] * accrualFactor; } } npv *= endDiscount_; return npv; } }