forked from paulgriffiths/financial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbond.h
More file actions
91 lines (65 loc) · 2.35 KB
/
Copy pathbond.h
File metadata and controls
91 lines (65 loc) · 2.35 KB
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
/*!
* \file bond.h
* \brief Bond classes and functions interface.
* \details Bond classes and functions interface.
* \author Paul Griffiths
* \copyright Copyright 2013 Paul Griffiths. Distributed under the terms
* of the GNU General Public License. <http://www.gnu.org/licenses/>
*/
#ifndef PG_FINANCIAL_BOND_H
#define PG_FINANCIAL_BOND_H
#include <vector>
//! User library namespace
namespace financial {
//! Simple bond class.
/*!
* Models a simple bond. Valuation is only possible at issuance.
* Accrued interest cannot be calculated. Maturity can only be
* expressed in whole periods.
*/
class SimpleBond {
public:
//! Constructor
/*!
* Constructor.
*
* \param principal the principal amount
* \param coupon the periodic coupon rate
* \param coupon_frequency the number of coupon payments each period
* \param maturity the number of periods to maturity
*/
explicit SimpleBond(const double principal,
const double coupon,
const int coupon_frequency,
const int maturity) :
m_principal(principal),
m_coupon(coupon),
m_coupon_frequency(coupon_frequency),
m_maturity(maturity) {};
//! Destructor
virtual ~SimpleBond() {};
//! DCF valuation
/*!
* Values a simple bond with discounted cash flows.
*
* \param discount_rate the discount rate to use.
* \return the present value of the bond
*/
double value(const double discount_rate) const;
private:
double m_principal; /*!< principal amount */
double m_coupon; /*!< periodic coupon */
int m_coupon_frequency; /*!< coupon payments per period */
int m_maturity; /*!< periods to maturity */
//! Returns the number of payments over the bond's lifetime.
/*!
* The final coupon payment and the return of principal is
* counted as a single payment, so for zero-coupon bonds
* this will return 1.
*
* \return the number of payments over the bond's lifetime.
*/
double num_payments() const;
};
} // namespace financial
#endif // PG_FINANCIAL_BOND_H