/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* Copyright (C) 2007 Ferdinando Ametrano Copyright (C) 2000, 2001, 2002, 2003 RiskMap srl Copyright (C) 2003, 2004, 2005, 2006, 2007 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 #include #include #include #include namespace QuantLib { VanillaSwap::VanillaSwap(Type type, Real nominal, const Schedule& fixedSchedule, Rate fixedRate, const DayCounter& fixedDayCount, const Schedule& floatSchedule, const boost::shared_ptr& index, Spread spread, const DayCounter& floatingDayCount, const Handle& termStructure) : Swap(termStructure, Leg(), Leg()), type_(type), fixedRate_(fixedRate), spread_(spread), nominal_(nominal) { BusinessDayConvention convention = floatSchedule.businessDayConvention(); Leg fixedLeg =FixedRateLeg(std::vector(1,nominal), fixedSchedule, std::vector(1,fixedRate), fixedDayCount, convention); Leg floatingLeg = IborLeg(std::vector(1,nominal), floatSchedule, index, floatingDayCount, convention, index->fixingDays(), std::vector(1,1.0), std::vector(1,spread)); boost::shared_ptr fictitiousPricer(new BlackIborCouponPricer(Handle())); setCouponPricer(floatingLeg,fictitiousPricer); Leg::const_iterator i; for (i = floatingLeg.begin(); i < floatingLeg.end(); ++i) registerWith(*i); legs_[0] = fixedLeg; legs_[1] = floatingLeg; if (type_==Payer) { payer_[0]=-1.0; payer_[1]=+1.0; } else { payer_[0]=+1.0; payer_[1]=-1.0; } } void VanillaSwap::setupArguments(PricingEngine::arguments* args) const { VanillaSwap::arguments* arguments = dynamic_cast(args); QL_REQUIRE(arguments != 0, "wrong argument type"); arguments->type = type_; arguments->nominal = nominal_; // reset in case it's not set later arguments->currentFloatingCoupon = Null(); Date settlement = termStructure_->referenceDate(); DayCounter counter = termStructure_->dayCounter(); Size i; const Leg& fixedCoupons = fixedLeg(); arguments->fixedResetTimes = arguments->fixedPayTimes = std::vector