-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbonds.h
394 lines (327 loc) · 18.3 KB
/
bonds.h
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
// Financial Analytics Library (FINAL)
// Copyright (c) 2004 - 2012 by Marek Sestak, [email protected]
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// 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
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef bondsH
#define bondsH
/** \file bonds.h
\brief Contains classes representing bonds.
TBond is the main class for operations with generic bonds.
All other classes are its descendants and represent
main types of government bonds for which calculations are performed
in a different way (in most cases it's accrued interest and a conventional
yield).
*/
/* List of changes:
04/22/05 - TFRTR a TBTNS: new rules applicable to calculation of accrued
interest on French government bonds
*/
#include "defs.h"
#include "security.h"
#include "linkers.h"
#pragma GCC diagnostic ignored "-Wwrite-strings"
namespace final {
class TBond: public TSecurity
{
protected:
floating coupon; // coupon rate (p.a.)
int frequency; // coupon frequency
floating redeem; // redemption value (in %s, eg. default=100)
int ncashflows; // number of cashflows in life of bond
TDate* cashflow_dates; // dates of cashflows
floating* cashflow_amounts; // amounts paid out
// note: cashflow_dates[0] is set equal to
// issued!
TDate intaccr; // interest accrual date
TDate firstcpn; // first coupon payment
int exdivdays; // number of days bond trades ex-dividend
// just one exception: 30 has meaning of
// 'one ex-dividend month' which is a case
// for CZGS
protected:
TBond( const TDate& amaturity, const TDate& aissued,
const TDate& aintaccr, const TDate& afirscpn, int abasis,
floating acoupon, int afrequency, floating aredeem,
int readjust );
// parametr readjust udava, jestli se maji inicializovat
// vsechny interni datove struktury (typicky nastavene
// ve funkci Readjust()). pokud je tedy readjust=false,
// neni v konstruktoru zavolana funkce Readjust() a
// je treba naplnit parametry cashflow_dates a
// cashflow_amounts.
public:
TBond( const TDate& amaturity, const TDate& aissued,
const TDate& aintaccr, const TDate& afirscpn, int abasis,
floating acoupon, int afrequency=1, floating aredeem=100.0 );
// maturita, issue dt, interest accrual dt, first coupon dt,
// basis, kupon, frekvence, redemption amount
virtual ~TBond();
virtual char* SecurityType() const { return "Generic Bond"; }
virtual int SecurityTypeNumber() const { return SEC_BOND; }
virtual TString SecurityDescriptor() const;
virtual int IsBond() const { return true; }
virtual int HasCoupon() const { return true; }
virtual floating Yield( const TDate& asettle, floating apx ) const;
virtual floating Price( const TDate& asettle, floating aytm ) const;
virtual floating TrueYield( const TDate& asettle, floating apx ) const;
virtual floating TruePrice( const TDate& asettle, floating aytm ) const;
virtual floating CompYield( const TDate& asettle, floating apx, int acomp ) const;
// funkce CompYield umoznuje vypocist yield s pozadovanym
// compoundingem acomp.
// Yield() normalne pouziva compounding shodny
// s frekvenci kuponu.
virtual TDate StandardSettlement( const TDate& atradedate ) const;
virtual TDate PrevCouponDate( const TDate& asettle ) const;
virtual TDate NextCouponDate( const TDate& asettle ) const;
virtual int NextCashflow( const TDate& asettle, TDate& anext,
floating& aamount ) const;
virtual int CashflowsTillMaturity( const TDate& asettle ) const;
virtual floating CashflowAmount( const TDate& adate ) const;
virtual floating DurationY( const TDate& asettle, floating aytm ) const;
virtual floating MDurationY( const TDate& asettle, floating aytm ) const;
virtual void ExDivDate( const TDate& asettle, TDate& aexdivdate ) const;
// k zadanemu settlementu vrati v aexdivdate
// pristi ex-dividend datum (tedy den, od kdy zacne nabihat
// dalsi kupon). pokud je exdivdays=0, vraci hodnotu
// navracenou NextCouponDate(asettle)...
virtual floating AccruedInterest( const TDate& asettle ) const;
TDate InterestAccrualDate() const { return intaccr; }
TDate FirstCouponDate() const { return firstcpn; }
int ExDividendDays() const { return exdivdays; }
floating Coupon() const { return coupon; }
virtual floating Redemption() const { return redeem; }
int Frequency() const { return frequency; }
protected:
virtual floating _Price( const TDate& asettle, floating aytm ) const;
virtual floating _Yield( const TDate& asettle, floating apx ) const;
virtual floating _YieldSimple( const TDate& asettle, floating apx ) const;
virtual floating _PriceSimple( const TDate& asettle, floating aytm ) const;
virtual floating _TrueYield( const TDate& asettle, floating apx ) const;
virtual floating _TruePrice( const TDate& asettle, floating aytm ) const;
virtual floating _TrueYieldSimple( const TDate& asettle, floating apx ) const;
virtual floating _TruePriceSimple( const TDate& asettle, floating ayield ) const;
virtual void Readjust();
void _Readjust();
int _FindFirstCouponDate( const TDate& asettle, int ignoreexdivs = false ) const;
};
class TBondAnnualComp : public TBond
{
protected:
TBondAnnualComp( const TDate& amaturity, const TDate& aissued,
const TDate& aintaccr, const TDate& afirscpn, int abasis,
floating acoupon, int afrequency, floating aredeem,
int readjust );
public:
TBondAnnualComp( const TDate& amaturity, const TDate& aissued,
const TDate& aintaccr, const TDate& afirscpn, int abasis,
floating acoupon, int afrequency, floating aredeem=100.0 );
virtual ~TBondAnnualComp();
virtual char* SecurityType() const { return "Generic Bond with annual compounding"; }
virtual int SecurityTypeNumber() const { return SEC_BOND_ANNUAL; }
virtual floating DurationY( const TDate& asettle, floating aytm ) const;
virtual floating MDurationY( const TDate& asettle, floating aytm ) const;
virtual floating CompYield( const TDate& asettle, floating apx, int acomp ) const;
protected:
virtual floating _Price( const TDate& asettle, floating aytm ) const;
virtual floating _TruePrice( const TDate& asettle, floating aytm ) const;
};
/* TODO : for some reason BTPS yield/price conversions are about hundred times slower than for generic TBond */
class TBTPS : public TBondAnnualComp
{
protected:
TBTPS( const TDate& amaturity, const TDate& aissued,
const TDate& aintaccr, const TDate& afirscpn, int abasis,
floating acoupon, int afrequency, floating aredeem,
int readjust );
public:
TBTPS( const TDate& amaturity, const TDate& aissued,
const TDate& aintaccr, const TDate& afirscpn, int abasis,
floating acoupon, int afrequency=2, floating aredeem=100.0 );
virtual ~TBTPS();
virtual char* SecurityType() const { return "Italian government bond (BTPS)"; }
virtual int SecurityTypeNumber() const { return SEC_BTPS; }
virtual floating ConvYield( const TDate& asettle, floating apx,
int around=true ) const
{ return TrueYield( asettle, apx ); }
virtual floating ConvPrice( const TDate& asettle, floating aytm,
int around=true ) const
{ return TruePrice( asettle, aytm ); }
virtual floating AccruedInterest( const TDate& asettle ) const;
};
class TSPGB : public TBondAnnualComp
{
protected:
TSPGB( const TDate& amaturity, const TDate& aissued,
const TDate& aintaccr, const TDate& afirscpn, int abasis,
floating acoupon, int afrequency, floating aredeem,
int readjust );
public:
TSPGB( const TDate& amaturity, const TDate& aissued,
const TDate& aintaccr, const TDate& afirscpn, int abasis,
floating acoupon, int afrequency, floating aredeem=100.0 );
virtual ~TSPGB();
virtual char* SecurityType() const { return "Spanish government bond (SPGB)"; }
virtual int SecurityTypeNumber() const { return SEC_SPGB; }
virtual floating ConvYield( const TDate& asettle, floating apx,
int around=true ) const
{ return TrueYield( asettle, apx ); }
virtual floating ConvPrice( const TDate& asettle, floating aytm,
int around=true ) const
{ return TruePrice( asettle, aytm ); }
};
class TFRTR : public TBond
{
protected:
TFRTR( const TDate& amaturity, const TDate& aissued,
const TDate& aintaccr, const TDate& afirscpn, int abasis,
floating acoupon, int afrequency, floating aredeem,
int readjust );
public:
TFRTR( const TDate& amaturity, const TDate& aissued,
const TDate& aintaccr, const TDate& afirscpn, int abasis,
floating acoupon, int afrequency=1, floating aredeem=100.0 );
virtual char* SecurityType() const { return "French government bond (FRTR)"; }
virtual int SecurityTypeNumber() const { return SEC_FRTR; }
virtual floating ConvYield( const TDate& asettle, floating apx, int around=true ) const;
virtual floating ConvPrice( const TDate& asettle, floating aytm, int around=true ) const;
virtual floating AccruedInterest( const TDate& asettle ) const;
virtual floating MarketValue( floating anominal, const TDate& asettle, floating apx ) const;
};
class TBTNS : public TBond
{
protected:
TBTNS( const TDate& amaturity, const TDate& aissued,
const TDate& aintaccr, const TDate& afirscpn, int abasis,
floating acoupon, int afrequency, floating aredeem,
int readjust );
public:
TBTNS( const TDate& amaturity, const TDate& aissued,
const TDate& aintaccr, const TDate& afirscpn, int abasis,
floating acoupon, int afrequency=1, floating aredeem=100.0 );
virtual TDate StandardSettlement( const TDate& atradedate ) const;
virtual floating AccruedInterest( const TDate& asettle ) const;
virtual char* SecurityType() const { return "French government bond (BTNS)"; }
virtual int SecurityTypeNumber() const { return SEC_BTNS; }
virtual floating ConvYield( const TDate& asettle, floating apx, int around=true ) const;
virtual floating ConvPrice( const TDate& asettle, floating aytm, int around=true ) const;
};
class TUKT : public TBond
{
protected:
TUKT( const TDate& amaturity, const TDate& aissued,
const TDate& aintaccr, const TDate& afirscpn, int abasis,
floating acoupon, int afrequency, floating aredeem,
int readjust );
public:
TUKT( const TDate& amaturity, const TDate& aissued,
const TDate& aintaccr, const TDate& afirscpn, int abasis,
floating acoupon, int afrequency=2, floating aredeem=100.0 );
virtual char* SecurityType() const { return "UK government bond (Gilts, UKT)"; }
virtual int SecurityTypeNumber() const { return SEC_UKT; }
virtual floating ConvYield( const TDate& asettle, floating apx, int around=true ) const;
virtual floating ConvPrice( const TDate& asettle, floating aytm, int around=true ) const;
};
class TCZGB : public TBond
{
protected:
TCZGB( const TDate& amaturity, const TDate& aissued,
const TDate& aintaccr, const TDate& afirscpn, int abasis,
floating acoupon, int afrequency, floating aredeem,
int readjust );
public:
TCZGB( const TDate& amaturity, const TDate& aissued,
const TDate& aintaccr, const TDate& afirscpn, int abasis,
floating acoupon, int afrequency=1, floating aredeem=100.0 );
virtual char* SecurityType() const { return "Czech government bond (CZGB)"; }
virtual int SecurityTypeNumber() const { return SEC_CZGB; }
};
class TJGB : public TBond
{
protected:
TJGB( const TDate& amaturity, const TDate& aissued,
const TDate& aintaccr, const TDate& afirscpn, int abasis,
floating acoupon, int afrequency, floating aredeem,
int readjust );
public:
TJGB( const TDate& amaturity, const TDate& aissued,
const TDate& aintaccr, const TDate& afirscpn, int abasis,
floating acoupon, int afrequency=1, floating aredeem=100.0 );
virtual char* SecurityType() const { return "Japanese government bond (JGB)"; }
virtual int SecurityTypeNumber() const { return SEC_JGB; }
virtual floating JapaneseSimpleYield( const TDate& asettle, floating apx ) const;
virtual floating JapaneseSimplePrice( const TDate& asettle, floating ayld ) const;
/* TODO : co settlementy na 29.2.???! */
virtual floating ConvYield( const TDate& asettle, floating apx, int around=true ) const;
virtual floating ConvPrice( const TDate& asettle, floating ayld, int around=true ) const;
virtual floating AccruedInterest( const TDate& asettle ) const;
virtual TDate StandardSettlement( const TDate& atradedate ) const;
protected:
void _Readjust();
};
class TUST : public TBond
{
protected:
TUST( const TDate& amaturity, const TDate& aissued,
const TDate& aintaccr, const TDate& afirscpn, int abasis,
floating acoupon, int afrequency, floating aredeem,
int readjust );
public:
TUST( const TDate& amaturity, const TDate& aissued,
const TDate& aintaccr, const TDate& afirscpn, int abasis,
floating acoupon, int afrequency=2, floating aredeem=100.0 );
virtual char* SecurityType() const { return "US treasury bond"; }
virtual int SecurityTypeNumber() const { return SEC_UST; }
virtual TDate StandardSettlement( const TDate& atradedate ) const;
};
class TACGB : public TBond
{
protected:
TACGB( const TDate& amaturity, const TDate& aissued,
const TDate& aintaccr, const TDate& afirscpn, int abasis,
floating acoupon, int afrequency, floating aredeem,
int readjust );
public:
TACGB( const TDate& amaturity, const TDate& aissued,
const TDate& aintaccr, const TDate& afirscpn, int abasis,
floating acoupon, int afrequency=1, floating aredeem=100.0 );
virtual floating ConvPrice( const TDate& asettle, floating aytm, int around=true ) const;
virtual floating AccruedInterest( const TDate& asettle ) const;
virtual void ExDivDate( const TDate& asettle, TDate& aexdivdate ) const;
virtual char* SecurityType() const { return "Australian government bond (ACGB)"; }
virtual int SecurityTypeNumber() const { return SEC_ACGB; }
};
class TACGBi : public TBond
{
TDataSeries* cpi;
protected:
TACGBi( const TDate& amaturity, const TDate& aissued,
const TDate& aintaccr, const TDate& afirscpn, int abasis,
floating acoupon, int afrequency, floating aredeem,
TDataSeries* acpi,
int readjust );
public:
TACGBi( const TDate& amaturity, const TDate& aissued,
const TDate& aintaccr, const TDate& afirscpn, int abasis,
floating acoupon, int afrequency=1, floating aredeem=100.0,
TDataSeries* acpi=NULL );
virtual void SetCPI( TDataSeries* acpi );
virtual void ExDivDate( const TDate& asettle, TDate& aexdivdate ) const;
virtual floating ConvPrice( const TDate& asettle, floating aytm, int around=true ) const;
virtual floating ConvYield( const TDate& asettle, floating aytm, int around=true ) const;
virtual floating AccruedInterest( const TDate& asettle ) const;
virtual char* SecurityType() const { return "Australian government inflation linked bond (ACGB)"; }
virtual int SecurityTypeNumber() const { return SEC_ACGBi; }
};
} // end of namespace final
#endif