-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathBondFairValueCalculator.php
146 lines (127 loc) · 4.52 KB
/
BondFairValueCalculator.php
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
<?php
namespace FinanCalc\Calculators {
use FinanCalc\Interfaces\Calculator\BondCalculatorAbstract;
use FinanCalc\Utils\Lambdas;
use FinanCalc\Utils\MathFuncs;
/**
* Class BondFairValueCalculator
* @package FinanCalc\Calculators
*/
class BondFairValueCalculator extends BondCalculatorAbstract
{
// valuation interest rate of the bond = 'i'
protected $bondVIR;
// INHERITED MEMBERS
// face value of the bond = 'F'
// $bondFaceValue;
// coupon rate of the bond per annum = 'c'
// $bondAnnualCouponRate;
// number of years to the maturity of the bond
// $bondYearsToMaturity;
// frequency of bond payments (expressed in a divisor of 12 months ~ 1 year)
// e.g.: divisor 2 means semi-annual payments
// $bondPaymentFrequency;
// props returned by the getResultAsArray method by default
protected $propResultArray = [
"bondFaceValue",
"bondAnnualCouponRate",
"bondVIR",
"bondYearsToMaturity",
"bondPaymentFrequency",
"bondFairValue"
];
/**
* @param $bondFaceValue
* @param $bondAnnualCouponRate
* @param $bondVIR
* @param $bondYearsToMaturity
* @param $bondPaymentFrequency
*/
public function __construct(
$bondFaceValue,
$bondAnnualCouponRate,
$bondVIR,
$bondYearsToMaturity,
$bondPaymentFrequency = 1
) {
$this->setBondFaceValue($bondFaceValue);
$this->setBondAnnualCouponRate($bondAnnualCouponRate);
$this->setBondVIR($bondVIR);
$this->setBondYearsToMaturity($bondYearsToMaturity);
$this->setBondPaymentFrequency($bondPaymentFrequency);
}
/**
* @param $bondVIR
*/
public function setBondVIR($bondVIR)
{
$this->setProperty("bondVIR", $bondVIR, Lambdas::checkIfPositive());
}
/**
* @return mixed
*/
public function getBondVIR()
{
return $this->bondVIR;
}
/**
* @return string
*/
public function getBondFairValue()
{
// we need to get the coupon rate per payment period = c/payment frequency
$couponRateForPeriod = MathFuncs::div(
$this->bondAnnualCouponRate,
$this->bondPaymentFrequency
);
// similarly, we need to calculate the VIR per payment period = i/payment frequency
$VIRForPeriod = MathFuncs::div(
$this->bondVIR,
$this->bondPaymentFrequency
);
// we also save the bond's number of payments to an auxiliary variable
$bondNoOfPayments = $this->getBondNoOfPayments();
// next, we also need the present value of the unit annuity pertaining to the bond, in arrears
$PVofUnitBondAnnuity =
MathFuncs::div(
MathFuncs::sub(
1,
Mathfuncs::pow(
MathFuncs::div(
1,
MathFuncs::add(
1,
$VIRForPeriod
)
),
$bondNoOfPayments
)
),
$VIRForPeriod
);
// now we can use the formula to calculate the real value of the bond (i.e., the present value of its payments)
// PV = F*[c*PVofUnitBondAnnuity+1/((1+i)^n)]
$fairValue =
MathFuncs::mul(
$this->bondFaceValue,
MathFuncs::add(
MathFuncs::mul(
$couponRateForPeriod,
$PVofUnitBondAnnuity
),
MathFuncs::div(
1,
MathFuncs::pow(
MathFuncs::add(
1,
$VIRForPeriod
),
$bondNoOfPayments
)
)
)
);
return $fairValue;
}
}
}