1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2006, 2007 Chiara Fornarola
5 Copyright (C) 2007, 2009, 2011 Ferdinando Ametrano
6 Copyright (C) 2007, 2009 StatPro Italia srl
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/*! \file assetswap.hpp
23 \brief Bullet bond vs Libor swap
24*/
25
26#ifndef quantlib_asset_swap_hpp
27#define quantlib_asset_swap_hpp
28
29#include <ql/instruments/swap.hpp>
30#include <ql/instruments/bond.hpp>
31#include <ql/time/schedule.hpp>
32#include <ql/time/daycounter.hpp>
33
34namespace QuantLib {
35
36 class IborIndex;
37
38 //! Bullet bond vs %Libor swap
39 /*! for mechanics of par asset swap and market asset swap, refer to
40 "Introduction to Asset Swap", Lehman Brothers European Fixed
41 Income Research - January 2000, D. O'Kane
42
43 \ingroup instruments
44
45 \warning bondCleanPrice must be the (forward) price at the
46 floatSchedule start date
47
48 \bug fair prices are not calculated correctly when using
49 indexed coupons.
50 */
51 class AssetSwap : public Swap {
52 public:
53 class arguments;
54 class results;
55
56 AssetSwap(bool payBondCoupon,
57 ext::shared_ptr<Bond> bond,
58 Real bondCleanPrice,
59 const ext::shared_ptr<IborIndex>& iborIndex,
60 Spread spread,
61 const Schedule& floatSchedule = Schedule(),
62 const DayCounter& floatingDayCount = DayCounter(),
63 bool parAssetSwap = true);
64
65 AssetSwap(bool parAssetSwap,
66 ext::shared_ptr<Bond> bond,
67 Real bondCleanPrice,
68 Real nonParRepayment,
69 Real gearing,
70 const ext::shared_ptr<IborIndex>& iborIndex,
71 Spread spread = 0.0,
72 const DayCounter& floatingDayCount = DayCounter(),
73 Date dealMaturity = Date(),
74 bool payBondCoupon = false);
75 // results
76 Spread fairSpread() const;
77 Real floatingLegBPS() const;
78 Real floatingLegNPV() const;
79 Real fairCleanPrice() const;
80 Real fairNonParRepayment() const;
81 // inspectors
82 bool parSwap() const { return parSwap_; }
83 Spread spread() const { return spread_; }
84 Real cleanPrice() const { return bondCleanPrice_; }
85 Real nonParRepayment() const { return nonParRepayment_; }
86 const ext::shared_ptr<Bond>& bond() const { return bond_; }
87 bool payBondCoupon() const { return (payer_[0] == -1.0); }
88 const Leg& bondLeg() const { return legs_[0]; }
89 const Leg& floatingLeg() const { return legs_[1]; }
90 // other
91 void setupArguments(PricingEngine::arguments* args) const override;
92 void fetchResults(const PricingEngine::results*) const override;
93
94 private:
95 void setupExpired() const override;
96 ext::shared_ptr<Bond> bond_;
97 Real bondCleanPrice_, nonParRepayment_;
98 Spread spread_;
99 bool parSwap_;
100 Date upfrontDate_;
101 // results
102 mutable Spread fairSpread_;
103 mutable Real fairCleanPrice_, fairNonParRepayment_;
104 };
105
106
107 //! %Arguments for asset swap calculation
108 class AssetSwap::arguments : public Swap::arguments {
109 public:
110 arguments() = default;
111 std::vector<Date> fixedResetDates;
112 std::vector<Date> fixedPayDates;
113 std::vector<Real> fixedCoupons;
114 std::vector<Time> floatingAccrualTimes;
115 std::vector<Date> floatingResetDates;
116 std::vector<Date> floatingFixingDates;
117 std::vector<Date> floatingPayDates;
118 std::vector<Spread> floatingSpreads;
119 void validate() const override;
120 };
121
122 //! %Results from simple swap calculation
123 class AssetSwap::results : public Swap::results {
124 public:
125 Spread fairSpread;
126 Real fairCleanPrice, fairNonParRepayment;
127 void reset() override;
128 };
129
130}
131
132#endif
133

source code of quantlib/ql/instruments/assetswap.hpp