-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBond.cpp
More file actions
55 lines (42 loc) · 1.41 KB
/
Bond.cpp
File metadata and controls
55 lines (42 loc) · 1.41 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
/*
* Bond.cpp
*
* Created on: Oct 23, 2016
* Author: Vadim
*/
#include "Bond.h"
#include <math.h>
//2c ii constructor continued
// 2c ii 2. Set asset yield to 0 (since it is paying discrete coupons)
//2c ii 3. Set default bond par value = 1000
//2c ii 4. Coupon frequency = 2
Bond::Bond(string symbol, double currentAssetPrice, double couponRate, double par, double couponFrequency,double annualYield): Asset(symbol,currentAssetPrice, annualYield){
//2c ii 1. set asset type to Bond
type = "BOND";
this->couponRate = couponRate;
}
//2c iii. Public function to set coupon rate
void Bond::setCouponRate(double newCoupRate){
couponRate = newCoupRate;
}
//2c iv. Override the total return function in base class (instead of continuous yield, you
//need to add coupon payments. For this calculation, assume today is a coupon
//payment date)
double Bond::totalReturn(double initPrice, double xMonths){
/*double totalReturn = 0.0;
for (int i = 0; i <= couponFrequency;++i ){
totalReturn+= par * couponRate;
}
*/
//double t = (xMonths/12)*couponFrequency;
//rounded t
double t=ceil (xMonths*couponFrequency/12);
double numerator = ((couponRate*par*t)/couponFrequency) + this->getCurrentAssetPrice() - initPrice;
return numerator/initPrice;
}
double Bond::getFrequency(){
return couponFrequency;
}
Bond::~Bond() {
// TODO Auto-generated destructor stub
}