QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
vanillaswap.cpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2000, 2001, 2002, 2003 RiskMap srl
5 Copyright (C) 2003, 2004, 2005, 2006, 2007 StatPro Italia srl
6 Copyright (C) 2007 Ferdinando Ametrano
7
8 This file is part of QuantLib, a free-software/open-source library
9 for financial quantitative analysts and developers - http://quantlib.org/
10
11 QuantLib is free software: you can redistribute it and/or modify it
12 under the terms of the QuantLib license. You should have received a
13 copy of the license along with this program; if not, please email
14 <quantlib-dev@lists.sf.net>. The license is also available online at
15 <http://quantlib.org/license.shtml>.
16
17 This program is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 FOR A PARTICULAR PURPOSE. See the license for more details.
20*/
21
22#include <ql/cashflows/iborcoupon.hpp>
23#include <ql/indexes/iborindex.hpp>
24#include <ql/instruments/vanillaswap.hpp>
25#include <ql/termstructures/yieldtermstructure.hpp>
26#include <utility>
27
28namespace QuantLib {
29
31 Real nominal,
32 Schedule fixedSchedule,
33 Rate fixedRate,
34 DayCounter fixedDayCount,
35 Schedule floatSchedule,
36 ext::shared_ptr<IborIndex> index,
37 Spread spread,
38 DayCounter floatingDayCount,
39 ext::optional<BusinessDayConvention> paymentConvention,
40 ext::optional<bool> useIndexedCoupons)
41 : FixedVsFloatingSwap(type, {nominal}, std::move(fixedSchedule), fixedRate, std::move(fixedDayCount),
42 {nominal}, std::move(floatSchedule), std::move(index), spread, std::move(floatingDayCount),
43 paymentConvention) {
44
45 legs_[1] = IborLeg(floatingSchedule(), iborIndex())
46 .withNotionals(this->floatingNominals())
47 .withPaymentDayCounter(this->floatingDayCount())
48 .withPaymentAdjustment(this->paymentConvention())
49 .withSpreads(this->spread())
50 .withIndexedCoupons(useIndexedCoupons);
51 for (Leg::const_iterator i = legs_[1].begin(); i < legs_[1].end(); ++i)
52 registerWith(*i);
53 }
54
56 const Leg& floatingCoupons = floatingLeg();
57 Size n = floatingCoupons.size();
58
59 args->floatingResetDates = args->floatingPayDates = args->floatingFixingDates = std::vector<Date>(n);
60 args->floatingAccrualTimes = std::vector<Time>(n);
61 args->floatingSpreads = std::vector<Spread>(n);
62 args->floatingCoupons = args->floatingNominals = std::vector<Real>(n);
63
64 for (Size i=0; i<n; ++i) {
65 auto coupon = ext::dynamic_pointer_cast<IborCoupon>(floatingCoupons[i]);
66
67 args->floatingResetDates[i] = coupon->accrualStartDate();
68 args->floatingPayDates[i] = coupon->date();
69 args->floatingNominals[i] = coupon->nominal();
70
71 args->floatingFixingDates[i] = coupon->fixingDate();
72 args->floatingAccrualTimes[i] = coupon->accrualPeriod();
73 args->floatingSpreads[i] = coupon->spread();
74 try {
75 args->floatingCoupons[i] = coupon->amount();
76 } catch (Error&) {
77 args->floatingCoupons[i] = Null<Real>();
78 }
79 }
80 }
81
82}
day counter class
Definition: daycounter.hpp:44
Base error class.
Definition: errors.hpp:39
Arguments for simple swap calculation
template class providing a null value for a given type.
Definition: null.hpp:76
Payment schedule.
Definition: schedule.hpp:40
void setupFloatingArguments(arguments *args) const override
Definition: vanillaswap.cpp:55
VanillaSwap(Type type, Real nominal, Schedule fixedSchedule, Rate fixedRate, DayCounter fixedDayCount, Schedule floatSchedule, ext::shared_ptr< IborIndex > iborIndex, Spread spread, DayCounter floatingDayCount, ext::optional< BusinessDayConvention > paymentConvention=ext::nullopt, ext::optional< bool > useIndexedCoupons=ext::nullopt)
Definition: vanillaswap.cpp:30
QL_REAL Real
real number
Definition: types.hpp:50
Real Spread
spreads on interest rates
Definition: types.hpp:74
Real Rate
interest rates
Definition: types.hpp:70
std::size_t Size
size of a container
Definition: types.hpp:58
Definition: any.hpp:35
std::vector< ext::shared_ptr< CashFlow > > Leg
Sequence of cash-flows.
Definition: cashflow.hpp:78