-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbonds.i
207 lines (202 loc) · 9.77 KB
/
bonds.i
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#ifndef quantlib_bonds_i
#define quantlib_bonds_i
%include instruments.i
%include calendars.i
%include daycounters.i
%include cashflows.i
%include interestrate.i
%{
using QuantLib::Bond;
using QuantLib::FixedRateBond;
%}
%shared_ptr(Bond)
class Bond : public Instrument {
%rename(bondYield) yield;
public:
Bond(Natural settlementDays,
const Calendar& calendar,
Real faceAmount,
const Date& maturityDate,
const Date& issueDate = Date(),
const Leg& cashflows = Leg());
Bond(Natural settlementDays,
const Calendar& calendar,
const Date& issueDate = Date(),
const Leg& coupons = Leg());
// public functions
Rate nextCouponRate(const Date& d = Date());
Rate previousCouponRate(const Date& d = Date());
// inspectors
Natural settlementDays() const;
Date settlementDate(Date d = Date());
Date startDate() const;
Date maturityDate() const;
Date issueDate() const;
std::vector<boost::shared_ptr<CashFlow> > cashflows() const;
std::vector<boost::shared_ptr<CashFlow> > redemptions() const;
boost::shared_ptr<CashFlow> redemption() const;
Calendar calendar() const;
std::vector<Real> notionals() const;
Real notional(Date d = Date()) const;
// calculations
Real cleanPrice();
Real cleanPrice(Rate yield,
const DayCounter &dc,
Compounding compounding,
Frequency frequency,
const Date& settlement = Date());
Real dirtyPrice();
Real dirtyPrice(Rate yield,
const DayCounter &dc,
Compounding compounding,
Frequency frequency,
const Date& settlement = Date());
Real yield(const DayCounter& dc,
Compounding compounding,
Frequency freq,
Real accuracy = 1.0e-8,
Size maxEvaluations = 100);
Real yield(Real cleanPrice,
const DayCounter& dc,
Compounding compounding,
Frequency freq,
const Date& settlement = Date(),
Real accuracy = 1.0e-8,
Size maxEvaluations = 100);
Real accruedAmount(const Date& settlement = Date());
Real settlementValue() const;
Real settlementValue(Real cleanPrice) const;
};
%shared_ptr(FixedRateBond)
class FixedRateBond : public Bond {
public:
FixedRateBond(
Integer settlementDays,
Real faceAmount,
const Schedule &schedule,
const std::vector<Rate>& coupons,
const DayCounter& paymentDayCounter,
BusinessDayConvention paymentConvention = QuantLib::Following,
Real redemption = 100.0,
Date issueDate = Date(),
const Calendar& paymentCalendar = Calendar(),
const Period& exCouponPeriod = Period(),
const Calendar& exCouponCalendar = Calendar(),
BusinessDayConvention exCouponConvention = Unadjusted,
bool exCouponEndOfMonth = false);
//! generic compounding and frequency InterestRate coupons
FixedRateBond(
Integer settlementDays,
Real faceAmount,
const Schedule& schedule,
const std::vector<InterestRate>& coupons,
BusinessDayConvention paymentConvention = Following,
Real redemption = 100.0,
const Date& issueDate = Date(),
const Calendar& paymentCalendar = Calendar(),
const Period& exCouponPeriod = Period(),
const Calendar& exCouponCalendar = Calendar(),
BusinessDayConvention exCouponConvention = Unadjusted,
bool exCouponEndOfMonth = false);
//! simple annual compounding coupon rates with internal schedule calculation
FixedRateBond(
Integer settlementDays,
const Calendar& couponCalendar,
Real faceAmount,
const Date& startDate,
const Date& maturityDate,
const Period& tenor,
const std::vector<Rate>& coupons,
const DayCounter& accrualDayCounter,
BusinessDayConvention accrualConvention = QuantLib::Following,
BusinessDayConvention paymentConvention = QuantLib::Following,
Real redemption = 100.0,
const Date& issueDate = Date(),
const Date& stubDate = Date(),
DateGeneration::Rule rule = QuantLib::DateGeneration::Backward,
bool endOfMonth = false,
const Calendar& paymentCalendar = Calendar(),
const Period& exCouponPeriod = Period(),
const Calendar& exCouponCalendar = Calendar(),
const BusinessDayConvention exCouponConvention = Unadjusted,
bool exCouponEndOfMonth = false);
%extend {
//! convenience wrapper around constructor taking rates
static boost::shared_ptr<FixedRateBond> from_rates(
Integer settlementDays,
Real faceAmount,
const Schedule &schedule,
const std::vector<Rate>& coupons,
const DayCounter& paymentDayCounter,
BusinessDayConvention paymentConvention = QuantLib::Following,
Real redemption = 100.0,
Date issueDate = Date(),
const Calendar& paymentCalendar = Calendar(),
const Period& exCouponPeriod = Period(),
const Calendar& exCouponCalendar = Calendar(),
BusinessDayConvention exCouponConvention = Unadjusted,
bool exCouponEndOfMonth = false) {
return boost::shared_ptr<FixedRateBond>(
new FixedRateBond(settlementDays, faceAmount, schedule, coupons,
paymentDayCounter, paymentConvention,
redemption, issueDate, paymentCalendar,
exCouponPeriod, exCouponCalendar,
exCouponConvention, exCouponEndOfMonth));
}
//! convenience wrapper around constructor taking interest rates
static boost::shared_ptr<FixedRateBond> from_interest_rates(
Integer settlementDays,
Real faceAmount,
const Schedule& schedule,
const std::vector<InterestRate>& coupons,
BusinessDayConvention paymentConvention = Following,
Real redemption = 100.0,
const Date& issueDate = Date(),
const Calendar& paymentCalendar = Calendar(),
const Period& exCouponPeriod = Period(),
const Calendar& exCouponCalendar = Calendar(),
BusinessDayConvention exCouponConvention = Unadjusted,
bool exCouponEndOfMonth = false) {
return boost::shared_ptr<FixedRateBond>(
new FixedRateBond(settlementDays, faceAmount, schedule, coupons,
paymentConvention, redemption,
issueDate, paymentCalendar,
exCouponPeriod, exCouponCalendar,
exCouponConvention, exCouponEndOfMonth));
}
//! convenience wrapper around constructor doing internal schedule calculation
static boost::shared_ptr<FixedRateBond> from_date_info(
Integer settlementDays,
const Calendar& couponCalendar,
Real faceAmount,
const Date& startDate,
const Date& maturityDate,
const Period& tenor,
const std::vector<Rate>& coupons,
const DayCounter& accrualDayCounter,
BusinessDayConvention accrualConvention = QuantLib::Following,
BusinessDayConvention paymentConvention = QuantLib::Following,
Real redemption = 100.0,
const Date& issueDate = Date(),
const Date& stubDate = Date(),
DateGeneration::Rule rule = QuantLib::DateGeneration::Backward,
bool endOfMonth = false,
const Calendar& paymentCalendar = Calendar(),
const Period& exCouponPeriod = Period(),
const Calendar& exCouponCalendar = Calendar(),
const BusinessDayConvention exCouponConvention = Unadjusted,
bool exCouponEndOfMonth = false) {
return boost::shared_ptr<FixedRateBond>(
new FixedRateBond(settlementDays, couponCalendar, faceAmount,
startDate, maturityDate, tenor,
coupons, accrualDayCounter, accrualConvention,
paymentConvention, redemption, issueDate,
stubDate, rule, endOfMonth, paymentCalendar,
exCouponPeriod, exCouponCalendar,
exCouponConvention, exCouponEndOfMonth));
}
}
Frequency frequency() const;
DayCounter dayCounter() const;
};
#endif //quantlib_bonds_i