/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* Copyright (C) 2001, 2002, 2003 Sadruddin Rejeb 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 #include #include #include #include namespace QuantLib { CapHelper::CapHelper(const Period& length, const Handle& volatility, const boost::shared_ptr& index, Frequency fixedLegFrequency, const DayCounter& fixedLegDayCounter, bool includeFirstSwaplet, const Handle& termStructure, bool calibrateVolatility) : CalibrationHelper(volatility,termStructure,calibrateVolatility) { Period indexTenor = index->tenor(); Rate fixedRate = 0.04; // dummy value Date startDate, maturity; if (includeFirstSwaplet) { startDate = termStructure->referenceDate(); maturity = termStructure->referenceDate() + length; } else { startDate = termStructure->referenceDate() + indexTenor; maturity = termStructure->referenceDate() + length; } boost::shared_ptr dummyIndex(new IborIndex("dummy", indexTenor, index->fixingDays(), index->currency(), index->fixingCalendar(), index->businessDayConvention(), index->endOfMonth(), termStructure->dayCounter(), termStructure)); std::vector nominals(1,1.0); Schedule floatSchedule(startDate, maturity, index->tenor(), index->fixingCalendar(), index->businessDayConvention(), index->businessDayConvention(), false, false); Leg floatingLeg = IborLeg(nominals, floatSchedule, index, DayCounter(), index->businessDayConvention(), 0); boost::shared_ptr fictitiousPricer(new BlackIborCouponPricer(Handle())); setCouponPricer(floatingLeg,fictitiousPricer); Schedule fixedSchedule(startDate, maturity, Period(fixedLegFrequency), index->fixingCalendar(), Unadjusted, Unadjusted, false, false); Leg fixedLeg = FixedRateLeg(nominals, fixedSchedule, std::vector(1, fixedRate), fixedLegDayCounter, index->businessDayConvention()); boost::shared_ptr swap( new Swap(termStructure, floatingLeg, fixedLeg)); Rate fairRate = fixedRate - swap->NPV()/(swap->legBPS(1)/1.0e-4); engine_ = boost::shared_ptr(); cap_ = boost::shared_ptr(new Cap(floatingLeg, std::vector(1, fairRate), termStructure, engine_)); marketValue_ = blackPrice(volatility_->value()); } void CapHelper::addTimesTo(std::list